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 import org.apache.maven.api.Node;
26 import org.apache.maven.api.NodeVisitor;
27 import org.eclipse.aether.artifact.Artifact;
28 import org.eclipse.aether.graph.Dependency;
29 import org.eclipse.aether.graph.DependencyNode;
30
31 public abstract class AbstractNode implements Node {
32
33 abstract org.eclipse.aether.graph.DependencyNode getDependencyNode();
34
35 @Override
36 public boolean accept(NodeVisitor visitor) {
37 if (visitor.enter(this)) {
38 for (Node child : getChildren()) {
39 if (!child.accept(visitor)) {
40 break;
41 }
42 }
43 }
44 return visitor.leave(this);
45 }
46
47 @Override
48 public Node filter(Predicate<Node> filter) {
49 List<Node> children =
50 getChildren().stream().filter(filter).map(n -> n.filter(filter)).collect(Collectors.toList());
51 return new WrapperNode(this, Collections.unmodifiableList(children));
52 }
53
54 @Override
55 public String asString() {
56 StringBuilder sb = new StringBuilder();
57
58 DependencyNode node = getDependencyNode();
59 Artifact artifact = node.getArtifact();
60 sb.append(artifact);
61
62 Dependency dependency = node.getDependency();
63 if (dependency != null) {
64 sb.append(":").append(dependency.getScope());
65 }
66
67 return sb.toString();
68 }
69
70 @Override
71 public String toString() {
72 return getDependencyNode().toString();
73 }
74 }