1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.internal.impl;
20
21 import java.util.Collections;
22 import java.util.List;
23 import java.util.function.Predicate;
24 import java.util.stream.Collectors;
25
26 import org.apache.maven.api.Node;
27 import org.apache.maven.api.NodeVisitor;
28 import org.eclipse.aether.artifact.Artifact;
29 import org.eclipse.aether.graph.Dependency;
30 import org.eclipse.aether.graph.DependencyNode;
31
32 public abstract class AbstractNode implements Node {
33
34 abstract org.eclipse.aether.graph.DependencyNode getDependencyNode();
35
36 @Override
37 public boolean accept(NodeVisitor visitor) {
38 if (visitor.enter(this)) {
39 for (Node child : getChildren()) {
40 if (!child.accept(visitor)) {
41 break;
42 }
43 }
44 }
45 return visitor.leave(this);
46 }
47
48 @Override
49 public Node filter(Predicate<Node> filter) {
50 List<Node> children =
51 getChildren().stream().filter(filter).map(n -> n.filter(filter)).collect(Collectors.toList());
52 return new WrapperNode(this, Collections.unmodifiableList(children));
53 }
54
55 @Override
56 public String asString() {
57 StringBuilder sb = new StringBuilder();
58
59 DependencyNode node = getDependencyNode();
60 Artifact artifact = node.getArtifact();
61 sb.append(artifact);
62
63 Dependency dependency = node.getDependency();
64 if (dependency != null) {
65 sb.append(":").append(dependency.getScope());
66 }
67
68 return sb.toString();
69 }
70
71 @Override
72 public String toString() {
73 return getDependencyNode().toString();
74 }
75 }