o Fixed resolution of transitive dependencies

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@813805 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-09-11 12:31:00 +00:00
parent 0553695bcb
commit 552a920fb0
4 changed files with 59 additions and 13 deletions

View File

@ -59,10 +59,10 @@ public class ArtifactResolutionResult
private List<ArtifactRepository> repositories;
private Set<Artifact> requestedArtifacts;
private Set<Artifact> artifacts;
private Set<ResolutionNode> resolutionNodes;
public Artifact getOriginatingArtifact()
{
return originatingArtifact;
@ -100,19 +100,19 @@ public class ArtifactResolutionResult
this.artifacts = artifacts;
}
public void addRequestedArtifact( Artifact artifact )
public Set<ResolutionNode> getResolutionNodes()
{
if ( requestedArtifacts == null )
if ( resolutionNodes == null )
{
requestedArtifacts = new LinkedHashSet<Artifact>();
resolutionNodes = new LinkedHashSet<ResolutionNode>();
}
requestedArtifacts.add( artifact );
return resolutionNodes;
}
public Set<Artifact> getRequestedArtifacts()
public void setResolutionNodes( Set<ResolutionNode> resolutionNodes )
{
return requestedArtifacts;
this.resolutionNodes = resolutionNodes;
}
public boolean hasMissingArtifacts()

View File

@ -493,15 +493,21 @@ public class DefaultArtifactResolver
return result;
}
if ( result.getArtifacts() != null )
if ( result.getResolutionNodes() != null )
{
for ( Artifact artifact : result.getArtifacts() )
ArtifactResolutionRequest childRequest = new ArtifactResolutionRequest( request );
for ( ResolutionNode node : result.getResolutionNodes() )
{
Artifact artifact = node.getArtifact();
try
{
if ( resolutionFilter == null || resolutionFilter.include( artifact ) )
{
resolve( artifact, request, request.getTransferListener(), false );
childRequest.setRemoteRepositories( node.getRemoteRepositories() );
resolve( artifact, childRequest, request.getTransferListener(), false );
}
}
catch ( ArtifactNotFoundException anfe )

View File

@ -170,7 +170,6 @@ public class DefaultLegacyArtifactCollector
// This is required right now.
result.addArtifact( artifact );
result.addRequestedArtifact( artifact );
}
}
}
@ -182,6 +181,8 @@ public class DefaultLegacyArtifactCollector
}
}
result.setResolutionNodes( set );
return result;
}

View File

@ -20,6 +20,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
@ -137,6 +138,8 @@ public class MavenMetadataSource
List<Dependency> managedDependencies = null;
List<ArtifactRepository> pomRepositories = null;
Artifact pomArtifact;
Artifact relocatedArtifact = null;
@ -177,6 +180,8 @@ public class MavenMetadataSource
DependencyManagement depMngt = rel.project.getDependencyManagement();
managedDependencies = ( depMngt != null ) ? depMngt.getDependencies() : null;
pomRepositories = rel.project.getRemoteArtifactRepositories();
}
}
@ -211,8 +216,11 @@ public class MavenMetadataSource
}
}
List<ArtifactRepository> aggregatedRepositories =
aggregateRepositories( request.getRemoteRepositories(), pomRepositories );
ResolutionGroup result =
new ResolutionGroup( pomArtifact, relocatedArtifact, artifacts, managedVersions, request.getRemoteRepositories() );
new ResolutionGroup( pomArtifact, relocatedArtifact, artifacts, managedVersions, aggregatedRepositories );
cache.put( artifact, request.isResolveManagedVersions(), request.getLocalRepository(),
request.getRemoteRepositories(), result );
@ -220,6 +228,37 @@ public class MavenMetadataSource
return result;
}
private List<ArtifactRepository> aggregateRepositories( List<ArtifactRepository> requestRepositories,
List<ArtifactRepository> pomRepositories )
{
List<ArtifactRepository> repositories = requestRepositories;
if ( pomRepositories != null && !pomRepositories.isEmpty() )
{
Map<String, ArtifactRepository> repos = new LinkedHashMap<String, ArtifactRepository>();
for ( ArtifactRepository repo : requestRepositories )
{
if ( !repos.containsKey( repo.getId() ) )
{
repos.put( repo.getId(), repo );
}
}
for ( ArtifactRepository repo : pomRepositories )
{
if ( !repos.containsKey( repo.getId() ) )
{
repos.put( repo.getId(), repo );
}
}
repositories = new ArrayList<ArtifactRepository>( repos.values() );
}
return repositories;
}
private Artifact createDependencyArtifact( Dependency dependency, Artifact owner, Artifact pom )
throws ArtifactMetadataRetrievalException
{