Search in sources :

Example 36 with DependencyNode

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

the class DefaultDependencyCollectorTest method assertEqualSubtree.

private static void assertEqualSubtree(DependencyNode expected, DependencyNode actual, LinkedList<DependencyNode> parents) {
    assertEquals("path: " + parents, expected.getDependency(), actual.getDependency());
    if (actual.getDependency() != null) {
        Artifact artifact = actual.getDependency().getArtifact();
        for (DependencyNode parent : parents) {
            if (parent.getDependency() != null && artifact.equals(parent.getDependency().getArtifact())) {
                return;
            }
        }
    }
    parents.addLast(expected);
    assertEquals("path: " + parents + ", expected: " + expected.getChildren() + ", actual: " + actual.getChildren(), expected.getChildren().size(), actual.getChildren().size());
    Iterator<DependencyNode> iterator1 = expected.getChildren().iterator();
    Iterator<DependencyNode> iterator2 = actual.getChildren().iterator();
    while (iterator1.hasNext()) {
        assertEqualSubtree(iterator1.next(), iterator2.next(), parents);
    }
    parents.removeLast();
}
Also used : DependencyNode(org.eclipse.aether.graph.DependencyNode) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 37 with DependencyNode

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

the class DefaultDependencyCollectorTest method testDependencyManagement_TransitiveDependencyManager.

@Test
public void testDependencyManagement_TransitiveDependencyManager() throws DependencyCollectionException, IOException {
    collector.setArtifactDescriptorReader(newReader("managed/"));
    parser = new DependencyGraphParser("artifact-descriptions/managed/");
    session.setDependencyManager(new TransitiveDependencyManager());
    final Dependency root = newDep("gid:root:ext:ver", "compile");
    CollectRequest request = new CollectRequest(root, Collections.singletonList(repository));
    request.addManagedDependency(newDep("gid:root:ext:must-retain-core-management"));
    CollectResult result = collector.collectDependencies(session, request);
    final DependencyNode expectedTree = parser.parseResource("management-tree.txt");
    assertEqualSubtree(expectedTree, result.getRoot());
    // Same test for root artifact (POM) request.
    final CollectRequest rootArtifactRequest = new CollectRequest();
    rootArtifactRequest.setRepositories(Collections.singletonList(repository));
    rootArtifactRequest.setRootArtifact(new DefaultArtifact("gid:root:ext:ver"));
    rootArtifactRequest.addDependency(newDep("gid:direct:ext:ver", "compile"));
    rootArtifactRequest.addManagedDependency(newDep("gid:root:ext:must-retain-core-management"));
    rootArtifactRequest.addManagedDependency(newDep("gid:direct:ext:must-retain-core-management"));
    rootArtifactRequest.addManagedDependency(newDep("gid:transitive-1:ext:managed-by-root"));
    session.setDependencyManager(new TransitiveDependencyManager());
    result = collector.collectDependencies(session, rootArtifactRequest);
    assertEqualSubtree(expectedTree, toDependencyResult(result.getRoot(), "compile", null));
}
Also used : TransitiveDependencyManager(org.eclipse.aether.util.graph.manager.TransitiveDependencyManager) DependencyGraphParser(org.eclipse.aether.internal.test.util.DependencyGraphParser) CollectResult(org.eclipse.aether.collection.CollectResult) DependencyNode(org.eclipse.aether.graph.DependencyNode) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Test(org.junit.Test)

Example 38 with DependencyNode

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

the class DefaultDependencyCollectorTest method testPartialResultOnError.

@Test
public void testPartialResultOnError() throws IOException {
    DependencyNode root = parser.parseResource("expectedPartialSubtreeOnError.txt");
    Dependency dependency = root.getDependency();
    CollectRequest request = new CollectRequest(dependency, Arrays.asList(repository));
    CollectResult result;
    try {
        result = collector.collectDependencies(session, request);
        fail("expected exception ");
    } catch (DependencyCollectionException e) {
        result = e.getResult();
        assertSame(request, result.getRequest());
        assertNotNull(result.getExceptions());
        assertEquals(1, result.getExceptions().size());
        assertTrue(result.getExceptions().get(0) instanceof ArtifactDescriptorException);
        assertEqualSubtree(root, result.getRoot());
    }
}
Also used : DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) CollectResult(org.eclipse.aether.collection.CollectResult) DependencyNode(org.eclipse.aether.graph.DependencyNode) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) Test(org.junit.Test)

Example 39 with DependencyNode

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

the class DefaultDependencyCollectorTest method testCyclicProjects.

@Test
public void testCyclicProjects() throws Exception {
    CollectRequest request = new CollectRequest(newDep("test:a:2"), Arrays.asList(repository));
    collector.setArtifactDescriptorReader(newReader("versionless-cycle/"));
    CollectResult result = collector.collectDependencies(session, request);
    DependencyNode root = result.getRoot();
    DependencyNode a1 = path(root, 0, 0);
    assertEquals("a", a1.getArtifact().getArtifactId());
    assertEquals("1", a1.getArtifact().getVersion());
    for (DependencyNode child : a1.getChildren()) {
        assertNotEquals("1", child.getArtifact().getVersion());
    }
    assertEquals(1, result.getCycles().size());
    DependencyCycle cycle = result.getCycles().get(0);
    assertEquals(Arrays.asList(), cycle.getPrecedingDependencies());
    assertEquals(Arrays.asList(root.getDependency(), path(root, 0).getDependency(), a1.getDependency()), cycle.getCyclicDependencies());
}
Also used : CollectResult(org.eclipse.aether.collection.CollectResult) DependencyNode(org.eclipse.aether.graph.DependencyNode) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) DependencyCycle(org.eclipse.aether.graph.DependencyCycle) CollectRequest(org.eclipse.aether.collection.CollectRequest) Test(org.junit.Test)

Example 40 with DependencyNode

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

the class DependencyGraphDumper method dump.

private static void dump(Context context, DependencyNode node, int depth, boolean last) {
    Line line = context.nodes.get(node);
    if (line != null) {
        if (line.id <= 0) {
            line.id = ++context.ids;
        }
        context.lines.add(new Line(null, line.id, depth, last));
        return;
    }
    Dependency dependency = node.getDependency();
    if (dependency == null) {
        line = new Line(null, 0, depth, last);
    } else {
        line = new Line(dependency, 0, depth, last);
    }
    context.lines.add(line);
    context.nodes.put(node, line);
    depth++;
    for (Iterator<DependencyNode> it = node.getChildren().iterator(); it.hasNext(); ) {
        DependencyNode child = it.next();
        dump(context, child, depth, !it.hasNext());
    }
}
Also used : DependencyNode(org.eclipse.aether.graph.DependencyNode) Dependency(org.eclipse.aether.graph.Dependency)

Aggregations

DependencyNode (org.eclipse.aether.graph.DependencyNode)258 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)56 DefaultDependencyNode (org.eclipse.aether.graph.DefaultDependencyNode)53 CollectRequest (org.eclipse.aether.collection.CollectRequest)52 ArrayList (java.util.ArrayList)39 IOException (java.io.IOException)29 List (java.util.List)27 CollectResult (org.eclipse.aether.collection.CollectResult)24 DependencyCollectionException (org.eclipse.aether.collection.DependencyCollectionException)22 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)22 PreorderNodeListGenerator (org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator)20 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)19 Path (java.nio.file.Path)18 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)18 File (java.io.File)17 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)17 Map (java.util.Map)16