Search in sources :

Example 41 with DependencyNode

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

the class DefaultDependencyCollectorTest method testSimpleCollection.

@Test
public void testSimpleCollection() throws DependencyCollectionException {
    Dependency dependency = newDep("gid:aid:ext:ver", "compile");
    CollectRequest request = new CollectRequest(dependency, Arrays.asList(repository));
    CollectResult result = collector.collectDependencies(session, request);
    assertEquals(0, result.getExceptions().size());
    DependencyNode root = result.getRoot();
    Dependency newDependency = root.getDependency();
    assertEquals(dependency, newDependency);
    assertEquals(dependency.getArtifact(), newDependency.getArtifact());
    assertEquals(1, root.getChildren().size());
    Dependency expect = newDep("gid:aid2:ext:ver", "compile");
    assertEquals(expect, root.getChildren().get(0).getDependency());
}
Also used : 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) Test(org.junit.Test)

Example 42 with DependencyNode

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

the class DependencyGraphParser method parse.

private DependencyNode parse(BufferedReader in) throws IOException {
    Iterator<String> substitutionIterator = (substitutions != null) ? substitutions.iterator() : null;
    String line = null;
    DependencyNode root = null;
    DependencyNode node = null;
    int prevLevel = 0;
    Map<String, DependencyNode> nodes = new HashMap<>();
    LinkedList<DependencyNode> stack = new LinkedList<>();
    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 IllegalStateException("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().reference != null) {
            String reference = ctx.getDefinition().reference;
            DependencyNode child = nodes.get(reference);
            if (child == null) {
                throw new IllegalStateException("undefined reference " + reference);
            }
            node.getChildren().add(child);
        } else {
            node = build(isRootNode ? null : stack.getLast(), ctx, isRootNode);
            if (isRootNode) {
                root = node;
                isRootNode = false;
            }
            if (ctx.getDefinition() != null && ctx.getDefinition().id != null) {
                nodes.put(ctx.getDefinition().id, node);
            }
        }
    }
    return root;
}
Also used : HashMap(java.util.HashMap) DependencyNode(org.eclipse.aether.graph.DependencyNode) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) LinkedList(java.util.LinkedList)

Example 43 with DependencyNode

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

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.eclipse.aether.graph.DependencyNode) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader)

Example 44 with DependencyNode

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

the class NearestVersionSelectorTest method testOverlappingCycles.

@Test
public void testOverlappingCycles() throws Exception {
    DependencyNode root = parseResource("overlapping-cycles.txt");
    assertSame(root, transform(root));
    assertEquals(2, root.getChildren().size());
}
Also used : DependencyNode(org.eclipse.aether.graph.DependencyNode) Test(org.junit.Test)

Example 45 with DependencyNode

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

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

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