Author: brett
Date: Mon Oct 3 21:02:46 2005
New Revision: 293514
URL: http://svn.apache.org/viewcvs?rev=293514&view=rev
Log:
PR: MNG-1048
make sure the scope in the current POM wins over all
Modified:
maven/components/trunk/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/AntResolutionListener.java
maven/components/trunk/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DebugResolutionListener.java
maven/components/trunk/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/WarningResolutionListener.java
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-ant/src/main/java/org/apache/maven/artifact/ant/AntResolutionListener.java
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/AntResolutionListener.java?rev=293514&r1=293513&r2=293514&view=diff
==============================================================================
---
maven/components/trunk/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/AntResolutionListener.java
(original)
+++
maven/components/trunk/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/AntResolutionListener.java
Mon Oct 3 21:02:46 2005
@@ -74,7 +74,8 @@
public void updateScopeCurrentPom( Artifact artifact, String scope )
{
- updateScope( artifact, scope );
+ project.log( indent + artifact.getId() + " (not setting scope to: " +
scope + "; local scope " +
+ artifact.getScope() + " wins)" );
}
public void selectVersionFromRange( Artifact artifact )
Modified:
maven/components/trunk/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DebugResolutionListener.java
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DebugResolutionListener.java?rev=293514&r1=293513&r2=293514&view=diff
==============================================================================
---
maven/components/trunk/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DebugResolutionListener.java
(original)
+++
maven/components/trunk/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DebugResolutionListener.java
Mon Oct 3 21:02:46 2005
@@ -68,7 +68,8 @@
public void updateScopeCurrentPom( Artifact artifact, String scope )
{
- updateScope( artifact, scope );
+ logger.debug( indent + artifact.getId() + " (not setting scope to: " +
scope + "; local scope " +
+ artifact.getScope() + " wins)" );
}
public void updateScope( Artifact artifact, String scope )
Modified:
maven/components/trunk/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/WarningResolutionListener.java
URL:
http://svn.apache.org/viewcvs/maven/components/trunk/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/WarningResolutionListener.java?rev=293514&r1=293513&r2=293514&view=diff
==============================================================================
---
maven/components/trunk/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/WarningResolutionListener.java
(original)
+++
maven/components/trunk/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/WarningResolutionListener.java
Mon Oct 3 21:02:46 2005
@@ -69,10 +69,9 @@
// TODO: better way than static? this might hide messages in a reactor
if ( !ignoredArtifacts.contains( artifact ) )
{
- logger.warn( "\n\tArtifact " + artifact.getId() + " has scope '" +
artifact.getScope() +
- "' replaced with '" + scope + "'\n" +
- "\tas a dependency has given a broader scope. If this is not
intended, use -X to locate the dependency,\n" +
- "\tor force the desired scope using dependencyManagement.\n" );
+ logger.warn( "\n\tArtifact " + artifact.getId() + " retains local
scope '" + artifact.getScope() +
+ "' overriding broader scope '" + scope + "'\n" +
+ "\tgiven by a dependency. If this is not intended, modify or
remove the local scope.\n" );
ignoredArtifacts.add( artifact );
}
}
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=293514&r1=293513&r2=293514&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
Mon Oct 3 21:02:46 2005
@@ -280,43 +280,41 @@
}
}
- private void checkScopeUpdate( ResolutionNode node, ResolutionNode
previous, List listeners )
+ private void checkScopeUpdate( ResolutionNode farthest, ResolutionNode
nearest, List listeners )
{
boolean updateScope = false;
- Artifact newArtifact = node.getArtifact();
- Artifact previousArtifact = previous.getArtifact();
+ Artifact farthestArtifact = farthest.getArtifact();
+ Artifact nearestArtifact = nearest.getArtifact();
- if ( Artifact.SCOPE_RUNTIME.equals( newArtifact.getScope() ) && (
- Artifact.SCOPE_TEST.equals( previousArtifact.getScope() ) ||
- Artifact.SCOPE_PROVIDED.equals( previousArtifact.getScope() )
) )
+ if ( Artifact.SCOPE_RUNTIME.equals( farthestArtifact.getScope() ) && (
+ Artifact.SCOPE_TEST.equals( nearestArtifact.getScope() ) ||
+ Artifact.SCOPE_PROVIDED.equals( nearestArtifact.getScope() ) )
)
{
updateScope = true;
}
- if ( Artifact.SCOPE_COMPILE.equals( newArtifact.getScope() ) &&
- !Artifact.SCOPE_COMPILE.equals( previousArtifact.getScope() ) )
+ if ( Artifact.SCOPE_COMPILE.equals( farthestArtifact.getScope() ) &&
+ !Artifact.SCOPE_COMPILE.equals( nearestArtifact.getScope() ) )
{
updateScope = true;
}
- if ( updateScope )
+ // current POM rules all
+ if ( nearest.getDepth() < 2 && updateScope )
{
- int event;
- if ( previous.getDepth() < 2 )
- {
- event = ResolutionListener.UPDATE_SCOPE_CURRENT_POM;
- }
- else
- {
- event = ResolutionListener.UPDATE_SCOPE;
- }
+ updateScope = false;
+
+ fireEvent( ResolutionListener.UPDATE_SCOPE_CURRENT_POM, listeners,
nearest, farthestArtifact );
+ }
- fireEvent( event, listeners, previous, newArtifact );
+ 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
- previousArtifact.setScope( newArtifact.getScope() );
+ nearestArtifact.setScope( farthestArtifact.getScope() );
}
}
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=293514&r1=293513&r2=293514&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
Mon Oct 3 21:02:46 2005
@@ -35,6 +35,7 @@
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;
@@ -249,7 +250,20 @@
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 version", "3.8.1", getArtifact( "junit",
res.getArtifacts() ).getVersion() );
- assertEquals( "Check scope", Artifact.SCOPE_COMPILE, getArtifact(
"junit", res.getArtifacts() ).getScope() );
+ assertEquals( "Check scope", Artifact.SCOPE_TEST, getArtifact(
"junit", res.getArtifacts() ).getScope() );
+ }
+
+ public void testResolveLocalWithNewerVersionButLesserScopeResolvedFirst()
+ throws ArtifactResolutionException,
InvalidVersionSpecificationException
+ {
+ ArtifactSpec b = createArtifact( "junit", "3.8.1", Artifact.SCOPE_TEST
);
+ ArtifactSpec a = createArtifact( "commons-logging", "1.0" );
+ a.addDependency( "junit", "3.7" );
+
+ 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 version", "3.8.1", getArtifact( "junit",
res.getArtifacts() ).getVersion() );
+ assertEquals( "Check scope", Artifact.SCOPE_TEST, getArtifact(
"junit", res.getArtifacts() ).getScope() );
}
public void testResolveNearestWithRanges()
@@ -380,7 +394,9 @@
ArtifactResolutionResult res = collect( createSet( new
Object[]{a.artifact, c.artifact} ) );
assertEquals( "Check artifact list", createSet( new
Object[]{a.artifact, modifiedC} ), res.getArtifacts() );
Artifact artifact = getArtifact( "c", res.getArtifacts() );
- assertEquals( "Check scope", Artifact.SCOPE_COMPILE,
artifact.getScope() );
+ // local wins now, and irrelevant if not local as test/provided aren't
transitive
+// assertEquals( "Check scope", Artifact.SCOPE_COMPILE,
artifact.getScope() );
+ assertEquals( "Check scope", Artifact.SCOPE_TEST, artifact.getScope()
);
}
public void testResolveRuntimeScopeOverTestScope()
@@ -396,21 +412,25 @@
ArtifactResolutionResult res = collect( createSet( new
Object[]{a.artifact, c.artifact} ) );
assertEquals( "Check artifact list", createSet( new
Object[]{a.artifact, modifiedC} ), res.getArtifacts() );
Artifact artifact = getArtifact( "c", res.getArtifacts() );
- assertEquals( "Check scope", Artifact.SCOPE_RUNTIME,
artifact.getScope() );
+ // local wins now, and irrelevant if not local as test/provided aren't
transitive
+// assertEquals( "Check scope", Artifact.SCOPE_RUNTIME,
artifact.getScope() );
+ assertEquals( "Check scope", Artifact.SCOPE_TEST, artifact.getScope()
);
}
public void testResolveCompileScopeOverRuntimeScope()
throws ArtifactResolutionException,
InvalidVersionSpecificationException
{
- ArtifactSpec a = createArtifact( "a", "1.0" );
- ArtifactSpec c = createArtifact( "c", "3.0", Artifact.SCOPE_RUNTIME );
+ ArtifactSpec root = createArtifact( "root", "1.0" );
+ ArtifactSpec a = root.addDependency( "a", "1.0" );
+ root.addDependency( "c", "3.0", Artifact.SCOPE_RUNTIME );
a.addDependency( "c", "2.0", Artifact.SCOPE_COMPILE );
Artifact modifiedC = createArtifact( "c", "3.0",
Artifact.SCOPE_COMPILE ).artifact;
- ArtifactResolutionResult res = collect( createSet( new
Object[]{a.artifact, c.artifact} ) );
- assertEquals( "Check artifact list", createSet( new
Object[]{a.artifact, modifiedC} ), res.getArtifacts() );
+ ArtifactResolutionResult res = collect( createSet( new
Object[]{root.artifact} ) );
+ assertEquals( "Check artifact list", createSet( new
Object[]{a.artifact, root.artifact, modifiedC} ),
+ res.getArtifacts() );
Artifact artifact = getArtifact( "c", res.getArtifacts() );
assertEquals( "Check scope", Artifact.SCOPE_COMPILE,
artifact.getScope() );
}
@@ -428,7 +448,9 @@
ArtifactResolutionResult res = collect( createSet( new
Object[]{a.artifact, c.artifact} ) );
assertEquals( "Check artifact list", createSet( new
Object[]{a.artifact, modifiedC} ), res.getArtifacts() );
Artifact artifact = getArtifact( "c", res.getArtifacts() );
- assertEquals( "Check scope", Artifact.SCOPE_COMPILE,
artifact.getScope() );
+ // local wins now, and irrelevant if not local as test/provided aren't
transitive
+// assertEquals( "Check scope", Artifact.SCOPE_COMPILE,
artifact.getScope() );
+ assertEquals( "Check scope", Artifact.SCOPE_PROVIDED,
artifact.getScope() );
}
public void testResolveRuntimeScopeOverProvidedScope()
@@ -444,7 +466,9 @@
ArtifactResolutionResult res = collect( createSet( new
Object[]{a.artifact, c.artifact} ) );
assertEquals( "Check artifact list", createSet( new
Object[]{a.artifact, modifiedC} ), res.getArtifacts() );
Artifact artifact = getArtifact( "c", res.getArtifacts() );
- assertEquals( "Check scope", Artifact.SCOPE_RUNTIME,
artifact.getScope() );
+ // local wins now, and irrelevant if not local as test/provided aren't
transitive
+// assertEquals( "Check scope", Artifact.SCOPE_RUNTIME,
artifact.getScope() );
+ assertEquals( "Check scope", Artifact.SCOPE_PROVIDED,
artifact.getScope() );
}
public void testProvidedScopeNotTransitive()
@@ -591,7 +615,7 @@
private static Set createSet( Object[] x )
{
- return new HashSet( Arrays.asList( x ) );
+ return new LinkedHashSet( Arrays.asList( x ) );
}
private class ArtifactSpec
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]