public void testSnapshotRangeBoundsCanContainSnapshots() throws InvalidVersionSpecificationException { VersionRange range = VersionRange.createFromVersionSpec("[1.0,1.2-SNAPSHOT]"); assertTrue(range.containsVersion(new ArtifactVersion("1.1-SNAPSHOT"))); assertTrue(range.containsVersion(new ArtifactVersion("1.2-SNAPSHOT"))); range = VersionRange.createFromVersionSpec("[1.0-SNAPSHOT,1.2]"); assertTrue(range.containsVersion(new ArtifactVersion("1.0-SNAPSHOT"))); assertTrue(range.containsVersion(new ArtifactVersion("1.1-SNAPSHOT"))); }
public boolean enforceVersion(String requiredVersionRange, ArtifactVersion actualVersion) throws InvalidVersionSpecificationException { VersionRange vr = null; vr = VersionRange.createFromVersionSpec(requiredVersionRange); return vr.containsVersion(actualVersion); }
public void testSnapshotSoftVersionCanContainSnapshot() throws InvalidVersionSpecificationException { VersionRange range = VersionRange.createFromVersionSpec("1.0-SNAPSHOT"); assertTrue(range.containsVersion(new ArtifactVersion("1.0-SNAPSHOT"))); }
public void testRange() throws InvalidVersionSpecificationException, OverConstrainedVersionException { Dependency artifact = null; VersionRange range = VersionRange.createFromVersionSpec("(,1.0]"); List<Restriction> restrictions = range.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()); 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()); 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()); 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(); assertEquals(CHECK_NUM_RESTRICTIONS, 1, restrictions.size()); restriction = (Restriction) restrictions.get(0); assertEquals(CHECK_LOWER_BOUND, "1.0", restriction.getLowerBound().toString()); assertTrue(CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive()); 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(); assertEquals(CHECK_NUM_RESTRICTIONS, 1, restrictions.size()); restriction = (Restriction) restrictions.get(0); assertEquals(CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString()); assertTrue(CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive()); 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(); assertEquals(CHECK_NUM_RESTRICTIONS, 1, restrictions.size()); restriction = (Restriction) restrictions.get(0); assertEquals(CHECK_LOWER_BOUND, "1.0", restriction.getLowerBound().toString()); assertTrue(CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive()); 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(); assertEquals(CHECK_NUM_RESTRICTIONS, 1, restrictions.size()); restriction = (Restriction) restrictions.get(0); assertEquals(CHECK_LOWER_BOUND, "1.5", restriction.getLowerBound().toString()); assertTrue(CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive()); 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(); assertEquals(CHECK_NUM_RESTRICTIONS, 2, restrictions.size()); restriction = (Restriction) restrictions.get(0); assertNull(CHECK_LOWER_BOUND, restriction.getLowerBound()); assertFalse(CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive()); assertEquals(CHECK_UPPER_BOUND, "1.0", restriction.getUpperBound().toString()); assertTrue(CHECK_UPPER_BOUND_INCLUSIVE, restriction.isUpperBoundInclusive()); assertNull(CHECK_VERSION_RECOMMENDATION, range.getRecommendedVersion()); restriction = (Restriction) restrictions.get(1); assertEquals(CHECK_LOWER_BOUND, "1.2", restriction.getLowerBound().toString()); assertTrue(CHECK_LOWER_BOUND_INCLUSIVE, restriction.isLowerBoundInclusive()); 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,)"); assertFalse(range.containsVersion(new ArtifactVersion("1.0-SNAPSHOT"))); range = VersionRange.createFromVersionSpec("[1.0,1.1-SNAPSHOT]"); assertTrue(range.containsVersion(new ArtifactVersion("1.1-SNAPSHOT"))); range = VersionRange.createFromVersionSpec("[5.0.9.0,5.0.10.0)"); assertTrue(range.containsVersion(new ArtifactVersion("5.0.9.0"))); }