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 static VersionRange createFromVersionSpec( String spec )
List restrictions = new ArrayList();
String process = spec;
ArtifactVersion version = null;
ArtifactVersion upperBound = null;
ArtifactVersion lowerBound = null;
while ( process.startsWith( "[" ) || process.startsWith( "(" ) )
{
@ -74,7 +76,20 @@ public static VersionRange createFromVersionSpec( String 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();
@ -143,6 +158,11 @@ private static Restriction parseRestriction( String spec )
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 );
}

View File

@ -124,15 +124,14 @@ public void testInvalidRanges()
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" );
/* TODO: not testing this presently
// overlap
checkInvalidRange( "[1.0,1.2),(1.1,1.3]" );
// overlap
checkInvalidRange( "[1.1,1.3),(1.0,1.2]" );
// ordering
checkInvalidRange( "(1.1,1.2],[1.0,1.1)" );
*/
}
public void testIntersections()