Search in sources :

Example 6 with DependencyResolutionException

use of org.eclipse.aether.resolution.DependencyResolutionException 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 DependencyResolutionException

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

the class AetherPluginResolverImpl method resolveDependencies.

private DependencyResult resolveDependencies(DependencyFilter classpathFilter, List<Dependency> dependencies) {
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setDependencies(dependencies);
    collectRequest.setRepositories(repositories);
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFilter);
    try {
        return repositorySystem.resolveDependencies(repositorySystemSession, dependencyRequest);
    } catch (DependencyResolutionException e) {
        throw new PluginRepositoryException("Cannot resolve plugin dependencies", e);
    }
}
Also used : PluginRepositoryException(com.buschmais.jqassistant.core.plugin.api.PluginRepositoryException) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) CollectRequest(org.eclipse.aether.collection.CollectRequest)

Example 8 with DependencyResolutionException

use of org.eclipse.aether.resolution.DependencyResolutionException in project zeppelin by apache.

the class DependencyResolver method getArtifactsWithDep.

/**
 * @param dependency
 * @param excludes list of pattern can either be of the form groupId:artifactId
 * @return
 * @throws Exception
 */
@Override
public List<ArtifactResult> getArtifactsWithDep(String dependency, Collection<String> excludes) throws RepositoryException {
    Artifact artifact = new DefaultArtifact(dependency);
    DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE);
    PatternExclusionsDependencyFilter exclusionFilter = new PatternExclusionsDependencyFilter(excludes);
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
    synchronized (repos) {
        for (RemoteRepository repo : repos) {
            collectRequest.addRepository(repo);
        }
    }
    DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.andFilter(exclusionFilter, classpathFilter));
    try {
        return system.resolveDependencies(session, dependencyRequest).getArtifactResults();
    } catch (NullPointerException | DependencyResolutionException ex) {
        throw new RepositoryException(String.format("Cannot fetch dependencies for %s", dependency), ex);
    }
}
Also used : DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyFilter(org.eclipse.aether.graph.DependencyFilter) PatternExclusionsDependencyFilter(org.eclipse.aether.util.filter.PatternExclusionsDependencyFilter) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) RepositoryException(org.eclipse.aether.RepositoryException) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) PatternExclusionsDependencyFilter(org.eclipse.aether.util.filter.PatternExclusionsDependencyFilter)

Example 9 with DependencyResolutionException

use of org.eclipse.aether.resolution.DependencyResolutionException in project byte-buddy by raphw.

the class ClassLoaderResolver method doResolve.

/**
     * Resolves a Maven coordinate to a class loader that can load all of the coordinates classes.
     *
     * @param mavenCoordinate The Maven coordinate to resolve.
     * @return A class loader that references all of the class loader's dependencies and which is a child of this class's class loader.
     * @throws MojoExecutionException If the user configuration results in an error.
     * @throws MojoFailureException   If the plugin application raises an error.
     */
private ClassLoader doResolve(MavenCoordinate mavenCoordinate) throws MojoExecutionException, MojoFailureException {
    List<URL> urls = new ArrayList<URL>();
    log.info("Resolving transformer dependency: " + mavenCoordinate);
    try {
        DependencyNode root = repositorySystem.collectDependencies(repositorySystemSession, new CollectRequest(new Dependency(mavenCoordinate.asArtifact(), "runtime"), remoteRepositories)).getRoot();
        repositorySystem.resolveDependencies(repositorySystemSession, new DependencyRequest().setRoot(root));
        PreorderNodeListGenerator preorderNodeListGenerator = new PreorderNodeListGenerator();
        root.accept(preorderNodeListGenerator);
        for (Artifact artifact : preorderNodeListGenerator.getArtifacts(false)) {
            urls.add(artifact.getFile().toURI().toURL());
        }
    } catch (DependencyCollectionException exception) {
        throw new MojoExecutionException("Could not collect dependencies for " + mavenCoordinate, exception);
    } catch (DependencyResolutionException exception) {
        throw new MojoExecutionException("Could not resolve dependencies for " + mavenCoordinate, exception);
    } catch (MalformedURLException exception) {
        throw new MojoFailureException("Could not resolve file as URL for " + mavenCoordinate, exception);
    }
    return new URLClassLoader(urls.toArray(new URL[urls.size()]), ByteBuddy.class.getClassLoader());
}
Also used : DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) MalformedURLException(java.net.MalformedURLException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ByteBuddy(net.bytebuddy.ByteBuddy) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) PreorderNodeListGenerator(org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator) URL(java.net.URL) Artifact(org.eclipse.aether.artifact.Artifact) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyNode(org.eclipse.aether.graph.DependencyNode) URLClassLoader(java.net.URLClassLoader) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException)

Example 10 with DependencyResolutionException

use of org.eclipse.aether.resolution.DependencyResolutionException in project qpid-broker-j by apache.

the class ClasspathQuery method getJarFiles.

private static Set<File> getJarFiles(final Collection<String> gavs) {
    Set<File> jars = new HashSet<>();
    for (final String gav : gavs) {
        Artifact artifact = new DefaultArtifact(gav);
        DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE);
        CollectRequest collectRequest = new CollectRequest();
        collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
        collectRequest.setRepositories(Booter.newRepositories());
        DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFlter);
        List<ArtifactResult> artifactResults = null;
        try {
            artifactResults = _mavenRepositorySystem.resolveDependencies(_mavenRepositorySession, dependencyRequest).getArtifactResults();
        } catch (DependencyResolutionException e) {
            throw new RuntimeException(String.format("Error while dependency resolution for '%s'", gav), e);
        }
        if (artifactResults == null) {
            throw new RuntimeException(String.format("Could not resolve dependency for '%s'", gav));
        }
        for (ArtifactResult artifactResult : artifactResults) {
            System.out.println(artifactResult.getArtifact() + " resolved to " + artifactResult.getArtifact().getFile());
        }
        jars.addAll(artifactResults.stream().map(result -> result.getArtifact().getFile()).collect(Collectors.toSet()));
    }
    return jars;
}
Also used : DependencyFilter(org.eclipse.aether.graph.DependencyFilter) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) File(java.io.File) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) HashSet(java.util.HashSet)

Aggregations

DependencyResolutionException (org.eclipse.aether.resolution.DependencyResolutionException)14 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)11 CollectRequest (org.eclipse.aether.collection.CollectRequest)10 Artifact (org.eclipse.aether.artifact.Artifact)9 Dependency (org.eclipse.aether.graph.Dependency)7 DependencyNode (org.eclipse.aether.graph.DependencyNode)7 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)6 DependencyCollectionException (org.eclipse.aether.collection.DependencyCollectionException)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)4 PreorderNodeListGenerator (org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator)4 IOException (java.io.IOException)3 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3 List (java.util.List)3 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)3 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)3 DependencyResult (org.eclipse.aether.resolution.DependencyResult)3 HashMap (java.util.HashMap)2