PR: MNG-505

empty restrictions means that nothing is valid, otherwise there will be one restriction EVERYTHING

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@219815 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-07-19 23:45:44 +00:00
parent 407c29c3e0
commit 5685fb9041
3 changed files with 45 additions and 13 deletions

View File

@ -32,6 +32,8 @@ public class Restriction
private final boolean upperBoundInclusive;
static final Restriction EVERYTHING = new Restriction( null, false, null, false );
public Restriction( ArtifactVersion lowerBound, boolean lowerBoundInclusive, ArtifactVersion upperBound,
boolean upperBoundInclusive )
{

View File

@ -110,6 +110,7 @@ public class VersionRange
else
{
version = new DefaultArtifactVersion( process );
restrictions.add( Restriction.EVERYTHING );
}
}
@ -182,13 +183,9 @@ public class VersionRange
List r1 = this.restrictions;
List r2 = restriction.restrictions;
List restrictions;
if ( r1.isEmpty() )
if ( r1.isEmpty() || r2.isEmpty() )
{
restrictions = r2;
}
else if ( r2.isEmpty() )
{
restrictions = r1;
restrictions = Collections.EMPTY_LIST;
}
else
{

View File

@ -55,9 +55,14 @@ public class VersionRangeTest
assertNull( CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion() );
range = VersionRange.createFromVersionSpec( "1.0" );
restrictions = range.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() );
assertEquals( CHECK_VERSION_RECOMMENDATION, "1.0", range.getRecommendedVersion().toString() );
restrictions = range.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
restriction = (Restriction) restrictions.get( 0 );
assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() );
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
range = VersionRange.createFromVersionSpec( "[1.0]" );
restrictions = range.getRestrictions();
@ -141,20 +146,32 @@ public class VersionRangeTest
VersionRange range2 = VersionRange.createFromVersionSpec( "1.1" );
VersionRange mergedRange = range1.restrict( range2 );
assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() );
assertEquals( CHECK_NUM_RESTRICTIONS, 0, mergedRange.getRestrictions().size() );
List restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
Restriction restriction = (Restriction) restrictions.get( 0 );
assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() );
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
mergedRange = range2.restrict( range1 );
assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() );
assertEquals( CHECK_NUM_RESTRICTIONS, 0, mergedRange.getRestrictions().size() );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
restriction = (Restriction) restrictions.get( 0 );
assertNull( CHECK_LOWER_BOUND, restriction.getLowerBound() );
assertFalse( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() );
assertFalse( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
// TODO: test reversed restrictions on all below
range1 = VersionRange.createFromVersionSpec( "[1.0,)" );
range2 = VersionRange.createFromVersionSpec( "1.1" );
mergedRange = range1.restrict( range2 );
assertEquals( CHECK_VERSION_RECOMMENDATION, "1.1", mergedRange.getRecommendedVersion().toString() );
List restrictions = mergedRange.getRestrictions();
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 1, restrictions.size() );
Restriction restriction = (Restriction) restrictions.get( 0 );
restriction = (Restriction) restrictions.get( 0 );
assertEquals( CHECK_LOWER_BOUND, "1.0", restriction.getLowerBound().toString() );
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertNull( CHECK_UPPER_BOUND, restriction.getUpperBound() );
@ -403,7 +420,6 @@ public class VersionRangeTest
assertEquals( CHECK_UPPER_BOUND, "1.1", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
// TODO: specify this differently from no restriction - no restriction should be null, or one restriction with null ends?
range1 = VersionRange.createFromVersionSpec( "[1.0,1.1)" );
range2 = VersionRange.createFromVersionSpec( "[1.1,1.4]" );
mergedRange = range1.restrict( range2 );
@ -584,6 +600,23 @@ public class VersionRangeTest
assertTrue( CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive() );
assertEquals( CHECK_UPPER_BOUND, "1.6", restriction.getUpperBound().toString() );
assertTrue( CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive() );
// test restricting empty sets
range1 = VersionRange.createFromVersionSpec( "[,1.1],[1.4,]" );
range2 = VersionRange.createFromVersionSpec( "[1.2,1.3]" );
range1 = range1.restrict( range2 );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() );
range1 = VersionRange.createFromVersionSpec( "[,1.1],[1.4,]" );
range2 = VersionRange.createFromVersionSpec( "[1.2,1.3]" );
range2 = range1.restrict( range2 );
mergedRange = range1.restrict( range2 );
assertNull( CHECK_VERSION_RECOMMENDATION, mergedRange.getRecommendedVersion() );
restrictions = mergedRange.getRestrictions();
assertEquals( CHECK_NUM_RESTRICTIONS, 0, restrictions.size() );
}
private void checkInvalidRange( String version )