[MNG-4400] [regression] Repository order from settings.xml is not respected during artifact resolution

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@829009 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-10-23 11:43:38 +00:00
parent 5160b63bc0
commit fce4db9c9c
3 changed files with 29 additions and 10 deletions

View File

@ -22,7 +22,9 @@ package org.apache.maven.project;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
@ -57,6 +59,8 @@ class RepositoryModelResolver
private ReactorModelPool reactorModelPool; private ReactorModelPool reactorModelPool;
private Set<String> repositoryIds;
public RepositoryModelResolver( RepositorySystem repositorySystem, ResolutionErrorHandler resolutionErrorHandler, public RepositoryModelResolver( RepositorySystem repositorySystem, ResolutionErrorHandler resolutionErrorHandler,
ProjectBuildingRequest projectBuildingRequest, ReactorModelPool reactorModelPool ) ProjectBuildingRequest projectBuildingRequest, ReactorModelPool reactorModelPool )
{ {
@ -78,24 +82,40 @@ class RepositoryModelResolver
} }
this.projectBuildingRequest = projectBuildingRequest; this.projectBuildingRequest = projectBuildingRequest;
if ( projectBuildingRequest.getRemoteRepositories() == null ) this.remoteRepositories = new ArrayList<ArtifactRepository>();
if ( projectBuildingRequest.getRemoteRepositories() != null )
{ {
throw new IllegalArgumentException( "no remote repositories specified" ); this.remoteRepositories.addAll( projectBuildingRequest.getRemoteRepositories() );
} }
this.remoteRepositories = new ArrayList<ArtifactRepository>( projectBuildingRequest.getRemoteRepositories() );
this.repositoryIds = new HashSet<String>();
this.reactorModelPool = reactorModelPool; this.reactorModelPool = reactorModelPool;
} }
private RepositoryModelResolver( RepositoryModelResolver original )
{
this.repositorySystem = original.repositorySystem;
this.resolutionErrorHandler = original.resolutionErrorHandler;
this.projectBuildingRequest = original.projectBuildingRequest;
this.reactorModelPool = original.reactorModelPool;
this.remoteRepositories = new ArrayList<ArtifactRepository>( original.remoteRepositories );
this.repositoryIds = new HashSet<String>( original.repositoryIds );
}
public ModelResolver newCopy() public ModelResolver newCopy()
{ {
return new RepositoryModelResolver( repositorySystem, resolutionErrorHandler, projectBuildingRequest, return new RepositoryModelResolver( this );
reactorModelPool );
} }
public void addRepository( Repository repository ) public void addRepository( Repository repository )
throws InvalidRepositoryException throws InvalidRepositoryException
{ {
if ( !repositoryIds.add( repository.getId() ) )
{
return;
}
try try
{ {
ArtifactRepository repo = repositorySystem.buildArtifactRepository( repository ); ArtifactRepository repo = repositorySystem.buildArtifactRepository( repository );
@ -106,7 +126,7 @@ class RepositoryModelResolver
repositorySystem.injectAuthentication( Arrays.asList( repo ), projectBuildingRequest.getServers() ); repositorySystem.injectAuthentication( Arrays.asList( repo ), projectBuildingRequest.getServers() );
remoteRepositories.add( 0, repo ); remoteRepositories.add( repo );
remoteRepositories = repositorySystem.getEffectiveRepositories( remoteRepositories ); remoteRepositories = repositorySystem.getEffectiveRepositories( remoteRepositories );
} }

View File

@ -23,7 +23,6 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
@ -387,7 +386,6 @@ public class DefaultModelBuilder
problems.setSource( model ); problems.setSource( model );
List<Repository> repositories = model.getRepositories(); List<Repository> repositories = model.getRepositories();
Collections.reverse( repositories );
for ( Repository repository : repositories ) for ( Repository repository : repositories )
{ {

View File

@ -46,8 +46,9 @@ public interface ModelResolver
throws UnresolvableModelException; throws UnresolvableModelException;
/** /**
* Adds a repository to use for subsequent resolution requests. The order in which repositories are added matters. * Adds a repository to use for subsequent resolution requests. The order in which repositories are added matters,
* When multiple repositories with the same identifier are added, only the last repository being added will be used. * repositories that were added first should also be searched first. When multiple repositories with the same
* identifier are added, only the first repository being added will be used.
* *
* @param repository The repository to add to the internal search chain, must not be {@code null}. * @param repository The repository to add to the internal search chain, must not be {@code null}.
* @throws InvalidRepositoryException If the repository could not be added (e.g. due to invalid URL or layout). * @throws InvalidRepositoryException If the repository could not be added (e.g. due to invalid URL or layout).