1 | |
package org.apache.maven.shared.dependency.graph.internal; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.util.List; |
23 | |
|
24 | |
import org.apache.maven.artifact.Artifact; |
25 | |
import org.apache.maven.shared.dependency.graph.DependencyNode; |
26 | |
import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor; |
27 | |
|
28 | |
public class DefaultDependencyNode |
29 | |
implements DependencyNode |
30 | |
{ |
31 | |
private final Artifact artifact; |
32 | |
|
33 | |
private final DependencyNode parent; |
34 | |
|
35 | |
private final String premanagedVersion; |
36 | |
|
37 | |
private final String premanagedScope; |
38 | |
|
39 | |
private final String versionConstraint; |
40 | |
|
41 | |
private List<DependencyNode> children; |
42 | |
|
43 | |
public DefaultDependencyNode( DependencyNode parent, Artifact artifact, String premanagedVersion, |
44 | |
String premanagedScope, String versionConstraint ) |
45 | 0 | { |
46 | 0 | this.parent = parent; |
47 | 0 | this.artifact = artifact; |
48 | 0 | this.premanagedVersion = premanagedVersion; |
49 | 0 | this.premanagedScope = premanagedScope; |
50 | 0 | this.versionConstraint = versionConstraint; |
51 | 0 | } |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
public boolean accept( DependencyNodeVisitor visitor ) |
62 | |
{ |
63 | 0 | if ( visitor.visit( this ) ) |
64 | |
{ |
65 | 0 | for ( DependencyNode child : getChildren() ) |
66 | |
{ |
67 | 0 | if ( !child.accept( visitor ) ) |
68 | |
{ |
69 | 0 | break; |
70 | |
} |
71 | |
} |
72 | |
} |
73 | |
|
74 | 0 | return visitor.endVisit( this ); |
75 | |
} |
76 | |
|
77 | |
public Artifact getArtifact() |
78 | |
{ |
79 | 0 | return artifact; |
80 | |
} |
81 | |
|
82 | |
public void setChildren( List<DependencyNode> children ) |
83 | |
{ |
84 | 0 | this.children = children; |
85 | 0 | } |
86 | |
|
87 | |
public List<DependencyNode> getChildren() |
88 | |
{ |
89 | 0 | return children; |
90 | |
} |
91 | |
|
92 | |
public DependencyNode getParent() |
93 | |
{ |
94 | 0 | return parent; |
95 | |
} |
96 | |
|
97 | |
public String getPremanagedVersion() |
98 | |
{ |
99 | 0 | return premanagedVersion; |
100 | |
} |
101 | |
|
102 | |
public String getPremanagedScope() |
103 | |
{ |
104 | 0 | return premanagedScope; |
105 | |
} |
106 | |
|
107 | |
public String getVersionConstraint() |
108 | |
{ |
109 | 0 | return versionConstraint; |
110 | |
} |
111 | |
|
112 | |
public String toNodeString() |
113 | |
{ |
114 | 0 | StringBuffer buffer = new StringBuffer(); |
115 | |
|
116 | 0 | buffer.append( artifact ); |
117 | |
|
118 | 0 | ItemAppender appender = new ItemAppender( buffer, " (", "; ", ")" ); |
119 | |
|
120 | 0 | if ( getPremanagedVersion() != null ) |
121 | |
{ |
122 | 0 | appender.append( "version managed from ", getPremanagedVersion() ); |
123 | |
} |
124 | |
|
125 | 0 | if ( getPremanagedScope() != null ) |
126 | |
{ |
127 | 0 | appender.append( "scope managed from ", getPremanagedScope() ); |
128 | |
} |
129 | |
|
130 | 0 | if ( getVersionConstraint() != null ) |
131 | |
{ |
132 | 0 | appender.append( "version selected from constraint ", getVersionConstraint() ); |
133 | |
} |
134 | |
|
135 | 0 | appender.flush(); |
136 | |
|
137 | 0 | return buffer.toString(); |
138 | |
} |
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
private static class ItemAppender |
144 | |
{ |
145 | |
private StringBuffer buffer; |
146 | |
|
147 | |
private String startToken; |
148 | |
|
149 | |
private String separatorToken; |
150 | |
|
151 | |
private String endToken; |
152 | |
|
153 | |
private boolean appended; |
154 | |
|
155 | |
public ItemAppender( StringBuffer buffer, String startToken, String separatorToken, String endToken ) |
156 | 0 | { |
157 | 0 | this.buffer = buffer; |
158 | 0 | this.startToken = startToken; |
159 | 0 | this.separatorToken = separatorToken; |
160 | 0 | this.endToken = endToken; |
161 | |
|
162 | 0 | appended = false; |
163 | 0 | } |
164 | |
|
165 | |
public ItemAppender append( String item1, String item2 ) |
166 | |
{ |
167 | 0 | appendToken(); |
168 | |
|
169 | 0 | buffer.append( item1 ).append( item2 ); |
170 | |
|
171 | 0 | return this; |
172 | |
} |
173 | |
|
174 | |
public void flush() |
175 | |
{ |
176 | 0 | if ( appended ) |
177 | |
{ |
178 | 0 | buffer.append( endToken ); |
179 | |
|
180 | 0 | appended = false; |
181 | |
} |
182 | 0 | } |
183 | |
|
184 | |
private void appendToken() |
185 | |
{ |
186 | 0 | buffer.append( appended ? separatorToken : startToken ); |
187 | |
|
188 | 0 | appended = true; |
189 | 0 | } |
190 | |
} |
191 | |
} |