PR: MNG-1233

corrected handling of scope based exclusions

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@326363 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-10-19 03:53:10 +00:00
parent 15442309bd
commit 31f17512f5
3 changed files with 71 additions and 33 deletions

View File

@ -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] );
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}
}