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
This commit is contained in:
John Dennis Casey 2005-07-16 01:24:13 +00:00
parent c6ad9aa729
commit c7d5e83520
13 changed files with 253 additions and 147 deletions

View File

@ -174,10 +174,10 @@ public class DefaultArtifactResolver
localRepository, remoteRepositories, source, filter, localRepository, remoteRepositories, source, filter,
artifactFactory, listeners ); artifactFactory, listeners );
for ( Iterator i = artifactResolutionResult.getArtifacts().iterator(); i.hasNext(); ) for ( Iterator i = artifactResolutionResult.getArtifactResolutionNodes().iterator(); i.hasNext(); )
{ {
Artifact artifact = (Artifact) i.next(); ResolutionNode node = (ResolutionNode) i.next();
resolve( artifact, remoteRepositories, localRepository ); resolve( node.getArtifact(), node.getRemoteRepositories(), localRepository );
} }
return artifactResolutionResult; return artifactResolutionResult;

View File

@ -19,6 +19,7 @@ package org.apache.maven.artifact.resolver;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactComponentTestCase; import org.apache.maven.artifact.ArtifactComponentTestCase;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource; 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.ArtifactRepository;
import java.util.ArrayList; import java.util.ArrayList;
@ -95,7 +96,7 @@ public class ArtifactResolverTest
ArtifactMetadataSource mds = new ArtifactMetadataSource() 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(); Set dependencies = new HashSet();
@ -104,7 +105,7 @@ public class ArtifactResolverTest
dependencies.add( createArtifact( "org.apache.maven", "h", "1.0", "jar" ) ); 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() 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(); Set dependencies = new HashSet();
@ -143,7 +144,7 @@ public class ArtifactResolverTest
dependencies.add( createArtifact( "org.apache.maven", "j", "1.0", "jar" ) ); dependencies.add( createArtifact( "org.apache.maven", "j", "1.0", "jar" ) );
} }
return dependencies; return new ResolutionGroup( dependencies, remoteRepositories );
} }
}; };

View File

@ -20,7 +20,6 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a> * @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
@ -28,6 +27,6 @@ import java.util.Set;
*/ */
public interface ArtifactMetadataSource public interface ArtifactMetadataSource
{ {
Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
throws ArtifactMetadataRetrievalException; throws ArtifactMetadataRetrievalException;
} }

View File

@ -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;
}
}

View File

@ -16,10 +16,9 @@ package org.apache.maven.artifact.resolver;
* limitations under the License. * limitations under the License.
*/ */
import java.util.HashMap; import java.util.HashSet;
import java.util.Map; import java.util.Iterator;
import java.util.Set; import java.util.Set;
import java.util.Collections;
/** /**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a> * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@ -27,27 +26,41 @@ import java.util.Collections;
*/ */
public class ArtifactResolutionResult public class ArtifactResolutionResult
{ {
private Set artifacts = Collections.EMPTY_SET; private Set resolutionNodes;
private Map conflicts;
// calculated.
private Set artifacts;
public ArtifactResolutionResult() public ArtifactResolutionResult()
{ {
conflicts = new HashMap();
} }
public Set getArtifacts() 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; 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;
} }
} }

View File

@ -20,15 +20,14 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource; 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.ArtifactRepository;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -60,8 +59,8 @@ public class DefaultArtifactCollector
{ {
Map resolvedArtifacts = new HashMap(); Map resolvedArtifacts = new HashMap();
ResolutionNode root = new ResolutionNode( originatingArtifact ); ResolutionNode root = new ResolutionNode( originatingArtifact, remoteRepositories );
root.addDependencies( artifacts, filter ); root.addDependencies( artifacts, remoteRepositories, filter );
recurse( root, resolvedArtifacts, managedVersions, localRepository, remoteRepositories, source, filter, recurse( root, resolvedArtifacts, managedVersions, localRepository, remoteRepositories, source, filter,
artifactFactory, listeners ); artifactFactory, listeners );
@ -77,13 +76,13 @@ public class DefaultArtifactCollector
artifact.setDependencyTrail( node.getDependencyTrail() ); artifact.setDependencyTrail( node.getDependencyTrail() );
set.add( artifact ); set.add( node );
} }
} }
ArtifactResolutionResult result = new ArtifactResolutionResult(); ArtifactResolutionResult result = new ArtifactResolutionResult();
result.setArtifacts( set ); result.setArtifactResolutionNodes( set );
return result; return result;
} }
@ -148,15 +147,17 @@ public class DefaultArtifactCollector
{ {
try try
{ {
Set artifacts = source.retrieve( child.getArtifact(), localRepository, remoteRepositories ); ResolutionGroup rGroup = source.retrieve( child.getArtifact(), localRepository, remoteRepositories );
child.addDependencies( artifacts, filter ); child.addDependencies( rGroup.getArtifacts(), rGroup.getResolutionRepositories(), filter );
} }
catch ( CyclicDependencyException e ) catch ( CyclicDependencyException e )
{ {
// would like to throw this, but we have crappy stuff in the repo // would like to throw this, but we have crappy stuff in the repo
// no logger to use here either just now // no logger to use here either just now
// TODO: should the remoteRepositories list be null here?!
fireEvent( ResolutionListener.OMIT_FOR_CYCLE, listeners, fireEvent( ResolutionListener.OMIT_FOR_CYCLE, listeners,
new ResolutionNode( e.getArtifact(), child ) ); new ResolutionNode( e.getArtifact(), null, child ) );
} }
catch ( ArtifactMetadataRetrievalException e ) 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;
}
}
} }

View File

@ -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;
}
}

View File

@ -20,6 +20,7 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource; 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.ArtifactRepository;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter; import org.apache.maven.artifact.resolver.filter.ExclusionSetFilter;
@ -339,12 +340,12 @@ public class DefaultArtifactCollectorTest
{ {
Map artifacts = new HashMap(); Map artifacts = new HashMap();
public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
throws ArtifactMetadataRetrievalException throws ArtifactMetadataRetrievalException
{ {
ArtifactSpec a = (ArtifactSpec) artifacts.get( artifact.getId() ); ArtifactSpec a = (ArtifactSpec) artifacts.get( artifact.getId() );
return createArtifacts( artifactFactory, a.dependencies, artifact.getScope(), return new ResolutionGroup( createArtifacts( artifactFactory, a.dependencies, artifact.getScope(),
artifact.getDependencyFilter() ); artifact.getDependencyFilter() ), Collections.EMPTY_LIST );
} }
private Set createArtifacts( ArtifactFactory artifactFactory, Set dependencies, String inheritedScope, private Set createArtifacts( ArtifactFactory artifactFactory, Set dependencies, String inheritedScope,

View File

@ -19,6 +19,7 @@ package org.apache.maven.plugin;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; 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.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
@ -423,8 +424,11 @@ public class DefaultPluginManager
remoteRepositories.addAll( project.getPluginArtifactRepositories() ); remoteRepositories.addAll( project.getPluginArtifactRepositories() );
ArtifactRepository localRepository = session.getLocalRepository(); ArtifactRepository localRepository = session.getLocalRepository();
Set dependencies = metadataSource.retrieve( pluginArtifact, localRepository,
ResolutionGroup resolutionGroup = metadataSource.retrieve( pluginArtifact, localRepository,
project.getPluginArtifactRepositories() ); project.getPluginArtifactRepositories() );
Set dependencies = resolutionGroup.getArtifacts();
ArtifactResolutionResult result = artifactResolver.resolveTransitively( dependencies, pluginArtifact, ArtifactResolutionResult result = artifactResolver.resolveTransitively( dependencies, pluginArtifact,
localRepository, localRepository,

View File

@ -20,6 +20,7 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource; 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.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.resolver.filter.AndArtifactFilter; 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.artifact.resolver.filter.ExcludesArtifactFilter;
import org.apache.maven.model.Dependency; import org.apache.maven.model.Dependency;
import org.apache.maven.model.Exclusion; 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.MavenProject;
import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException; import org.apache.maven.project.ProjectBuildingException;
@ -47,24 +47,17 @@ public class MavenMetadataSource
{ {
private MavenProjectBuilder mavenProjectBuilder; private MavenProjectBuilder mavenProjectBuilder;
private ArtifactResolver artifactResolver;
private ArtifactFactory artifactFactory; private ArtifactFactory artifactFactory;
/** // TODO: Remove resolver from params list.
* @todo remove.
*/
private MavenXpp3Reader reader = new MavenXpp3Reader();
public MavenMetadataSource( ArtifactResolver artifactResolver, MavenProjectBuilder projectBuilder, public MavenMetadataSource( ArtifactResolver artifactResolver, MavenProjectBuilder projectBuilder,
ArtifactFactory artifactFactory ) ArtifactFactory artifactFactory )
{ {
this.artifactResolver = artifactResolver;
this.mavenProjectBuilder = projectBuilder; this.mavenProjectBuilder = projectBuilder;
this.artifactFactory = artifactFactory; this.artifactFactory = artifactFactory;
} }
public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
throws ArtifactMetadataRetrievalException throws ArtifactMetadataRetrievalException
{ {
// TODO: only metadata is really needed - resolve as metadata // TODO: only metadata is really needed - resolve as metadata
@ -82,12 +75,15 @@ public class MavenMetadataSource
localRepository ); localRepository );
dependencies = p.getDependencies(); dependencies = p.getDependencies();
artifact.setDownloadUrl( pomArtifact.getDownloadUrl() ); artifact.setDownloadUrl( pomArtifact.getDownloadUrl() );
Set artifacts = createArtifacts( artifactFactory, dependencies, artifact.getScope(), artifact.getDependencyFilter() );
return new ResolutionGroup( artifacts, p.getRemoteArtifactRepositories() );
} }
catch ( ProjectBuildingException e ) catch ( ProjectBuildingException e )
{ {
throw new ArtifactMetadataRetrievalException( "Unable to read the metadata file", 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, public static Set createArtifacts( ArtifactFactory artifactFactory, List dependencies, String inheritedScope,

View File

@ -18,6 +18,7 @@ package org.apache.maven.project;
import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository; 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.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.PlexusTestCase;
@ -38,6 +39,8 @@ public abstract class MavenProjectTestCase
private ArtifactFactory artifactFactory; private ArtifactFactory artifactFactory;
private ArtifactRepositoryFactory artifactRepositoryFactory;
protected void setUp() protected void setUp()
throws Exception throws Exception
{ {
@ -45,6 +48,7 @@ public abstract class MavenProjectTestCase
projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE ); projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
artifactRepositoryFactory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
@ -100,7 +104,7 @@ public abstract class MavenProjectTestCase
throws Exception throws Exception
{ {
return projectBuilder.buildWithDependencies( pom, getLocalRepository(), return projectBuilder.buildWithDependencies( pom, getLocalRepository(),
new ProjectClasspathArtifactResolver.Source( artifactFactory ), new ProjectClasspathArtifactResolver.Source( artifactFactory, artifactRepositoryFactory, getContainer() ),
Collections.EMPTY_LIST ); Collections.EMPTY_LIST );
} }

View File

@ -20,7 +20,9 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource; 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.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.DefaultArtifactResolver; 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.Dependency;
import org.apache.maven.model.Model; import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; 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.IOUtil;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@ -41,18 +48,26 @@ import java.util.Set;
public class ProjectClasspathArtifactResolver public class ProjectClasspathArtifactResolver
extends DefaultArtifactResolver extends DefaultArtifactResolver
implements Contextualizable
{ {
private ArtifactRepositoryFactory repositoryFactory;
private PlexusContainer container;
public static class Source public static class Source
implements ArtifactMetadataSource implements ArtifactMetadataSource
{ {
private ArtifactFactory artifactFactory; 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.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 throws ArtifactMetadataRetrievalException
{ {
Model model = null; Model model = null;
@ -86,7 +101,20 @@ public class ProjectClasspathArtifactResolver
{ {
IOUtil.close( r ); 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 ) protected Set createArtifacts( List dependencies, String inheritedScope )
@ -108,7 +136,7 @@ public class ProjectClasspathArtifactResolver
return projectArtifacts; return projectArtifacts;
} }
} }
public void resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository ) public void resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
throws ArtifactResolutionException throws ArtifactResolutionException
{ {
@ -121,7 +149,7 @@ public class ProjectClasspathArtifactResolver
throws ArtifactResolutionException throws ArtifactResolutionException
{ {
return super.resolveTransitively( artifacts, originatingArtifact, localRepository, remoteRepositories, return super.resolveTransitively( artifacts, originatingArtifact, localRepository, remoteRepositories,
new Source( artifactFactory ), filter ); new Source( artifactFactory, repositoryFactory, container ), filter );
} }
public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact, public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact,
@ -130,7 +158,13 @@ public class ProjectClasspathArtifactResolver
throws ArtifactResolutionException throws ArtifactResolutionException
{ {
return super.resolveTransitively( artifacts, originatingArtifact, remoteRepositories, localRepository, 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 );
} }
} }

View File

@ -24,6 +24,9 @@
<requirement> <requirement>
<role>org.apache.maven.artifact.factory.ArtifactFactory</role> <role>org.apache.maven.artifact.factory.ArtifactFactory</role>
</requirement> </requirement>
<requirement>
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
</requirement>
<requirement> <requirement>
<role>org.apache.maven.artifact.resolver.ArtifactCollector</role> <role>org.apache.maven.artifact.resolver.ArtifactCollector</role>
</requirement> </requirement>