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