Search in sources :

Example 36 with DependencyNode

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

the class NearestVersionConflictResolverTest method testUnsolvableRangeConflictBetweenHardConstraints.

@Test(expected = UnsolvableVersionConflictException.class)
public void testUnsolvableRangeConflictBetweenHardConstraints() throws Exception {
    // root
    // +- b:1
    // |  \- a:[1]
    // \- c:1
    //    \- a:[2]
    DependencyNode a1 = builder.artifactId("a").version("1").range("[1]").build();
    DependencyNode a2 = builder.artifactId("a").version("2").range("[2]").build();
    DependencyNode b = builder.artifactId("b").version("1").build();
    DependencyNode c = builder.artifactId("c").version("1").build();
    b.getChildren().add(a1);
    c.getChildren().add(a2);
    DependencyNode root = builder.artifactId(null).build();
    root.getChildren().add(b);
    root.getChildren().add(c);
    Map<DependencyNode, Object> conflictIds = new IdentityHashMap<DependencyNode, Object>();
    conflictIds.put(a1, "a");
    conflictIds.put(a2, "a");
    conflictIds.put(b, "b");
    conflictIds.put(c, "c");
    context.put(TransformationContextKeys.CONFLICT_IDS, conflictIds);
    NearestVersionConflictResolver transformer = new NearestVersionConflictResolver();
    root = transformer.transformGraph(root, context);
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) IdentityHashMap(java.util.IdentityHashMap) Test(org.junit.Test)

Example 37 with DependencyNode

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

the class NearestVersionConflictResolverTest method testSelectedVersionAtDeeperLevelThanOriginallySeen.

@Test
public void testSelectedVersionAtDeeperLevelThanOriginallySeen() throws Exception {
    // root
    // +- a
    // |  \- b:1           # will be removed in favor of b:2
    // |     \- j:1        # nearest version of j in dirty tree
    // +- c
    // |  \- d
    // |     \- e
    // |        \- j:1
    // \- b:2
    DependencyNode j = builder.artifactId("j").build();
    DependencyNode b1 = builder.artifactId("b").version("1").build();
    b1.getChildren().add(j);
    DependencyNode a = builder.artifactId("a").build();
    a.getChildren().add(b1);
    DependencyNode e = builder.artifactId("e").build();
    e.getChildren().add(j);
    DependencyNode d = builder.artifactId("d").build();
    d.getChildren().add(e);
    DependencyNode c = builder.artifactId("c").build();
    c.getChildren().add(d);
    DependencyNode b2 = builder.artifactId("b").version("2").build();
    DependencyNode root = builder.artifactId(null).build();
    root.getChildren().add(a);
    root.getChildren().add(c);
    root.getChildren().add(b2);
    Map<DependencyNode, Object> conflictIds = new IdentityHashMap<DependencyNode, Object>();
    conflictIds.put(j, "j");
    conflictIds.put(a, "a");
    conflictIds.put(b1, "b");
    conflictIds.put(b2, "b");
    conflictIds.put(c, "c");
    conflictIds.put(d, "d");
    conflictIds.put(e, "e");
    context.put(TransformationContextKeys.CONFLICT_IDS, conflictIds);
    NearestVersionConflictResolver transformer = new NearestVersionConflictResolver();
    root = transformer.transformGraph(root, context);
    List<DependencyNode> trail = find(root, "j");
    assertEquals(5, trail.size());
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) IdentityHashMap(java.util.IdentityHashMap) Test(org.junit.Test)

Example 38 with DependencyNode

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

the class PatternInclusionsDependencyFilterTest method acceptTestCornerCases.

@Test
public void acceptTestCornerCases() {
    NodeBuilder builder = new NodeBuilder();
    builder.artifactId("testArtifact");
    DependencyNode node = builder.build();
    List<DependencyNode> parents = new LinkedList<DependencyNode>();
    // Empty String, Empty List
    assertTrue(accept(node, ""));
    assertFalse(new PatternInclusionsDependencyFilter(new LinkedList<String>()).accept(node, parents));
    assertFalse(new PatternInclusionsDependencyFilter((String[]) null).accept(node, parents));
    assertFalse(new PatternInclusionsDependencyFilter((VersionScheme) null, "[1,10]").accept(node, parents));
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) NodeBuilder(org.sonatype.aether.test.util.NodeBuilder) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 39 with DependencyNode

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

the class FilteringDependencyVisitorTest method testFilterCalledWithProperParentStack.

@Test
public void testFilterCalledWithProperParentStack() throws Exception {
    DependencyNode root = parse("parents.txt");
    final StringBuilder buffer = new StringBuilder(256);
    DependencyFilter filter = new DependencyFilter() {

        public boolean accept(DependencyNode node, List<DependencyNode> parents) {
            for (DependencyNode parent : parents) {
                buffer.append(parent.getDependency().getArtifact().getArtifactId());
            }
            buffer.append(",");
            return false;
        }
    };
    FilteringDependencyVisitor visitor = new FilteringDependencyVisitor(new PreorderNodeListGenerator(), filter);
    root.accept(visitor);
    assertEquals(",a,ba,cba,a,ea,", buffer.toString());
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) DependencyFilter(org.sonatype.aether.graph.DependencyFilter) List(java.util.List) Test(org.junit.Test)

Example 40 with DependencyNode

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

the class PathRecordingDependencyVisitorTest method testFilterCalledWithProperParentStack.

@Test
public void testFilterCalledWithProperParentStack() throws Exception {
    DependencyNode root = parse("parents.txt");
    final StringBuilder buffer = new StringBuilder(256);
    DependencyFilter filter = new DependencyFilter() {

        public boolean accept(DependencyNode node, List<DependencyNode> parents) {
            for (DependencyNode parent : parents) {
                buffer.append(parent.getDependency().getArtifact().getArtifactId());
            }
            buffer.append(",");
            return false;
        }
    };
    PathRecordingDependencyVisitor visitor = new PathRecordingDependencyVisitor(filter);
    root.accept(visitor);
    assertEquals(",a,ba,cba,a,ea,", buffer.toString());
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) DependencyFilter(org.sonatype.aether.graph.DependencyFilter) List(java.util.List) 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