From 5d0298a9421f53ce2c2c71a1ad73e25b1387effa Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Mon, 22 Aug 2005 20:31:24 +0000 Subject: [PATCH] Resolving: MNG-757 according to the comments in the issue. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@239243 13f79535-47bb-0310-9956-ffa450edef68 --- .../project/artifact/MavenMetadataSource.java | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java index 427a79906a..732faf717f 100644 --- a/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java +++ b/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java @@ -58,6 +58,9 @@ public class MavenMetadataSource private ArtifactFactory artifactFactory; + // lazily instantiated and cached. + private MavenProject superProject; + /** * Retrieve the metadata for the project from the repository. * Uses the ProjectBuilder, to enable post-processing and inheritance calculation before retrieving the @@ -134,12 +137,65 @@ public class MavenMetadataSource Set artifacts = project.createArtifacts( artifactFactory, artifact.getScope(), artifact.getDependencyFilter() ); - return new ResolutionGroup( pomArtifact, artifacts, project.getRemoteArtifactRepositories() ); + + List repositories = aggregateRepositoryLists( remoteRepositories, project.getRemoteArtifactRepositories() ); + + return new ResolutionGroup( pomArtifact, artifacts, repositories ); } catch ( InvalidVersionSpecificationException e ) { throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file", e ); } + catch ( ProjectBuildingException e ) + { + throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file", e ); + } + } + + private List aggregateRepositoryLists( List remoteRepositories, List remoteArtifactRepositories ) + throws ProjectBuildingException + { + if ( superProject == null ) + { + superProject = mavenProjectBuilder.buildStandaloneSuperProject( null ); + } + + List repositories = new ArrayList(); + + repositories.addAll( remoteRepositories ); + + // ensure that these are defined + for ( Iterator it = superProject.getRemoteArtifactRepositories().iterator(); it.hasNext(); ) + { + ArtifactRepository superRepo = (ArtifactRepository) it.next(); + + for ( Iterator aggregatedIterator = repositories.iterator(); aggregatedIterator.hasNext(); ) + { + ArtifactRepository repo = (ArtifactRepository) aggregatedIterator.next(); + + // if the repository exists in the list and was introduced by another POM's super-pom, + // remove it...the repository definitions from the super-POM should only be at the end of + // the list. + // if the repository has been redefined, leave it. + if ( repo.getId().equals( superRepo.getId() ) && repo.getUrl().equals( superRepo.getUrl() ) ) + { + aggregatedIterator.remove(); + } + } + } + + // this list should contain the super-POM repositories, so we don't have to explicitly add them back. + for ( Iterator it = remoteArtifactRepositories.iterator(); it.hasNext(); ) + { + ArtifactRepository repository = (ArtifactRepository) it.next(); + + if ( !repositories.contains( repository ) ) + { + repositories.add( repository ); + } + } + + return repositories; } public static Set createArtifacts( ArtifactFactory artifactFactory, List dependencies, String inheritedScope,