MNG-4216: Remove all direct usage of DefaultArtifactRepository

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@786995 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-06-21 11:39:10 +00:00
parent 262ff7908f
commit ea5445af38
19 changed files with 465 additions and 186 deletions

View File

@ -1,22 +1,18 @@
package org.apache.maven.artifact.factory;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
import org.apache.maven.artifact.Artifact;
@ -27,73 +23,27 @@ public interface ArtifactFactory
String ROLE = ArtifactFactory.class.getName();
// TODO: deprecate and chase down (probably used for copying only)
Artifact createArtifact( String groupId,
String artifactId,
String version,
String scope,
String type );
Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type );
Artifact createArtifactWithClassifier( String groupId,
String artifactId,
String version,
String type,
String classifier );
Artifact createArtifactWithClassifier( String groupId, String artifactId, String version, String type, String classifier );
Artifact createDependencyArtifact( String groupId,
String artifactId,
VersionRange versionRange,
String type,
String classifier,
String scope );
Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type, String classifier, String scope );
Artifact createDependencyArtifact( String groupId,
String artifactId,
VersionRange versionRange,
String type,
String classifier,
String scope,
boolean optional );
Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type, String classifier, String scope, boolean optional );
Artifact createDependencyArtifact( String groupId,
String artifactId,
VersionRange versionRange,
String type,
String classifier,
String scope,
String inheritedScope );
Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type, String classifier, String scope, String inheritedScope );
Artifact createDependencyArtifact( String groupId,
String artifactId,
VersionRange versionRange,
String type,
String classifier,
String scope,
String inheritedScope,
boolean optional );
Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type, String classifier, String scope, String inheritedScope, boolean optional );
Artifact createBuildArtifact( String groupId,
String artifactId,
String version,
String packaging );
Artifact createBuildArtifact( String groupId, String artifactId, String version, String packaging );
Artifact createProjectArtifact( String groupId,
String artifactId,
String version );
Artifact createProjectArtifact( String groupId, String artifactId, String version );
Artifact createParentArtifact( String groupId,
String artifactId,
String version );
Artifact createParentArtifact( String groupId, String artifactId, String version );
Artifact createPluginArtifact( String groupId,
String artifactId,
VersionRange versionRange );
Artifact createPluginArtifact( String groupId, String artifactId, VersionRange versionRange );
Artifact createProjectArtifact( String groupId,
String artifactId,
String version,
String scope );
Artifact createProjectArtifact( String groupId, String artifactId, String version, String scope );
Artifact createExtensionArtifact( String groupId,
String artifactId,
VersionRange versionRange );
Artifact createExtensionArtifact( String groupId, String artifactId, VersionRange versionRange );
}

View File

@ -1,27 +1,20 @@
package org.apache.maven.artifact.repository;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
import java.io.File;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.UnknownRepositoryLayoutException;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
@ -34,35 +27,18 @@ public interface ArtifactRepositoryFactory
String LOCAL_REPOSITORY_ID = "local";
ArtifactRepository createLocalRepository( File localRepositoryDirectory )
throws InvalidRepositoryException;
ArtifactRepositoryLayout getLayout( String layoutId )
throws UnknownRepositoryLayoutException;
ArtifactRepository createDeploymentArtifactRepository( String id,
String url,
String layoutId,
boolean uniqueVersion )
ArtifactRepository createDeploymentArtifactRepository( String id, String url, String layoutId, boolean uniqueVersion )
throws UnknownRepositoryLayoutException;
ArtifactRepository createDeploymentArtifactRepository( String id,
String url,
ArtifactRepositoryLayout layout,
boolean uniqueVersion );
ArtifactRepository createDeploymentArtifactRepository( String id, String url, ArtifactRepositoryLayout layout, boolean uniqueVersion );
ArtifactRepository createArtifactRepository( String id,
String url,
String layoutId,
ArtifactRepositoryPolicy snapshots,
ArtifactRepositoryPolicy releases )
ArtifactRepository createArtifactRepository( String id, String url, String layoutId, ArtifactRepositoryPolicy snapshots, ArtifactRepositoryPolicy releases )
throws UnknownRepositoryLayoutException;
ArtifactRepository createArtifactRepository( String id,
String url,
ArtifactRepositoryLayout repositoryLayout,
ArtifactRepositoryPolicy snapshots,
ArtifactRepositoryPolicy releases );
ArtifactRepository createArtifactRepository( String id, String url, ArtifactRepositoryLayout repositoryLayout, ArtifactRepositoryPolicy snapshots, ArtifactRepositoryPolicy releases );
void setGlobalUpdatePolicy( String snapshotPolicy );

View File

@ -45,10 +45,6 @@ public class DefaultArtifactRepository
private ArtifactRepositoryPolicy releases;
private boolean blacklisted;
public DefaultArtifactRepository()
{
}
/**
* Create a local repository or a test repository.

View File

@ -19,12 +19,9 @@ package org.apache.maven.artifact.repository;
* under the License.
*/
import java.io.File;
import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Map;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.UnknownRepositoryLayoutException;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.codehaus.plexus.component.annotations.Component;
@ -83,7 +80,7 @@ public class DefaultArtifactRepositoryFactory
ArtifactRepositoryLayout repositoryLayout,
boolean uniqueVersion )
{
return new DefaultArtifactRepository( id, url, repositoryLayout, uniqueVersion );
return createArtifactRepository( id, url, repositoryLayout, null, null );
}
public ArtifactRepository createArtifactRepository( String id,
@ -139,7 +136,7 @@ public class DefaultArtifactRepositoryFactory
releases.setChecksumPolicy( globalChecksumPolicy );
}
DefaultArtifactRepository repository = new DefaultArtifactRepository( id, url, repositoryLayout, snapshots, releases );
ArtifactRepository repository = new MavenArtifactRepository( id, url, repositoryLayout, snapshots, releases );
repository.setBlacklisted( blacklisted );
artifactRepositories.put( id, repository );
@ -156,30 +153,4 @@ public class DefaultArtifactRepositoryFactory
{
globalChecksumPolicy = checksumPolicy;
}
public ArtifactRepository createLocalRepository( File localRepositoryDirectory )
throws InvalidRepositoryException
{
ArtifactRepositoryLayout layout = getLayout( DEFAULT_LAYOUT_ID );
DefaultArtifactRepository repo;
try
{
repo = new DefaultArtifactRepository( LOCAL_REPOSITORY_ID,
localRepositoryDirectory.toURI()
.toURL()
.toExternalForm(),
layout, new ArtifactRepositoryPolicy(),
new ArtifactRepositoryPolicy() );
}
catch ( MalformedURLException e )
{
throw new InvalidRepositoryException( "Invalid local repository directory: "
+ localRepositoryDirectory
+ ". Cannot render URL.", LOCAL_REPOSITORY_ID, e );
}
repo.setBasedir( localRepositoryDirectory.getAbsolutePath() );
return repo;
}
}
}

View File

@ -0,0 +1,351 @@
package org.apache.maven.artifact.repository;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.io.File;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
//TODO: http://jira.codehaus.org/browse/MNG-4215
//TODO: completely separate local and remote artifact repositories
public class MavenArtifactRepository
implements ArtifactRepository
{
public static final int UNKNOWN_PORT = -1;
private String id;
private String url;
private String basedir;
private String protocol;
private ArtifactRepositoryLayout layout;
private ArtifactRepositoryPolicy snapshots;
private ArtifactRepositoryPolicy releases;
//TODO: this should be tracked externally, not by the repository itself
private boolean blacklisted;
public MavenArtifactRepository()
{
}
/**
* Create a remote download repository.
*
* @param id the unique identifier of the repository
* @param url the URL of the repository
* @param layout the layout of the repository
* @param snapshots the policies to use for snapshots
* @param releases the policies to use for releases
*/
public MavenArtifactRepository( String id, String url, ArtifactRepositoryLayout layout, ArtifactRepositoryPolicy snapshots, ArtifactRepositoryPolicy releases )
{
this.id = id;
this.url = url;
this.layout = layout;
//
// Derive these from the URL
//
this.protocol = protocol( url );
this.basedir = basedir( url );
this.snapshots = snapshots;
this.releases = releases;
if ( this.snapshots == null )
{
this.snapshots = new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE );
}
if ( this.releases == null )
{
this.releases = new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE );
}
}
public String pathOf( Artifact artifact )
{
return layout.pathOf( artifact );
}
public String pathOfRemoteRepositoryMetadata( ArtifactMetadata artifactMetadata )
{
return layout.pathOfRemoteRepositoryMetadata( artifactMetadata );
}
public String pathOfLocalRepositoryMetadata( ArtifactMetadata metadata, ArtifactRepository repository )
{
return layout.pathOfLocalRepositoryMetadata( metadata, repository );
}
public void setLayout( ArtifactRepositoryLayout layout )
{
this.layout = layout;
}
public ArtifactRepositoryLayout getLayout()
{
return layout;
}
public void setSnapshotUpdatePolicy( ArtifactRepositoryPolicy snapshots )
{
this.snapshots = snapshots;
}
public ArtifactRepositoryPolicy getSnapshots()
{
return snapshots;
}
public void setReleaseUpdatePolicy( ArtifactRepositoryPolicy releases )
{
this.releases = releases;
}
public ArtifactRepositoryPolicy getReleases()
{
return releases;
}
public String getKey()
{
return getId();
}
public boolean isBlacklisted()
{
return blacklisted;
}
public void setBlacklisted( boolean blacklisted )
{
this.blacklisted = blacklisted;
}
public String toString()
{
StringBuffer sb = new StringBuffer();
sb.append( " id: " ).append( getId() ).append( "\n" );
sb.append( " url: " ).append( getUrl() ).append( "\n" );
sb.append( " layout: " ).append( layout != null ? layout.getId() : "none" ).append( "\n" );
if ( snapshots != null )
{
sb.append( "snapshots: [enabled => " ).append( snapshots.isEnabled() );
sb.append( ", update => " ).append( snapshots.getUpdatePolicy() ).append( "]\n" );
}
if ( releases != null )
{
sb.append( " releases: [enabled => " ).append( releases.isEnabled() );
sb.append( ", update => " ).append( releases.getUpdatePolicy() ).append( "]\n" );
}
return sb.toString();
}
public Artifact find( Artifact artifact )
{
File artifactFile = new File( getBasedir(), pathOf( artifact ) );
// We need to set the file here or the resolver will fail with an NPE, not fully equipped to deal
// with multiple local repository implementations yet.
artifact.setFile( artifactFile );
if( artifactFile.exists() )
{
artifact.setResolved( true );
}
return artifact;
}
public String getId()
{
return id;
}
public String getUrl()
{
return url;
}
public String getBasedir()
{
return basedir;
}
public String getProtocol()
{
return protocol;
}
public void setId( String id )
{
this.id = id;
}
public void setUrl( String url )
{
this.url = url;
}
public void setBasedir( String basedir )
{
this.basedir = basedir;
}
public void setProtocol( String protocol )
{
this.protocol = protocol;
}
// Path Utils
/**
* /**
* Return the protocol name.
* <br/>
* E.g: for input
* <code>http://www.codehause.org</code> this method will return <code>http</code>
*
* @param url the url
* @return the host name
*/
public static String protocol( final String url )
{
final int pos = url.indexOf( ":" );
if ( pos == -1 )
{
return "";
}
return url.substring( 0, pos ).trim();
}
/**
* Derive the path portion of the given URL.
*
* @param url the repository URL
* @return the basedir of the repository
* @todo need to URL decode for spaces?
*/
public String basedir( String url )
{
String retValue = null;
if ( protocol.equalsIgnoreCase( "file" ) )
{
retValue = url.substring( protocol.length() + 1 );
// special case: if omitted // on protocol, keep path as is
if ( retValue.startsWith( "//" ) )
{
retValue = retValue.substring( 2 );
if ( retValue.length() >= 2 && ( retValue.charAt( 1 ) == '|' || retValue.charAt( 1 ) == ':' ) )
{
// special case: if there is a windows drive letter, then keep the original return value
retValue = retValue.charAt( 0 ) + ":" + retValue.substring( 2 );
}
else
{
// Now we expect the host
int index = retValue.indexOf( "/" );
if ( index >= 0 )
{
retValue = retValue.substring( index + 1 );
}
// special case: if there is a windows drive letter, then keep the original return value
if ( retValue.length() >= 2 && ( retValue.charAt( 1 ) == '|' || retValue.charAt( 1 ) == ':' ) )
{
retValue = retValue.charAt( 0 ) + ":" + retValue.substring( 2 );
}
else if ( index >= 0 )
{
// leading / was previously stripped
retValue = "/" + retValue;
}
}
}
// special case: if there is a windows drive letter using |, switch to :
if ( retValue.length() >= 2 && retValue.charAt( 1 ) == '|' )
{
retValue = retValue.charAt( 0 ) + ":" + retValue.substring( 2 );
}
}
if ( retValue == null )
{
retValue = "/";
}
return retValue.trim();
}
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ( ( id == null ) ? 0 : id.hashCode() );
return result;
}
public boolean equals( Object obj )
{
if ( this == obj )
{
return true;
}
if ( obj == null )
{
return false;
}
if ( getClass() != obj.getClass() )
{
return false;
}
final ArtifactRepository other = (ArtifactRepository) obj;
if ( id == null )
{
if ( other.getId() != null )
{
return false;
}
}
else if ( !id.equals( other.getId() ) )
{
return false;
}
return true;
}
}

View File

@ -29,6 +29,7 @@ import java.util.List;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
@ -43,13 +44,15 @@ public abstract class AbstractArtifactComponentTestCase
{
protected ArtifactFactory artifactFactory;
protected ArtifactRepositoryFactory artifactRepositoryFactory;
@Override
protected void setUp()
throws Exception
{
super.setUp();
artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
artifactFactory = lookup( ArtifactFactory.class);
artifactRepositoryFactory = lookup( ArtifactRepositoryFactory.class );
}
@Override
@ -80,7 +83,7 @@ public abstract class AbstractArtifactComponentTestCase
ArtifactRepositoryLayout repoLayout =
(ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
return new DefaultArtifactRepository( "test", "file://" + f.getPath(), repoLayout );
return artifactRepositoryFactory.createArtifactRepository( "test", "file://" + f.getPath(), repoLayout, null, null );
}
protected String getRepositoryLayout()
@ -98,7 +101,7 @@ public abstract class AbstractArtifactComponentTestCase
ArtifactRepositoryLayout repoLayout =
(ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
return new DefaultArtifactRepository( "local", "file://" + f.getPath(), repoLayout );
return artifactRepositoryFactory.createArtifactRepository( "local", "file://" + f.getPath(), repoLayout, null, null );
}
protected ArtifactRepository remoteRepository()
@ -111,7 +114,7 @@ public abstract class AbstractArtifactComponentTestCase
ArtifactRepositoryLayout repoLayout =
(ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
return new DefaultArtifactRepository( "test", "file://" + f.getPath(), repoLayout,
return artifactRepositoryFactory.createArtifactRepository( "test", "file://" + f.getPath(), repoLayout,
new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy() );
}
@ -121,7 +124,7 @@ public abstract class AbstractArtifactComponentTestCase
ArtifactRepositoryLayout repoLayout =
(ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
return new DefaultArtifactRepository( "test", "http://foo.bar/repository", repoLayout );
return artifactRepositoryFactory.createArtifactRepository( "test", "http://foo.bar/repository", repoLayout, null, null );
}
protected void assertRemoteArtifactPresent( Artifact artifact )

View File

@ -30,6 +30,7 @@ import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
@ -62,15 +63,16 @@ public class DefaultWagonManagerTest
private TransferListener transferListener = new Debug();
private ArtifactFactory artifactFactory;
private ArtifactRepositoryFactory artifactRepositoryFactory;
protected void setUp()
throws Exception
{
super.setUp();
wagonManager = (DefaultWagonManager) lookup( WagonManager.class );
artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
wagonManager = (DefaultWagonManager) lookup( WagonManager.class );
artifactFactory = lookup( ArtifactFactory.class );
artifactRepositoryFactory = lookup( ArtifactRepositoryFactory.class );
}
@Override
@ -91,8 +93,8 @@ public class DefaultWagonManagerTest
Artifact artifact = createTestPomArtifact( "target/test-data/get-missing-pom" );
List<ArtifactRepository> repos = new ArrayList<ArtifactRepository>();
repos.add(new DefaultArtifactRepository( "repo1", "string://url1", new ArtifactRepositoryLayoutStub() ));
repos.add(new DefaultArtifactRepository( "repo2", "string://url2", new ArtifactRepositoryLayoutStub() ));
repos.add(artifactRepositoryFactory.createArtifactRepository( "repo1", "string://url1", new ArtifactRepositoryLayoutStub(), null, null ));
repos.add(artifactRepositoryFactory.createArtifactRepository( "repo2", "string://url2", new ArtifactRepositoryLayoutStub(), null, null ));
StringWagon wagon = (StringWagon) wagonManager.getWagon( "string" );
wagon.addExpectedContent( repos.get(0).getLayout().pathOf( artifact ), "expected" );
@ -259,12 +261,9 @@ public class DefaultWagonManagerTest
private ArtifactRepository createStringRepo()
{
ArtifactRepository repo =
new DefaultArtifactRepository( "id", "string://url", new ArtifactRepositoryLayoutStub() );
return repo;
return artifactRepositoryFactory.createArtifactRepository( "id", "string://url", new ArtifactRepositoryLayoutStub(), null, null );
}
/**
* Build an ArtifactRepository object.
*
@ -274,7 +273,7 @@ public class DefaultWagonManagerTest
*/
private ArtifactRepository getRepo( String id, String url )
{
return new DefaultArtifactRepository( id, url, new DefaultRepositoryLayout() );
return artifactRepositoryFactory.createArtifactRepository( id, url, new DefaultRepositoryLayout(), null, null );
}
/**
@ -369,11 +368,9 @@ public class DefaultWagonManagerTest
public void xtestChecksumVerification()
throws Exception
{
ArtifactRepositoryPolicy policy =
new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS,
ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL );
ArtifactRepository repo =
new DefaultArtifactRepository( "id", "string://url", new ArtifactRepositoryLayoutStub(), policy, policy );
ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy( true, ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS, ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL );
ArtifactRepository repo = artifactRepositoryFactory.createArtifactRepository( "id", "string://url", new ArtifactRepositoryLayoutStub(), policy, policy );
Artifact artifact =
new DefaultArtifact( "sample.group", "sample-art", VersionRange.createFromVersion( "1.0" ), "scope",

View File

@ -32,6 +32,7 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.versioning.VersionRange;
@ -62,12 +63,14 @@ public class PluginParameterExpressionEvaluatorTest
private static final String FS = System.getProperty( "file.separator" );
private ArtifactFactory factory;
private ArtifactRepositoryFactory artifactRepositoryFactory;
public void setUp()
throws Exception
{
super.setUp();
factory = lookup( ArtifactFactory.class );
artifactRepositoryFactory = lookup( ArtifactRepositoryFactory.class );
}
@Override
@ -343,7 +346,7 @@ public class PluginParameterExpressionEvaluatorTest
createExpressionEvaluator( createDefaultProject(), null, new Properties() );
Object value = expressionEvaluator.evaluate( "${localRepository}" );
assertEquals( "local", ( (DefaultArtifactRepository) value ).getId() );
assertEquals( "local", ( (ArtifactRepository) value ).getId() );
}
public void testTwoExpressions()
@ -398,7 +401,7 @@ public class PluginParameterExpressionEvaluatorTest
{
ArtifactRepositoryLayout repoLayout = lookup( ArtifactRepositoryLayout.class, "legacy" );
ArtifactRepository repo = new DefaultArtifactRepository( "local", "target/repo", repoLayout );
ArtifactRepository repo = artifactRepositoryFactory.createArtifactRepository( "local", "target/repo", repoLayout, null, null );
MutablePlexusContainer container = (MutablePlexusContainer) getContainer();
MavenSession session = createSession( container, repo, executionProperties );

View File

@ -26,6 +26,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.model.validation.ModelValidationResult;
import org.apache.maven.repository.RepositorySystem;
import org.codehaus.plexus.PlexusTestCase;
/**
@ -37,11 +38,13 @@ public abstract class AbstractMavenProjectTestCase
{
protected ProjectBuilder projectBuilder;
protected RepositorySystem repositorySystem;
protected void setUp()
throws Exception
{
super.setUp();
if ( getContainer().hasComponent( ProjectBuilder.class, "test" ) )
{
projectBuilder = lookup( ProjectBuilder.class, "test" );
@ -51,6 +54,8 @@ public abstract class AbstractMavenProjectTestCase
// default over to the main project builder...
projectBuilder = lookup( ProjectBuilder.class );
}
repositorySystem = lookup( RepositorySystem.class );
}
@Override
@ -70,7 +75,9 @@ public abstract class AbstractMavenProjectTestCase
@Override
protected String getCustomConfigurationName()
{
return AbstractMavenProjectTestCase.class.getName().replace( '.', '/' ) + ".xml";
String name = AbstractMavenProjectTestCase.class.getName().replace( '.', '/' ) + ".xml";
System.out.println( name );
return name;
}
// ----------------------------------------------------------------------
@ -105,7 +112,7 @@ public abstract class AbstractMavenProjectTestCase
{
ArtifactRepositoryLayout repoLayout = lookup( ArtifactRepositoryLayout.class, "legacy" );
ArtifactRepository r = new DefaultArtifactRepository( "local", "file://" + getLocalRepositoryPath().getAbsolutePath(), repoLayout );
ArtifactRepository r = repositorySystem.createArtifactRepository( "local", "file://" + getLocalRepositoryPath().getAbsolutePath(), repoLayout, null, null );
return r;
}

View File

@ -111,7 +111,7 @@ public class DefaultMavenProjectBuilderTest
throws Exception
{
ArtifactRepositoryLayout repoLayout = lookup( ArtifactRepositoryLayout.class, "legacy" );
ArtifactRepository r = new DefaultArtifactRepository( "local", "file://" + localRepoDir.getAbsolutePath(), repoLayout );
ArtifactRepository r = repositorySystem.createArtifactRepository( "local", "file://" + localRepoDir.getAbsolutePath(), repoLayout, null, null );
return r;
}

View File

@ -29,6 +29,7 @@ import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.project.harness.PomTestWrapper;
import org.apache.maven.repository.RepositorySystem;
import org.codehaus.plexus.PlexusTestCase;
public class PomConstructionTest
@ -41,7 +42,9 @@ public class PomConstructionTest
private static String BASE_MIXIN_DIR = BASE_DIR + "/resources-mixins";
private DefaultProjectBuilder projectBuilder;
private RepositorySystem repositorySystem;
private File testDirectory;
protected void setUp()
@ -50,6 +53,7 @@ public class PomConstructionTest
testDirectory = new File( getBasedir(), BASE_POM_DIR );
new File( getBasedir(), BASE_MIXIN_DIR );
projectBuilder = (DefaultProjectBuilder) lookup( ProjectBuilder.class );
repositorySystem = lookup( RepositorySystem.class );
}
@Override
@ -1671,7 +1675,7 @@ public class PomConstructionTest
String localRepoUrl =
System.getProperty( "maven.repo.local", System.getProperty( "user.home" ) + "/.m2/repository" );
localRepoUrl = "file://" + localRepoUrl;
config.setLocalRepository( new DefaultArtifactRepository( "local", localRepoUrl, new DefaultRepositoryLayout() ) );
config.setLocalRepository( repositorySystem.createArtifactRepository( "local", localRepoUrl, new DefaultRepositoryLayout(), null, null ) );
config.setActiveProfileIds( Arrays.asList( profileIds ) );
config.setExecutionProperties( executionProperties );
config.setLenientValidation( lenientValidation );

View File

@ -23,6 +23,7 @@ import java.io.File;
import java.util.Iterator;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.repository.RepositorySystem;
public class ProjectClasspathTest
extends AbstractMavenProjectTestCase
@ -36,6 +37,8 @@ public class ProjectClasspathTest
// the metadata source looks up the default impl, so we have to trick it
getContainer().addComponent( projectBuilder, ProjectBuilder.class, "default" );
repositorySystem = lookup( RepositorySystem.class );
}
@Override

View File

@ -12,6 +12,7 @@ import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.project.harness.PomTestWrapper;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.IOUtil;
@ -26,6 +27,8 @@ public class PomConstructionWithSettingsTest
private static String BASE_POM_DIR = BASE_DIR + "/resources-settings";
private DefaultProjectBuilder projectBuilder;
private RepositorySystem repositorySystem;
private File testDirectory;
@ -34,6 +37,7 @@ public class PomConstructionWithSettingsTest
{
testDirectory = new File( getBasedir(), BASE_POM_DIR );
projectBuilder = (DefaultProjectBuilder) lookup( ProjectBuilder.class );
repositorySystem = lookup( RepositorySystem.class );
}
@Override
@ -83,7 +87,7 @@ public class PomConstructionWithSettingsTest
String localRepoUrl = System.getProperty( "maven.repo.local", System.getProperty( "user.home" ) + "/.m2/repository" );
localRepoUrl = "file://" + localRepoUrl;
config.setLocalRepository( new DefaultArtifactRepository( "local", localRepoUrl, new DefaultRepositoryLayout() ) );
config.setLocalRepository( repositorySystem.createArtifactRepository( "local", localRepoUrl, new DefaultRepositoryLayout(), null, null ) );
config.setActiveProfileIds( settings.getActiveProfiles() );
return new PomTestWrapper( pomFile, projectBuilder.build( pomFile, config ) );

View File

@ -29,6 +29,7 @@ import java.util.Set;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
@ -60,7 +61,7 @@ public class DefaultMirrorBuilder
logger.warn( "You are using a mirror that doesn't declare an <id/> element. Using \'" + id + "\' instead:\nId: " + id + "\nmirrorOf: " + mirrorOf + "\nurl: " + url + "\n" );
}
ArtifactRepository mirror = new DefaultArtifactRepository( id, url, null );
ArtifactRepository mirror = repositoryFactory.createArtifactRepository( id, url, (ArtifactRepositoryLayout)null, null, null );
if ( !mirrors.containsKey( mirrorOf ) )
{

View File

@ -23,7 +23,7 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.MavenArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
/**
@ -31,7 +31,7 @@ import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
* and user local repository.
*/
public class DelegatingLocalArtifactRepository
extends DefaultArtifactRepository
extends MavenArtifactRepository
{
private LocalArtifactRepository buildReactor;

View File

@ -21,9 +21,10 @@ package org.apache.maven.repository;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.MavenArtifactRepository;
public abstract class LocalArtifactRepository
extends DefaultArtifactRepository
extends MavenArtifactRepository
{
public static final String IDE_WORKSPACE = "ide-workspace";

View File

@ -25,6 +25,8 @@ import java.util.List;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.model.Dependency;
@ -75,6 +77,8 @@ public interface RepositorySystem
ArtifactRepository createLocalRepository( File localRepository )
throws InvalidRepositoryException;
ArtifactRepository createArtifactRepository( String id, String url, ArtifactRepositoryLayout repositoryLayout, ArtifactRepositoryPolicy snapshots, ArtifactRepositoryPolicy releases );
/**
* Calculates the effective repositories for the given input repositories. This process will essentially remove
* duplicate repositories by merging them into one equivalent repository. It is worth to point out that merging does

View File

@ -299,6 +299,11 @@ public class LegacyRepositorySystem
return artifactRepositoryFactory.createArtifactRepository( repositoryId, url, defaultArtifactRepositoryLayout, snapshotsPolicy, releasesPolicy );
}
public ArtifactRepository createArtifactRepository( String id, String url, ArtifactRepositoryLayout repositoryLayout, ArtifactRepositoryPolicy snapshots, ArtifactRepositoryPolicy releases )
{
return artifactRepositoryFactory.createArtifactRepository( id, url, repositoryLayout, snapshots, releases );
}
public ArtifactResolutionResult resolve( ArtifactResolutionRequest request )
{
/*

View File

@ -1,6 +1,7 @@
package org.apache.maven.repository;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.codehaus.plexus.PlexusTestCase;
@ -9,11 +10,13 @@ public class MirrorProcessorTest
extends PlexusTestCase
{
private DefaultMirrorBuilder mirrorBuilder;
private ArtifactRepositoryFactory repositorySystem;
protected void setUp()
throws Exception
{
mirrorBuilder = (DefaultMirrorBuilder) lookup( MirrorBuilder.class );
repositorySystem = lookup( ArtifactRepositoryFactory.class );
mirrorBuilder.clearMirrors();
}
@ -179,7 +182,7 @@ public class MirrorProcessorTest
*/
private ArtifactRepository getRepo( String id, String url )
{
return new DefaultArtifactRepository( id, url, new DefaultRepositoryLayout() );
return repositorySystem.createArtifactRepository( id, url, new DefaultRepositoryLayout(), null, null );
}
/**