Java Code Examples for org.eclipse.aether.resolution.VersionRangeResult#getHighestVersion()

The following examples show how to use org.eclipse.aether.resolution.VersionRangeResult#getHighestVersion() . 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: 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 2
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 3
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 4
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();
}