Search in sources :

Example 91 with Artifact

use of org.eclipse.aether.artifact.Artifact in project fabric8 by jboss-fuse.

the class AetherBasedResolver method collectDependenciesFromPom.

protected DependencyNode collectDependenciesFromPom(File rootPom, Model model, Filter<Dependency> excludeDependencyFilter) throws RepositoryException, IOException {
    Map<String, String> props = Collections.singletonMap(ArtifactProperties.LOCAL_PATH, rootPom.toString());
    // lets load the model so we can get the version which is required for the transformer...
    String groupId = model.getGroupId();
    String artifactId = model.getArtifactId();
    String pomVersion = model.getVersion();
    String packaging = "pom";
    if (groupId == null || artifactId == null || pomVersion == null) {
        throw new IllegalArgumentException("Pomegranate pom.xml has missing groupId:artifactId:version " + groupId + ":" + artifactId + ":" + pomVersion);
    }
    Artifact root = new DefaultArtifact(groupId, artifactId, null, packaging, pomVersion, props, rootPom);
    return collectDependencies(root, pomVersion, excludeDependencyFilter);
}
Also used : Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 92 with Artifact

use of org.eclipse.aether.artifact.Artifact in project spf4j by zolyfarkas.

the class MavenRepositoryUtils method resolveArtifactAndDependencies.

public static Set<File> resolveArtifactAndDependencies(final String scope, final String groupId, final String artifactId, final String classifier, final String extension, final String versionExpr, final List<RemoteRepository> repos, final RepositorySystem repositorySystem, final RepositorySystemSession session) throws DependencyResolutionException {
    Artifact artifact = new DefaultArtifact(groupId, artifactId, classifier, extension, versionExpr);
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new Dependency(artifact, scope));
    collectRequest.setRepositories(repos);
    DependencyFilter dependencyFilter = DependencyFilterUtils.classpathFilter(scope);
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, dependencyFilter);
    DependencyResult depresult = repositorySystem.resolveDependencies(session, dependencyRequest);
    List<ArtifactResult> artifactResults = depresult.getArtifactResults();
    Set<File> result = Sets.newHashSetWithExpectedSize(artifactResults.size());
    for (ArtifactResult ar : artifactResults) {
        result.add(ar.getArtifact().getFile());
    }
    return result;
}
Also used : DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyResult(org.eclipse.aether.resolution.DependencyResult) DependencyFilter(org.eclipse.aether.graph.DependencyFilter) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 93 with Artifact

use of org.eclipse.aether.artifact.Artifact in project liferay-ide by liferay.

the class AetherUtil method getLatestAvailableArtifact.

public static Artifact getLatestAvailableArtifact(String gavCoords) {
    Artifact retval = null;
    RepositorySystem system = newRepositorySystem();
    RepositorySystemSession session = newRepositorySystemSession(system);
    String latestVersion = getLatestVersion(gavCoords, system, session);
    String[] gav = gavCoords.split(":");
    Artifact defaultArtifact = new DefaultArtifact(gav[0] + ":" + gav[1] + ":" + latestVersion);
    ArtifactRequest artifactRequest = new ArtifactRequest();
    artifactRequest.setArtifact(defaultArtifact);
    artifactRequest.addRepository(newCentralRepository());
    try {
        ArtifactResult artifactResult = system.resolveArtifact(session, artifactRequest);
        retval = artifactResult.getArtifact();
    } catch (ArtifactResolutionException e) {
        LiferayMavenCore.logError("Unable to get latest Liferay archetype", e);
        artifactRequest.setArtifact(new DefaultArtifact(gavCoords));
        try {
            retval = system.resolveArtifact(session, artifactRequest).getArtifact();
        } catch (ArtifactResolutionException e1) {
            LiferayMavenCore.logError("Unable to get default Liferay archetype", e1);
        }
    }
    if (retval == null) {
        retval = defaultArtifact;
    }
    return retval;
}
Also used : RepositorySystem(org.eclipse.aether.RepositorySystem) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 94 with Artifact

use of org.eclipse.aether.artifact.Artifact 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 95 with Artifact

use of org.eclipse.aether.artifact.Artifact 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)

Aggregations

Artifact (org.eclipse.aether.artifact.Artifact)122 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)97 File (java.io.File)51 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)34 Dependency (org.eclipse.aether.graph.Dependency)32 IOException (java.io.IOException)29 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)26 ArrayList (java.util.ArrayList)23 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)22 List (java.util.List)20 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)18 CollectRequest (org.eclipse.aether.collection.CollectRequest)15 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)15 DependencyNode (org.eclipse.aether.graph.DependencyNode)14 ArtifactDescriptorResult (org.eclipse.aether.resolution.ArtifactDescriptorResult)14 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)13 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)13 URL (java.net.URL)12 Map (java.util.Map)12 RepositorySystem (org.eclipse.aether.RepositorySystem)11