From c7d5e83520949f2577db6ad37e63c27cb10f4ae3 Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Sat, 16 Jul 2005 01:24:13 +0000 Subject: [PATCH] Resolving: MNG-397 o Added ResolutionGroup class which contains a set of artifacts and a list of repositories to resolve them. o Made the ResolutionNode a standalone class, and added the remote repositories to it o Changed ArtifactMetadataSource.retrieve(..) to return ResolutionGroup rather than Set, in order to help keep track of the repositories which should be used to resolve the retrieved artifacts. We need some tests for this... git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@219276 13f79535-47bb-0310-9956-ffa450edef68 --- .../resolver/DefaultArtifactResolver.java | 6 +- .../resolver/ArtifactResolverTest.java | 9 +- .../metadata/ArtifactMetadataSource.java | 3 +- .../artifact/metadata/ResolutionGroup.java | 28 +++++ .../resolver/ArtifactResolutionResult.java | 37 ++++-- .../resolver/DefaultArtifactCollector.java | 114 ++--------------- .../artifact/resolver/ResolutionNode.java | 117 ++++++++++++++++++ .../DefaultArtifactCollectorTest.java | 7 +- .../maven/plugin/DefaultPluginManager.java | 6 +- .../project/artifact/MavenMetadataSource.java | 18 ++- .../maven/project/MavenProjectTestCase.java | 6 +- .../ProjectClasspathArtifactResolver.java | 46 ++++++- .../maven/project/ProjectClasspathTest.xml | 3 + 13 files changed, 253 insertions(+), 147 deletions(-) create mode 100644 maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ResolutionGroup.java create mode 100644 maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java index a207647005..4b7f5cb10c 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java @@ -174,10 +174,10 @@ public class DefaultArtifactResolver localRepository, remoteRepositories, source, filter, artifactFactory, listeners ); - for ( Iterator i = artifactResolutionResult.getArtifacts().iterator(); i.hasNext(); ) + for ( Iterator i = artifactResolutionResult.getArtifactResolutionNodes().iterator(); i.hasNext(); ) { - Artifact artifact = (Artifact) i.next(); - resolve( artifact, remoteRepositories, localRepository ); + ResolutionNode node = (ResolutionNode) i.next(); + resolve( node.getArtifact(), node.getRemoteRepositories(), localRepository ); } return artifactResolutionResult; diff --git a/maven-artifact-manager/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java b/maven-artifact-manager/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java index 31d1327f5b..494e2b18f9 100644 --- a/maven-artifact-manager/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java +++ b/maven-artifact-manager/src/test/java/org/apache/maven/artifact/resolver/ArtifactResolverTest.java @@ -19,6 +19,7 @@ package org.apache.maven.artifact.resolver; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.ArtifactComponentTestCase; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; +import org.apache.maven.artifact.metadata.ResolutionGroup; import org.apache.maven.artifact.repository.ArtifactRepository; import java.util.ArrayList; @@ -95,7 +96,7 @@ public class ArtifactResolverTest ArtifactMetadataSource mds = new ArtifactMetadataSource() { - public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) + public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) { Set dependencies = new HashSet(); @@ -104,7 +105,7 @@ public class ArtifactResolverTest dependencies.add( createArtifact( "org.apache.maven", "h", "1.0", "jar" ) ); } - return dependencies; + return new ResolutionGroup( dependencies, remoteRepositories ); } }; @@ -134,7 +135,7 @@ public class ArtifactResolverTest ArtifactMetadataSource mds = new ArtifactMetadataSource() { - public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) + public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) { Set dependencies = new HashSet(); @@ -143,7 +144,7 @@ public class ArtifactResolverTest dependencies.add( createArtifact( "org.apache.maven", "j", "1.0", "jar" ) ); } - return dependencies; + return new ResolutionGroup( dependencies, remoteRepositories ); } }; diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataSource.java b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataSource.java index 500f20d9a6..716428e300 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataSource.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadataSource.java @@ -20,7 +20,6 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; import java.util.List; -import java.util.Set; /** * @author Jason van Zyl @@ -28,6 +27,6 @@ import java.util.Set; */ public interface ArtifactMetadataSource { - Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) + ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) throws ArtifactMetadataRetrievalException; } \ No newline at end of file diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ResolutionGroup.java b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ResolutionGroup.java new file mode 100644 index 0000000000..f02da12451 --- /dev/null +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ResolutionGroup.java @@ -0,0 +1,28 @@ +package org.apache.maven.artifact.metadata; + +import java.util.List; +import java.util.Set; + +public class ResolutionGroup +{ + + private final Set artifacts; + private final List resolutionRepositories; + + public ResolutionGroup( Set artifacts, List resolutionRepositories ) + { + this.artifacts = artifacts; + this.resolutionRepositories = resolutionRepositories; + } + + public Set getArtifacts() + { + return artifacts; + } + + public List getResolutionRepositories() + { + return resolutionRepositories; + } + +} diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionResult.java b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionResult.java index c227e7f3cf..f0f4fa5128 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionResult.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionResult.java @@ -16,10 +16,9 @@ package org.apache.maven.artifact.resolver; * limitations under the License. */ -import java.util.HashMap; -import java.util.Map; +import java.util.HashSet; +import java.util.Iterator; import java.util.Set; -import java.util.Collections; /** * @author Jason van Zyl @@ -27,27 +26,41 @@ import java.util.Collections; */ public class ArtifactResolutionResult { - private Set artifacts = Collections.EMPTY_SET; - - private Map conflicts; + private Set resolutionNodes; + // calculated. + private Set artifacts; + public ArtifactResolutionResult() { - conflicts = new HashMap(); } public Set getArtifacts() { + if ( artifacts == null ) + { + artifacts = new HashSet(); + + for ( Iterator it = resolutionNodes.iterator(); it.hasNext(); ) + { + ResolutionNode node = (ResolutionNode) it.next(); + artifacts.add( node.getArtifact() ); + } + } + return artifacts; } - - public Map getConflicts() + + public Set getArtifactResolutionNodes() { - return conflicts; + return resolutionNodes; } - public void setArtifacts( Set artifacts ) + public void setArtifactResolutionNodes( Set resolutionNodes ) { - this.artifacts = artifacts; + this.resolutionNodes = resolutionNodes; + + // clear the cache + this.artifacts = null; } } diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java index 746dfb4266..969501d37f 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java @@ -20,15 +20,14 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; +import org.apache.maven.artifact.metadata.ResolutionGroup; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; -import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -60,8 +59,8 @@ public class DefaultArtifactCollector { Map resolvedArtifacts = new HashMap(); - ResolutionNode root = new ResolutionNode( originatingArtifact ); - root.addDependencies( artifacts, filter ); + ResolutionNode root = new ResolutionNode( originatingArtifact, remoteRepositories ); + root.addDependencies( artifacts, remoteRepositories, filter ); recurse( root, resolvedArtifacts, managedVersions, localRepository, remoteRepositories, source, filter, artifactFactory, listeners ); @@ -77,13 +76,13 @@ public class DefaultArtifactCollector artifact.setDependencyTrail( node.getDependencyTrail() ); - set.add( artifact ); + set.add( node ); } } ArtifactResolutionResult result = new ArtifactResolutionResult(); - result.setArtifacts( set ); + result.setArtifactResolutionNodes( set ); return result; } @@ -148,15 +147,17 @@ public class DefaultArtifactCollector { try { - Set artifacts = source.retrieve( child.getArtifact(), localRepository, remoteRepositories ); - child.addDependencies( artifacts, filter ); + ResolutionGroup rGroup = source.retrieve( child.getArtifact(), localRepository, remoteRepositories ); + child.addDependencies( rGroup.getArtifacts(), rGroup.getResolutionRepositories(), filter ); } catch ( CyclicDependencyException e ) { // would like to throw this, but we have crappy stuff in the repo // no logger to use here either just now + + // TODO: should the remoteRepositories list be null here?! fireEvent( ResolutionListener.OMIT_FOR_CYCLE, listeners, - new ResolutionNode( e.getArtifact(), child ) ); + new ResolutionNode( e.getArtifact(), null, child ) ); } catch ( ArtifactMetadataRetrievalException e ) { @@ -249,99 +250,4 @@ public class DefaultArtifactCollector } } - private static class ResolutionNode - { - private Artifact artifact; - - private List children = null; - - private final List parents; - - private final int depth; - - private final ResolutionNode parent; - - public ResolutionNode( Artifact artifact ) - { - this.artifact = artifact; - this.depth = 0; - this.parents = Collections.EMPTY_LIST; - this.parent = null; - } - - public ResolutionNode( Artifact artifact, ResolutionNode parent ) - { - this.artifact = artifact; - this.depth = parent.depth + 1; - this.parents = new ArrayList(); - this.parents.addAll( parent.parents ); - this.parents.add( parent.getKey() ); - this.parent = parent; - } - - public Artifact getArtifact() - { - return artifact; - } - - public Object getKey() - { - return artifact.getDependencyConflictId(); - } - - public void addDependencies( Set artifacts, ArtifactFilter filter ) - throws CyclicDependencyException - { - children = new ArrayList( artifacts.size() ); - - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact a = (Artifact) i.next(); - - if ( filter == null || filter.include( a ) ) - { - if ( parents.contains( a.getDependencyConflictId() ) ) - { - a.setDependencyTrail( getDependencyTrail() ); - - throw new CyclicDependencyException( "A dependency has introduced a cycle", a ); - } - - children.add( new ResolutionNode( a, this ) ); - } - } - } - - public List getDependencyTrail() - { - List path = new LinkedList(); - ResolutionNode node = this; - while ( node != null ) - { - path.add( 0, node.getArtifact().getId() ); - node = node.parent; - } - return path; - } - - public boolean isResolved() - { - return children != null; - } - - public Iterator getChildrenIterator() - { - return children.iterator(); - } - - public int getDepth() - { - return depth; - } - - public void setArtifact( Artifact artifact ) - { - this.artifact = artifact; - } - } } diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java new file mode 100644 index 0000000000..e9b044dcfa --- /dev/null +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java @@ -0,0 +1,117 @@ +package org.apache.maven.artifact.resolver; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +public class ResolutionNode +{ + private Artifact artifact; + + private List children = null; + + private final List parents; + + private final int depth; + + private final ResolutionNode parent; + + private final List remoteRepositories; + + public ResolutionNode( Artifact artifact, List remoteRepositories ) + { + this.artifact = artifact; + this.remoteRepositories = remoteRepositories; + this.depth = 0; + this.parents = Collections.EMPTY_LIST; + this.parent = null; + } + + public ResolutionNode( Artifact artifact, List remoteRepositories, ResolutionNode parent ) + { + this.artifact = artifact; + this.remoteRepositories = remoteRepositories; + this.depth = parent.depth + 1; + this.parents = new ArrayList(); + this.parents.addAll( parent.parents ); + this.parents.add( parent.getKey() ); + this.parent = parent; + } + + public Artifact getArtifact() + { + return artifact; + } + + public Object getKey() + { + return artifact.getDependencyConflictId(); + } + + public void addDependencies( Set artifacts, List remoteRepositories, ArtifactFilter filter ) + throws CyclicDependencyException + { + children = new ArrayList( artifacts.size() ); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact a = (Artifact) i.next(); + + if ( filter == null || filter.include( a ) ) + { + if ( parents.contains( a.getDependencyConflictId() ) ) + { + a.setDependencyTrail( getDependencyTrail() ); + + throw new CyclicDependencyException( "A dependency has introduced a cycle", a ); + } + + children.add( new ResolutionNode( a, remoteRepositories, this ) ); + } + } + } + + public List getDependencyTrail() + { + List path = new LinkedList(); + ResolutionNode node = this; + while ( node != null ) + { + path.add( 0, node.getArtifact().getId() ); + node = node.parent; + } + return path; + } + + public boolean isResolved() + { + return children != null; + } + + public Iterator getChildrenIterator() + { + return children.iterator(); + } + + public int getDepth() + { + return depth; + } + + public void setArtifact( Artifact artifact ) + { + this.artifact = artifact; + } + + public List getRemoteRepositories() + { + return remoteRepositories; + } + +} diff --git a/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java b/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java index 1dbc55546b..b3491b4e04 100644 --- a/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java +++ b/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java @@ -20,6 +20,7 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; +import org.apache.maven.artifact.metadata.ResolutionGroup; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter; @@ -339,12 +340,12 @@ public class DefaultArtifactCollectorTest { Map artifacts = new HashMap(); - public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) + public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) throws ArtifactMetadataRetrievalException { ArtifactSpec a = (ArtifactSpec) artifacts.get( artifact.getId() ); - return createArtifacts( artifactFactory, a.dependencies, artifact.getScope(), - artifact.getDependencyFilter() ); + return new ResolutionGroup( createArtifacts( artifactFactory, a.dependencies, artifact.getScope(), + artifact.getDependencyFilter() ), Collections.EMPTY_LIST ); } private Set createArtifacts( ArtifactFactory artifactFactory, Set dependencies, String inheritedScope, diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index f67fe8bf21..2dfb16ded9 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -19,6 +19,7 @@ package org.apache.maven.plugin; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; +import org.apache.maven.artifact.metadata.ResolutionGroup; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; @@ -423,8 +424,11 @@ public class DefaultPluginManager remoteRepositories.addAll( project.getPluginArtifactRepositories() ); ArtifactRepository localRepository = session.getLocalRepository(); - Set dependencies = metadataSource.retrieve( pluginArtifact, localRepository, + + ResolutionGroup resolutionGroup = metadataSource.retrieve( pluginArtifact, localRepository, project.getPluginArtifactRepositories() ); + + Set dependencies = resolutionGroup.getArtifacts(); ArtifactResolutionResult result = artifactResolver.resolveTransitively( dependencies, pluginArtifact, localRepository, 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 9091376aa3..d1751126bc 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 @@ -20,6 +20,7 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; +import org.apache.maven.artifact.metadata.ResolutionGroup; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.resolver.filter.AndArtifactFilter; @@ -27,7 +28,6 @@ import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter; import org.apache.maven.model.Dependency; import org.apache.maven.model.Exclusion; -import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.ProjectBuildingException; @@ -47,24 +47,17 @@ public class MavenMetadataSource { private MavenProjectBuilder mavenProjectBuilder; - private ArtifactResolver artifactResolver; - private ArtifactFactory artifactFactory; - /** - * @todo remove. - */ - private MavenXpp3Reader reader = new MavenXpp3Reader(); - + // TODO: Remove resolver from params list. public MavenMetadataSource( ArtifactResolver artifactResolver, MavenProjectBuilder projectBuilder, ArtifactFactory artifactFactory ) { - this.artifactResolver = artifactResolver; this.mavenProjectBuilder = projectBuilder; this.artifactFactory = artifactFactory; } - public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) + public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) throws ArtifactMetadataRetrievalException { // TODO: only metadata is really needed - resolve as metadata @@ -82,12 +75,15 @@ public class MavenMetadataSource localRepository ); dependencies = p.getDependencies(); artifact.setDownloadUrl( pomArtifact.getDownloadUrl() ); + + Set artifacts = createArtifacts( artifactFactory, dependencies, artifact.getScope(), artifact.getDependencyFilter() ); + + return new ResolutionGroup( artifacts, p.getRemoteArtifactRepositories() ); } catch ( ProjectBuildingException e ) { throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file", e ); } - return createArtifacts( artifactFactory, dependencies, artifact.getScope(), artifact.getDependencyFilter() ); } public static Set createArtifacts( ArtifactFactory artifactFactory, List dependencies, String inheritedScope, diff --git a/maven-project/src/test/java/org/apache/maven/project/MavenProjectTestCase.java b/maven-project/src/test/java/org/apache/maven/project/MavenProjectTestCase.java index 936aad2e4d..7c6e38dd5d 100644 --- a/maven-project/src/test/java/org/apache/maven/project/MavenProjectTestCase.java +++ b/maven-project/src/test/java/org/apache/maven/project/MavenProjectTestCase.java @@ -18,6 +18,7 @@ package org.apache.maven.project; 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.codehaus.plexus.PlexusTestCase; @@ -38,6 +39,8 @@ public abstract class MavenProjectTestCase private ArtifactFactory artifactFactory; + private ArtifactRepositoryFactory artifactRepositoryFactory; + protected void setUp() throws Exception { @@ -45,6 +48,7 @@ public abstract class MavenProjectTestCase projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE ); artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); + artifactRepositoryFactory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); } // ---------------------------------------------------------------------- @@ -100,7 +104,7 @@ public abstract class MavenProjectTestCase throws Exception { return projectBuilder.buildWithDependencies( pom, getLocalRepository(), - new ProjectClasspathArtifactResolver.Source( artifactFactory ), + new ProjectClasspathArtifactResolver.Source( artifactFactory, artifactRepositoryFactory, getContainer() ), Collections.EMPTY_LIST ); } diff --git a/maven-project/src/test/java/org/apache/maven/project/ProjectClasspathArtifactResolver.java b/maven-project/src/test/java/org/apache/maven/project/ProjectClasspathArtifactResolver.java index 1b3a4b9e03..a5d318df45 100644 --- a/maven-project/src/test/java/org/apache/maven/project/ProjectClasspathArtifactResolver.java +++ b/maven-project/src/test/java/org/apache/maven/project/ProjectClasspathArtifactResolver.java @@ -20,7 +20,9 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; +import org.apache.maven.artifact.metadata.ResolutionGroup; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.DefaultArtifactResolver; @@ -28,6 +30,11 @@ import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.model.Dependency; import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.codehaus.plexus.PlexusConstants; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.context.Context; +import org.codehaus.plexus.context.ContextException; +import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; @@ -41,18 +48,26 @@ import java.util.Set; public class ProjectClasspathArtifactResolver extends DefaultArtifactResolver + implements Contextualizable { + private ArtifactRepositoryFactory repositoryFactory; + private PlexusContainer container; + public static class Source implements ArtifactMetadataSource { private ArtifactFactory artifactFactory; + private final ArtifactRepositoryFactory repositoryFactory; + private final PlexusContainer container; - public Source( ArtifactFactory artifactFactory ) + public Source( ArtifactFactory artifactFactory, ArtifactRepositoryFactory repositoryFactory, PlexusContainer container ) { this.artifactFactory = artifactFactory; + this.repositoryFactory = repositoryFactory; + this.container = container; } - public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) + public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) throws ArtifactMetadataRetrievalException { Model model = null; @@ -86,7 +101,20 @@ public class ProjectClasspathArtifactResolver { IOUtil.close( r ); } - return createArtifacts( model.getDependencies(), artifact.getScope() ); + + Set artifacts = createArtifacts( model.getDependencies(), artifact.getScope() ); + + List artifactRepositories; + try + { + artifactRepositories = ProjectUtils.buildArtifactRepositories( model.getRepositories(), repositoryFactory, container ); + } + catch ( ProjectBuildingException e ) + { + throw new ArtifactMetadataRetrievalException( e ); + } + + return new ResolutionGroup( artifacts, artifactRepositories ); } protected Set createArtifacts( List dependencies, String inheritedScope ) @@ -108,7 +136,7 @@ public class ProjectClasspathArtifactResolver return projectArtifacts; } } - + public void resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository ) throws ArtifactResolutionException { @@ -121,7 +149,7 @@ public class ProjectClasspathArtifactResolver throws ArtifactResolutionException { return super.resolveTransitively( artifacts, originatingArtifact, localRepository, remoteRepositories, - new Source( artifactFactory ), filter ); + new Source( artifactFactory, repositoryFactory, container ), filter ); } public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact, @@ -130,7 +158,13 @@ public class ProjectClasspathArtifactResolver throws ArtifactResolutionException { return super.resolveTransitively( artifacts, originatingArtifact, remoteRepositories, localRepository, - new Source( artifactFactory ) ); + new Source( artifactFactory, repositoryFactory, container ) ); + } + + public void contextualize( Context context ) + throws ContextException + { + this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); } } \ No newline at end of file diff --git a/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml b/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml index ee33a26b0b..161a3de9bd 100644 --- a/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml +++ b/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml @@ -24,6 +24,9 @@ org.apache.maven.artifact.factory.ArtifactFactory + + org.apache.maven.artifact.repository.ArtifactRepositoryFactory + org.apache.maven.artifact.resolver.ArtifactCollector