Search in sources :

Example 6 with DependencyNode

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

the class DependencyGraphParserTest method testChildNullDependency.

@Test
public void testChildNullDependency() throws IOException {
    String literal = "gid:aid:ext:ver\n+- (null)";
    DependencyNode root = parser.parseLiteral(literal);
    assertNotNull(root.getDependency());
    assertEquals(1, root.getChildren().size());
    assertNull(root.getChildren().get(0).getDependency());
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) Test(org.junit.Test)

Example 7 with DependencyNode

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

the class DependencyGraphParserTest method testId.

@Test
public void testId() throws IOException {
    String def = "(id)gid:aid:ext:ver\n\\- ^id";
    DependencyNode node = parser.parseLiteral(def);
    assertNodeProperties(node, "");
    assertNotNull(node.getChildren());
    assertEquals(1, node.getChildren().size());
    assertSame(node, node.getChildren().get(0));
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) Test(org.junit.Test)

Example 8 with DependencyNode

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

the class DependencyGraphParser method parseLiteral.

/**
     * Parse the given graph definition.
     */
public DependencyNode parseLiteral(String dependencyGraph) throws IOException {
    BufferedReader reader = new BufferedReader(new StringReader(dependencyGraph));
    DependencyNode node = parse(reader);
    reader.close();
    return node;
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader)

Example 9 with DependencyNode

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

the class DependencyGraphParser method addNode.

private void addNode(DependencyNode root, int level, List<NodeEntry> entries) {
    NodeEntry entry = new NodeEntry();
    Dependency dependency = root.getDependency();
    StringBuilder defBuilder = new StringBuilder();
    if (dependency == null) {
        defBuilder.append("(null)");
    } else {
        Artifact artifact = dependency.getArtifact();
        defBuilder.append(artifact.getGroupId()).append(":").append(artifact.getArtifactId()).append(":").append(artifact.getExtension()).append(":").append(artifact.getVersion());
        if (dependency.getScope() != null && (!"".equals(dependency.getScope()))) {
            defBuilder.append(":").append(dependency.getScope());
        }
        Map<String, String> properties = artifact.getProperties();
        if (!(properties == null || properties.isEmpty())) {
            for (Map.Entry<String, String> prop : properties.entrySet()) {
                defBuilder.append(";").append(prop.getKey()).append("=").append(prop.getValue());
            }
        }
    }
    entry.setDefinition(defBuilder.toString());
    entry.setLevel(level++);
    entries.add(entry);
    for (DependencyNode node : root.getChildren()) {
        addNode(node, level, entries);
    }
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) Dependency(org.sonatype.aether.graph.Dependency) HashMap(java.util.HashMap) Map(java.util.Map) Artifact(org.sonatype.aether.artifact.Artifact)

Example 10 with DependencyNode

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

the class DependencyGraphParser method build.

private DependencyNode build(DependencyNode parent, LineContext ctx, boolean isRoot) {
    ArtifactDefinition def = ctx.getDefinition();
    if (!isRoot && parent == null) {
        throw new IllegalArgumentException("dangling node: " + def);
    } else if (ctx.getLevel() == 0 && parent != null) {
        throw new IllegalArgumentException("inconsistent leveling (parent for level 0?): " + def);
    }
    NodeBuilder builder = new NodeBuilder();
    if (def != null) {
        builder.artifactId(def.getArtifactId()).groupId(def.getGroupId());
        builder.ext(def.getExtension()).version(def.getVersion()).scope(def.getScope());
        builder.properties(ctx.getProperties());
    }
    DependencyNode node = builder.build();
    if (parent != null) {
        parent.getChildren().add(node);
    }
    return node;
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode)

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