FAQ
Author: brett
Date: Mon Sep 12 21:20:44 2005
New Revision: 280489

URL: http://svn.apache.org/viewcvs?rev=280489&view=rev
Log:
always use the nearest as that is the defined strategy for now. If we change the strategy to newest, a different approach is needed than just adjusting the node range as it doesn't take into account the right children.

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/versioning/VersionRange.java
maven/components/trunk/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java
maven/components/trunk/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/VersionRangeTest.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=280489&r1=280488&r2=280489&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 Sep 12 21:20:44 2005
@@ -137,9 +137,10 @@
}
else
{
- VersionRange newRange = previousRange.restrict( currentRange );
- previous.getArtifact().setVersionRange( newRange );
- node.getArtifact().setVersionRange( newRange );
+ // TODO: shouldn't need to double up on this work, only done for simplicity of handling recommended
+ // version but the restriction is identical
+ previous.getArtifact().setVersionRange( previousRange.restrict( currentRange ) );
+ node.getArtifact().setVersionRange( currentRange.restrict( previousRange ) );
}

// previous one is more dominant

Modified: maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java?rev=280489&r1=280488&r2=280489&view=diff
==============================================================================
--- maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java (original)
+++ maven/components/trunk/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java Mon Sep 12 21:20:44 2005
@@ -185,8 +185,6 @@

public VersionRange restrict( VersionRange restriction )
{
- ArtifactVersion version = max( recommendedVersion, restriction.getRecommendedVersion() );
-
List r1 = this.restrictions;
List r2 = restriction.restrictions;
List restrictions;
@@ -199,23 +197,32 @@
restrictions = intersection( r1, r2 );
}

- if ( version != null && restrictions.size() > 0 )
+ ArtifactVersion version = null;
+ if ( restrictions.size() > 0 )
{
boolean found = false;
for ( Iterator i = restrictions.iterator(); i.hasNext() && !found; )
{
Restriction r = (Restriction) i.next();

- if ( r.containsVersion( version ) )
+ if ( recommendedVersion != null && r.containsVersion( recommendedVersion ) )
{
+ // if we find the original, use that
+ version = recommendedVersion;
found = true;
}
+ else if ( version == null && restriction.getRecommendedVersion() != null &&
+ r.containsVersion( restriction.getRecommendedVersion() ) )
+ {
+ // use this if we can, but prefer the original if possible
+ version = restriction.getRecommendedVersion();
+ }
}
-
- if ( !found )
- {
- version = null;
- }
+ }
+ else
+ {
+ // no range, so the recommended version is valid
+ version = recommendedVersion;
}

return new VersionRange( version, restrictions );
@@ -504,7 +511,7 @@
return matched;
}

- private boolean containsVersion( ArtifactVersion version )
+ public boolean containsVersion( ArtifactVersion version )
{
boolean matched = false;
for ( Iterator i = restrictions.iterator(); i.hasNext() && !matched; )

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=280489&r1=280488&r2=280489&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 Sep 12 21:20:44 2005
@@ -123,7 +123,7 @@
assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, c.artifact} ), res.getArtifacts() );
}

- public void testResolveNearest()
+ public void testResolveNearestNewestIsNearest()
throws ArtifactResolutionException
{
ArtifactSpec a = createArtifact( "a", "1.0" );
@@ -136,6 +136,21 @@
assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, b.artifact, c.artifact} ),
res.getArtifacts() );
assertEquals( "Check version", "3.0", getArtifact( "c", res.getArtifacts() ).getVersion() );
+ }
+
+ public void testResolveNearestOldestIsNearest()
+ throws ArtifactResolutionException
+ {
+ ArtifactSpec a = createArtifact( "a", "1.0" );
+ ArtifactSpec b = a.addDependency( "b", "1.0" );
+ ArtifactSpec c = a.addDependency( "c", "2.0" );
+
+ b.addDependency( "c", "3.0" );
+
+ ArtifactResolutionResult res = collect( a );
+ assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, b.artifact, c.artifact} ),
+ res.getArtifacts() );
+ assertEquals( "Check version", "2.0", getArtifact( "c", res.getArtifacts() ).getVersion() );
}

public void testResolveNearestWithRanges()

Modified: maven/components/trunk/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/VersionRangeTest.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/VersionRangeTest.java?rev=280489&r1=280488&r2=280489&view=diff
==============================================================================
--- maven/components/trunk/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/VersionRangeTest.java (original)
+++ maven/components/trunk/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/VersionRangeTest.java Mon Sep 12 21:20:44 2005
@@ -145,7 +145,9 @@
VersionRange range1 = VersionRange.createFromVersionSpec( "1.0" );
VersionRange range2 = VersionRange.createFromVersionSpec( "1.1" );
VersionRange mergedRange = range1.restrict( range2 );
- assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() );
+ // TODO: current policy is to retain the original version - is this correct, do we need strategies or is that handled elsewhere?
+// assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() );
+ assertEquals( CHECK_VERSION_RECOMMENDATION, "1.0", mergedRange.getRecommendedVersion().toString() );
List restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
Restriction restriction = (Restriction) restrictions.get( 0 );



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdev @
categoriesmaven
postedSep 13, '05 at 4:20a
activeSep 13, '05 at 4:20a
posts1
users1
websitemaven.apache.org
irc#maven

1 user in discussion

Brett: 1 post

People

Translate

site design / logo © 2021 Grokbase