Search in sources :

Example 11 with DependencyNode

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

the class ReplaceConflictingVersionResolver method updateNonSelectedVersions.

private void updateNonSelectedVersions(ConflictGroup group, Map<?, ?> conflictIds) {
    for (Position pos : group.positions) {
        DependencyNode parent = pos.parent;
        List<DependencyNode> children = parent.getChildren();
        List<DependencyNode> toAdd = new ArrayList<DependencyNode>();
        for (Iterator<DependencyNode> it = children.iterator(); it.hasNext(); ) {
            DependencyNode child = it.next();
            Object key = conflictIds.get(child);
            if (group.key.equals(key)) {
                if (!group.pruned && group.position != null && group.version != null && group.position.depth == pos.depth && group.version.equals(child.getVersion())) {
                    group.pruned = true;
                } else {
                    it.remove();
                    // now lets add the common dependency
                    if (group.versionDependency == null) {
                        throw new IllegalStateException("Should have a versionDependency for group: " + group + " and version: " + group.version);
                    }
                    toAdd.add(group.versionDependency);
                }
            }
        }
        children.addAll(toAdd);
    }
}
Also used : DependencyNode(org.eclipse.aether.graph.DependencyNode) ArrayList(java.util.ArrayList)

Example 12 with DependencyNode

use of org.eclipse.aether.graph.DependencyNode in project mule by mulesoft.

the class DependencyResolver method resolveDependencies.

/**
 * Resolves and filters transitive dependencies for the root and direct dependencies.
 * <p/>
 * If both a root dependency and direct dependencies are given, the direct dependencies will be merged with the direct
 * dependencies from the root dependency's artifact descriptor, giving higher priority to the dependencies from the root.
 *
 * @param root {@link Dependency} node from to collect its dependencies, may be {@code null}
 * @param directDependencies {@link List} of direct {@link Dependency} to collect its transitive dependencies, may be
 *        {@code null}
 * @param managedDependencies {@link List} of managed {@link Dependency}s to be used for resolving the depedency graph, may be
 *        {@code null}
 * @param dependencyFilter {@link DependencyFilter} to include/exclude dependency nodes during collection and resolve operation.
 *        May be {@code null} to no filter
 * @param remoteRepositories {@link RemoteRepository} to be used when resolving dependencies in addition to the ones already defined in the context.
 * @return a {@link List} of {@link File}s for each dependency resolved
 * @throws {@link DependencyCollectionException} if the dependency tree could not be built
 * @thwows {@link DependencyResolutionException} if the dependency tree could not be built or any dependency artifact could not
 *         be resolved
 */
public List<File> resolveDependencies(Dependency root, List<Dependency> directDependencies, List<Dependency> managedDependencies, DependencyFilter dependencyFilter, List<RemoteRepository> remoteRepositories) throws DependencyCollectionException, DependencyResolutionException {
    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(root);
    collectRequest.setDependencies(directDependencies);
    collectRequest.setManagedDependencies(managedDependencies);
    collectRequest.setRepositories(resolutionContext.getRemoteRepositories());
    // Has to set authentication to these remote repositories as they may come from a pom descriptor
    remoteRepositories.forEach(remoteRepository -> {
        RemoteRepository authenticatedRemoteRepository = setAuthentication(remoteRepository);
        if (!collectRequest.getRepositories().contains(authenticatedRemoteRepository)) {
            collectRequest.addRepository(authenticatedRemoteRepository);
        }
    });
    DependencyNode node;
    try {
        logger.debug("Collecting dependencies for '{}'", printCollectRequest(collectRequest));
        node = repositoryState.getSystem().collectDependencies(repositoryState.getSession(), collectRequest).getRoot();
        logDependencyGraph(node, collectRequest);
        DependencyRequest dependencyRequest = new DependencyRequest();
        dependencyRequest.setRoot(node);
        dependencyRequest.setCollectRequest(collectRequest);
        if (dependencyFilter != null) {
            dependencyRequest.setFilter(dependencyFilter);
        }
        node = repositoryState.getSystem().resolveDependencies(repositoryState.getSession(), dependencyRequest).getRoot();
    } catch (DependencyResolutionException e) {
        logger.warn("Dependencies couldn't be resolved for request '{}', {}", collectRequest, e.getMessage());
        node = e.getResult().getRoot();
        logUnresolvedArtifacts(node, e);
        throw e;
    }
    List<File> files = getFiles(node);
    return files;
}
Also used : DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyNode(org.eclipse.aether.graph.DependencyNode) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) CollectRequest(org.eclipse.aether.collection.CollectRequest) File(java.io.File)

Example 13 with DependencyNode

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

use of org.eclipse.aether.graph.DependencyNode in project activemq-artemis by apache.

the class ArtemisAbstractPlugin method explodeDependencies.

protected List<Artifact> explodeDependencies(Artifact artifact) throws DependencyCollectionException {
    final List<Artifact> dependencies = new LinkedList<>();
    CollectRequest exploreDependenciesRequest = new CollectRequest(new Dependency(artifact, "compile"), remoteRepos);
    CollectResult result = repositorySystem.collectDependencies(repoSession, exploreDependenciesRequest);
    final AtomicInteger level = new AtomicInteger(0);
    DependencyNode node = result.getRoot();
    StringWriter writer = new StringWriter();
    final PrintWriter strPrint = new PrintWriter(writer);
    strPrint.println("Dependencies explored for " + artifact + ":");
    if (node != null) {
        node.accept(new DependencyVisitor() {

            @Override
            public boolean visitEnter(DependencyNode node) {
                for (int i = 0; i < level.get(); i++) {
                    strPrint.print("!...");
                }
                level.incrementAndGet();
                strPrint.println("Dependency:: " + node.getDependency() + " node = " + node.getArtifact());
                dependencies.add(node.getArtifact());
                return true;
            }

            @Override
            public boolean visitLeave(DependencyNode node) {
                level.decrementAndGet();
                return true;
            }
        });
    }
    getLog().info(writer.toString());
    return dependencies;
}
Also used : StringWriter(java.io.StringWriter) CollectResult(org.eclipse.aether.collection.CollectResult) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DependencyNode(org.eclipse.aether.graph.DependencyNode) DependencyVisitor(org.eclipse.aether.graph.DependencyVisitor) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) LinkedList(java.util.LinkedList) PrintWriter(java.io.PrintWriter)

Example 15 with DependencyNode

use of org.eclipse.aether.graph.DependencyNode in project druid by druid-io.

the class PullDependencies method downloadExtension.

private void downloadExtension(Artifact versionedArtifact, File toLocation, Dependencies exclusions) {
    final CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot(new Dependency(versionedArtifact, JavaScopes.RUNTIME));
    final DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.andFilter(DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME), (node, parents) -> {
        String scope = node.getDependency().getScope();
        if (scope != null) {
            scope = StringUtils.toLowerCase(scope);
            if ("provided".equals(scope)) {
                return false;
            }
            if ("test".equals(scope)) {
                return false;
            }
            if ("system".equals(scope)) {
                return false;
            }
        }
        if (exclusions.contain(node.getArtifact())) {
            return false;
        }
        for (DependencyNode parent : parents) {
            if (exclusions.contain(parent.getArtifact())) {
                return false;
            }
        }
        return true;
    }));
    try {
        log.info("Start downloading extension [%s]", versionedArtifact);
        final List<Artifact> artifacts = aether.resolveArtifacts(dependencyRequest);
        for (Artifact artifact : artifacts) {
            if (exclusions.contain(artifact)) {
                log.debug("Skipped Artifact[%s]", artifact);
            } else {
                log.info("Adding file [%s] at [%s]", artifact.getFile().getName(), toLocation.getAbsolutePath());
                org.apache.commons.io.FileUtils.copyFileToDirectory(artifact.getFile(), toLocation);
            }
        }
    } catch (Exception e) {
        log.error(e, "Unable to resolve artifacts for [%s].", dependencyRequest);
        throw new RuntimeException(e);
    }
    log.info("Finish downloading extension [%s]", versionedArtifact);
}
Also used : Option(com.github.rvesse.airline.annotations.Option) Logger(org.apache.druid.java.util.common.logger.Logger) TeslaAether(io.tesla.aether.TeslaAether) TaskConfig(org.apache.druid.indexing.common.config.TaskConfig) DependencyFilterUtils(org.eclipse.aether.util.filter.DependencyFilterUtils) Proxy(org.eclipse.aether.repository.Proxy) Inject(com.google.inject.Inject) URISyntaxException(java.net.URISyntaxException) Dependency(org.eclipse.aether.graph.Dependency) JavaScopes(org.eclipse.aether.util.artifact.JavaScopes) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) ImmutableList(com.google.common.collect.ImmutableList) ExtensionsConfig(org.apache.druid.guice.ExtensionsConfig) URI(java.net.URI) Repository(io.tesla.aether.Repository) Command(com.github.rvesse.airline.annotations.Command) FileUtils(org.apache.druid.java.util.common.FileUtils) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) CollectRequest(org.eclipse.aether.collection.CollectRequest) OutputStream(java.io.OutputStream) PrintStream(java.io.PrintStream) RepositorySystemSessionProvider(io.tesla.aether.guice.RepositorySystemSessionProvider) DependencyNode(org.eclipse.aether.graph.DependencyNode) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) StringUtils(org.apache.druid.java.util.common.StringUtils) Artifact(org.eclipse.aether.artifact.Artifact) Set(java.util.Set) ISE(org.apache.druid.java.util.common.ISE) IOException(java.io.IOException) SuppressForbidden(io.netty.util.SuppressForbidden) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) Collectors(java.util.stream.Collectors) SetMultimap(com.google.common.collect.SetMultimap) File(java.io.File) Authentication(org.eclipse.aether.repository.Authentication) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) List(java.util.List) VisibleForTesting(com.google.common.annotations.VisibleForTesting) DefaultTeslaAether(io.tesla.aether.internal.DefaultTeslaAether) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyNode(org.eclipse.aether.graph.DependencyNode) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

DependencyNode (org.eclipse.aether.graph.DependencyNode)28 Artifact (org.eclipse.aether.artifact.Artifact)14 CollectRequest (org.eclipse.aether.collection.CollectRequest)14 Dependency (org.eclipse.aether.graph.Dependency)13 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)12 ArrayList (java.util.ArrayList)11 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)10 File (java.io.File)8 List (java.util.List)8 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)8 DependencyResolutionException (org.eclipse.aether.resolution.DependencyResolutionException)8 IOException (java.io.IOException)7 DependencyCollectionException (org.eclipse.aether.collection.DependencyCollectionException)7 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)7 ArtifactRequest (org.eclipse.aether.resolution.ArtifactRequest)6 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)6 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)5 PreorderNodeListGenerator (org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator)5 MalformedURLException (java.net.MalformedURLException)4 RepositorySystem (org.eclipse.aether.RepositorySystem)4