Search in sources :

Example 26 with DependencyNode

use of org.sonatype.aether.graph.DependencyNode in project sonatype-aether by sonatype.

the class NearestVersionConflictResolverTest method testNearestSoftVersionPrunedByFartherRange.

@Test
public void testNearestSoftVersionPrunedByFartherRange() throws Exception {
    // root
    // +- a:1
    // |  \- c:2
    // \- b:1
    //    \- c:[1]
    DependencyNode a = builder.artifactId("a").version("1").build();
    DependencyNode b = builder.artifactId("b").version("1").build();
    DependencyNode c1 = builder.artifactId("c").version("1").range("[1]").build();
    DependencyNode c2 = builder.artifactId("c").version("2").build();
    a.getChildren().add(c2);
    b.getChildren().add(c1);
    DependencyNode root = builder.artifactId(null).build();
    root.getChildren().add(a);
    root.getChildren().add(b);
    Map<DependencyNode, Object> conflictIds = new IdentityHashMap<DependencyNode, Object>();
    conflictIds.put(a, "a");
    conflictIds.put(b, "b");
    conflictIds.put(c1, "c");
    conflictIds.put(c2, "c");
    context.put(TransformationContextKeys.CONFLICT_IDS, conflictIds);
    NearestVersionConflictResolver transformer = new NearestVersionConflictResolver();
    root = transformer.transformGraph(root, context);
    assertEquals(2, root.getChildren().size());
    assertSame(a, root.getChildren().get(0));
    assertSame(b, root.getChildren().get(1));
    assertTrue(a.getChildren().isEmpty());
    assertEquals(1, b.getChildren().size());
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) IdentityHashMap(java.util.IdentityHashMap) Test(org.junit.Test)

Example 27 with DependencyNode

use of org.sonatype.aether.graph.DependencyNode in project sonatype-aether by sonatype.

the class SimpleConflictMarker method mark.

private void mark(DependencyNode node, Map<DependencyNode, Object> conflictIds) {
    Dependency dependency = node.getDependency();
    if (dependency != null) {
        Artifact artifact = dependency.getArtifact();
        String key = String.format("%s:%s:%s:%s", artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), artifact.getExtension());
        if (conflictIds.put(node, key) != null) {
            return;
        }
    }
    for (DependencyNode child : node.getChildren()) {
        mark(child, conflictIds);
    }
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) Dependency(org.sonatype.aether.graph.Dependency) Artifact(org.sonatype.aether.artifact.Artifact)

Example 28 with DependencyNode

use of org.sonatype.aether.graph.DependencyNode in project sonatype-aether by sonatype.

the class JavaDependencyContextRefinerTest method testRefineToTest.

@Test
public void testRefineToTest() throws IOException, RepositoryException {
    String expected = "project/test";
    DependencyNode node = parser.parseLiteral("gid:aid:ext:ver:test");
    node.setRequestContext("project");
    DependencyNode refinedNode = refiner.transformGraph(node, context);
    assertEquals(expected, refinedNode.getRequestContext());
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) Test(org.junit.Test)

Example 29 with DependencyNode

use of org.sonatype.aether.graph.DependencyNode in project sonatype-aether by sonatype.

the class JavaEffectiveScopeCalculatorTest method testScopeOfDirectDependencyWinsConflictAndGetsUsedForInheritanceToChildrenEverywhereInGraph.

@Test
public void testScopeOfDirectDependencyWinsConflictAndGetsUsedForInheritanceToChildrenEverywhereInGraph() throws Exception {
    DependencyNode root = parser.parse("direct-with-conflict-and-inheritance.txt");
    root = transform(root);
    expectScope("test", root, 0, 0);
    expectScope("test", root, 1, 0, 0);
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) Test(org.junit.Test)

Example 30 with DependencyNode

use of org.sonatype.aether.graph.DependencyNode in project sonatype-aether by sonatype.

the class JavaEffectiveScopeCalculatorTest method testDirectNodesAlwaysWin.

@Test
public void testDirectNodesAlwaysWin() throws IOException, RepositoryException {
    for (Scope directScope : Scope.values()) {
        String direct = directScope.toString();
        parser.setSubstitutions(direct);
        DependencyNode root = parser.parse("direct-nodes-winning.txt");
        String msg = String.format("direct node should be setting scope ('%s') for all nodes.\n" + parser.dump(root), direct);
        root = transform(root);
        msg += "\ntransformed:\n" + parser.dump(root);
        expectScope(msg, direct, root, 0);
        expectScope(msg, direct, root, 1, 0);
        expectScope(msg, direct, root, 2, 0);
        expectScope(msg, direct, root, 3, 0);
        expectScope(msg, direct, root, 4, 0);
    }
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) Test(org.junit.Test)

Aggregations

DependencyNode (org.sonatype.aether.graph.DependencyNode)114 Test (org.junit.Test)82 NodeBuilder (org.sonatype.aether.test.util.NodeBuilder)20 Dependency (org.sonatype.aether.graph.Dependency)14 IdentityHashMap (java.util.IdentityHashMap)13 CollectRequest (org.sonatype.aether.collection.CollectRequest)12 CollectResult (org.sonatype.aether.collection.CollectResult)11 List (java.util.List)8 Map (java.util.Map)8 LinkedList (java.util.LinkedList)7 Artifact (org.sonatype.aether.artifact.Artifact)6 DependencyFilter (org.sonatype.aether.graph.DependencyFilter)5 ArrayList (java.util.ArrayList)4 DependencyGraphTransformationContext (org.sonatype.aether.collection.DependencyGraphTransformationContext)4 ConflictMarker (org.sonatype.aether.util.graph.transformer.ConflictMarker)4 HashMap (java.util.HashMap)3 ArtifactDescriptorException (org.sonatype.aether.resolution.ArtifactDescriptorException)3 BufferedReader (java.io.BufferedReader)2 HashSet (java.util.HashSet)2 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)2