[MNG-5135] Regression: in some cases aggregator mojo is unable to resolve dependencies with custom packaging

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1151424 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2011-07-27 10:48:35 +00:00
parent 4be95217be
commit e877a035d7
1 changed files with 42 additions and 28 deletions

View File

@ -93,41 +93,55 @@ public class LifecycleDependencyResolver
boolean aggregating, Set<Artifact> projectArtifacts )
throws LifecycleExecutionException
{
if ( project.getDependencyArtifacts() == null )
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
try
{
try
ClassLoader projectRealm = project.getClassRealm();
if ( projectRealm != null && projectRealm != tccl )
{
project.setDependencyArtifacts( project.createArtifacts( artifactFactory, null, null ) );
Thread.currentThread().setContextClassLoader( projectRealm );
}
catch ( InvalidDependencyVersionException e )
if ( project.getDependencyArtifacts() == null )
{
throw new LifecycleExecutionException( e );
}
}
Set<Artifact> artifacts =
getDependencies( project, scopesToCollect, scopesToResolve, session, aggregating, projectArtifacts );
project.setResolvedArtifacts( artifacts );
Map<String, Artifact> map = new HashMap<String, Artifact>();
for ( Artifact artifact : artifacts )
{
map.put( artifact.getDependencyConflictId(), artifact );
}
for ( Artifact artifact : project.getDependencyArtifacts() )
{
if ( artifact.getFile() == null )
{
Artifact resolved = map.get( artifact.getDependencyConflictId() );
if ( resolved != null )
try
{
artifact.setFile( resolved.getFile() );
artifact.setDependencyTrail( resolved.getDependencyTrail() );
artifact.setResolvedVersion( resolved.getVersion() );
artifact.setResolved( true );
project.setDependencyArtifacts( project.createArtifacts( artifactFactory, null, null ) );
}
catch ( InvalidDependencyVersionException e )
{
throw new LifecycleExecutionException( e );
}
}
Set<Artifact> artifacts =
getDependencies( project, scopesToCollect, scopesToResolve, session, aggregating, projectArtifacts );
project.setResolvedArtifacts( artifacts );
Map<String, Artifact> map = new HashMap<String, Artifact>();
for ( Artifact artifact : artifacts )
{
map.put( artifact.getDependencyConflictId(), artifact );
}
for ( Artifact artifact : project.getDependencyArtifacts() )
{
if ( artifact.getFile() == null )
{
Artifact resolved = map.get( artifact.getDependencyConflictId() );
if ( resolved != null )
{
artifact.setFile( resolved.getFile() );
artifact.setDependencyTrail( resolved.getDependencyTrail() );
artifact.setResolvedVersion( resolved.getVersion() );
artifact.setResolved( true );
}
}
}
}
finally
{
Thread.currentThread().setContextClassLoader( tccl );
}
}