You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ca...@apache.org on 2006/01/25 00:27:04 UTC
svn commit: r372053 - in /maven/components/trunk/maven-artifact/src:
main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java
test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java
Author: carlos
Date: Tue Jan 24 15:26:59 2006
New Revision: 372053
URL: http://svn.apache.org/viewcvs?rev=372053&view=rev
Log:
Dependencies in two paths are not added to resolution when scope needs to be updated in the nearest due to any of nearest parents
PR: MNG-1895
Modified:
maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java
maven/components/trunk/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java
Modified: maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java?rev=372053&r1=372052&r2=372053&view=diff
==============================================================================
--- maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java (original)
+++ maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java Tue Jan 24 15:26:59 2006
@@ -201,14 +201,15 @@
if ( checkScopeUpdate( farthest, nearest, listeners ) )
{
fireEvent( ResolutionListener.UPDATE_SCOPE, listeners, nearest, farthest.getArtifact() );
-
- // 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
- nearest.getArtifact().setScope( farthest.getArtifact().getScope() );
+ /* we need nearest version but farthest scope */
+ nearest.disable();
+ farthest.getArtifact().setVersion( nearest.getArtifact().getVersion() );
+ }
+ else
+ {
+ farthest.disable();
}
fireEvent( ResolutionListener.OMIT_FOR_NEARER, listeners, farthest, nearest.getArtifact() );
- farthest.disable();
}
}
}
Modified: maven/components/trunk/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java?rev=372053&r1=372052&r2=372053&view=diff
==============================================================================
--- maven/components/trunk/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java (original)
+++ maven/components/trunk/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java Tue Jan 24 15:26:59 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() );
}