PR: MNG-1205

o Fixed unit test for resolving direct optional dependencies.
o Added isChildOfRootNode() method in ResolutionNode, to check whether the parent node's parent is null.
o Added check in the artifact collector to include optional artifacts if they are direct dependencies of the root node.



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@332213 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-11-10 03:14:08 +00:00
parent ed7cc01b88
commit 1bdeecccad
3 changed files with 8 additions and 4 deletions

View File

@ -82,7 +82,7 @@ public class DefaultArtifactCollector
if ( node.filterTrail( filter ) ) if ( node.filterTrail( filter ) )
{ {
// If it was optional, we don't add it or its children, just allow the update of the version and scope // If it was optional, we don't add it or its children, just allow the update of the version and scope
if ( !artifact.isOptional() ) if ( node.isChildOfRootNode() || !artifact.isOptional() )
{ {
artifact.setDependencyTrail( node.getDependencyTrail() ); artifact.setDependencyTrail( node.getDependencyTrail() );
@ -224,7 +224,7 @@ public class DefaultArtifactCollector
{ {
ResolutionNode child = (ResolutionNode) i.next(); ResolutionNode child = (ResolutionNode) i.next();
// We leave in optional ones, but don't pick up its dependencies // We leave in optional ones, but don't pick up its dependencies
if ( !child.isResolved() && !child.getArtifact().isOptional() ) if ( !child.isResolved() && ( !child.getArtifact().isOptional() || child.isChildOfRootNode() ) )
{ {
Artifact artifact = child.getArtifact(); Artifact artifact = child.getArtifact();
try try

View File

@ -146,6 +146,11 @@ public class ResolutionNode
{ {
return children != null; return children != null;
} }
public boolean isChildOfRootNode()
{
return parent != null && parent.parent == null;
}
public Iterator getChildrenIterator() public Iterator getChildrenIterator()
{ {

View File

@ -497,9 +497,8 @@ public class DefaultArtifactCollectorTest
throws ArtifactResolutionException, InvalidVersionSpecificationException throws ArtifactResolutionException, InvalidVersionSpecificationException
{ {
ArtifactSpec a = createArtifact( "a", "1.0" ); ArtifactSpec a = createArtifact( "a", "1.0" );
createArtifact( "b", "1.0", true );
ArtifactSpec b = createArtifact( "b", "1.0" ); ArtifactSpec b = createArtifact( "b", "1.0", true );
ArtifactResolutionResult res = collect( createSet( new Object[]{a.artifact, b.artifact} ) ); ArtifactResolutionResult res = collect( createSet( new Object[]{a.artifact, b.artifact} ) );
assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, b.artifact} ), res.getArtifacts() ); assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, b.artifact} ), res.getArtifacts() );