You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by br...@apache.org on 2006/02/22 03:21:13 UTC
svn commit: r379650 - in /maven/components/trunk/maven-artifact/src:
main/java/org/apache/maven/artifact/resolver/
test/java/org/apache/maven/artifact/resolver/
Author: brett
Date: Tue Feb 21 18:21:10 2006
New Revision: 379650
URL: http://svn.apache.org/viewcvs?rev=379650&view=rev
Log:
[MNG-1895] merge changes from branch
Modified:
maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java
maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.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=379650&r1=379649&r2=379650&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 Feb 21 18:21:10 2006
@@ -81,7 +81,7 @@
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
if ( node.isChildOfRootNode() || !artifact.isOptional() )
{
@@ -137,18 +137,7 @@
VersionRange previousRange = previous.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 )
- {
- // 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
+ if ( previousRange != null && currentRange != null )
{
// TODO: shouldn't need to double up on this work, only done for simplicity of handling recommended
// version but the restriction is identical
@@ -185,7 +174,8 @@
// TODO: should this be part of mediation?
// previous one is more dominant
- ResolutionNode nearest, farthest;
+ ResolutionNode nearest;
+ ResolutionNode farthest;
if ( previous.getDepth() <= node.getDepth() )
{
nearest = previous;
@@ -197,11 +187,9 @@
farthest = previous;
}
- /* if we need to update scope of nearest to use farthest scope */
if ( checkScopeUpdate( farthest, nearest, listeners ) )
{
- fireEvent( ResolutionListener.UPDATE_SCOPE, listeners, nearest, farthest.getArtifact() );
- /* we need nearest version but farthest scope */
+ // if we need to update scope of nearest to use farthest scope, use the nearest version, but farthest scope
nearest.disable();
farthest.getArtifact().setVersion( nearest.getArtifact().getVersion() );
}
@@ -321,13 +309,14 @@
}
/**
- * 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>.
- * @param farthest farthest resolution node
- * @param nearest nearest resolution node
+ *
+ * @param farthest farthest resolution node
+ * @param nearest nearest resolution node
* @param listeners
*/
- private boolean checkScopeUpdate( ResolutionNode farthest, ResolutionNode nearest, List listeners )
+ boolean checkScopeUpdate( ResolutionNode farthest, ResolutionNode nearest, List listeners )
{
boolean updateScope = false;
Artifact farthestArtifact = farthest.getArtifact();
@@ -352,6 +341,16 @@
updateScope = false;
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;
Modified: maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java?rev=379650&r1=379649&r2=379650&view=diff
==============================================================================
--- maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java (original)
+++ maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/resolver/ResolutionNode.java Tue Feb 21 18:21:10 2006
@@ -146,7 +146,7 @@
{
return children != null;
}
-
+
public boolean isChildOfRootNode()
{
return parent != null && parent.parent == null;
@@ -219,7 +219,7 @@
public String toString()
{
- return artifact.toString() + " (" + depth + ")";
+ return artifact.toString() + " (" + depth + "; " + ( active ? "enabled" : "disabled" ) + ")";
}
}
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=379650&r1=379649&r2=379650&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 Feb 21 18:21:10 2006
@@ -16,17 +16,6 @@
* 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.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
@@ -41,6 +30,17 @@
import org.apache.maven.artifact.versioning.VersionRange;
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.
*
@@ -504,8 +504,8 @@
ArtifactResolutionResult res = collect( createSet( new Object[]{a.artifact, b.artifact} ) );
assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, b.artifact} ), res.getArtifacts() );
}
-
- public void testScopeUpdate( )
+
+ public void testScopeUpdate()
throws InvalidVersionSpecificationException, ArtifactResolutionException
{
/* farthest = compile */
@@ -543,7 +543,7 @@
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
{
@@ -560,13 +560,13 @@
a.addDependency( c );
ArtifactSpec dNearest = createArtifact( "d", "2.0" );
b.addDependency( dNearest );
- ArtifactSpec dFarthest = createArtifact( "d", "2.0", farthestScope );
+ ArtifactSpec dFarthest = createArtifact( "d", "3.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 );
+ checkScopeUpdate( a, b, expectedScope, "2.0" );
}
}
@@ -579,13 +579,13 @@
a.addDependency( c );
ArtifactSpec dNearest = createArtifact( "d", "2.0", nearestScope );
b.addDependency( dNearest );
- ArtifactSpec dFarthest = createArtifact( "d", "2.0", farthestScope );
+ ArtifactSpec dFarthest = createArtifact( "d", "3.0", farthestScope );
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
{
ScopeArtifactFilter filter;
@@ -602,10 +602,18 @@
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() );
assertNotNull( "MNG-1895 Dependency was not added to resolution", artifact );
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()
@@ -659,7 +667,7 @@
}
private ArtifactResolutionResult collect( Set artifacts, ArtifactFilter filter )
- throws ArtifactResolutionException
+ throws ArtifactResolutionException
{
return artifactCollector.collect( artifacts, projectArtifact.artifact, null, null, source, filter,
Collections.EMPTY_LIST );
@@ -754,7 +762,7 @@
}
return dep;
}
-
+
private ArtifactSpec addDependency( String id, String version, String scope, boolean optional )
throws InvalidVersionSpecificationException
{