Search in sources :

Example 1 with Version

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

the class FindNewestVersion method main.

public static void main(String[] args) throws Exception {
    System.out.println("------------------------------------------------------------");
    System.out.println(FindNewestVersion.class.getSimpleName());
    RepositorySystem system = Booter.newRepositorySystem();
    RepositorySystemSession session = Booter.newRepositorySystemSession(system);
    Artifact artifact = new DefaultArtifact("org.sonatype.aether:aether-util:[0,)");
    RemoteRepository repo = Booter.newCentralRepository();
    VersionRangeRequest rangeRequest = new VersionRangeRequest();
    rangeRequest.setArtifact(artifact);
    rangeRequest.addRepository(repo);
    VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest);
    Version newestVersion = rangeResult.getHighestVersion();
    System.out.println("Newest version " + newestVersion + " from repository " + rangeResult.getRepository(newestVersion));
}
Also used : RepositorySystem(org.sonatype.aether.RepositorySystem) RepositorySystemSession(org.sonatype.aether.RepositorySystemSession) VersionRangeResult(org.sonatype.aether.resolution.VersionRangeResult) Version(org.sonatype.aether.version.Version) RemoteRepository(org.sonatype.aether.repository.RemoteRepository) VersionRangeRequest(org.sonatype.aether.resolution.VersionRangeRequest) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact)

Example 2 with Version

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

the class AbstractVersionTest method assertOrder.

protected void assertOrder(int expected, String version1, String version2) {
    Version v1 = newVersion(version1);
    Version v2 = newVersion(version2);
    if (expected > 0) {
        assertEquals("expected " + v1 + " > " + v2, 1, Integer.signum(v1.compareTo(v2)));
        assertEquals("expected " + v2 + " < " + v1, -1, Integer.signum(v2.compareTo(v1)));
        assertEquals("expected " + v1 + " != " + v2, false, v1.equals(v2));
        assertEquals("expected " + v2 + " != " + v1, false, v2.equals(v1));
    } else if (expected < 0) {
        assertEquals("expected " + v1 + " < " + v2, -1, Integer.signum(v1.compareTo(v2)));
        assertEquals("expected " + v2 + " > " + v1, 1, Integer.signum(v2.compareTo(v1)));
        assertEquals("expected " + v1 + " != " + v2, false, v1.equals(v2));
        assertEquals("expected " + v2 + " != " + v1, false, v2.equals(v1));
    } else {
        assertEquals("expected " + v1 + " == " + v2, 0, v1.compareTo(v2));
        assertEquals("expected " + v2 + " == " + v1, 0, v2.compareTo(v1));
        assertEquals("expected " + v1 + " == " + v2, true, v1.equals(v2));
        assertEquals("expected " + v2 + " == " + v1, true, v2.equals(v1));
        assertEquals("expected #(" + v1 + ") == #(" + v1 + ")", v1.hashCode(), v2.hashCode());
    }
}
Also used : Version(org.sonatype.aether.version.Version)

Example 3 with Version

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

the class StubVersionRangeResolver method resolveVersionRange.

public VersionRangeResult resolveVersionRange(RepositorySystemSession session, VersionRangeRequest request) throws VersionRangeResolutionException {
    String version = request.getArtifact().getVersion();
    boolean range = false;
    if (version.matches("\\[[^,]+,.*")) {
        version = version.substring(1, version.indexOf(',', 1));
        range = true;
    }
    VersionRangeResult result = new VersionRangeResult(request);
    StubVersion ver = new StubVersion(version);
    result.setVersions(Arrays.asList((Version) ver));
    if (range && !request.getRepositories().isEmpty()) {
        result.setRepository(ver, request.getRepositories().get(0));
    }
    return result;
}
Also used : VersionRangeResult(org.sonatype.aether.resolution.VersionRangeResult) Version(org.sonatype.aether.version.Version) StubVersion(org.sonatype.aether.test.util.impl.StubVersion) StubVersion(org.sonatype.aether.test.util.impl.StubVersion)

Example 4 with Version

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

the class NearestVersionConflictResolver method backtrack.

private void backtrack(ConflictGroup group, Map<?, ?> conflictIds, DependencyNode root) throws UnsolvableVersionConflictException {
    group.version = null;
    for (Iterator<Map.Entry<DependencyNode, Position>> it = group.candidates.entrySet().iterator(); it.hasNext(); ) {
        Map.Entry<DependencyNode, Position> entry = it.next();
        Version version = entry.getKey().getVersion();
        Position pos = entry.getValue();
        if (!isAcceptable(group, version)) {
            it.remove();
        } else if (group.version == null || isNearer(pos, version, group.position, group.version)) {
            group.version = version;
            group.position = pos;
        }
    }
    if (group.version == null) {
        throw newFailure(group, conflictIds, root);
    }
}
Also used : Version(org.sonatype.aether.version.Version) DependencyNode(org.sonatype.aether.graph.DependencyNode) IdentityHashMap(java.util.IdentityHashMap) Map(java.util.Map)

Example 5 with Version

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

Aggregations

Version (org.sonatype.aether.version.Version)8 VersionRangeResult (org.sonatype.aether.resolution.VersionRangeResult)5 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)4 VersionRangeRequest (org.sonatype.aether.resolution.VersionRangeRequest)4 Artifact (org.sonatype.aether.artifact.Artifact)3 RepositorySystem (org.sonatype.aether.RepositorySystem)2 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)2 DependencyManager (org.sonatype.aether.collection.DependencyManager)2 DependencySelector (org.sonatype.aether.collection.DependencySelector)2 DependencyTraverser (org.sonatype.aether.collection.DependencyTraverser)2 Dependency (org.sonatype.aether.graph.Dependency)2 ArtifactDescriptorException (org.sonatype.aether.resolution.ArtifactDescriptorException)2 ArtifactDescriptorRequest (org.sonatype.aether.resolution.ArtifactDescriptorRequest)2 ArtifactDescriptorResult (org.sonatype.aether.resolution.ArtifactDescriptorResult)2 VersionRangeResolutionException (org.sonatype.aether.resolution.VersionRangeResolutionException)2 DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)2 ArrayList (java.util.ArrayList)1 IdentityHashMap (java.util.IdentityHashMap)1 List (java.util.List)1 Map (java.util.Map)1