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;
}
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");
}
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);
}
}
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;
}
Aggregations