org.eclipse.aether.resolution.VersionRangeRequest Java Examples

The following examples show how to use org.eclipse.aether.resolution.VersionRangeRequest. 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: MavenDependencyResolver.java    From spring-cloud-formula with Apache License 2.0 6 votes vote down vote up
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 #2
Source File: LibertyFeatureVersionIT.java    From boost with Eclipse Public License 1.0 6 votes vote down vote up
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 #3
Source File: RepositoryUtility.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
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 #4
Source File: SdkResolver.java    From appengine-maven-plugin with Apache License 2.0 6 votes vote down vote up
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: RepositoryModelResolver.java    From archiva with Apache License 2.0 6 votes vote down vote up
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 #6
Source File: AbstractLibertySupport.java    From ci.maven with Apache License 2.0 6 votes vote down vote up
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 #7
Source File: AbstractMavenArtifactRepositoryManager.java    From galleon with Apache License 2.0 5 votes vote down vote up
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 #8
Source File: MavenArtifactResolver.java    From quarkus with Apache License 2.0 5 votes vote down vote up
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 #9
Source File: AetherStubDownloader.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
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 #10
Source File: ArtifactResolver.java    From revapi with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #11
Source File: SdkResolver.java    From gcloud-maven-plugin with Apache License 2.0 5 votes vote down vote up
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 #12
Source File: DependencyResolver.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
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 #13
Source File: MavenAddonDependencyResolver.java    From furnace with Eclipse Public License 1.0 5 votes vote down vote up
private VersionRangeResult getVersions(RepositorySystem system, Settings settings, RepositorySystemSession session,
         List<RemoteRepository> repositories,
         String addonName,
         String version)
{
   try
   {
      String[] split = addonName.split(",");
      if (split.length == 2)
      {
         version = split[1];
      }
      if (version == null || version.isEmpty())
      {
         version = "[,)";
      }
      else if (!version.matches("(\\(|\\[).*?(\\)|\\])"))
      {
         version = "[" + version + "]";
      }

      Artifact artifact = new DefaultArtifact(toMavenCoords(AddonId.from(addonName, version)));
      VersionRangeRequest rangeRequest = new VersionRangeRequest(artifact, repositories, null);
      VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest);
      return rangeResult;
   }
   catch (Exception e)
   {
      throw new RuntimeException("Failed to look up versions for [" + addonName + "]", e);
   }
}
 
Example #14
Source File: Aether.java    From migration-tooling with Apache License 2.0 4 votes vote down vote up
/** 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 #15
Source File: DependencyResolver.java    From pinpoint with Apache License 2.0 3 votes vote down vote up
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();
}