mirror of https://github.com/apache/maven.git
[MNG-1895] merge changes from branch
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@379650 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
578764fba6
commit
806eaeb017
|
@ -81,7 +81,7 @@ public class DefaultArtifactCollector
|
||||||
|
|
||||||
if ( node.filterTrail( filter ) )
|
if ( node.filterTrail( filter ) )
|
||||||
{
|
{
|
||||||
// If it was optional and not a direct dependency,
|
// If it was optional and not a direct dependency,
|
||||||
// we don't add it or its children, just allow the update of the version and scope
|
// we don't add it or its children, just allow the update of the version and scope
|
||||||
if ( node.isChildOfRootNode() || !artifact.isOptional() )
|
if ( node.isChildOfRootNode() || !artifact.isOptional() )
|
||||||
{
|
{
|
||||||
|
@ -137,18 +137,7 @@ public class DefaultArtifactCollector
|
||||||
VersionRange previousRange = previous.getArtifact().getVersionRange();
|
VersionRange previousRange = previous.getArtifact().getVersionRange();
|
||||||
VersionRange currentRange = node.getArtifact().getVersionRange();
|
VersionRange currentRange = node.getArtifact().getVersionRange();
|
||||||
|
|
||||||
// TODO: why do we force the version on it? what if they don't match?
|
if ( previousRange != null && currentRange != null )
|
||||||
if ( previousRange == null )
|
|
||||||
{
|
|
||||||
// version was already resolved
|
|
||||||
node.getArtifact().setVersion( previous.getArtifact().getVersion() );
|
|
||||||
}
|
|
||||||
else if ( currentRange == null )
|
|
||||||
{
|
|
||||||
// version was already resolved
|
|
||||||
previous.getArtifact().setVersion( node.getArtifact().getVersion() );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// TODO: shouldn't need to double up on this work, only done for simplicity of handling recommended
|
// TODO: shouldn't need to double up on this work, only done for simplicity of handling recommended
|
||||||
// version but the restriction is identical
|
// version but the restriction is identical
|
||||||
|
@ -185,7 +174,8 @@ public class DefaultArtifactCollector
|
||||||
|
|
||||||
// TODO: should this be part of mediation?
|
// TODO: should this be part of mediation?
|
||||||
// previous one is more dominant
|
// previous one is more dominant
|
||||||
ResolutionNode nearest, farthest;
|
ResolutionNode nearest;
|
||||||
|
ResolutionNode farthest;
|
||||||
if ( previous.getDepth() <= node.getDepth() )
|
if ( previous.getDepth() <= node.getDepth() )
|
||||||
{
|
{
|
||||||
nearest = previous;
|
nearest = previous;
|
||||||
|
@ -197,11 +187,9 @@ public class DefaultArtifactCollector
|
||||||
farthest = previous;
|
farthest = previous;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if we need to update scope of nearest to use farthest scope */
|
|
||||||
if ( checkScopeUpdate( farthest, nearest, listeners ) )
|
if ( checkScopeUpdate( farthest, nearest, listeners ) )
|
||||||
{
|
{
|
||||||
fireEvent( ResolutionListener.UPDATE_SCOPE, listeners, nearest, farthest.getArtifact() );
|
// if we need to update scope of nearest to use farthest scope, use the nearest version, but farthest scope
|
||||||
/* we need nearest version but farthest scope */
|
|
||||||
nearest.disable();
|
nearest.disable();
|
||||||
farthest.getArtifact().setVersion( nearest.getArtifact().getVersion() );
|
farthest.getArtifact().setVersion( nearest.getArtifact().getVersion() );
|
||||||
}
|
}
|
||||||
|
@ -321,13 +309,14 @@ public class DefaultArtifactCollector
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the scope of the nearest needs to be updated with the scope of the farthest.
|
* Check if the scope needs to be updated.
|
||||||
* <a href="http://docs.codehaus.org/x/IGU#DependencyMediationandConflictResolution-Scoperesolution">More info</a>.
|
* <a href="http://docs.codehaus.org/x/IGU#DependencyMediationandConflictResolution-Scoperesolution">More info</a>.
|
||||||
* @param farthest farthest resolution node
|
*
|
||||||
* @param nearest nearest resolution node
|
* @param farthest farthest resolution node
|
||||||
|
* @param nearest nearest resolution node
|
||||||
* @param listeners
|
* @param listeners
|
||||||
*/
|
*/
|
||||||
private boolean checkScopeUpdate( ResolutionNode farthest, ResolutionNode nearest, List listeners )
|
boolean checkScopeUpdate( ResolutionNode farthest, ResolutionNode nearest, List listeners )
|
||||||
{
|
{
|
||||||
boolean updateScope = false;
|
boolean updateScope = false;
|
||||||
Artifact farthestArtifact = farthest.getArtifact();
|
Artifact farthestArtifact = farthest.getArtifact();
|
||||||
|
@ -354,6 +343,16 @@ public class DefaultArtifactCollector
|
||||||
fireEvent( ResolutionListener.UPDATE_SCOPE_CURRENT_POM, listeners, nearest, farthestArtifact );
|
fireEvent( ResolutionListener.UPDATE_SCOPE_CURRENT_POM, listeners, nearest, farthestArtifact );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( updateScope )
|
||||||
|
{
|
||||||
|
fireEvent( ResolutionListener.UPDATE_SCOPE, listeners, nearest, farthestArtifact );
|
||||||
|
|
||||||
|
// previously we cloned the artifact, but it is more effecient to just update the scope
|
||||||
|
// if problems are later discovered that the original object needs its original scope value, cloning may
|
||||||
|
// again be appropriate
|
||||||
|
nearestArtifact.setScope( farthestArtifact.getScope() );
|
||||||
|
}
|
||||||
|
|
||||||
return updateScope;
|
return updateScope;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,7 @@ public class ResolutionNode
|
||||||
{
|
{
|
||||||
return children != null;
|
return children != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isChildOfRootNode()
|
public boolean isChildOfRootNode()
|
||||||
{
|
{
|
||||||
return parent != null && parent.parent == null;
|
return parent != null && parent.parent == null;
|
||||||
|
@ -219,7 +219,7 @@ public class ResolutionNode
|
||||||
|
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return artifact.toString() + " (" + depth + ")";
|
return artifact.toString() + " (" + depth + "; " + ( active ? "enabled" : "disabled" ) + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,17 +16,6 @@ package org.apache.maven.artifact.resolver;
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||||
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||||
|
@ -41,6 +30,17 @@ import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException
|
||||||
import org.apache.maven.artifact.versioning.VersionRange;
|
import org.apache.maven.artifact.versioning.VersionRange;
|
||||||
import org.codehaus.plexus.PlexusTestCase;
|
import org.codehaus.plexus.PlexusTestCase;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the default artifact collector.
|
* Test the default artifact collector.
|
||||||
*
|
*
|
||||||
|
@ -504,8 +504,8 @@ public class DefaultArtifactCollectorTest
|
||||||
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() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testScopeUpdate( )
|
public void testScopeUpdate()
|
||||||
throws InvalidVersionSpecificationException, ArtifactResolutionException
|
throws InvalidVersionSpecificationException, ArtifactResolutionException
|
||||||
{
|
{
|
||||||
/* farthest = compile */
|
/* farthest = compile */
|
||||||
|
@ -543,7 +543,7 @@ public class DefaultArtifactCollectorTest
|
||||||
checkScopeUpdate( Artifact.SCOPE_TEST, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_SYSTEM );
|
checkScopeUpdate( Artifact.SCOPE_TEST, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_SYSTEM );
|
||||||
checkScopeUpdate( Artifact.SCOPE_TEST, Artifact.SCOPE_TEST, Artifact.SCOPE_TEST );
|
checkScopeUpdate( Artifact.SCOPE_TEST, Artifact.SCOPE_TEST, Artifact.SCOPE_TEST );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkScopeUpdate( String farthestScope, String nearestScope, String expectedScope )
|
private void checkScopeUpdate( String farthestScope, String nearestScope, String expectedScope )
|
||||||
throws ArtifactResolutionException, InvalidVersionSpecificationException
|
throws ArtifactResolutionException, InvalidVersionSpecificationException
|
||||||
{
|
{
|
||||||
|
@ -560,13 +560,13 @@ public class DefaultArtifactCollectorTest
|
||||||
a.addDependency( c );
|
a.addDependency( c );
|
||||||
ArtifactSpec dNearest = createArtifact( "d", "2.0" );
|
ArtifactSpec dNearest = createArtifact( "d", "2.0" );
|
||||||
b.addDependency( dNearest );
|
b.addDependency( dNearest );
|
||||||
ArtifactSpec dFarthest = createArtifact( "d", "2.0", farthestScope );
|
ArtifactSpec dFarthest = createArtifact( "d", "3.0", farthestScope );
|
||||||
c.addDependency( dFarthest );
|
c.addDependency( dFarthest );
|
||||||
|
|
||||||
/* system and provided dependencies are not transitive */
|
/* system and provided dependencies are not transitive */
|
||||||
if ( !Artifact.SCOPE_SYSTEM.equals( nearestScope ) && !Artifact.SCOPE_PROVIDED.equals( nearestScope ) )
|
if ( !Artifact.SCOPE_SYSTEM.equals( nearestScope ) && !Artifact.SCOPE_PROVIDED.equals( nearestScope ) )
|
||||||
{
|
{
|
||||||
checkScopeUpdate( a, b, expectedScope );
|
checkScopeUpdate( a, b, expectedScope, "2.0" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,13 +579,13 @@ public class DefaultArtifactCollectorTest
|
||||||
a.addDependency( c );
|
a.addDependency( c );
|
||||||
ArtifactSpec dNearest = createArtifact( "d", "2.0", nearestScope );
|
ArtifactSpec dNearest = createArtifact( "d", "2.0", nearestScope );
|
||||||
b.addDependency( dNearest );
|
b.addDependency( dNearest );
|
||||||
ArtifactSpec dFarthest = createArtifact( "d", "2.0", farthestScope );
|
ArtifactSpec dFarthest = createArtifact( "d", "3.0", farthestScope );
|
||||||
c.addDependency( dFarthest );
|
c.addDependency( dFarthest );
|
||||||
|
|
||||||
checkScopeUpdate( a, b, expectedScope );
|
checkScopeUpdate( a, b, expectedScope, "2.0" );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkScopeUpdate( ArtifactSpec a, ArtifactSpec b, String expectedScope )
|
private void checkScopeUpdate( ArtifactSpec a, ArtifactSpec b, String expectedScope, String expectedVersion )
|
||||||
throws ArtifactResolutionException, InvalidVersionSpecificationException
|
throws ArtifactResolutionException, InvalidVersionSpecificationException
|
||||||
{
|
{
|
||||||
ScopeArtifactFilter filter;
|
ScopeArtifactFilter filter;
|
||||||
|
@ -602,10 +602,18 @@ public class DefaultArtifactCollectorTest
|
||||||
filter = new ScopeArtifactFilter( expectedScope );
|
filter = new ScopeArtifactFilter( expectedScope );
|
||||||
}
|
}
|
||||||
|
|
||||||
ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, b.artifact } ), filter );
|
ArtifactResolutionResult res = collect( createSet( new Object[]{a.artifact, b.artifact} ), filter );
|
||||||
Artifact artifact = getArtifact( "d", res.getArtifacts() );
|
Artifact artifact = getArtifact( "d", res.getArtifacts() );
|
||||||
assertNotNull( "MNG-1895 Dependency was not added to resolution", artifact );
|
assertNotNull( "MNG-1895 Dependency was not added to resolution", artifact );
|
||||||
assertEquals( "Check scope", expectedScope, artifact.getScope() );
|
assertEquals( "Check scope", expectedScope, artifact.getScope() );
|
||||||
|
assertEquals( "Check version", expectedVersion, artifact.getVersion() );
|
||||||
|
|
||||||
|
ArtifactSpec d = createArtifact( "d", "1.0" );
|
||||||
|
res = collect( createSet( new Object[]{a.artifact, b.artifact, d.artifact} ), filter );
|
||||||
|
artifact = getArtifact( "d", res.getArtifacts() );
|
||||||
|
assertNotNull( "MNG-1895 Dependency was not added to resolution", artifact );
|
||||||
|
assertEquals( "Check scope", d.artifact.getScope(), artifact.getScope() );
|
||||||
|
assertEquals( "Check version", "1.0", artifact.getVersion() );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disabledtestOptionalNotTransitiveButVersionIsInfluential()
|
public void disabledtestOptionalNotTransitiveButVersionIsInfluential()
|
||||||
|
@ -659,7 +667,7 @@ public class DefaultArtifactCollectorTest
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArtifactResolutionResult collect( Set artifacts, ArtifactFilter filter )
|
private ArtifactResolutionResult collect( Set artifacts, ArtifactFilter filter )
|
||||||
throws ArtifactResolutionException
|
throws ArtifactResolutionException
|
||||||
{
|
{
|
||||||
return artifactCollector.collect( artifacts, projectArtifact.artifact, null, null, source, filter,
|
return artifactCollector.collect( artifacts, projectArtifact.artifact, null, null, source, filter,
|
||||||
Collections.EMPTY_LIST );
|
Collections.EMPTY_LIST );
|
||||||
|
@ -754,7 +762,7 @@ public class DefaultArtifactCollectorTest
|
||||||
}
|
}
|
||||||
return dep;
|
return dep;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArtifactSpec addDependency( String id, String version, String scope, boolean optional )
|
private ArtifactSpec addDependency( String id, String version, String scope, boolean optional )
|
||||||
throws InvalidVersionSpecificationException
|
throws InvalidVersionSpecificationException
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue