PR: MNG-505

test for correct ordering and overlap

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@219631 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-07-19 08:41:28 +00:00
parent 27cdfc3cd1
commit d7d6c11a4b
2 changed files with 22 additions and 3 deletions

View File

@ -54,6 +54,8 @@ public class VersionRange
List restrictions = new ArrayList(); List restrictions = new ArrayList();
String process = spec; String process = spec;
ArtifactVersion version = null; ArtifactVersion version = null;
ArtifactVersion upperBound = null;
ArtifactVersion lowerBound = null;
while ( process.startsWith( "[" ) || process.startsWith( "(" ) ) while ( process.startsWith( "[" ) || process.startsWith( "(" ) )
{ {
@ -74,7 +76,20 @@ public class VersionRange
throw new InvalidVersionSpecificationException( "Unbounded range: " + spec ); throw new InvalidVersionSpecificationException( "Unbounded range: " + spec );
} }
restrictions.add( parseRestriction( process.substring( 0, index + 1 ) ) ); Restriction restriction = parseRestriction( process.substring( 0, index + 1 ) );
if ( lowerBound == null )
{
lowerBound = restriction.getLowerBound();
}
if ( upperBound != null )
{
if ( restriction.getLowerBound() == null || restriction.getLowerBound().compareTo( upperBound ) < 0 )
{
throw new InvalidVersionSpecificationException( "Ranges overlap: " + spec );
}
}
restrictions.add( restriction );
upperBound = restriction.getUpperBound();
process = process.substring( index + 1 ).trim(); process = process.substring( index + 1 ).trim();
@ -143,6 +158,11 @@ public class VersionRange
upperVersion = new DefaultArtifactVersion( upperBound ); upperVersion = new DefaultArtifactVersion( upperBound );
} }
if ( upperVersion != null && lowerVersion != null && upperVersion.compareTo( lowerVersion ) < 0 )
{
throw new InvalidVersionSpecificationException( "Range defies version ordering: " + spec );
}
restriction = new Restriction( lowerVersion, lowerBoundInclusive, upperVersion, upperBoundInclusive ); restriction = new Restriction( lowerVersion, lowerBoundInclusive, upperVersion, upperBoundInclusive );
} }

View File

@ -124,15 +124,14 @@ public class VersionRangeTest
checkInvalidRange( "(1.0,1.0]" ); checkInvalidRange( "(1.0,1.0]" );
checkInvalidRange( "[1.0,1.0)" ); checkInvalidRange( "[1.0,1.0)" );
checkInvalidRange( "(1.0,1.0)" ); checkInvalidRange( "(1.0,1.0)" );
checkInvalidRange( "[1.1,1.0]" );
checkInvalidRange( "[1.0,1.2),1.3" ); checkInvalidRange( "[1.0,1.2),1.3" );
/* TODO: not testing this presently
// overlap // overlap
checkInvalidRange( "[1.0,1.2),(1.1,1.3]" ); checkInvalidRange( "[1.0,1.2),(1.1,1.3]" );
// overlap // overlap
checkInvalidRange( "[1.1,1.3),(1.0,1.2]" ); checkInvalidRange( "[1.1,1.3),(1.0,1.2]" );
// ordering // ordering
checkInvalidRange( "(1.1,1.2],[1.0,1.1)" ); checkInvalidRange( "(1.1,1.2],[1.0,1.1)" );
*/
} }
public void testIntersections() public void testIntersections()