Search in sources :

Example 6 with VersionRangeResolutionException

use of org.eclipse.aether.resolution.VersionRangeResolutionException in project pinpoint by naver.

the class DependencyResolver method resolveDependencySets.

public Map<String, List<Artifact>> resolveDependencySets(String... dependencies) {
    List<List<Artifact>> companions = resolve(dependencies);
    List<List<List<Artifact>>> xxx = new ArrayList<>();
    for (List<Artifact> companion : companions) {
        Artifact representative = companion.get(0);
        List<Version> versions;
        try {
            versions = getVersions(representative);
        } catch (VersionRangeResolutionException e) {
            throw new IllegalArgumentException("Fail to resolve version of: " + representative);
        }
        if (versions.isEmpty()) {
            throw new IllegalArgumentException("No version in the given range: " + representative);
        }
        List<List<Artifact>> companionVersions = new ArrayList<>(versions.size());
        for (Version version : versions) {
            List<Artifact> companionVersion = new ArrayList<>(companion.size());
            for (Artifact artifact : companion) {
                Artifact verArtifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getExtension(), version.toString());
                companionVersion.add(verArtifact);
            }
            companionVersions.add(companionVersion);
        }
        xxx.add(companionVersions);
    }
    Map<String, List<Artifact>> result = combination(xxx);
    return result;
}
Also used : ArrayList(java.util.ArrayList) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) Version(org.eclipse.aether.version.Version) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException)

Example 7 with VersionRangeResolutionException

use of org.eclipse.aether.resolution.VersionRangeResolutionException in project liferay-ide by liferay.

the class AetherUtil method getLatestVersion.

public static String getLatestVersion(String gavCoords, RepositorySystem system, RepositorySystemSession session) {
    String retval = null;
    String[] gav = gavCoords.split(":");
    if ((gav == null) || (gav.length != 3)) {
        throw new IllegalArgumentException("gavCoords should be group:artifactId:version");
    }
    Artifact artifact = new DefaultArtifact(gav[0] + ":" + gav[1] + ":[" + gav[2] + ",)");
    VersionRangeRequest rangeRequest = new VersionRangeRequest();
    rangeRequest.setArtifact(artifact);
    rangeRequest.addRepository(newCentralRepository());
    try {
        VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest);
        Version newestVersion = rangeResult.getHighestVersion();
        List<Version> versions = rangeResult.getVersions();
        if ((versions.size() > 1) && newestVersion.toString().endsWith("-SNAPSHOT")) {
            retval = versions.get(versions.size() - 2).toString();
        } else if (newestVersion != null) {
            retval = newestVersion.toString();
        }
    } catch (VersionRangeResolutionException vrre) {
        LiferayMavenCore.logError("Unable to get latest artifact version.", vrre);
    }
    if (retval == null) {
        retval = gav[2];
    }
    return retval;
}
Also used : VersionRangeResult(org.eclipse.aether.resolution.VersionRangeResult) Version(org.eclipse.aether.version.Version) VersionRangeRequest(org.eclipse.aether.resolution.VersionRangeRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException)

Example 8 with VersionRangeResolutionException

use of org.eclipse.aether.resolution.VersionRangeResolutionException in project revapi by revapi.

the class ArtifactResolver method resolveNewestMatching.

/**
 * 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
 * @throws VersionRangeResolutionException
 */
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;
        }
    };
}
Also used : AbstractForwardingRepositorySystemSession(org.eclipse.aether.AbstractForwardingRepositorySystemSession) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) VersionRangeResult(org.eclipse.aether.resolution.VersionRangeResult) Version(org.eclipse.aether.version.Version) ArrayList(java.util.ArrayList) VersionRangeRequest(org.eclipse.aether.resolution.VersionRangeRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException)

Example 9 with VersionRangeResolutionException

use of org.eclipse.aether.resolution.VersionRangeResolutionException in project revapi by revapi.

the class Analyzer method resolveArtifacts.

@SuppressWarnings("unchecked")
void resolveArtifacts() {
    if (resolvedOldApi == null) {
        final ArtifactResolver resolver = new ArtifactResolver(repositorySystem, repositorySystemSession, project.getRemoteProjectRepositories());
        Function<String, MavenArchive> toFileArchive = gav -> {
            try {
                Artifact a = resolveConstrained(project, gav, versionRegex, resolver);
                return MavenArchive.of(a);
            } catch (ArtifactResolutionException | VersionRangeResolutionException | IllegalArgumentException e) {
                throw new MarkerException(e.getMessage(), e);
            }
        };
        List<MavenArchive> oldArchives = new ArrayList<>(1);
        try {
            if (oldGavs != null) {
                oldArchives = Stream.of(oldGavs).map(toFileArchive).collect(toList());
            }
            if (oldArtifacts != null) {
                oldArchives.addAll(Stream.of(oldArtifacts).map(MavenArchive::of).collect(toList()));
            }
        } catch (MarkerException | IllegalArgumentException e) {
            String message = "Failed to resolve old artifacts: " + e.getMessage() + ".";
            if (failOnMissingArchives) {
                throw new IllegalStateException(message, e);
            } else {
                log.warn(message + " The API analysis will proceed comparing the new archives against an empty" + " archive.");
            }
        }
        List<MavenArchive> newArchives = new ArrayList<>(1);
        try {
            if (newGavs != null) {
                newArchives = Stream.of(newGavs).map(toFileArchive).collect(toList());
            }
            if (newArtifacts != null) {
                newArchives.addAll(Stream.of(newArtifacts).map(MavenArchive::of).collect(toList()));
            }
        } catch (MarkerException | IllegalArgumentException e) {
            String message = "Failed to resolve new artifacts: " + e.getMessage() + ".";
            if (failOnMissingArchives) {
                throw new IllegalStateException(message, e);
            } else {
                log.warn(message + " The API analysis will not proceed.");
                return;
            }
        }
        // now we need to be a little bit clever. When using RELEASE or LATEST as the version of the old artifact
        // it might happen that it gets resolved to the same version as the new artifacts - this notoriously happens
        // when releasing using the release plugin - you first build your artifacts, put them into the local repo
        // and then do the site updates for the released version. When you do the site, maven will find the released
        // version in the repo and resolve RELEASE to it. You compare it against what you just built, i.e. the same
        // code, et voila, the site report doesn't ever contain any found differences...
        Set<MavenArchive> oldTransitiveDeps = new HashSet<>();
        Set<MavenArchive> newTransitiveDeps = new HashSet<>();
        if (resolveDependencies) {
            String[] resolvedOld = oldArchives.stream().map(MavenArchive::getName).toArray(String[]::new);
            String[] resolvedNew = newArchives.stream().map(MavenArchive::getName).toArray(String[]::new);
            oldTransitiveDeps.addAll(collectDeps("old", resolver, resolvedOld));
            newTransitiveDeps.addAll(collectDeps("new", resolver, resolvedNew));
        }
        resolvedOldApi = API.of(oldArchives).supportedBy(oldTransitiveDeps).build();
        resolvedNewApi = API.of(newArchives).supportedBy(newTransitiveDeps).build();
    }
}
Also used : Arrays(java.util.Arrays) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) PlexusConfiguration(org.codehaus.plexus.configuration.PlexusConfiguration) XmlToJson(org.revapi.configuration.XmlToJson) MavenProject(org.apache.maven.project.MavenProject) Locale(java.util.Locale) Map(java.util.Map) ArtifactResolver(org.revapi.maven.utils.ArtifactResolver) API(org.revapi.API) RepositoryPolicy(org.eclipse.aether.repository.RepositoryPolicy) Set(java.util.Set) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) Artifact(org.eclipse.aether.artifact.Artifact) AnalysisResult(org.revapi.AnalysisResult) Reader(java.io.Reader) Revapi(org.revapi.Revapi) FileNotFoundException(java.io.FileNotFoundException) ValidationResult(org.revapi.configuration.ValidationResult) List(java.util.List) Stream(java.util.stream.Stream) RepositoryUtils(org.apache.maven.RepositoryUtils) ScopeDependencyTraverser(org.revapi.maven.utils.ScopeDependencyTraverser) ModelNode(org.jboss.dmr.ModelNode) Pattern(java.util.regex.Pattern) Spliterator(java.util.Spliterator) RepositorySystem(org.eclipse.aether.RepositorySystem) Reporter(org.revapi.Reporter) XmlPlexusConfiguration(org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration) Xpp3DomBuilder(org.codehaus.plexus.util.xml.Xpp3DomBuilder) Function(java.util.function.Function) Supplier(java.util.function.Supplier) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Charset(java.nio.charset.Charset) StreamSupport(java.util.stream.StreamSupport) JSONUtil(org.revapi.configuration.JSONUtil) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) Iterator(java.util.Iterator) AnalysisContext(org.revapi.AnalysisContext) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Log(org.apache.maven.plugin.logging.Log) InputStreamReader(java.io.InputStreamReader) File(java.io.File) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) Collectors.toList(java.util.stream.Collectors.toList) RepositoryException(org.eclipse.aether.RepositoryException) Collections(java.util.Collections) ScopeDependencySelector(org.revapi.maven.utils.ScopeDependencySelector) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ArtifactResolver(org.revapi.maven.utils.ArtifactResolver) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) HashSet(java.util.HashSet)

Example 10 with VersionRangeResolutionException

use of org.eclipse.aether.resolution.VersionRangeResolutionException in project drools by kiegroup.

the class MavenRepository method resolveVersion.

public Version resolveVersion(String artifactName) {
    Artifact artifact = new DefaultArtifact(artifactName);
    VersionRangeRequest versionRequest = new VersionRangeRequest();
    versionRequest.setArtifact(artifact);
    for (RemoteRepository repo : remoteRepositoriesForRequest) {
        versionRequest.addRepository(repo);
    }
    try {
        VersionRangeResult versionRangeResult = aether.getSystem().resolveVersionRange(aether.getSession(), versionRequest);
        return versionRangeResult.getHighestVersion();
    } catch (VersionRangeResolutionException e) {
        if (log.isDebugEnabled()) {
            log.debug("Unable to resolve version range for artifact: " + artifactName, e);
        } else {
            log.warn("Unable to resolve version range for artifact: " + artifactName);
        }
        return null;
    }
}
Also used : VersionRangeResult(org.eclipse.aether.resolution.VersionRangeResult) VersionRangeRequest(org.eclipse.aether.resolution.VersionRangeRequest) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException)

Aggregations

VersionRangeResolutionException (org.eclipse.aether.resolution.VersionRangeResolutionException)14 Artifact (org.eclipse.aether.artifact.Artifact)11 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)10 Version (org.eclipse.aether.version.Version)9 VersionRangeRequest (org.eclipse.aether.resolution.VersionRangeRequest)8 VersionRangeResult (org.eclipse.aether.resolution.VersionRangeResult)8 File (java.io.File)6 ArrayList (java.util.ArrayList)6 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)6 MavenProject (org.apache.maven.project.MavenProject)5 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)5 IOException (java.io.IOException)4 List (java.util.List)4 FileNotFoundException (java.io.FileNotFoundException)3 Map (java.util.Map)3 DefaultArtifactVersion (org.apache.maven.artifact.versioning.DefaultArtifactVersion)3 Model (org.apache.maven.model.Model)3 SPluginBundleVersion (org.bimserver.interfaces.objects.SPluginBundleVersion)3 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)3 RepositorySystem (org.eclipse.aether.RepositorySystem)3