1 package org.apache.maven.plugin.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
37 public class TGFDependencyNodeVisitor
38 extends AbstractSerializingVisitor
39 implements DependencyNodeVisitor
40 {
41
42
43
44
45
46
47 static final class EdgeAppender
48 {
49
50
51
52 private DependencyNode from;
53
54
55
56
57 private DependencyNode to;
58
59
60
61
62 private String label;
63
64
65
66
67
68
69
70
71 public EdgeAppender( DependencyNode from, DependencyNode to, String label )
72 {
73 super();
74 this.from = from;
75 this.to = to;
76 this.label = label;
77 }
78
79
80
81
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 public boolean endVisit( DependencyNode node )
114 {
115 if ( node.getParent() == null || node.getParent() == node )
116 {
117
118 writer.println( "#" );
119 for ( EdgeAppender edge : edges )
120 {
121 writer.println( edge.toString() );
122 }
123 }
124 else
125 {
126 DependencyNode p = node.getParent();
127
128 edges.add( new EdgeAppender( p, node, node.getArtifact().getScope() ) );
129 }
130 return true;
131 }
132
133
134
135
136 public boolean visit( DependencyNode node )
137 {
138
139 writer.write( generateId( node ) );
140 writer.write( " " );
141 writer.println( node.toNodeString() );
142 return true;
143 }
144
145
146
147
148
149
150
151
152
153
154 private static String generateId( DependencyNode node )
155 {
156 return String.valueOf( node.hashCode() );
157 }
158 }