diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionResult.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionResult.java index f447cc1b33..9103e37363 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionResult.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionResult.java @@ -59,10 +59,10 @@ public class ArtifactResolutionResult private List repositories; - private Set requestedArtifacts; - private Set artifacts; + private Set resolutionNodes; + public Artifact getOriginatingArtifact() { return originatingArtifact; @@ -100,19 +100,19 @@ public class ArtifactResolutionResult this.artifacts = artifacts; } - public void addRequestedArtifact( Artifact artifact ) + public Set getResolutionNodes() { - if ( requestedArtifacts == null ) + if ( resolutionNodes == null ) { - requestedArtifacts = new LinkedHashSet(); + resolutionNodes = new LinkedHashSet(); } - requestedArtifacts.add( artifact ); + return resolutionNodes; } - public Set getRequestedArtifacts() + public void setResolutionNodes( Set resolutionNodes ) { - return requestedArtifacts; + this.resolutionNodes = resolutionNodes; } public boolean hasMissingArtifacts() diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java index 6289d8d6e9..ff9663ac49 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java @@ -493,15 +493,21 @@ public class DefaultArtifactResolver return result; } - if ( result.getArtifacts() != null ) + if ( result.getResolutionNodes() != null ) { - for ( Artifact artifact : result.getArtifacts() ) + ArtifactResolutionRequest childRequest = new ArtifactResolutionRequest( request ); + + for ( ResolutionNode node : result.getResolutionNodes() ) { + Artifact artifact = node.getArtifact(); + try { if ( resolutionFilter == null || resolutionFilter.include( artifact ) ) { - resolve( artifact, request, request.getTransferListener(), false ); + childRequest.setRemoteRepositories( node.getRemoteRepositories() ); + + resolve( artifact, childRequest, request.getTransferListener(), false ); } } catch ( ArtifactNotFoundException anfe ) diff --git a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/DefaultLegacyArtifactCollector.java b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/DefaultLegacyArtifactCollector.java index 85e2f121b2..e0f4903e4e 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/DefaultLegacyArtifactCollector.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/legacy/resolver/DefaultLegacyArtifactCollector.java @@ -170,7 +170,6 @@ public class DefaultLegacyArtifactCollector // This is required right now. result.addArtifact( artifact ); - result.addRequestedArtifact( artifact ); } } } @@ -182,6 +181,8 @@ public class DefaultLegacyArtifactCollector } } + result.setResolutionNodes( set ); + return result; } diff --git a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java index 8ed555f8c9..47ea760717 100644 --- a/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java +++ b/maven-core/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -137,6 +138,8 @@ public class MavenMetadataSource List managedDependencies = null; + List pomRepositories = null; + Artifact pomArtifact; Artifact relocatedArtifact = null; @@ -177,6 +180,8 @@ public class MavenMetadataSource DependencyManagement depMngt = rel.project.getDependencyManagement(); managedDependencies = ( depMngt != null ) ? depMngt.getDependencies() : null; + + pomRepositories = rel.project.getRemoteArtifactRepositories(); } } @@ -211,8 +216,11 @@ public class MavenMetadataSource } } + List aggregatedRepositories = + aggregateRepositories( request.getRemoteRepositories(), pomRepositories ); + ResolutionGroup result = - new ResolutionGroup( pomArtifact, relocatedArtifact, artifacts, managedVersions, request.getRemoteRepositories() ); + new ResolutionGroup( pomArtifact, relocatedArtifact, artifacts, managedVersions, aggregatedRepositories ); cache.put( artifact, request.isResolveManagedVersions(), request.getLocalRepository(), request.getRemoteRepositories(), result ); @@ -220,6 +228,37 @@ public class MavenMetadataSource return result; } + private List aggregateRepositories( List requestRepositories, + List pomRepositories ) + { + List repositories = requestRepositories; + + if ( pomRepositories != null && !pomRepositories.isEmpty() ) + { + Map repos = new LinkedHashMap(); + + for ( ArtifactRepository repo : requestRepositories ) + { + if ( !repos.containsKey( repo.getId() ) ) + { + repos.put( repo.getId(), repo ); + } + } + + for ( ArtifactRepository repo : pomRepositories ) + { + if ( !repos.containsKey( repo.getId() ) ) + { + repos.put( repo.getId(), repo ); + } + } + + repositories = new ArrayList( repos.values() ); + } + + return repositories; + } + private Artifact createDependencyArtifact( Dependency dependency, Artifact owner, Artifact pom ) throws ArtifactMetadataRetrievalException {