Search in sources :

Example 6 with DependencyResult

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

the class ArtifactResolver method collectTransitiveDeps.

protected void collectTransitiveDeps(String gav, Set<Artifact> resolvedArtifacts, Set<Exception> failures) throws RepositoryException {
    final Artifact rootArtifact = resolveArtifact(gav);
    CollectRequest collectRequest = new CollectRequest(new Dependency(rootArtifact, null), repositories);
    DependencyRequest request = new DependencyRequest(collectRequest, null);
    DependencyResult result;
    try {
        result = repositorySystem.resolveDependencies(session, request);
    } catch (DependencyResolutionException dre) {
        result = dre.getResult();
    }
    result.getRoot().accept(new TreeDependencyVisitor(new DependencyVisitor() {

        @Override
        public boolean visitEnter(DependencyNode node) {
            return true;
        }

        @Override
        public boolean visitLeave(DependencyNode node) {
            Dependency dep = node.getDependency();
            if (dep == null || dep.getArtifact().equals(rootArtifact)) {
                return true;
            }
            resolvedArtifacts.add(dep.getArtifact());
            return true;
        }
    }));
    failures.addAll(result.getCollectExceptions());
}
Also used : DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyResult(org.eclipse.aether.resolution.DependencyResult) DependencyVisitor(org.eclipse.aether.graph.DependencyVisitor) TreeDependencyVisitor(org.eclipse.aether.util.graph.visitor.TreeDependencyVisitor) DependencyNode(org.eclipse.aether.graph.DependencyNode) TreeDependencyVisitor(org.eclipse.aether.util.graph.visitor.TreeDependencyVisitor) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact)

Example 7 with DependencyResult

use of org.eclipse.aether.resolution.DependencyResult in project jqa-core-framework by buschmais.

the class AetherPluginResolverImpl method resolvePlugins.

private DependencyResult resolvePlugins(List<Dependency> dependencies) {
    DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(RUNTIME);
    DependencyResult dependencyResult = resolveDependencies(classpathFilter, dependencies);
    if (log.isDebugEnabled()) {
        logDependencyTree(dependencyResult.getRoot(), 0);
    }
    return dependencyResult;
}
Also used : DependencyResult(org.eclipse.aether.resolution.DependencyResult) DependencyFilter(org.eclipse.aether.graph.DependencyFilter)

Example 8 with DependencyResult

use of org.eclipse.aether.resolution.DependencyResult in project intellij-community by JetBrains.

the class ArtifactRepositoryManager method resolveDependency.

public Collection<File> resolveDependency(String groupId, String artifactId, String version) throws Exception {
    final DependencyRequest dependencyRequest = new DependencyRequest(createCollectRequest(groupId, artifactId, toVersion(version)), DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE));
    final DependencyResult result = ourSystem.resolveDependencies(mySession, dependencyRequest);
    final List<File> files = new ArrayList<>();
    for (ArtifactResult artifactResult : result.getArtifactResults()) {
        files.add(artifactResult.getArtifact().getFile());
    }
    return files;
}
Also used : DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyResult(org.eclipse.aether.resolution.DependencyResult) ArrayList(java.util.ArrayList) File(java.io.File) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult)

Example 9 with DependencyResult

use of org.eclipse.aether.resolution.DependencyResult 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 10 with DependencyResult

use of org.eclipse.aether.resolution.DependencyResult in project gate-core by GateNLP.

the class SimpleMavenCache method cacheArtifact.

public void cacheArtifact(Artifact artifact) throws IOException, SettingsBuildingException, DependencyCollectionException, DependencyResolutionException, ArtifactResolutionException, ModelBuildingException {
    List<RemoteRepository> repos = getRepositoryList();
    Dependency dependency = new Dependency(artifact, "runtime");
    RepositorySystem repoSystem = getRepositorySystem();
    RepositorySystemSession repoSession = getRepositorySession(repoSystem, null);
    CollectRequest collectRequest = new CollectRequest(dependency, repos);
    DependencyNode node = repoSystem.collectDependencies(repoSession, collectRequest).getRoot();
    DependencyRequest dependencyRequest = new DependencyRequest();
    dependencyRequest.setRoot(node);
    DependencyResult result = repoSystem.resolveDependencies(repoSession, dependencyRequest);
    for (ArtifactResult ar : result.getArtifactResults()) {
        // generate output file name from the *requested* artifact rather
        // than the resolved one (e.g. if we requested a -SNAPSHOT version
        // but got a timestamped one)
        File file = getArtifactFile(ar.getRequest().getArtifact());
        FileUtils.copyFile(ar.getArtifact().getFile(), file);
        // get the POM corresponding to the specific resolved JAR
        Artifact pomArtifact = new SubArtifact(ar.getArtifact(), "", "pom");
        ArtifactRequest artifactRequest = new ArtifactRequest(pomArtifact, repos, null);
        ArtifactResult artifactResult = repoSystem.resolveArtifact(repoSession, artifactRequest);
        // but copy it to a file named for the original requested version number
        file = getArtifactFile(new SubArtifact(ar.getRequest().getArtifact(), "", "pom"));
        FileUtils.copyFile(artifactResult.getArtifact().getFile(), file);
        cacheParents(artifactResult.getArtifact().getFile(), repoSystem, repoSession, repos);
    }
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DependencyResult(org.eclipse.aether.resolution.DependencyResult) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) Utils.getRepositorySystem(gate.util.maven.Utils.getRepositorySystem) RepositorySystem(org.eclipse.aether.RepositorySystem) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyNode(org.eclipse.aether.graph.DependencyNode) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) File(java.io.File)

Aggregations

DependencyResult (org.eclipse.aether.resolution.DependencyResult)12 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)10 CollectRequest (org.eclipse.aether.collection.CollectRequest)8 Dependency (org.eclipse.aether.graph.Dependency)7 Artifact (org.eclipse.aether.artifact.Artifact)6 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)6 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)6 File (java.io.File)4 ArrayList (java.util.ArrayList)4 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)4 DependencyNode (org.eclipse.aether.graph.DependencyNode)3 DependencyResolutionException (org.eclipse.aether.resolution.DependencyResolutionException)3 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 RepositorySystem (org.eclipse.aether.RepositorySystem)2 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)2 SubArtifact (org.eclipse.aether.util.artifact.SubArtifact)2 PluginClassLoader (com.buschmais.jqassistant.core.plugin.api.PluginClassLoader)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 Utils.getRepositorySystem (gate.util.maven.Utils.getRepositorySystem)1