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