Search in sources :

Example 1 with VersionConstraint

use of org.sonatype.aether.version.VersionConstraint 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 VersionConstraint

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

the class GenericVersionSchemeTest method testEnumeratedVersions.

@Test
public void testEnumeratedVersions() throws InvalidVersionSpecificationException {
    VersionConstraint c = scheme.parseVersionConstraint("1.0");
    assertEquals("1.0", c.getVersion().toString());
    assertTrue(c.containsVersion(new GenericVersion("1.0")));
    c = scheme.parseVersionConstraint("[1.0]");
    assertEquals(null, c.getVersion());
    assertTrue(c.containsVersion(new GenericVersion("1.0")));
    c = scheme.parseVersionConstraint("[1.0],[2.0]");
    assertTrue(c.containsVersion(new GenericVersion("1.0")));
    assertTrue(c.containsVersion(new GenericVersion("2.0")));
    c = scheme.parseVersionConstraint("[1.0],[2.0],[3.0]");
    assertContains(c, "1.0", "2.0", "3.0");
    assertNotContains(c, "1.5");
    c = scheme.parseVersionConstraint("[1,3),(3,5)");
    assertContains(c, "1", "2", "4");
    assertNotContains(c, "3", "5");
    c = scheme.parseVersionConstraint("[1,3),(3,)");
    assertContains(c, "1", "2", "4");
    assertNotContains(c, "3");
}
Also used : VersionConstraint(org.sonatype.aether.version.VersionConstraint) Test(org.junit.Test)

Example 3 with VersionConstraint

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

the class NearestVersionConflictResolver method selectVersion.

private void selectVersion(DependencyNode node, DependencyNode parent, int depth, Map<DependencyNode, Integer> depths, ConflictGroup group, Map<?, ?> conflictIds, DependencyNode root) throws RepositoryException {
    Integer smallestDepth = depths.get(node);
    if (smallestDepth == null || smallestDepth.intValue() > depth) {
        depths.put(node, Integer.valueOf(depth));
    } else {
        return;
    }
    Object key = conflictIds.get(node);
    if (group.key.equals(key)) {
        Position pos = new Position(parent, depth);
        if (parent != null) {
            group.positions.add(pos);
        }
        VersionConstraint constraint = node.getVersionConstraint();
        boolean backtrack = false;
        boolean hardConstraint = !constraint.getRanges().isEmpty();
        if (hardConstraint) {
            if (group.constraints.add(constraint)) {
                if (group.version != null && !constraint.containsVersion(group.version)) {
                    backtrack = true;
                }
            }
        }
        if (isAcceptable(group, node.getVersion())) {
            group.candidates.put(node, pos);
            if (backtrack) {
                backtrack(group, conflictIds, root);
            } else if (group.version == null || isNearer(pos, node.getVersion(), group.position, group.version)) {
                group.version = node.getVersion();
                group.position = pos;
            }
        } else {
            if (backtrack) {
                backtrack(group, conflictIds, root);
            }
            return;
        }
    }
    depth++;
    for (DependencyNode child : node.getChildren()) {
        selectVersion(child, node, depth, depths, group, conflictIds, root);
    }
}
Also used : VersionConstraint(org.sonatype.aether.version.VersionConstraint) DependencyNode(org.sonatype.aether.graph.DependencyNode)

Example 4 with VersionConstraint

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

the class GenericVersionScheme method parseVersionConstraint.

public VersionConstraint parseVersionConstraint(final String constraint) throws InvalidVersionSpecificationException {
    GenericVersionConstraint result = new GenericVersionConstraint();
    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)

Aggregations

VersionConstraint (org.sonatype.aether.version.VersionConstraint)4 InvalidVersionSpecificationException (org.sonatype.aether.version.InvalidVersionSpecificationException)2 VersionRange (org.sonatype.aether.version.VersionRange)2 Test (org.junit.Test)1 DependencyNode (org.sonatype.aether.graph.DependencyNode)1