org.eclipse.aether.resolution.VersionRangeResolutionException Java Examples
The following examples show how to use
org.eclipse.aether.resolution.VersionRangeResolutionException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LibertyFeatureVersionIT.java From boost with Eclipse Public License 1.0 | 6 votes |
private String getLatestLibertyRuntimeVersion() { String libertyVersion = null; RemoteRepository central = new RemoteRepository.Builder("central", "default", "http://repo1.maven.org/maven2/") .build(); RepositorySystem repoSystem = newRepositorySystem(); RepositorySystemSession session = newSession(repoSystem); String version = "[19.0.0.6,)"; Artifact artifact = new DefaultArtifact("io.openliberty:openliberty-runtime:" + version); VersionRangeRequest request = new VersionRangeRequest(artifact, Arrays.asList(central), null); try { VersionRangeResult versionResult = repoSystem.resolveVersionRange(session, request); libertyVersion = versionResult.getHighestVersion().toString(); } catch (VersionRangeResolutionException e) { e.printStackTrace(); } return libertyVersion; }
Example #2
Source File: AbstractLibertySupport.java From ci.maven with Apache License 2.0 | 6 votes |
private String resolveVersionRange(String groupId, String artifactId, String extension, String version) throws VersionRangeResolutionException { org.eclipse.aether.artifact.Artifact aetherArtifact = new org.eclipse.aether.artifact.DefaultArtifact(groupId, artifactId, extension, version); VersionRangeRequest rangeRequest = new VersionRangeRequest(); rangeRequest.setArtifact(aetherArtifact); rangeRequest.setRepositories(repositories); VersionRangeResult rangeResult = this.repositorySystem.resolveVersionRange(this.repoSession, rangeRequest); if (rangeResult == null || rangeResult.getHighestVersion() == null) { throw new VersionRangeResolutionException(rangeResult, "Unable to resolve version range fram " + groupId + ":" + artifactId + ":" + extension + ":" + version); } getLog().debug("Available versions: " + rangeResult.getVersions()); return rangeResult.getHighestVersion().toString(); }
Example #3
Source File: RepositoryModelResolver.java From archiva with Apache License 2.0 | 6 votes |
public ModelSource resolveModel(Dependency dependency) throws UnresolvableModelException { try { Artifact artifact = new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(), "", "pom", dependency.getVersion()); VersionRangeRequest versionRangeRequest = new VersionRangeRequest(artifact, null, null); VersionRangeResult versionRangeResult = this.versionRangeResolver.resolveVersionRange(this.session, versionRangeRequest); if (versionRangeResult.getHighestVersion() == null) { throw new UnresolvableModelException(String.format("No versions matched the requested dependency version range '%s'", dependency.getVersion()), dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion()); } else if (versionRangeResult.getVersionConstraint() != null && versionRangeResult.getVersionConstraint().getRange() != null && versionRangeResult.getVersionConstraint().getRange().getUpperBound() == null) { throw new UnresolvableModelException(String.format("The requested dependency version range '%s' does not specify an upper bound", dependency.getVersion()), dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion()); } else { dependency.setVersion(versionRangeResult.getHighestVersion().toString()); return this.resolveModel(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion()); } } catch (VersionRangeResolutionException var5) { throw new UnresolvableModelException(var5.getMessage(), dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), var5); } }
Example #4
Source File: SdkResolver.java From appengine-maven-plugin with Apache License 2.0 | 6 votes |
private static String determineNewestVersion(RepositorySystem repoSystem, RepositorySystemSession repoSession, List<RemoteRepository>[] repos) throws MojoExecutionException { String version;VersionRangeRequest rangeRequest = new VersionRangeRequest(); rangeRequest.setArtifact(new DefaultArtifact(SDK_GROUP_ID + ":" + SDK_ARTIFACT_ID + ":[0,)")); for(List<RemoteRepository> repoList : repos) { for(RemoteRepository repo : repoList) { rangeRequest.addRepository(repo); } } VersionRangeResult rangeResult; try { rangeResult = repoSystem.resolveVersionRange(repoSession, rangeRequest); } catch (VersionRangeResolutionException e) { throw new MojoExecutionException("Could not resolve latest version of the App Engine Java SDK", e); } List<Version> versions = rangeResult.getVersions(); Collections.sort(versions); Version newest = Iterables.getLast(versions); version = newest.toString(); return version; }
Example #5
Source File: RepositoryUtility.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
private static VersionRangeResult findVersionRange( RepositorySystem repositorySystem, RepositorySystemSession session, String groupId, String artifactId) throws MavenRepositoryException { Artifact artifactWithVersionRange = new DefaultArtifact(groupId, artifactId, null, "(0,]"); VersionRangeRequest request = new VersionRangeRequest( artifactWithVersionRange, ImmutableList.of(RepositoryUtility.CENTRAL), null); try { return repositorySystem.resolveVersionRange(session, request); } catch (VersionRangeResolutionException ex) { throw new MavenRepositoryException(ex); } }
Example #6
Source File: MavenDependencyResolver.java From spring-cloud-formula with Apache License 2.0 | 6 votes |
public List<Version> getAllVersions(String groupId, String artifactId) { String repositoryUrl = "http://maven.repo/nexus/content/groups/public"; RepositorySystem repoSystem = newRepositorySystem(); RepositorySystemSession session = newSession(repoSystem); RemoteRepository central = null; central = new RemoteRepository.Builder("central", "default", repositoryUrl).build(); Artifact artifact = new DefaultArtifact(groupId + ":" + artifactId + ":[0,)"); VersionRangeRequest rangeRequest = new VersionRangeRequest(); rangeRequest.setArtifact(artifact); rangeRequest.addRepository(central); VersionRangeResult rangeResult; try { rangeResult = repoSystem.resolveVersionRange(session, rangeRequest); } catch (VersionRangeResolutionException e) { throw new RuntimeException(e); } List<Version> versions = rangeResult.getVersions().stream() .filter(v -> !v.toString().toLowerCase().endsWith("-snapshot")) .filter(v -> !groupId.contains("org.springframework") || v.toString().equals("2.0.0.RELEASE")) .collect(Collectors.toList()); logger.info("artifact: {}, Available versions: {}", artifact, versions); return versions; }
Example #7
Source File: VersionResolver.java From migration-tooling with Apache License 2.0 | 5 votes |
/** * Given a set of maven coordinates, obtains a list of valid versions in ascending order. * Note, for soft pinned versions, it interprets it as the following version range: "[version,)" */ private List<String> requestVersionList(String groupId, String artifactId, String versionSpec) throws VersionRangeResolutionException, InvalidArtifactCoordinateException { String transformedSpec = makeVersionRange(versionSpec); Artifact artifact = ArtifactBuilder.fromCoords(groupId, artifactId, transformedSpec); return aether.requestVersionRange(artifact); }
Example #8
Source File: VersionResolverTest.java From migration-tooling with Apache License 2.0 | 5 votes |
/** * Ensures that an exception is thrown if there is a version range resolution exception. * This occurs when aether is unable to resolve the version. */ @Test(expected = ArtifactBuilder.InvalidArtifactCoordinateException.class) public void failsOnResolutionException() throws InvalidArtifactCoordinateException, VersionRangeResolutionException { Aether aether = Mockito.mock(Aether.class); Mockito.when(aether.requestVersionRange(any())) .thenThrow(new VersionRangeResolutionException(any())); VersionResolver resolver = new VersionResolver(aether); resolver.resolveVersion("something", "something", "1.0"); }
Example #9
Source File: VersionResolverTest.java From migration-tooling with Apache License 2.0 | 5 votes |
/** * Ensures that an exception is thrown if there is an invalid version range. An invalid version range * is one which is either (1) equal to null or (2) returns null when asked for highest version. */ @Test(expected = ArtifactBuilder.InvalidArtifactCoordinateException.class) public void failsOnInvalidVersionRange() throws VersionRangeResolutionException, InvalidArtifactCoordinateException { Aether aether = Mockito.mock(Aether.class); // Using `anyRangeResult()` will ensure that rangeResult.highestVersion() == null. Mockito.when(aether.requestVersionRange(any())) .thenReturn(anyList()); VersionResolver resolver = new VersionResolver(aether); resolver.resolveVersion("something", "something", "1.0"); }
Example #10
Source File: VersionResolverTest.java From migration-tooling with Apache License 2.0 | 5 votes |
/** * Asserts that given a soft pinned version specification, it selects that version, * and does not get the highest version. "3.4" is an example of a soft pinned version specification. */ @Test public void softPinnedVersion_versionExists() throws InvalidArtifactCoordinateException, VersionRangeResolutionException { Aether aether = Mockito.mock(Aether.class); Artifact artifact = ArtifactBuilder.fromCoords("something:something:[1.0,)"); Mockito.when(aether.requestVersionRange(artifact)).thenReturn(newArrayList("1.0", "1.2")); VersionResolver resolver = new VersionResolver(aether); String version = resolver.resolveVersion("something", "something", "1.0"); assertThat(version).isEqualTo("1.0"); }
Example #11
Source File: VersionResolverTest.java From migration-tooling with Apache License 2.0 | 5 votes |
/** * Asserts that if a soft pinned version specification DNE, it selects the nearest version. */ @Test public void softPinnedVersion_versionDoesNotExist() throws InvalidArtifactCoordinateException, VersionRangeResolutionException { Aether aether = Mockito.mock(Aether.class); Artifact artifact = ArtifactBuilder.fromCoords("something:something:[1.0,)"); Mockito.when(aether.requestVersionRange(artifact)).thenReturn(newArrayList("1.2", "2.0", "3.0")); VersionResolver resolver = new VersionResolver(aether); String version = resolver.resolveVersion("something", "something", "1.0"); assertThat(version).isEqualTo("1.2"); }
Example #12
Source File: VersionResolverTest.java From migration-tooling with Apache License 2.0 | 5 votes |
/** * Asserts that the VersionResolver selects the highest version from the list of versions * provided by aether. */ @Test public void selectsHighestVersion() throws InvalidArtifactCoordinateException, VersionRangeResolutionException { Aether aether = Mockito.mock(Aether.class); Artifact artifact; artifact = ArtifactBuilder.fromCoords("com.hello:something:[,)"); Mockito.when( aether.requestVersionRange(artifact)).thenReturn(newArrayList("1.0", "1.2", "1.3")); VersionResolver resolver = new VersionResolver(aether); String version = resolver.resolveVersion("com.hello", "something", "[,)"); assertThat(version).isEqualTo("1.3"); }
Example #13
Source File: AetherStubDownloader.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
private String resolveHighestArtifactVersion(String stubsGroup, String stubsModule, String classifier, String version) { Artifact artifact = new DefaultArtifact(stubsGroup, stubsModule, classifier, ARTIFACT_EXTENSION, version); VersionRangeRequest versionRangeRequest = new VersionRangeRequest(artifact, this.remoteRepos, null); VersionRangeResult rangeResult; try { rangeResult = this.repositorySystem.resolveVersionRange(this.session, versionRangeRequest); if (log.isDebugEnabled()) { log.debug("Resolved version range is [" + rangeResult + "]"); } } catch (VersionRangeResolutionException e) { throw new IllegalStateException("Cannot resolve version range", e); } if (rangeResult.getHighestVersion() == null) { throw new IllegalArgumentException("For groupId [" + stubsGroup + "] artifactId [" + stubsModule + "] " + "and classifier [" + classifier + "] the version was not resolved! The following exceptions took place " + rangeResult.getExceptions()); } return rangeResult.getHighestVersion() == null ? null : rangeResult.getHighestVersion().toString(); }
Example #14
Source File: MavenArtifactResolver.java From quarkus with Apache License 2.0 | 5 votes |
public VersionRangeResult resolveVersionRange(Artifact artifact) throws BootstrapMavenException { try { return repoSystem.resolveVersionRange(repoSession, new VersionRangeRequest() .setArtifact(artifact) .setRepositories(remoteRepos)); } catch (VersionRangeResolutionException ex) { throw new BootstrapMavenException("Failed to resolve version range for " + artifact, ex); } }
Example #15
Source File: Analyzer.java From revapi with Apache License 2.0 | 5 votes |
/** * Resolves the gav using the resolver. If the gav corresponds to the project artifact and is an unresolved version * for a RELEASE or LATEST, the gav is resolved such it a release not newer than the project version is found that * optionally corresponds to the provided version regex, if provided. * * <p>If the gav exactly matches the current project, the file of the artifact is found on the filesystem in * target directory and the resolver is ignored. * * @param project the project to restrict by, if applicable * @param gav the gav to resolve * @param versionRegex the optional regex the version must match to be considered. * @param resolver the version resolver to use * @return the resolved artifact matching the criteria. * @throws VersionRangeResolutionException on error * @throws ArtifactResolutionException on error */ static Artifact resolveConstrained(MavenProject project, String gav, Pattern versionRegex, ArtifactResolver resolver) throws VersionRangeResolutionException, ArtifactResolutionException { boolean latest = gav.endsWith(":LATEST"); if (latest || gav.endsWith(":RELEASE")) { Artifact a = new DefaultArtifact(gav); if (latest) { versionRegex = versionRegex == null ? ANY : versionRegex; } else { versionRegex = versionRegex == null ? ANY_NON_SNAPSHOT : versionRegex; } String upTo = project.getGroupId().equals(a.getGroupId()) && project.getArtifactId().equals(a.getArtifactId()) ? project.getVersion() : null; return resolver.resolveNewestMatching(gav, upTo, versionRegex, latest, latest); } else { String projectGav = getProjectArtifactCoordinates(project, null); Artifact ret = null; if (projectGav.equals(gav)) { ret = findProjectArtifact(project); } return ret == null ? resolver.resolveArtifact(gav) : ret; } }
Example #16
Source File: ArtifactResolver.java From revapi with Apache License 2.0 | 5 votes |
/** * Tries to find the newest version of the artifact that matches given regular expression. * The found version will be older than the {@code upToVersion} or newest available if {@code upToVersion} is null. * * @param gav the coordinates of the artifact. The version part is ignored * @param upToVersion the version up to which the versions will be matched * @param versionMatcher the matcher to match the version * @param remoteOnly true if only remotely available artifacts should be considered * @param upToInclusive whether the {@code upToVersion} should be considered inclusive or exclusive * @return the resolved artifact */ public Artifact resolveNewestMatching(String gav, @Nullable String upToVersion, Pattern versionMatcher, boolean remoteOnly, boolean upToInclusive) throws VersionRangeResolutionException, ArtifactResolutionException { Artifact artifact = new DefaultArtifact(gav); artifact = artifact.setVersion(upToVersion == null ? "[,)" : "[," + upToVersion + (upToInclusive ? "]" : ")")); VersionRangeRequest rangeRequest = new VersionRangeRequest(artifact, repositories, null); RepositorySystemSession session = remoteOnly ? makeRemoteOnly(this.session) : this.session; VersionRangeResult result = repositorySystem.resolveVersionRange(session, rangeRequest); List<Version> versions = new ArrayList<>(result.getVersions()); Collections.reverse(versions); for(Version v : versions) { if (versionMatcher.matcher(v.toString()).matches()) { return resolveArtifact(artifact.setVersion(v.toString()), session); } } throw new VersionRangeResolutionException(result) { @Override public String getMessage() { return "Failed to find a version of artifact '" + gav + "' that would correspond to an expression '" + versionMatcher + "'. The versions found were: " + versions; } }; }
Example #17
Source File: SdkResolver.java From gcloud-maven-plugin with Apache License 2.0 | 5 votes |
private static String determineNewestVersion(RepositorySystem repoSystem, RepositorySystemSession repoSession, List<RemoteRepository>[] repos) throws MojoExecutionException { String version; VersionRangeRequest rangeRequest = new VersionRangeRequest(); rangeRequest.setArtifact(new DefaultArtifact(SDK_GROUP_ID + ":" + SDK_ARTIFACT_ID + ":[0,)")); for (List<RemoteRepository> repoList : repos) { for (RemoteRepository repo : repoList) { rangeRequest.addRepository(repo); } } VersionRangeResult rangeResult; try { rangeResult = repoSystem.resolveVersionRange(repoSession, rangeRequest); } catch (VersionRangeResolutionException e) { throw new MojoExecutionException( "Could not resolve latest version of the App Engine Java SDK", e); } List<Version> versions = rangeResult.getVersions(); Collections.sort(versions); Version newest = Iterables.getLast(versions); version = newest.toString(); return version; }
Example #18
Source File: DependencyResolver.java From pinpoint with Apache License 2.0 | 5 votes |
public List<Version> getVersions(Artifact artifact) throws VersionRangeResolutionException { VersionRangeRequest rangeRequest = new VersionRangeRequest(); rangeRequest.setArtifact(artifact); rangeRequest.setRepositories(repositories); VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest); List<Version> versions = new ArrayList<Version>(rangeResult.getVersions()); Collections.sort(versions); return versions; }
Example #19
Source File: AbstractMavenArtifactRepositoryManager.java From galleon with Apache License 2.0 | 5 votes |
private VersionRangeResult getVersionRange(Artifact artifact) throws MavenUniverseException { VersionRangeRequest rangeRequest = new VersionRangeRequest(); rangeRequest.setArtifact(artifact); rangeRequest.setRepositories(getRepositories()); VersionRangeResult rangeResult; try { rangeResult = repoSystem.resolveVersionRange(getSession(), rangeRequest); } catch (VersionRangeResolutionException ex) { throw new MavenUniverseException(ex.getLocalizedMessage(), ex); } return rangeResult; }
Example #20
Source File: ReportAggregateMojo.java From revapi with Apache License 2.0 | 4 votes |
private ProjectVersions getRunConfig(MavenProject project) { ProjectVersions ret = new ProjectVersions(); Plugin revapiPlugin = findRevapi(project); if (revapiPlugin == null) { return ret; } Xpp3Dom pluginConfig = (Xpp3Dom) revapiPlugin.getConfiguration(); String[] oldArtifacts = getArtifacts(pluginConfig, "oldArtifacts"); String[] newArtifacts = getArtifacts(pluginConfig, "newArtifacts"); String oldVersion = getValueOfChild(pluginConfig, "oldVersion"); if (oldVersion == null) { oldVersion = System.getProperties().getProperty(Props.oldVersion.NAME, Props.oldVersion.DEFAULT_VALUE); } String newVersion = getValueOfChild(pluginConfig, "newVersion"); if (newVersion == null) { newVersion = System.getProperties().getProperty(Props.newVersion.NAME, project.getVersion()); } String defaultOldArtifact = Analyzer.getProjectArtifactCoordinates(project, oldVersion); String defaultNewArtifact = Analyzer.getProjectArtifactCoordinates(project, newVersion); if (oldArtifacts == null || oldArtifacts.length == 0) { if (!project.getArtifact().getArtifactHandler().isAddedToClasspath()) { return ret; } oldArtifacts = new String[]{defaultOldArtifact}; } if (newArtifacts == null || newArtifacts.length == 0) { if (!project.getArtifact().getArtifactHandler().isAddedToClasspath()) { return ret; } newArtifacts = new String[]{defaultNewArtifact}; } String versionRegexString = getValueOfChild(pluginConfig, "versionFormat"); Pattern versionRegex = versionRegexString == null ? null : Pattern.compile(versionRegexString); DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repositorySystemSession); session.setDependencySelector(getRevapiDependencySelector(resolveProvidedDependencies, resolveTransitiveProvidedDependencies)); session.setDependencyTraverser(getRevapiDependencyTraverser(resolveProvidedDependencies, resolveTransitiveProvidedDependencies)); if (alwaysCheckForReleaseVersion) { session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS); } ArtifactResolver resolver = new ArtifactResolver(repositorySystem, session, mavenSession.getCurrentProject().getRemoteProjectRepositories()); Function<String, Artifact> resolve = gav -> { try { return Analyzer.resolveConstrained(project, gav, versionRegex, resolver); } catch (VersionRangeResolutionException | ArtifactResolutionException e) { getLog().warn("Could not resolve artifact '" + gav + "' with message: " + e.getMessage()); return null; } }; ret.oldGavs = Stream.of(oldArtifacts).map(resolve).filter(f -> f != null).toArray(Artifact[]::new); ret.newGavs = Stream.of(newArtifacts).map(resolve).filter(f -> f != null).toArray(Artifact[]::new); return ret; }
Example #21
Source File: Aether.java From migration-tooling with Apache License 2.0 | 4 votes |
/** Given an artifacts requests a version range for it. */ List<String> requestVersionRange(Artifact artifact) throws VersionRangeResolutionException { VersionRangeRequest rangeRequest = new VersionRangeRequest(artifact, remoteRepositories, null); VersionRangeResult result = repositorySystem.resolveVersionRange(repositorySystemSession, rangeRequest); return result.getVersions().stream().map(Version::toString).collect(toList()); }
Example #22
Source File: DependencyResolver.java From pinpoint with Apache License 2.0 | 3 votes |
public String getNewestVersion(String groupId, String artifactId) throws VersionRangeResolutionException { Artifact artifact = new DefaultArtifact(groupId, artifactId, "jar", "[0,)"); VersionRangeRequest rangeRequest = new VersionRangeRequest(); rangeRequest.setArtifact(artifact); rangeRequest.setRepositories(repositories); VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest); Version newestVersion = rangeResult.getHighestVersion(); return newestVersion.toString(); }