/** * Expands a version range to a list of matching versions, in ascending order. For example, resolves "[3.8,4.0)" to * ["3.8", "3.8.1", "3.8.2"]. * * @param request The version range request, must not be {@code null} * @return The version range result, never {@code null}. * @throws org.sonatype.aether.resolution.VersionRangeResolutionException If the requested range could not be parsed. Note that an empty range does * not raise an exception. */ public VersionRangeResult resolveVersionRange( VersionRangeRequest request ) throws VersionRangeResolutionException { return repository.resolveVersionRange(session, request); }
public VersionRangeResult resolveVersions(String groupId, String artifactId, String classifier, String extension, String version) { final RepositorySystemSession session = newSession(); Artifact artifact = new DefaultArtifact(groupId, artifactId, classifier, extension, version); if (artifact.getVersion().equals("LATEST")) { artifact = artifact.setVersion(LATEST_VERSION_RANGE); } final VersionRangeRequest request = new VersionRangeRequest(artifact, m_remoteRepos, null); try { return m_repoSystem.resolveVersionRange(session, request); } catch (VersionRangeResolutionException e) { final VersionRangeResult result = new VersionRangeResult(request); result.setVersions(Arrays.asList((Version) new VersionImpl(version))); return result; } }
/** * Tries to resolve versions = LATEST using an open range version query. * If it succeeds, version of artifact is set to the highest available version. * * @param session to be used. * @param artifact to be used * @return an artifact with version set properly (highest if available) * @throws org.sonatype.aether.resolution.VersionRangeResolutionException * in case of resolver errors. */ private Artifact resolveLatestVersionRange(RepositorySystemSession session, Artifact artifact) throws VersionRangeResolutionException { if (artifact.getVersion().equals("LATEST")) { artifact = artifact.setVersion(LATEST_VERSION_RANGE); VersionRangeResult versionResult = m_repoSystem.resolveVersionRange(session, new VersionRangeRequest(artifact, m_remoteRepos, null)); if (versionResult != null) { Version v = versionResult.getHighestVersion(); if (v != null) { artifact = artifact.setVersion(v.toString()); } else { throw new VersionRangeResolutionException(versionResult, "Not highest version found for " + artifact); } } } return artifact; }
VersionRangeResult rangeResult = maven.resolveVersionRange(session, rangeRequest); return rangeResult;