Search in sources :

Example 61 with DependencyNode

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

the class NearestVersionSelectorTest method testSelectHighestVersionFromMultipleVersionsAtSameLevel.

@Test
public void testSelectHighestVersionFromMultipleVersionsAtSameLevel() throws Exception {
    DependencyNode root = parseResource("sibling-versions.txt");
    assertSame(root, transform(root));
    assertEquals(1, root.getChildren().size());
    assertEquals("3", root.getChildren().get(0).getArtifact().getVersion());
}
Also used : DependencyNode(org.eclipse.aether.graph.DependencyNode) Test(org.junit.Test)

Example 62 with DependencyNode

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

the class CloningDependencyVisitor method visitEnter.

public final boolean visitEnter(DependencyNode node) {
    boolean recurse = true;
    DependencyNode clone = clones.get(node);
    if (clone == null) {
        clone = clone(node);
        clones.put(node, clone);
    } else {
        recurse = false;
    }
    DependencyNode parent = parents.peek();
    if (parent == null) {
        root = clone;
    } else {
        parent.getChildren().add(clone);
    }
    parents.push(clone);
    return recurse;
}
Also used : DependencyNode(org.eclipse.aether.graph.DependencyNode) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode)

Example 63 with DependencyNode

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

the class DefaultDependencyCollector method doRecurse.

@SuppressWarnings("checkstyle:parameternumber")
private void doRecurse(Args args, DependencyProcessingContext parentContext, ArtifactDescriptorResult descriptorResult, DefaultDependencyNode child) {
    DefaultDependencyCollectionContext context = args.collectionContext;
    context.set(parentContext.dependency, descriptorResult.getManagedDependencies());
    DependencySelector childSelector = parentContext.depSelector != null ? parentContext.depSelector.deriveChildSelector(context) : null;
    DependencyManager childManager = parentContext.depManager != null ? parentContext.depManager.deriveChildManager(context) : null;
    DependencyTraverser childTraverser = parentContext.depTraverser != null ? parentContext.depTraverser.deriveChildTraverser(context) : null;
    VersionFilter childFilter = parentContext.verFilter != null ? parentContext.verFilter.deriveChildFilter(context) : null;
    final List<RemoteRepository> childRepos = args.ignoreRepos ? parentContext.repositories : remoteRepositoryManager.aggregateRepositories(args.session, parentContext.repositories, descriptorResult.getRepositories(), true);
    Object key = args.pool.toKey(parentContext.dependency.getArtifact(), childRepos, childSelector, childManager, childTraverser, childFilter);
    List<DependencyNode> children = args.pool.getChildren(key);
    if (children == null) {
        args.pool.putChildren(key, child.getChildren());
        List<DependencyNode> parents = new ArrayList<>(parentContext.parents);
        parents.add(child);
        for (Dependency dependency : descriptorResult.getDependencies()) {
            args.dependencyProcessingQueue.add(new DependencyProcessingContext(childSelector, childManager, childTraverser, childFilter, childRepos, descriptorResult.getManagedDependencies(), parents, dependency));
        }
    } else {
        child.setChildren(children);
    }
}
Also used : ArrayList(java.util.ArrayList) DependencyManager(org.eclipse.aether.collection.DependencyManager) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) DependencyTraverser(org.eclipse.aether.collection.DependencyTraverser) Dependency(org.eclipse.aether.graph.Dependency) VersionFilter(org.eclipse.aether.collection.VersionFilter) DependencySelector(org.eclipse.aether.collection.DependencySelector) DependencyNode(org.eclipse.aether.graph.DependencyNode) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode)

Example 64 with DependencyNode

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

the class DefaultDependencyCycle method find.

/**
 * Searches for a node associated with the given artifact. A version of the artifact is not considered during the
 * search.
 *
 * @param nodes a list representing single path in the dependency graph. First element is the root.
 * @param artifact to find among the parent nodes.
 * @return the index of the node furthest from the root and associated with the given artifact, or {@literal -1} if
 * there is no such node.
 */
public static int find(List<DependencyNode> nodes, Artifact artifact) {
    for (int i = nodes.size() - 1; i >= 0; i--) {
        DependencyNode node = nodes.get(i);
        Artifact a = node.getArtifact();
        if (a == null) {
            break;
        }
        if (!a.getArtifactId().equals(artifact.getArtifactId())) {
            continue;
        }
        if (!a.getGroupId().equals(artifact.getGroupId())) {
            continue;
        }
        if (!a.getExtension().equals(artifact.getExtension())) {
            continue;
        }
        if (!a.getClassifier().equals(artifact.getClassifier())) {
            continue;
        }
        return i;
    }
    return -1;
}
Also used : DependencyNode(org.eclipse.aether.graph.DependencyNode) Artifact(org.eclipse.aether.artifact.Artifact)

Example 65 with DependencyNode

use of org.eclipse.aether.graph.DependencyNode in project kie-soup by kiegroup.

the class MavenRepository method getArtifactDependecies.

public List<DependencyDescriptor> getArtifactDependecies(String artifactName) {
    Artifact artifact = new DefaultArtifact(artifactName);
    CollectRequest collectRequest = new CollectRequest();
    Dependency root = new Dependency(artifact, "");
    collectRequest.setRoot(root);
    for (RemoteRepository repo : remoteRepositoriesForRequest) {
        collectRequest.addRepository(repo);
    }
    CollectResult collectResult;
    try {
        collectResult = aether.getSystem().collectDependencies(aether.getSession(), collectRequest);
    } catch (DependencyCollectionException e) {
        throw new RuntimeException(e);
    }
    CollectDependencyVisitor visitor = new CollectDependencyVisitor();
    collectResult.getRoot().accept(visitor);
    List<DependencyDescriptor> descriptors = new ArrayList<DependencyDescriptor>();
    for (DependencyNode node : visitor.getDependencies()) {
        // skip root to not add artifact as dependency
        if (node.getDependency().equals(root)) {
            continue;
        }
        descriptors.add(new DependencyDescriptor(node.getDependency().getArtifact()));
    }
    return descriptors;
}
Also used : DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) CollectResult(org.eclipse.aether.collection.CollectResult) ArrayList(java.util.ArrayList) 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) DependencyNode(org.eclipse.aether.graph.DependencyNode) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

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