From d7d6c11a4bc4e2205d5fff5ebea4516836c58391 Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Tue, 19 Jul 2005 08:41:28 +0000 Subject: [PATCH] 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 --- .../artifact/versioning/VersionRange.java | 22 ++++++++++++++++++- .../artifact/versioning/VersionRangeTest.java | 3 +-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java index e332ee0c6e..5d1c8b583e 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/versioning/VersionRange.java @@ -54,6 +54,8 @@ public class VersionRange 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 class VersionRange 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 @@ public class VersionRange 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 ); } diff --git a/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/VersionRangeTest.java b/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/VersionRangeTest.java index 360789ebbf..7c04378f49 100644 --- a/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/VersionRangeTest.java +++ b/maven-artifact/src/test/java/org/apache/maven/artifact/versioning/VersionRangeTest.java @@ -124,15 +124,14 @@ public class VersionRangeTest 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()