mirror of
https://github.com/apache/maven.git
synced 2025-03-04 15:49:34 +00:00
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:
parent
c6ad9aa729
commit
c7d5e83520
@ -174,10 +174,10 @@ private ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact or
|
||||
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;
|
||||
|
@ -19,6 +19,7 @@
|
||||
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 void testTransitiveResolutionWhereAllArtifactsArePresentInTheLocalReposit
|
||||
|
||||
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 Set retrieve( Artifact artifact, ArtifactRepository localRepository, List
|
||||
dependencies.add( createArtifact( "org.apache.maven", "h", "1.0", "jar" ) );
|
||||
}
|
||||
|
||||
return dependencies;
|
||||
return new ResolutionGroup( dependencies, remoteRepositories );
|
||||
}
|
||||
};
|
||||
|
||||
@ -134,7 +135,7 @@ public void testTransitiveResolutionWhereAllArtifactsAreNotPresentInTheLocalRepo
|
||||
|
||||
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 Set retrieve( Artifact artifact, ArtifactRepository localRepository, List
|
||||
dependencies.add( createArtifact( "org.apache.maven", "j", "1.0", "jar" ) );
|
||||
}
|
||||
|
||||
return dependencies;
|
||||
return new ResolutionGroup( dependencies, remoteRepositories );
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -20,7 +20,6 @@
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
|
||||
@ -28,6 +27,6 @@
|
||||
*/
|
||||
public interface ArtifactMetadataSource
|
||||
{
|
||||
Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
|
||||
ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
|
||||
throws ArtifactMetadataRetrievalException;
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -16,10 +16,9 @@
|
||||
* 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 <a href="mailto:jason@maven.org">Jason van Zyl</a>
|
||||
@ -27,27 +26,41 @@
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -20,15 +20,14 @@
|
||||
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 ArtifactResolutionResult collect( Set artifacts, Artifact originatingArti
|
||||
{
|
||||
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 ArtifactResolutionResult collect( Set artifacts, Artifact originatingArti
|
||||
|
||||
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 @@ private void recurse( ResolutionNode node, Map resolvedArtifacts, Map managedVer
|
||||
{
|
||||
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 @@ private void fireEvent( int event, List listeners, ResolutionNode node, Artifact
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -20,6 +20,7 @@
|
||||
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 @@ private class Source
|
||||
{
|
||||
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,
|
||||
|
@ -19,6 +19,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.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 @@ private void ensurePluginContainerIsComplete( PluginDescriptor pluginDescriptor,
|
||||
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,
|
||||
|
@ -20,6 +20,7 @@
|
||||
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.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 Set retrieve( Artifact artifact, ArtifactRepository localRepository, List
|
||||
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,
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
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 @@ protected void setUp()
|
||||
|
||||
projectBuilder = (MavenProjectBuilder) lookup( MavenProjectBuilder.ROLE );
|
||||
artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
|
||||
artifactRepositoryFactory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
@ -100,7 +104,7 @@ protected MavenProject getProjectWithDependencies( File pom )
|
||||
throws Exception
|
||||
{
|
||||
return projectBuilder.buildWithDependencies( pom, getLocalRepository(),
|
||||
new ProjectClasspathArtifactResolver.Source( artifactFactory ),
|
||||
new ProjectClasspathArtifactResolver.Source( artifactFactory, artifactRepositoryFactory, getContainer() ),
|
||||
Collections.EMPTY_LIST );
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,9 @@
|
||||
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.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 @@
|
||||
|
||||
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 Set retrieve( Artifact artifact, ArtifactRepository localRepository, List
|
||||
{
|
||||
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 @@ protected Set createArtifacts( List dependencies, String inheritedScope )
|
||||
return projectArtifacts;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void resolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
|
||||
throws ArtifactResolutionException
|
||||
{
|
||||
@ -121,7 +149,7 @@ public ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact ori
|
||||
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 ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact ori
|
||||
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 );
|
||||
}
|
||||
|
||||
}
|
@ -24,6 +24,9 @@
|
||||
<requirement>
|
||||
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.artifact.repository.ArtifactRepositoryFactory</role>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<role>org.apache.maven.artifact.resolver.ArtifactCollector</role>
|
||||
</requirement>
|
||||
|
Loading…
x
Reference in New Issue
Block a user