Search in sources :

Example 91 with DependencyNode

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

the class PatternInclusionsDependencyFilterTest method acceptTestMatches.

@Test
public void acceptTestMatches() {
    NodeBuilder builder = new NodeBuilder();
    builder.groupId("com.example.test").artifactId("testArtifact").ext("jar").version("1.0.3");
    DependencyNode node = builder.build();
    // full match
    assertEquals("com.example.test:testArtifact:jar:1.0.3", true, accept(node, "com.example.test:testArtifact:jar:1.0.3"));
    // single wildcard
    assertEquals("*:testArtifact:jar:1.0.3", true, accept(node, "*:testArtifact:jar:1.0.3"));
    assertEquals("com.example.test:*:jar:1.0.3", true, accept(node, "com.example.test:*:jar:1.0.3"));
    assertEquals("com.example.test:testArtifact:*:1.0.3", true, accept(node, "com.example.test:testArtifact:*:1.0.3"));
    assertEquals("com.example.test:testArtifact:*:1.0.3", true, accept(node, "com.example.test:testArtifact:*:1.0.3"));
    // implicit wildcard
    assertEquals(":testArtifact:jar:1.0.3", true, accept(node, ":testArtifact:jar:1.0.3"));
    assertEquals("com.example.test::jar:1.0.3", true, accept(node, "com.example.test::jar:1.0.3"));
    assertEquals("com.example.test:testArtifact::1.0.3", true, accept(node, "com.example.test:testArtifact::1.0.3"));
    assertEquals("com.example.test:testArtifact:jar:", true, accept(node, "com.example.test:testArtifact:jar:"));
    // multi wildcards
    assertEquals("*:*:jar:1.0.3", true, accept(node, "*:*:jar:1.0.3"));
    assertEquals("com.example.test:*:*:1.0.3", true, accept(node, "com.example.test:*:*:1.0.3"));
    assertEquals("com.example.test:testArtifact:*:*", true, accept(node, "com.example.test:testArtifact:*:*"));
    assertEquals("*:testArtifact:jar:*", true, accept(node, "*:testArtifact:jar:*"));
    assertEquals("*:*:jar:*", true, accept(node, "*:*:jar:*"));
    assertEquals(":*:jar:", true, accept(node, ":*:jar:"));
    // partial wildcards
    assertEquals("*.example.test:testArtifact:jar:1.0.3", true, accept(node, "*.example.test:testArtifact:jar:1.0.3"));
    assertEquals("com.example.test:testArtifact:*ar:1.0.*", true, accept(node, "com.example.test:testArtifact:*ar:1.0.*"));
    assertEquals("com.example.test:testArtifact:jar:1.0.*", true, accept(node, "com.example.test:testArtifact:jar:1.0.*"));
    assertEquals("*.example.*:testArtifact:jar:1.0.3", true, accept(node, "*.example.*:testArtifact:jar:1.0.3"));
    // wildcard as empty string
    assertEquals("com.example.test*:testArtifact:jar:1.0.3", true, accept(node, "com.example.test*:testArtifact:jar:1.0.3"));
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) NodeBuilder(org.sonatype.aether.test.util.NodeBuilder) Test(org.junit.Test)

Example 92 with DependencyNode

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

the class DependencyGraphParser method parse.

private DependencyNode parse(BufferedReader in) throws IOException {
    if (substitutions != null) {
        substitutionIterator = substitutions.iterator();
    }
    String line = null;
    DependencyNode root = null;
    DependencyNode node = null;
    int prevLevel = 0;
    LinkedList<DependencyNode> stack = new LinkedList<DependencyNode>();
    boolean isRootNode = true;
    while ((line = in.readLine()) != null) {
        line = cutComment(line);
        if (isEmpty(line)) {
            // skip empty line
            continue;
        }
        if (isEOFMarker(line)) {
            // stop parsing
            break;
        }
        while (line.contains("%s")) {
            if (!substitutionIterator.hasNext()) {
                throw new IllegalArgumentException("not enough substitutions to fill placeholders");
            }
            line = line.replaceFirst("%s", substitutionIterator.next());
        }
        LineContext ctx = createContext(line);
        if (prevLevel < ctx.getLevel()) {
            // previous node is new parent
            stack.add(node);
        }
        // get to real parent
        while (prevLevel > ctx.getLevel()) {
            stack.removeLast();
            prevLevel -= 1;
        }
        prevLevel = ctx.getLevel();
        if (ctx.getDefinition() != null && ctx.getDefinition().isReference()) {
            DependencyNode child = reference(ctx.getDefinition().getReference());
            node.getChildren().add(child);
            node = child;
        } else {
            node = build(isRootNode ? null : stack.getLast(), ctx, isRootNode);
            if (isRootNode) {
                root = node;
                isRootNode = false;
            }
            if (ctx.getDefinition() != null && ctx.getDefinition().hasId()) {
                this.nodes.put(ctx.getDefinition().getId(), node);
            }
        }
    }
    this.nodes.clear();
    return root;
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) LinkedList(java.util.LinkedList)

Example 93 with DependencyNode

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

the class DependencyGraphParser method parseMultiple.

/**
     * Parse multiple graphs in one resource, divided by "---".
     */
public List<DependencyNode> parseMultiple(String resource) throws IOException {
    URL res = this.getClass().getClassLoader().getResource(prefix + resource);
    if (res == null) {
        throw new IOException("Could not find classpath resource " + prefix + resource);
    }
    BufferedReader reader = new BufferedReader(new InputStreamReader(res.openStream(), "UTF-8"));
    List<DependencyNode> ret = new ArrayList<DependencyNode>();
    DependencyNode root = null;
    while ((root = parse(reader)) != null) {
        ret.add(root);
    }
    return ret;
}
Also used : InputStreamReader(java.io.InputStreamReader) DependencyNode(org.sonatype.aether.graph.DependencyNode) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URL(java.net.URL)

Example 94 with DependencyNode

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

the class DependencyGraphParserTest method testResourceLoadingWithPrefix.

@Test
public void testResourceLoadingWithPrefix() throws UnsupportedEncodingException, IOException {
    String prefix = "org/sonatype/aether/test/util/";
    parser = new DependencyGraphParser(prefix);
    String name = "testResourceLoading.txt";
    DependencyNode node = parser.parse(name);
    assertEquals(0, node.getChildren().size());
    assertNodeProperties(node, "");
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) Test(org.junit.Test)

Example 95 with DependencyNode

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

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.sonatype.aether.graph.DependencyNode) Artifact(org.sonatype.aether.artifact.Artifact)

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