[MNG-4842] [regression] Repositories discovered in dependency POMs override repositories configured for original resolution request of POM

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1002852 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2010-09-29 21:31:34 +00:00
parent b428381d99
commit 789ee6703e
6 changed files with 112 additions and 24 deletions

View File

@ -208,9 +208,9 @@ public class DefaultProjectBuilder
ReactorModelPool modelPool )
{
ModelResolver resolver =
new ReactorModelResolver( configuration.getRepositorySession(), artifactResolver,
repositoryManager,
RepositoryUtils.toRepos( configuration.getRemoteRepositories() ), modelPool );
new ProjectModelResolver( configuration.getRepositorySession(), artifactResolver, repositoryManager,
RepositoryUtils.toRepos( configuration.getRemoteRepositories() ),
configuration.getRepositoryMerging(), modelPool );
ModelBuildingRequest request = new DefaultModelBuildingRequest();

View File

@ -105,24 +105,48 @@ public class DefaultProjectBuildingHelper
ProjectBuildingRequest request )
throws InvalidRepositoryException
{
List<ArtifactRepository> artifactRepositories = new ArrayList<ArtifactRepository>();
Collection<String> repoIds = new HashSet<String>();
List<ArtifactRepository> internalRepositories = new ArrayList<ArtifactRepository>();
for ( Repository repository : pomRepositories )
{
artifactRepositories.add( repositorySystem.buildArtifactRepository( repository ) );
repoIds.add( repository.getId() );
internalRepositories.add( repositorySystem.buildArtifactRepository( repository ) );
}
repositorySystem.injectMirror( request.getRepositorySession(), artifactRepositories );
repositorySystem.injectMirror( request.getRepositorySession(), internalRepositories );
repositorySystem.injectProxy( request.getRepositorySession(), artifactRepositories );
repositorySystem.injectProxy( request.getRepositorySession(), internalRepositories );
repositorySystem.injectAuthentication( request.getRepositorySession(), artifactRepositories );
repositorySystem.injectAuthentication( request.getRepositorySession(), internalRepositories );
if ( externalRepositories != null )
List<ArtifactRepository> dominantRepositories;
List<ArtifactRepository> recessiveRepositories;
if ( ProjectBuildingRequest.RepositoryMerging.REQUEST_DOMINANT.equals( request.getRepositoryMerging() ) )
{
for ( ArtifactRepository repository : externalRepositories )
dominantRepositories = externalRepositories;
recessiveRepositories = internalRepositories;
}
else
{
dominantRepositories = internalRepositories;
recessiveRepositories = externalRepositories;
}
List<ArtifactRepository> artifactRepositories = new ArrayList<ArtifactRepository>();
Collection<String> repoIds = new HashSet<String>();
if ( dominantRepositories != null )
{
for ( ArtifactRepository repository : dominantRepositories )
{
repoIds.add( repository.getId() );
artifactRepositories.add( repository );
}
}
if ( recessiveRepositories != null )
{
for ( ArtifactRepository repository : recessiveRepositories )
{
if ( repoIds.add( repository.getId() ) )
{

View File

@ -61,6 +61,8 @@ public class DefaultProjectBuildingRequest
private boolean resolveDependencies;
private RepositoryMerging repositoryMerging = RepositoryMerging.POM_DOMINANT;
public DefaultProjectBuildingRequest()
{
processPlugins = true;
@ -301,4 +303,19 @@ public class DefaultProjectBuildingRequest
return this;
}
public DefaultProjectBuildingRequest setRepositoryMerging( RepositoryMerging repositoryMerging )
{
if ( repositoryMerging == null )
{
throw new IllegalArgumentException( "repository merge mode not specified" );
}
this.repositoryMerging = repositoryMerging;
return this;
}
public RepositoryMerging getRepositoryMerging()
{
return repositoryMerging;
}
}

View File

@ -151,4 +151,39 @@ public interface ProjectBuildingRequest
ProjectBuildingRequest setRepositorySession( RepositorySystemSession repositorySession );
/**
* Sets the merge mode used to combine repositories declared in the POM with the repositories specified in this
* request.
*
* @param mode The repository merge mode, must not be {@code null}.
* @return This request for chaining, never {@code null}.
* @see #setRemoteRepositories(List)
*/
ProjectBuildingRequest setRepositoryMerging( RepositoryMerging mode );
/**
* Gets the merge mode used to combine repositories declared in the POM with the repositories specified in this
* request
*
* @return The merge mode, never {@code null}.
*/
RepositoryMerging getRepositoryMerging();
/**
* The possible merge modes for combining remote repositories.
*/
enum RepositoryMerging
{
/**
* The repositories declared in the POM have precedence over the repositories specified in the request.
*/
POM_DOMINANT,
/**
* The repositories specified in the request have precedence over the repositories declared in the POM.
*/
REQUEST_DOMINANT,
}
}

View File

@ -48,7 +48,7 @@ import org.sonatype.aether.util.artifact.DefaultArtifact;
*
* @author Benjamin Bentmann
*/
class ReactorModelResolver
class ProjectModelResolver
implements ModelResolver
{
@ -60,7 +60,7 @@ class ReactorModelResolver
private List<RemoteRepository> pomRepositories;
private final List<RemoteRepository> defaultRepositories;
private final List<RemoteRepository> externalRepositories;
private final ArtifactResolver resolver;
@ -70,28 +70,32 @@ class ReactorModelResolver
private final ReactorModelPool modelPool;
public ReactorModelResolver( RepositorySystemSession session, ArtifactResolver resolver,
private final ProjectBuildingRequest.RepositoryMerging repositoryMerging;
public ProjectModelResolver( RepositorySystemSession session, ArtifactResolver resolver,
RemoteRepositoryManager remoteRepositoryManager, List<RemoteRepository> repositories,
ReactorModelPool modelPool )
ProjectBuildingRequest.RepositoryMerging repositoryMerging, ReactorModelPool modelPool )
{
this.session = session;
this.resolver = resolver;
this.remoteRepositoryManager = remoteRepositoryManager;
this.pomRepositories = new ArrayList<RemoteRepository>();
this.defaultRepositories = repositories;
this.externalRepositories = repositories;
this.repositories = repositories;
this.repositoryMerging = repositoryMerging;
this.repositoryIds = new HashSet<String>();
this.modelPool = modelPool;
}
private ReactorModelResolver( ReactorModelResolver original )
private ProjectModelResolver( ProjectModelResolver original )
{
this.session = original.session;
this.resolver = original.resolver;
this.remoteRepositoryManager = original.remoteRepositoryManager;
this.pomRepositories = original.pomRepositories;
this.defaultRepositories = original.defaultRepositories;
this.externalRepositories = original.externalRepositories;
this.repositories = original.repositories;
this.repositoryMerging = original.repositoryMerging;
this.repositoryIds = new HashSet<String>( original.repositoryIds );
this.modelPool = original.modelPool;
}
@ -106,10 +110,17 @@ class ReactorModelResolver
List<RemoteRepository> newRepositories = Collections.singletonList( convert( repository ) );
pomRepositories =
remoteRepositoryManager.aggregateRepositories( session, pomRepositories, newRepositories, true );
repositories =
remoteRepositoryManager.aggregateRepositories( session, pomRepositories, defaultRepositories, false );
if ( ProjectBuildingRequest.RepositoryMerging.REQUEST_DOMINANT.equals( repositoryMerging ) )
{
repositories = remoteRepositoryManager.aggregateRepositories( session, repositories, newRepositories, true );
}
else
{
pomRepositories =
remoteRepositoryManager.aggregateRepositories( session, pomRepositories, newRepositories, true );
repositories =
remoteRepositoryManager.aggregateRepositories( session, pomRepositories, externalRepositories, false );
}
}
private static RemoteRepository convert( Repository repository )
@ -145,7 +156,7 @@ class ReactorModelResolver
public ModelResolver newCopy()
{
return new ReactorModelResolver( this );
return new ProjectModelResolver( this );
}
public ModelSource resolveModel( String groupId, String artifactId, String version )

View File

@ -573,6 +573,7 @@ public class MavenMetadataSource
configuration.setRemoteRepositories( repositoryRequest.getRemoteRepositories() );
configuration.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
configuration.setProcessPlugins( false );
configuration.setRepositoryMerging( ProjectBuildingRequest.RepositoryMerging.REQUEST_DOMINANT );
configuration.setSystemProperties( getSystemProperties() );
configuration.setRepositorySession( legacySupport.getRepositorySession() );