From d20f6c96fe3a5fc59bd3604bbc813b50fb69ae7f Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Thu, 7 Jun 2007 12:39:05 +0000 Subject: [PATCH] [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 --- .../artifact/versioning/VersionRange.java | 21 +--------------- .../DefaultArtifactCollectorTest.java | 2 +- .../artifact/versioning/VersionRangeTest.java | 24 ++++++++++++++++++- 3 files changed, 25 insertions(+), 22 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 f35fa21cc6..fa8ce259da 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 @@ -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; } diff --git a/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java b/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java index 5c45cc3807..c20bc313cd 100644 --- a/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java +++ b/maven-artifact/src/test/java/org/apache/maven/artifact/resolver/DefaultArtifactCollectorTest.java @@ -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() ); 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 ec29b3d11b..ebc60eafc4 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 @@ -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()