[MNG-4696] [regression] MavenProject.getDependencyArtifacts() misses elements

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@949801 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2010-05-31 16:34:51 +00:00
parent bb39b48044
commit 9be1144e4e
2 changed files with 13 additions and 25 deletions

View File

@ -18,14 +18,15 @@ package org.apache.maven.lifecycle.internal;
import org.apache.maven.ProjectDependenciesResolver; import org.apache.maven.ProjectDependenciesResolver;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException; import org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException;
import org.apache.maven.execution.MavenSession; import org.apache.maven.execution.MavenSession;
import org.apache.maven.lifecycle.LifecycleExecutionException; import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.lifecycle.MavenExecutionPlan; import org.apache.maven.lifecycle.MavenExecutionPlan;
import org.apache.maven.model.Dependency;
import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProject;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.logging.Logger;
@ -50,6 +51,9 @@ public class LifecycleDependencyResolver
@Requirement @Requirement
private Logger logger; private Logger logger;
@Requirement
private ArtifactFactory artifactFactory;
@SuppressWarnings({"UnusedDeclaration"}) @SuppressWarnings({"UnusedDeclaration"})
public LifecycleDependencyResolver() public LifecycleDependencyResolver()
{ {
@ -117,16 +121,19 @@ public class LifecycleDependencyResolver
Set<Artifact> artifacts = Set<Artifact> artifacts =
getProjectDependencies( project, scopesToCollect, scopesToResolve, session, aggregating, getProjectDependencies( project, scopesToCollect, scopesToResolve, session, aggregating,
projectArtifacts ); projectArtifacts );
updateProjectArtifacts( project, artifacts );
}
private void updateProjectArtifacts( MavenProject project, Set<Artifact> artifacts )
{
project.setResolvedArtifacts( artifacts ); project.setResolvedArtifacts( artifacts );
if ( project.getDependencyArtifacts() == null ) if ( project.getDependencyArtifacts() == null )
{ {
project.setDependencyArtifacts( getDependencyArtifacts( project, artifacts ) ); try
{
project.setDependencyArtifacts( project.createArtifacts( artifactFactory, null, null ) );
}
catch ( InvalidDependencyVersionException e )
{
throw new LifecycleExecutionException( e );
}
} }
} }
@ -197,25 +204,6 @@ public class LifecycleDependencyResolver
return artifacts; return artifacts;
} }
private Set<Artifact> getDependencyArtifacts( MavenProject project, Set<Artifact> artifacts )
{
Set<String> directDependencies = new HashSet<String>( project.getDependencies().size() * 2 );
for ( Dependency dependency : project.getDependencies() )
{
directDependencies.add( dependency.getManagementKey() );
}
Set<Artifact> dependencyArtifacts = new LinkedHashSet<Artifact>( project.getDependencies().size() * 2 );
for ( Artifact artifact : artifacts )
{
if ( directDependencies.contains( artifact.getDependencyConflictId() ) )
{
dependencyArtifacts.add( artifact );
}
}
return dependencyArtifacts;
}
private boolean areAllArtifactsInReactor( Collection<MavenProject> projects, Collection<Artifact> artifacts ) private boolean areAllArtifactsInReactor( Collection<MavenProject> projects, Collection<Artifact> artifacts )
{ {
Set<String> projectKeys = getReactorProjectKeys( projects ); Set<String> projectKeys = getReactorProjectKeys( projects );