Search in sources :

Example 66 with DependencyNode

use of org.eclipse.aether.graph.DependencyNode in project maven by apache.

the class DefaultMavenPluginManager method resolveExtensionArtifacts.

private List<Artifact> resolveExtensionArtifacts(Plugin extensionPlugin, List<RemoteRepository> repositories, RepositorySystemSession session) throws PluginResolutionException {
    DependencyNode root = pluginDependenciesResolver.resolve(extensionPlugin, null, null, repositories, session);
    PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
    root.accept(nlg);
    return toMavenArtifacts(root, nlg);
}
Also used : DependencyNode(org.eclipse.aether.graph.DependencyNode) PreorderNodeListGenerator(org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator)

Example 67 with DependencyNode

use of org.eclipse.aether.graph.DependencyNode in project maven by apache.

the class DefaultPluginDependenciesResolver method resolveInternal.

private DependencyNode resolveInternal(Plugin plugin, Artifact pluginArtifact, DependencyFilter dependencyFilter, List<RemoteRepository> repositories, RepositorySystemSession session) throws PluginResolutionException {
    RequestTrace trace = RequestTrace.newChild(null, plugin);
    if (pluginArtifact == null) {
        pluginArtifact = toArtifact(plugin, session);
    }
    DependencyFilter collectionFilter = new ScopeDependencyFilter("provided", "test");
    DependencyFilter resolutionFilter = AndDependencyFilter.newInstance(collectionFilter, dependencyFilter);
    DependencyNode node;
    try {
        DependencySelector selector = AndDependencySelector.newInstance(session.getDependencySelector(), new WagonExcluder());
        DefaultRepositorySystemSession pluginSession = new DefaultRepositorySystemSession(session);
        pluginSession.setDependencySelector(selector);
        pluginSession.setDependencyGraphTransformer(session.getDependencyGraphTransformer());
        CollectRequest request = new CollectRequest();
        request.setRequestContext(REPOSITORY_CONTEXT);
        request.setRepositories(repositories);
        request.setRoot(new org.eclipse.aether.graph.Dependency(pluginArtifact, null));
        for (Dependency dependency : plugin.getDependencies()) {
            org.eclipse.aether.graph.Dependency pluginDep = RepositoryUtils.toDependency(dependency, session.getArtifactTypeRegistry());
            if (!JavaScopes.SYSTEM.equals(pluginDep.getScope())) {
                pluginDep = pluginDep.setScope(JavaScopes.RUNTIME);
            }
            request.addDependency(pluginDep);
        }
        DependencyRequest depRequest = new DependencyRequest(request, resolutionFilter);
        depRequest.setTrace(trace);
        request.setTrace(RequestTrace.newChild(trace, depRequest));
        node = repoSystem.collectDependencies(pluginSession, request).getRoot();
        if (logger.isDebugEnabled()) {
            node.accept(new GraphLogger());
        }
        depRequest.setRoot(node);
        repoSystem.resolveDependencies(session, depRequest);
    } catch (DependencyCollectionException e) {
        throw new PluginResolutionException(plugin, e);
    } catch (DependencyResolutionException e) {
        throw new PluginResolutionException(plugin, e.getCause());
    }
    return node;
}
Also used : DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) PluginResolutionException(org.apache.maven.plugin.PluginResolutionException) DependencyFilter(org.eclipse.aether.graph.DependencyFilter) AndDependencyFilter(org.eclipse.aether.util.filter.AndDependencyFilter) ScopeDependencyFilter(org.eclipse.aether.util.filter.ScopeDependencyFilter) RequestTrace(org.eclipse.aether.RequestTrace) Dependency(org.apache.maven.model.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) AndDependencySelector(org.eclipse.aether.util.graph.selector.AndDependencySelector) DependencySelector(org.eclipse.aether.collection.DependencySelector) DependencyNode(org.eclipse.aether.graph.DependencyNode) ScopeDependencyFilter(org.eclipse.aether.util.filter.ScopeDependencyFilter) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException)

Example 68 with DependencyNode

use of org.eclipse.aether.graph.DependencyNode in project maven by apache.

the class BootstrapCoreExtensionManager method resolveExtension.

private List<Artifact> resolveExtension(CoreExtension extension, RepositorySystemSession repoSession, List<RemoteRepository> repositories, DependencyFilter dependencyFilter, Interpolator interpolator) throws ExtensionResolutionException {
    try {
        /* TODO: Enhance the PluginDependenciesResolver to provide a
             * resolveCoreExtension method which uses a CoreExtension
             * object instead of a Plugin as this makes no sense.
             */
        Plugin plugin = new Plugin();
        plugin.setGroupId(interpolator.interpolate(extension.getGroupId()));
        plugin.setArtifactId(interpolator.interpolate(extension.getArtifactId()));
        plugin.setVersion(interpolator.interpolate(extension.getVersion()));
        DependencyNode root = pluginDependenciesResolver.resolveCoreExtension(plugin, dependencyFilter, repositories, repoSession);
        PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
        root.accept(nlg);
        return nlg.getArtifacts(false);
    } catch (PluginResolutionException e) {
        throw new ExtensionResolutionException(extension, e.getCause());
    } catch (InterpolationException e) {
        throw new ExtensionResolutionException(extension, e);
    }
}
Also used : PluginResolutionException(org.apache.maven.plugin.PluginResolutionException) DependencyNode(org.eclipse.aether.graph.DependencyNode) InterpolationException(org.codehaus.plexus.interpolation.InterpolationException) PreorderNodeListGenerator(org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator) Plugin(org.apache.maven.model.Plugin)

Example 69 with DependencyNode

use of org.eclipse.aether.graph.DependencyNode in project maven by apache.

the class RepositoryUtils method toArtifacts.

public static void toArtifacts(Collection<org.apache.maven.artifact.Artifact> artifacts, Collection<? extends DependencyNode> nodes, List<String> trail, DependencyFilter filter) {
    for (DependencyNode node : nodes) {
        org.apache.maven.artifact.Artifact artifact = toArtifact(node.getDependency());
        List<String> nodeTrail = new ArrayList<>(trail.size() + 1);
        nodeTrail.addAll(trail);
        nodeTrail.add(artifact.getId());
        if (filter == null || filter.accept(node, Collections.emptyList())) {
            artifact.setDependencyTrail(nodeTrail);
            artifacts.add(artifact);
        }
        toArtifacts(artifacts, node.getChildren(), nodeTrail, filter);
    }
}
Also used : DependencyNode(org.eclipse.aether.graph.DependencyNode) ArrayList(java.util.ArrayList)

Example 70 with DependencyNode

use of org.eclipse.aether.graph.DependencyNode in project quarkus by quarkusio.

the class BootstrapAppModelResolver method doResolveModel.

private ApplicationModel doResolveModel(ArtifactCoords coords, List<Dependency> directMvnDeps, ArtifactCoords managingProject, Set<ArtifactKey> reloadableModules) throws AppModelResolverException {
    if (coords == null) {
        throw new IllegalArgumentException("Application artifact is null");
    }
    final Artifact mvnArtifact = toAetherArtifact(coords);
    List<Dependency> managedDeps = List.of();
    List<RemoteRepository> managedRepos = List.of();
    if (managingProject != null) {
        final ArtifactDescriptorResult managingDescr = mvn.resolveDescriptor(toAetherArtifact(managingProject));
        managedDeps = managingDescr.getManagedDependencies();
        managedRepos = mvn.newResolutionRepositories(managingDescr.getRepositories());
    }
    final ResolvedDependency appArtifact = resolve(coords, mvnArtifact, managedRepos);
    final List<String> excludedScopes;
    if (test) {
        excludedScopes = List.of();
    } else if (devmode) {
        excludedScopes = List.of("test");
    } else {
        excludedScopes = List.of("provided", "test");
    }
    final DependencyNode resolvedDeps = mvn.resolveManagedDependencies(mvnArtifact, directMvnDeps, managedDeps, managedRepos, excludedScopes.toArray(new String[0])).getRoot();
    ArtifactDescriptorResult appArtifactDescr = mvn.resolveDescriptor(toAetherArtifact(appArtifact));
    if (managingProject == null) {
        managedDeps = appArtifactDescr.getManagedDependencies();
    } else {
        final List<Dependency> mergedManagedDeps = new ArrayList<>(managedDeps.size());
        final Set<ArtifactKey> mergedKeys = new HashSet<>(managedDeps.size());
        for (Dependency dep : managedDeps) {
            mergedKeys.add(getKey(dep.getArtifact()));
            mergedManagedDeps.add(dep);
        }
        for (Dependency dep : appArtifactDescr.getManagedDependencies()) {
            final Artifact artifact = dep.getArtifact();
            if (!mergedKeys.contains(getKey(artifact))) {
                mergedManagedDeps.add(dep);
            }
        }
        managedDeps = mergedManagedDeps;
    }
    final List<RemoteRepository> repos = mvn.aggregateRepositories(managedRepos, mvn.newResolutionRepositories(appArtifactDescr.getRepositories()));
    return buildAppModel(appArtifact, resolvedDeps, reloadableModules, managedDeps, repos);
}
Also used : ArtifactKey(io.quarkus.maven.dependency.ArtifactKey) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) ArrayList(java.util.ArrayList) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) Dependency(org.eclipse.aether.graph.Dependency) ResolvableDependency(io.quarkus.maven.dependency.ResolvableDependency) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) DependencyNode(org.eclipse.aether.graph.DependencyNode) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) HashSet(java.util.HashSet)

Aggregations

DependencyNode (org.eclipse.aether.graph.DependencyNode)267 Test (org.junit.Test)107 Artifact (org.eclipse.aether.artifact.Artifact)63 Dependency (org.eclipse.aether.graph.Dependency)59 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)53 CollectRequest (org.eclipse.aether.collection.CollectRequest)53 DefaultDependencyNode (org.eclipse.aether.graph.DefaultDependencyNode)53 ArrayList (java.util.ArrayList)39 IOException (java.io.IOException)28 List (java.util.List)26 CollectResult (org.eclipse.aether.collection.CollectResult)24 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)24 DependencyCollectionException (org.eclipse.aether.collection.DependencyCollectionException)22 PreorderNodeListGenerator (org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator)21 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)19 File (java.io.File)17 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)17 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)17 Path (java.nio.file.Path)16 NodeBuilder (org.eclipse.aether.internal.test.util.NodeBuilder)16