You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jv...@apache.org on 2006/02/21 17:59:36 UTC
svn commit: r379531 - in
/maven/components/branches/maven-2.0.x/maven-artifact/src:
main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java
test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java
Author: jvanzyl
Date: Tue Feb 21 08:59:26 2006
New Revision: 379531
URL: http://svn.apache.org/viewcvs?rev=379531&view=rev
Log:
merging in revisions 371857, 372026, 372027, 372053
Modified:
maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java
maven/components/branches/maven-2.0.x/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java
Modified: maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java
URL: http://svn.apache.org/viewcvs/maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java?rev=379531&r1=379530&r2=379531&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java (original)
+++ maven/components/branches/maven-2.0.x/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java Tue Feb 21 08:59:26 2006
@@ -185,26 +185,31 @@
// TODO: should this be part of mediation?
// previous one is more dominant
+ ResolutionNode nearest, farthest;
if ( previous.getDepth() <= node.getDepth() )
{
- checkScopeUpdate( node, previous, listeners );
+ nearest = previous;
+ farthest = node;
}
else
{
- checkScopeUpdate( previous, node, listeners );
+ nearest = node;
+ farthest = previous;
}
- if ( previous.getDepth() <= node.getDepth() )
+ /* if we need to update scope of nearest to use farthest scope */
+ if ( checkScopeUpdate( farthest, nearest, listeners ) )
{
- // previous was nearer
- fireEvent( ResolutionListener.OMIT_FOR_NEARER, listeners, node, previous.getArtifact() );
- node.disable();
+ fireEvent( ResolutionListener.UPDATE_SCOPE, listeners, nearest, farthest.getArtifact() );
+ /* we need nearest version but farthest scope */
+ nearest.disable();
+ farthest.getArtifact().setVersion( nearest.getArtifact().getVersion() );
}
else
{
- fireEvent( ResolutionListener.OMIT_FOR_NEARER, listeners, previous, node.getArtifact() );
- previous.disable();
+ farthest.disable();
}
+ fireEvent( ResolutionListener.OMIT_FOR_NEARER, listeners, farthest, nearest.getArtifact() );
}
}
}
@@ -316,13 +321,13 @@
}
/**
- * Check if the scope needs to be updated.
+ * Check if the scope of the nearest needs to be updated with the scope of the farthest.
* <a href="http://docs.codehaus.org/x/IGU#DependencyMediationandConflictResolution-Scoperesolution">More info</a>.
* @param farthest farthest resolution node
* @param nearest nearest resolution node
* @param listeners
*/
- void checkScopeUpdate( ResolutionNode farthest, ResolutionNode nearest, List listeners )
+ private boolean checkScopeUpdate( ResolutionNode farthest, ResolutionNode nearest, List listeners )
{
boolean updateScope = false;
Artifact farthestArtifact = farthest.getArtifact();
@@ -351,7 +356,7 @@
if ( updateScope )
{
- fireEvent( ResolutionListener.UPDATE_SCOPE, listeners, farthest, nearestArtifact );
+ fireEvent( ResolutionListener.UPDATE_SCOPE, listeners, farthest, 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
Modified: maven/components/branches/maven-2.0.x/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java
URL: http://svn.apache.org/viewcvs/maven/components/branches/maven-2.0.x/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java?rev=379531&r1=379530&r2=379531&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java (original)
+++ maven/components/branches/maven-2.0.x/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java Tue Feb 21 08:59:26 2006
@@ -18,7 +18,6 @@
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -506,58 +505,104 @@
assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, b.artifact} ), res.getArtifacts() );
}
- public void testCheckScopeUpdate()
+ public void testScopeUpdate( )
throws InvalidVersionSpecificationException, ArtifactResolutionException
{
/* farthest = compile */
checkScopeUpdate( Artifact.SCOPE_COMPILE, Artifact.SCOPE_COMPILE, Artifact.SCOPE_COMPILE );
checkScopeUpdate( Artifact.SCOPE_COMPILE, Artifact.SCOPE_PROVIDED, Artifact.SCOPE_COMPILE );
- //checkScopeUpdate( Artifact.SCOPE_COMPILE, Artifact.SCOPE_RUNTIME, Artifact.SCOPE_COMPILE );
+ checkScopeUpdate( Artifact.SCOPE_COMPILE, Artifact.SCOPE_RUNTIME, Artifact.SCOPE_COMPILE );
checkScopeUpdate( Artifact.SCOPE_COMPILE, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_COMPILE );
- //checkScopeUpdate( Artifact.SCOPE_COMPILE, Artifact.SCOPE_TEST, Artifact.SCOPE_COMPILE );
+ checkScopeUpdate( Artifact.SCOPE_COMPILE, Artifact.SCOPE_TEST, Artifact.SCOPE_COMPILE );
/* farthest = provided */
checkScopeUpdate( Artifact.SCOPE_PROVIDED, Artifact.SCOPE_COMPILE, Artifact.SCOPE_COMPILE );
- //checkScopeUpdate( Artifact.SCOPE_PROVIDED, Artifact.SCOPE_PROVIDED, Artifact.SCOPE_PROVIDED );
+ checkScopeUpdate( Artifact.SCOPE_PROVIDED, Artifact.SCOPE_PROVIDED, Artifact.SCOPE_PROVIDED );
checkScopeUpdate( Artifact.SCOPE_PROVIDED, Artifact.SCOPE_RUNTIME, Artifact.SCOPE_RUNTIME );
- //checkScopeUpdate( Artifact.SCOPE_PROVIDED, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_SYSTEM );
+ checkScopeUpdate( Artifact.SCOPE_PROVIDED, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_SYSTEM );
checkScopeUpdate( Artifact.SCOPE_PROVIDED, Artifact.SCOPE_TEST, Artifact.SCOPE_TEST );
/* farthest = runtime */
checkScopeUpdate( Artifact.SCOPE_RUNTIME, Artifact.SCOPE_COMPILE, Artifact.SCOPE_COMPILE );
- //checkScopeUpdate( Artifact.SCOPE_RUNTIME, Artifact.SCOPE_PROVIDED, Artifact.SCOPE_RUNTIME );
+ checkScopeUpdate( Artifact.SCOPE_RUNTIME, Artifact.SCOPE_PROVIDED, Artifact.SCOPE_RUNTIME );
checkScopeUpdate( Artifact.SCOPE_RUNTIME, Artifact.SCOPE_RUNTIME, Artifact.SCOPE_RUNTIME );
- //checkScopeUpdate( Artifact.SCOPE_RUNTIME, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_SYSTEM );
- //checkScopeUpdate( Artifact.SCOPE_RUNTIME, Artifact.SCOPE_TEST, Artifact.SCOPE_RUNTIME );
+ checkScopeUpdate( Artifact.SCOPE_RUNTIME, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_SYSTEM );
+ checkScopeUpdate( Artifact.SCOPE_RUNTIME, Artifact.SCOPE_TEST, Artifact.SCOPE_RUNTIME );
/* farthest = system */
checkScopeUpdate( Artifact.SCOPE_SYSTEM, Artifact.SCOPE_COMPILE, Artifact.SCOPE_COMPILE );
- //checkScopeUpdate( Artifact.SCOPE_SYSTEM, Artifact.SCOPE_PROVIDED, Artifact.SCOPE_PROVIDED );
+ checkScopeUpdate( Artifact.SCOPE_SYSTEM, Artifact.SCOPE_PROVIDED, Artifact.SCOPE_PROVIDED );
checkScopeUpdate( Artifact.SCOPE_SYSTEM, Artifact.SCOPE_RUNTIME, Artifact.SCOPE_RUNTIME );
- //checkScopeUpdate( Artifact.SCOPE_SYSTEM, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_SYSTEM );
+ checkScopeUpdate( Artifact.SCOPE_SYSTEM, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_SYSTEM );
checkScopeUpdate( Artifact.SCOPE_SYSTEM, Artifact.SCOPE_TEST, Artifact.SCOPE_TEST );
/* farthest = test */
checkScopeUpdate( Artifact.SCOPE_TEST, Artifact.SCOPE_COMPILE, Artifact.SCOPE_COMPILE );
- //checkScopeUpdate( Artifact.SCOPE_TEST, Artifact.SCOPE_PROVIDED, Artifact.SCOPE_PROVIDED );
+ checkScopeUpdate( Artifact.SCOPE_TEST, Artifact.SCOPE_PROVIDED, Artifact.SCOPE_PROVIDED );
checkScopeUpdate( Artifact.SCOPE_TEST, Artifact.SCOPE_RUNTIME, Artifact.SCOPE_RUNTIME );
- //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 );
}
-
+
private void checkScopeUpdate( String farthestScope, String nearestScope, String expectedScope )
throws ArtifactResolutionException, InvalidVersionSpecificationException
{
+ checkScopeUpdateDirect( farthestScope, nearestScope, expectedScope );
+ checkScopeUpdateTransitively( farthestScope, nearestScope, expectedScope );
+ }
+
+ private void checkScopeUpdateTransitively( String farthestScope, String nearestScope, String expectedScope )
+ throws ArtifactResolutionException, InvalidVersionSpecificationException
+ {
ArtifactSpec a = createArtifact( "a", "1.0" );
ArtifactSpec b = createArtifact( "b", "1.0", nearestScope );
ArtifactSpec c = createArtifact( "c", "1.0" );
a.addDependency( c );
- ArtifactSpec d = createArtifact( "d", "2.0" );
- b.addDependency( d );
- c.addDependency( "d", "2.0", farthestScope );
+ ArtifactSpec dNearest = createArtifact( "d", "2.0" );
+ b.addDependency( dNearest );
+ ArtifactSpec dFarthest = createArtifact( "d", "2.0", farthestScope );
+ c.addDependency( dFarthest );
+
+ /* system and provided dependencies are not transitive */
+ if ( !Artifact.SCOPE_SYSTEM.equals( nearestScope ) && !Artifact.SCOPE_PROVIDED.equals( nearestScope ) )
+ {
+ checkScopeUpdate( a, b, expectedScope );
+ }
+ }
+
+ private void checkScopeUpdateDirect( String farthestScope, String nearestScope, String expectedScope )
+ throws ArtifactResolutionException, InvalidVersionSpecificationException
+ {
+ ArtifactSpec a = createArtifact( "a", "1.0" );
+ ArtifactSpec b = createArtifact( "b", "1.0" );
+ ArtifactSpec c = createArtifact( "c", "1.0" );
+ a.addDependency( c );
+ ArtifactSpec dNearest = createArtifact( "d", "2.0", nearestScope );
+ b.addDependency( dNearest );
+ ArtifactSpec dFarthest = createArtifact( "d", "2.0", farthestScope );
+ c.addDependency( dFarthest );
+
+ checkScopeUpdate( a, b, expectedScope );
+ }
- ArtifactResolutionResult res = collect( createSet( new Object[]{a.artifact, b.artifact} ),
- new ScopeArtifactFilter( expectedScope ) );
+ private void checkScopeUpdate( ArtifactSpec a, ArtifactSpec b, String expectedScope )
+ throws ArtifactResolutionException, InvalidVersionSpecificationException
+ {
+ ScopeArtifactFilter filter;
+ if ( Artifact.SCOPE_PROVIDED.equals( expectedScope ) )
+ {
+ filter = new ScopeArtifactFilter( Artifact.SCOPE_COMPILE );
+ }
+ else if ( Artifact.SCOPE_SYSTEM.equals( expectedScope ) )
+ {
+ filter = new ScopeArtifactFilter( Artifact.SCOPE_COMPILE );
+ }
+ else
+ {
+ filter = new ScopeArtifactFilter( expectedScope );
+ }
+
+ ArtifactResolutionResult res = collect( createSet( new Object[] { a.artifact, b.artifact } ), filter );
Artifact artifact = getArtifact( "d", res.getArtifacts() );
assertNotNull( "MNG-1895 Dependency was not added to resolution", artifact );
assertEquals( "Check scope", expectedScope, artifact.getScope() );
@@ -776,8 +821,9 @@
versionRange = VersionRange.createFromVersionSpec( d.getVersion() );
}
Artifact artifact;
- if ( d.getScope().equals( Artifact.SCOPE_TEST ) )
+ if ( d.getScope().equals( Artifact.SCOPE_TEST ) || d.getScope().equals( Artifact.SCOPE_PROVIDED ) )
{
+ /* don't call createDependencyArtifact as it'll ignore test and provided scopes */
artifact = artifactFactory.createArtifact( d.getGroupId(), d.getArtifactId(), d.getVersion(), d
.getScope(), d.getType() );
}