diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java index d58d88be70..4547c66cb6 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java @@ -79,12 +79,15 @@ public class DefaultArtifactCollector { Artifact artifact = node.getArtifact(); - // If it was optional, we don't add it or its children, just allow the update of the version and scope - if ( !node.getArtifact().isOptional() ) + if ( node.filterTrail( filter ) ) { - artifact.setDependencyTrail( node.getDependencyTrail() ); + // If it was optional, we don't add it or its children, just allow the update of the version and scope + if ( !artifact.isOptional() ) + { + artifact.setDependencyTrail( node.getDependencyTrail() ); - set.add( node ); + set.add( node ); + } } } } @@ -165,10 +168,12 @@ public class DefaultArtifactCollector for ( int j = 0; j < 2; j++ ) { Artifact resetArtifact = resetNodes[j].getArtifact(); - if ( resetArtifact.getVersion() == null && resetArtifact.getVersionRange() != null && resetArtifact.getAvailableVersions() != null ) + if ( resetArtifact.getVersion() == null && resetArtifact.getVersionRange() != null && + resetArtifact.getAvailableVersions() != null ) { - resetArtifact.selectVersion( resetArtifact.getVersionRange().matchVersion( resetArtifact.getAvailableVersions() ).toString() ); + resetArtifact.selectVersion( resetArtifact.getVersionRange().matchVersion( + resetArtifact.getAvailableVersions() ).toString() ); fireEvent( ResolutionListener.SELECT_VERSION_FROM_RANGE, listeners, resetNodes[j] ); } } diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java index d47f880de7..ef477942d7 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java @@ -19,7 +19,6 @@ package org.apache.maven.artifact.resolver; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.versioning.OverConstrainedVersionException; -import org.apache.maven.artifact.versioning.VersionRange; import java.util.ArrayList; import java.util.Collections; @@ -44,6 +43,8 @@ public class ResolutionNode private boolean active = true; + private List trail; + public ResolutionNode( Artifact artifact, List remoteRepositories ) { this.artifact = artifact; @@ -85,45 +86,60 @@ public class ResolutionNode { Artifact a = (Artifact) i.next(); - if ( filter == null || filter.include( a ) ) + if ( parents.contains( a.getDependencyConflictId() ) ) { - if ( parents.contains( a.getDependencyConflictId() ) ) - { - a.setDependencyTrail( getDependencyTrail() ); + a.setDependencyTrail( getDependencyTrail() ); - throw new CyclicDependencyException( "A dependency has introduced a cycle", a ); - } - - children.add( new ResolutionNode( a, remoteRepositories, this ) ); + throw new CyclicDependencyException( "A dependency has introduced a cycle", a ); } + + children.add( new ResolutionNode( a, remoteRepositories, this ) ); } } else { children = Collections.EMPTY_LIST; } + trail = null; } public List getDependencyTrail() throws OverConstrainedVersionException { - List path = new LinkedList(); - ResolutionNode node = this; - while ( node != null ) - { - Artifact artifact = node.getArtifact(); - if ( artifact.getVersion() == null ) - { - // set the recommended version - VersionRange versionRange = artifact.getVersionRange(); - String version = artifact.getSelectedVersion().toString(); - artifact.selectVersion( version ); - } + List trial = getTrail(); - path.add( 0, artifact.getId() ); - node = node.parent; + List ret = new ArrayList( trial.size() ); + for ( Iterator i = trial.iterator(); i.hasNext(); ) + { + Artifact artifact = (Artifact) i.next(); + ret.add( artifact.getId() ); } - return path; + return ret; + } + + private List getTrail() + throws OverConstrainedVersionException + { + if ( trail == null ) + { + List ids = new LinkedList(); + ResolutionNode node = this; + while ( node != null ) + { + Artifact artifact = node.getArtifact(); + if ( artifact.getVersion() == null ) + { + // set the recommended version + String version = artifact.getSelectedVersion().toString(); + artifact.selectVersion( version ); + } + + ids.add( 0, artifact ); + node = node.parent; + } + trail = ids; + } + return trail; } public boolean isResolved() @@ -177,4 +193,22 @@ public class ResolutionNode } } } + + public boolean filterTrail( ArtifactFilter filter ) + throws OverConstrainedVersionException + { + boolean success = true; + if ( filter != null ) + { + for ( Iterator i = getTrail().iterator(); i.hasNext() && success; ) + { + Artifact artifact = (Artifact) i.next(); + if ( !filter.include( artifact ) ) + { + success = false; + } + } + } + return success; + } } diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilter.java b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilter.java index da9442cfdd..86086d9a1a 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilter.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/filter/ScopeArtifactFilter.java @@ -35,7 +35,7 @@ public class ScopeArtifactFilter private final boolean testScope; private final boolean providedScope; - + private final boolean systemScope; public ScopeArtifactFilter( String scope ) @@ -98,8 +98,7 @@ public class ScopeArtifactFilter } else { - // TODO: should this be true? Does it even happen? - return false; + return true; } } }