Search in sources :

Example 6 with DependencyFilter

use of org.eclipse.aether.graph.DependencyFilter 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 7 with DependencyFilter

use of org.eclipse.aether.graph.DependencyFilter in project bnd by bndtools.

the class DependencyResolver method resolve.

public Map<File, ArtifactResult> resolve() throws MojoExecutionException {
    if (resolvedDependencies != null) {
        return resolvedDependencies;
    }
    DependencyResolutionRequest request = new DefaultDependencyResolutionRequest(project, session);
    request.setResolutionFilter(new DependencyFilter() {

        @Override
        public boolean accept(DependencyNode node, List<DependencyNode> parents) {
            if (node.getDependency() != null) {
                return scopes.contains(node.getDependency().getScope());
            }
            return false;
        }
    });
    DependencyResolutionResult result;
    try {
        result = resolver.resolve(request);
    } catch (DependencyResolutionException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }
    Map<File, ArtifactResult> dependencies = new HashMap<>();
    DependencyNode dependencyGraph = result.getDependencyGraph();
    if (dependencyGraph != null && !dependencyGraph.getChildren().isEmpty()) {
        List<RemoteRepository> remoteRepositories = new ArrayList<>(project.getRemoteProjectRepositories());
        ArtifactRepository deployRepo = project.getDistributionManagementArtifactRepository();
        if (deployRepo != null) {
            remoteRepositories.add(RepositoryUtils.toRepo(deployRepo));
        }
        discoverArtifacts(dependencies, dependencyGraph.getChildren(), project.getArtifact().getId(), remoteRepositories);
    }
    return resolvedDependencies = dependencies;
}
Also used : DependencyResolutionResult(org.apache.maven.project.DependencyResolutionResult) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DependencyFilter(org.eclipse.aether.graph.DependencyFilter) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) DefaultDependencyResolutionRequest(org.apache.maven.project.DefaultDependencyResolutionRequest) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) DependencyResolutionRequest(org.apache.maven.project.DependencyResolutionRequest) DefaultDependencyResolutionRequest(org.apache.maven.project.DefaultDependencyResolutionRequest) DependencyNode(org.eclipse.aether.graph.DependencyNode) DependencyResolutionException(org.apache.maven.project.DependencyResolutionException) File(java.io.File)

Example 8 with DependencyFilter

use of org.eclipse.aether.graph.DependencyFilter 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)

Example 9 with DependencyFilter

use of org.eclipse.aether.graph.DependencyFilter in project fabric8 by jboss-fuse.

the class AetherBasedResolver method resolveDependencies.

protected DependencyNode resolveDependencies(RepositorySystemSession session, List<RemoteRepository> repos, DependencyNode pomNode, Dependency dependency, final Filter<Dependency> shouldExclude) throws FailedToResolveDependency {
    if (!DependencyFilters.matches(dependency, shouldExclude)) {
        CollectRequest cr = new CollectRequest(dependency, repos);
        // request.setRequestContext("runtime");
        try {
            DependencyNode node = m_repoSystem.collectDependencies(session, cr).getRoot();
            DependencyFilter filter = new DependencyFilter() {

                public boolean accept(DependencyNode node, List<DependencyNode> parents) {
                    return !DependencyFilters.matches(node, shouldExclude);
                }
            };
            DependencyRequest request = new DependencyRequest(cr, filter);
            m_repoSystem.resolveDependencies(session, request);
            return node;
        } catch (DependencyResolutionException | DependencyCollectionException e) {
            handleDependencyResolveFailure(pomNode, dependency, e);
        }
    }
    return null;
}
Also used : DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) DependencyNode(org.eclipse.aether.graph.DependencyNode) DependencyFilter(org.eclipse.aether.graph.DependencyFilter) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) CollectRequest(org.eclipse.aether.collection.CollectRequest)

Example 10 with DependencyFilter

use of org.eclipse.aether.graph.DependencyFilter 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)

Aggregations

DependencyFilter (org.eclipse.aether.graph.DependencyFilter)14 Dependency (org.eclipse.aether.graph.Dependency)10 Artifact (org.eclipse.aether.artifact.Artifact)9 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)9 CollectRequest (org.eclipse.aether.collection.CollectRequest)9 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)9 File (java.io.File)7 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)6 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)5 IOException (java.io.IOException)4 List (java.util.List)4 DependencyResult (org.eclipse.aether.resolution.DependencyResult)4 MalformedURLException (java.net.MalformedURLException)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)2 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)2 Maps.newLinkedHashMap (com.google.common.collect.Maps.newLinkedHashMap)2 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)2 Sets.newLinkedHashSet (com.google.common.collect.Sets.newLinkedHashSet)2