[MNG-2988] Ranges with inclusive upper bounds are not validated against metadata

Submitted by: Mark Hobson
Merged from: maven-2.0.x branch r545150


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@545156 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2007-06-07 12:39:05 +00:00
parent 0c1b689e52
commit d20f6c96fe
3 changed files with 25 additions and 22 deletions

View File

@ -34,8 +34,6 @@ import java.util.List;
*/
public class VersionRange
{
private final ArtifactVersion RELEASE = new DefaultArtifactVersion( "RELEASE" );
private final ArtifactVersion recommendedVersion;
private final List restrictions;
@ -469,16 +467,8 @@ public class VersionRange
{
throw new OverConstrainedVersionException( "The artifact has no valid ranges", artifact );
}
else
{
Restriction restriction = (Restriction) restrictions.get( restrictions.size() - 1 );
version = restriction.getUpperBound();
if ( version == null )
{
version = RELEASE;
}
}
version = null;
}
return version;
}
@ -497,15 +487,6 @@ public class VersionRange
{
throw new OverConstrainedVersionException( "The artifact has no valid ranges", artifact );
}
else
{
Restriction restriction = (Restriction) restrictions.get( restrictions.size() - 1 );
if ( restriction.getUpperBound() != null )
{
value = restriction.isUpperBoundInclusive();
}
}
}
return value;
}

View File

@ -292,10 +292,10 @@ public class DefaultArtifactCollectorTest
ArtifactSpec b = a.addDependency( "b", "1.0" );
a.addDependency( "c", "[2.0,2.5]" );
b.addDependency( "c", "[1.0,3.0]" );
ArtifactSpec c = createArtifact( "c", "2.5" );
ArtifactResolutionResult res = collect( a );
ArtifactSpec c = createArtifact( "c", "2.5" );
assertEquals( "Check artifact list", createSet( new Object[]{a.artifact, b.artifact, c.artifact} ),
res.getArtifacts() );
assertEquals( "Check version", "2.5", getArtifact( "c", res.getArtifacts() ).getVersion() );

View File

@ -23,6 +23,8 @@ import junit.framework.TestCase;
import java.util.List;
import org.apache.maven.artifact.Artifact;
/**
* Tests version range construction.
*
@ -44,9 +46,15 @@ public class VersionRangeTest
private static final String CHECK_VERSION_RECOMMENDATION = "check version recommended";
private static final String CHECK_SELECTED_VERSION_KNOWN = "check selected version known";
private static final String CHECK_SELECTED_VERSION = "check selected version";
public void testRange()
throws InvalidVersionSpecificationException
throws InvalidVersionSpecificationException, OverConstrainedVersionException
{
Artifact artifact = null;
VersionRange range = VersionRange.createFromVersionSpec( "(,1.0]" );
List restrictions = range.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
@ -56,6 +64,8 @@ public class VersionRangeTest
assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) );
assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) );
range = VersionRange.createFromVersionSpec( "1.0" );
assertEquals( CHECK_VERSION_RECOMMENDATION, "1.0", range.getRecommendedVersion().toString() );
@ -66,6 +76,8 @@ public class VersionRangeTest
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertTrue( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) );
assertEquals( CHECK_SELECTED_VERSION, "1.0", range.getSelectedVersion( artifact ).toString() );
range = VersionRange.createFromVersionSpec( "[1.0]" );
restrictions = range.getRestrictions();
@ -76,6 +88,8 @@ public class VersionRangeTest
assertEquals( CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) );
assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) );
range = VersionRange.createFromVersionSpec( "[1.2,1.3]" );
restrictions = range.getRestrictions();
@ -86,6 +100,8 @@ public class VersionRangeTest
assertEquals( CHECK_UPPER_BOUND, "1.3", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) );
assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) );
range = VersionRange.createFromVersionSpec( "[1.0,2.0)" );
restrictions = range.getRestrictions();
@ -96,6 +112,8 @@ public class VersionRangeTest
assertEquals( CHECK_UPPER_BOUND, "2.0", restriction.getUpperBound().toString() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) );
assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) );
range = VersionRange.createFromVersionSpec( "[1.5,)" );
restrictions = range.getRestrictions();
@ -106,6 +124,8 @@ public class VersionRangeTest
assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) );
assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) );
range = VersionRange.createFromVersionSpec( "(,1.0],[1.2,)" );
restrictions = range.getRestrictions();
@ -122,6 +142,8 @@ public class VersionRangeTest
assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
assertFalse( CHECK_SELECTED_VERSION_KNOWN, range.isSelectedVersionKnown( artifact ) );
assertNull( CHECK_SELECTED_VERSION, range.getSelectedVersion( artifact ) );
}
public void testInvalidRanges()