1 package org.apache.maven.plugins.dependency.tree;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.Writer;
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import org.apache.maven.shared.dependency.graph.DependencyNode;
27 import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor;
28
29
30
31
32
33
34
35
36 public class TGFDependencyNodeVisitor
37 extends AbstractSerializingVisitor
38 implements DependencyNodeVisitor
39 {
40
41
42
43
44
45
46 static final class EdgeAppender
47 {
48
49
50
51 private DependencyNode from;
52
53
54
55
56 private DependencyNode to;
57
58
59
60
61 private String label;
62
63
64
65
66
67
68
69
70 EdgeAppender( DependencyNode from, DependencyNode to, String label )
71 {
72 super();
73 this.from = from;
74 this.to = to;
75 this.label = label;
76 }
77
78
79
80
81 @Override
82 public String toString()
83 {
84 StringBuilder result = new StringBuilder( generateId( from ) );
85 result.append( ' ' ).append( generateId( to ) );
86 if ( label != null )
87 {
88 result.append( ' ' ).append( label );
89 }
90 return result.toString();
91 }
92
93 }
94
95
96
97
98 private List<EdgeAppender> edges = new ArrayList<EdgeAppender>();
99
100
101
102
103
104
105 public TGFDependencyNodeVisitor( Writer writer )
106 {
107 super( writer );
108 }
109
110
111
112
113 @Override
114 public boolean endVisit( DependencyNode node )
115 {
116 if ( node.getParent() == null || node.getParent() == node )
117 {
118
119 writer.println( "#" );
120 for ( EdgeAppender edge : edges )
121 {
122 writer.println( edge.toString() );
123 }
124 }
125 else
126 {
127 DependencyNode p = node.getParent();
128
129 edges.add( new EdgeAppender( p, node, node.getArtifact().getScope() ) );
130 }
131 return true;
132 }
133
134
135
136
137 @Override
138 public boolean visit( DependencyNode node )
139 {
140
141 writer.write( generateId( node ) );
142 writer.write( " " );
143 writer.println( node.toNodeString() );
144 return true;
145 }
146
147
148
149
150
151
152
153
154
155
156 private static String generateId( DependencyNode node )
157 {
158 return String.valueOf( node.hashCode() );
159 }
160 }