Map managedVersions, ArtifactResolutionRequest repositoryRequest,
ArtifactMetadataSource source, ArtifactFilter filter,
List<ResolutionListener> listeners,
List<ConflictResolver> conflictResolvers )
{
ArtifactResolutionResult result = new ArtifactResolutionResult();
result.setOriginatingArtifact( originatingArtifact );
if ( conflictResolvers == null )
{
conflictResolvers = Collections.singletonList( defaultConflictResolver );
}
Map<Object, List<ResolutionNode>> resolvedArtifacts = new LinkedHashMap<Object, List<ResolutionNode>>();
ResolutionNode root = new ResolutionNode( originatingArtifact, repositoryRequest.getRemoteRepositories() );
try
{
root.addDependencies( artifacts, repositoryRequest.getRemoteRepositories(), filter );
}
catch ( CyclicDependencyException e )
{
result.addCircularDependencyException( e );
return result;
}
catch ( OverConstrainedVersionException e )
{
result.addVersionRangeViolation( e );
return result;
}
ManagedVersionMap versionMap = getManagedVersionsMap( originatingArtifact, managedVersions );
try
{
recurse( result, root, resolvedArtifacts, versionMap, repositoryRequest, source, filter, listeners,
conflictResolvers );
}
catch ( CyclicDependencyException e )
{
logger.debug( "While recursing: " + e.getMessage(), e );
result.addCircularDependencyException( e );
}
catch ( OverConstrainedVersionException e )
{
logger.debug( "While recursing: " + e.getMessage(), e );
result.addVersionRangeViolation( e );
}
catch ( ArtifactResolutionException e )
{
logger.debug( "While recursing: " + e.getMessage(), e );
result.addErrorArtifactException( e );
}
Set<ResolutionNode> set = new LinkedHashSet<ResolutionNode>();
for ( List<ResolutionNode> nodes : resolvedArtifacts.values() )
{
for ( ResolutionNode node : nodes )
{
if ( !node.equals( root ) && node.isActive() )
{
Artifact artifact = node.getArtifact();
try
{
if ( node.filterTrail( filter ) )
{
// If it was optional and not a direct dependency,
// we don't add it or its children, just allow the update of the version and artifactScope
if ( node.isChildOfRootNode() || !artifact.isOptional() )
{
artifact.setDependencyTrail( node.getDependencyTrail() );
set.add( node );
// This is required right now.
result.addArtifact( artifact );
}
}
}
catch ( OverConstrainedVersionException e )
{
result.addVersionRangeViolation( e );
}
}
}
}
result.setArtifactResolutionNodes( set );
return result;
}