Search in sources :

Example 1 with InvalidVersionSpecificationException

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

use of org.sonatype.aether.version.InvalidVersionSpecificationException 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 3 with InvalidVersionSpecificationException

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

Example 4 with InvalidVersionSpecificationException

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

the class NodeBuilder method build.

public DependencyNode build() {
    Dependency dependency = null;
    TestDependencyNode node = new TestDependencyNode();
    if (artifactId != null && artifactId.length() > 0) {
        Artifact artifact = new StubArtifact(groupId, artifactId, classifier, ext, version, properties);
        dependency = new Dependency(artifact, scope, optional);
        node.setDependency(dependency);
        try {
            node.setVersion(versionScheme.parseVersion(version));
            node.setVersionConstraint(versionScheme.parseVersionConstraint(range != null ? range : version));
        } catch (InvalidVersionSpecificationException e) {
            throw new IllegalArgumentException("bad version: " + e.getMessage(), e);
        }
    }
    node.setRequestContext(context);
    node.setRelocations(relocations);
    return node;
}
Also used : TestDependencyNode(org.sonatype.aether.test.util.impl.TestDependencyNode) InvalidVersionSpecificationException(org.sonatype.aether.version.InvalidVersionSpecificationException) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Dependency(org.sonatype.aether.graph.Dependency) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact)

Aggregations

InvalidVersionSpecificationException (org.sonatype.aether.version.InvalidVersionSpecificationException)4 VersionRange (org.sonatype.aether.version.VersionRange)3 VersionConstraint (org.sonatype.aether.version.VersionConstraint)2 Artifact (org.sonatype.aether.artifact.Artifact)1 Dependency (org.sonatype.aether.graph.Dependency)1 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)1 TestDependencyNode (org.sonatype.aether.test.util.impl.TestDependencyNode)1 Version (org.sonatype.aether.version.Version)1