Search in sources :

Example 1 with VersionRange

use of org.sonatype.aether.version.VersionRange in project sonatype-aether by sonatype.

the class TestVersionScheme method parseVersionConstraint.

public VersionConstraint parseVersionConstraint(final String constraint) throws InvalidVersionSpecificationException {
    TestVersionConstraint result = new TestVersionConstraint();
    String process = constraint;
    while (process.startsWith("[") || process.startsWith("(")) {
        int index1 = process.indexOf(")");
        int index2 = process.indexOf("]");
        int index = index2;
        if (index2 < 0 || (index1 >= 0 && index1 < index2)) {
            index = index1;
        }
        if (index < 0) {
            throw new InvalidVersionSpecificationException(constraint, "Unbounded version range " + constraint);
        }
        VersionRange range = parseVersionRange(process.substring(0, index + 1));
        result.addRange(range);
        process = process.substring(index + 1).trim();
        if (process.length() > 0 && process.startsWith(",")) {
            process = process.substring(1).trim();
        }
    }
    if (process.length() > 0 && !result.getRanges().isEmpty()) {
        throw new InvalidVersionSpecificationException(constraint, "Invalid version range " + constraint + ", expected [ or ( but got " + process);
    }
    if (result.getRanges().isEmpty()) {
        result.setVersion(parseVersion(constraint));
    }
    return result;
}
Also used : InvalidVersionSpecificationException(org.sonatype.aether.version.InvalidVersionSpecificationException) VersionRange(org.sonatype.aether.version.VersionRange) VersionConstraint(org.sonatype.aether.version.VersionConstraint)

Example 2 with VersionRange

use of org.sonatype.aether.version.VersionRange in project sonatype-aether by sonatype.

the class GenericVersionRangeTest method testLowerBoundInclusiveUpperBoundExclusive.

@Test
public void testLowerBoundInclusiveUpperBoundExclusive() {
    VersionRange range = parseValid("[1.2.3.4.5,1.2.3.4.6)");
    assertContains(range, "1.2.3.4.5");
    assertNotContains(range, "1.2.3.4.6");
    assertEquals(range, parseValid(range.toString()));
}
Also used : VersionRange(org.sonatype.aether.version.VersionRange) Test(org.junit.Test)

Example 3 with VersionRange

use of org.sonatype.aether.version.VersionRange in project sonatype-aether by sonatype.

the class GenericVersionRangeTest method testLowerBoundExclusiveUpperBoundExclusive.

@Test
public void testLowerBoundExclusiveUpperBoundExclusive() {
    VersionRange range = parseValid("(1,3)");
    assertNotContains(range, "1");
    assertContains(range, "2-SNAPSHOT");
    assertNotContains(range, "3");
    assertEquals(range, parseValid(range.toString()));
}
Also used : VersionRange(org.sonatype.aether.version.VersionRange) Test(org.junit.Test)

Example 4 with VersionRange

use of org.sonatype.aether.version.VersionRange in project sonatype-aether by sonatype.

the class PatternInclusionsDependencyFilter method isVersionIncludedInRange.

private boolean isVersionIncludedInRange(final String version, final String range) {
    if (versionScheme == null) {
        return false;
    } else {
        try {
            final Version parsedVersion = versionScheme.parseVersion(version);
            final VersionRange parsedRange = versionScheme.parseVersionRange(range);
            return parsedRange.containsVersion(parsedVersion);
        } catch (final InvalidVersionSpecificationException e) {
            return false;
        }
    }
}
Also used : InvalidVersionSpecificationException(org.sonatype.aether.version.InvalidVersionSpecificationException) Version(org.sonatype.aether.version.Version) VersionRange(org.sonatype.aether.version.VersionRange)

Example 5 with VersionRange

use of org.sonatype.aether.version.VersionRange in project sonatype-aether by sonatype.

the class GenericVersionRangeTest method testLowerBoundExclusiveUpperBoundInclusive.

@Test
public void testLowerBoundExclusiveUpperBoundInclusive() {
    VersionRange range = parseValid("(1a,1b]");
    assertNotContains(range, "1a");
    assertContains(range, "1b");
    assertEquals(range, parseValid(range.toString()));
}
Also used : VersionRange(org.sonatype.aether.version.VersionRange) Test(org.junit.Test)

Aggregations

VersionRange (org.sonatype.aether.version.VersionRange)8 Test (org.junit.Test)5 InvalidVersionSpecificationException (org.sonatype.aether.version.InvalidVersionSpecificationException)3 VersionConstraint (org.sonatype.aether.version.VersionConstraint)2 Version (org.sonatype.aether.version.Version)1