ArtifactResolutionRequest collectionRequest = request;
if ( request.isResolveTransitively() )
{
MetadataResolutionRequest metadataRequest = new DefaultMetadataResolutionRequest( request );
metadataRequest.setArtifact( rootArtifact );
metadataRequest.setResolveManagedVersions( managedVersions == null );
try
{
ResolutionGroup resolutionGroup = source.retrieve( metadataRequest );
if ( managedVersions == null )
{
managedVersions = resolutionGroup.getManagedVersions();
}
Set<Artifact> directArtifacts = resolutionGroup.getArtifacts();
if ( artifacts == null || artifacts.isEmpty() )
{
artifacts = directArtifacts;
}
else
{
List<Artifact> allArtifacts = new ArrayList<Artifact>();
allArtifacts.addAll( artifacts );
allArtifacts.addAll( directArtifacts );
Map<String, Artifact> mergedArtifacts = new LinkedHashMap<String, Artifact>();
for ( Artifact artifact : allArtifacts )
{
String conflictId = artifact.getDependencyConflictId();
if ( !mergedArtifacts.containsKey( conflictId ) )
{
mergedArtifacts.put( conflictId, artifact );
}
}
artifacts = new LinkedHashSet<Artifact>( mergedArtifacts.values() );
}
collectionRequest = new ArtifactResolutionRequest( request );
collectionRequest.setServers( request.getServers() );
collectionRequest.setMirrors( request.getMirrors() );
collectionRequest.setProxies( request.getProxies() );
collectionRequest.setRemoteRepositories( resolutionGroup.getResolutionRepositories() );
}
catch ( ArtifactMetadataRetrievalException e )
{
ArtifactResolutionException are =
new ArtifactResolutionException( "Unable to get dependency information for " + rootArtifact.getId()
+ ": " + e.getMessage(), rootArtifact, metadataRequest.getRemoteRepositories(), e );
result.addMetadataResolutionException( are );
return result;
}
}