for ( Version version : versions )
{
Artifact originalArtifact = dependency.getArtifact().setVersion( version.toString() );
Dependency d = dependency.setArtifact( originalArtifact );
ArtifactDescriptorResult descriptorResult;
try
{
ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
descriptorRequest.setArtifact( d.getArtifact() );
descriptorRequest.setRepositories( repositories );
descriptorRequest.setRequestContext( result.getRequest().getRequestContext() );
descriptorRequest.setTrace( trace );
if ( noDescriptor )
{
descriptorResult = new ArtifactDescriptorResult( descriptorRequest );
}
else
{
Object key = pool.toKey( descriptorRequest );
descriptorResult = pool.getDescriptor( key, descriptorRequest );
if ( descriptorResult == null )
{
descriptorResult = descriptorReader.readArtifactDescriptor( session, descriptorRequest );
pool.putDescriptor( key, descriptorResult );
}
}
}
catch ( ArtifactDescriptorException e )
{
result.addException( e );
continue;
}
d = d.setArtifact( descriptorResult.getArtifact() );
if ( findDuplicate( edges, d.getArtifact() ) != null )
{
cycle = true;
continue;
}
if ( !descriptorResult.getRelocations().isEmpty() )
{
relocations = descriptorResult.getRelocations();
disableVersionManagement =
originalArtifact.getGroupId().equals( d.getArtifact().getGroupId() )
&& originalArtifact.getArtifactId().equals( d.getArtifact().getArtifactId() );
dependency = d;
continue thisDependency;
}
d = pool.intern( d.setArtifact( pool.intern( d.getArtifact() ) ) );
DependencySelector childSelector = null;
DependencyManager childManager = null;
DependencyTraverser childTraverser = null;
List<RemoteRepository> childRepos = null;
Object key = null;
boolean recurse = traverse && !descriptorResult.getDependencies().isEmpty();
if ( recurse )
{
DefaultDependencyCollectionContext context =
new DefaultDependencyCollectionContext( session, d,
descriptorResult.getManagedDependencies() );
childSelector = depSelector.deriveChildSelector( context );
childManager = depManager.deriveChildManager( context );
childTraverser = depTraverser.deriveChildTraverser( context );
childRepos =
remoteRepositoryManager.aggregateRepositories( session, repositories,
descriptorResult.getRepositories(), true );
key = pool.toKey( d.getArtifact(), childRepos, childSelector, childManager, childTraverser );
}
else
{
key = pool.toKey( d.getArtifact(), repositories );
}
List<RemoteRepository> repos;
ArtifactRepository repo = rangeResult.getRepository( version );
if ( repo instanceof RemoteRepository )
{
repos = Collections.singletonList( (RemoteRepository) repo );
}
else if ( repo == null )
{
repos = repositories;
}
else
{
repos = Collections.emptyList();
}
boolean cacheNode = false;
GraphNode child = pool.getNode( key );
if ( child == null )
{
child = new GraphNode();
child.setAliases( descriptorResult.getAliases() );
child.setRepositories( repos );
cacheNode = true;
}
else
{
recurse = false;
if ( repos.size() < child.getRepositories().size() )
{
child.setRepositories( repos );
}
}
GraphNode node = edges.getFirst().getTarget();
GraphEdge edge = new GraphEdge( node, child );
edge.setDependency( d );
edge.setScope( d.getScope() );
edge.setPremanagedScope( premanagedScope );
edge.setPremanagedVersion( premanagedVersion );
edge.setRelocations( relocations );
edge.setVersionConstraint( rangeResult.getVersionConstraint() );
edge.setVersion( version );
edge.setRequestContext( result.getRequest().getRequestContext() );
node.getOutgoingEdges().add( edge );
if ( recurse )
{
edges.addFirst( edge );
if ( process( session, trace, result, edges, descriptorResult.getDependencies(), childRepos,
childSelector, childManager, childTraverser, pool ) )
{
cycle = true;
cacheNode = false;
}