1 | |
package org.apache.maven.plugins.enforcer; |
2 | |
|
3 | |
import java.util.ArrayList; |
4 | |
import java.util.Iterator; |
5 | |
import java.util.List; |
6 | |
|
7 | |
import org.apache.maven.plugin.AbstractMojo; |
8 | |
import org.apache.maven.plugin.MojoExecutionException; |
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | 0 | public class HelpMojo |
20 | |
extends AbstractMojo |
21 | |
{ |
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
private boolean detail; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
private java.lang.String goal; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
private int lineLength; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
private int indentSize; |
49 | |
|
50 | |
|
51 | |
|
52 | |
public void execute() |
53 | |
throws MojoExecutionException |
54 | |
{ |
55 | 0 | if ( lineLength <= 0 ) |
56 | |
{ |
57 | 0 | getLog().warn( "The parameter 'lineLength' should be positive, using '80' as default." ); |
58 | 0 | lineLength = 80; |
59 | |
} |
60 | 0 | if ( indentSize <= 0 ) |
61 | |
{ |
62 | 0 | getLog().warn( "The parameter 'indentSize' should be positive, using '2' as default." ); |
63 | 0 | indentSize = 2; |
64 | |
} |
65 | |
|
66 | 0 | StringBuffer sb = new StringBuffer(); |
67 | |
|
68 | 0 | append( sb, "org.apache.maven.plugins:maven-enforcer-plugin:1.0.1", 0 ); |
69 | 0 | append( sb, "", 0 ); |
70 | |
|
71 | 0 | append( sb, "Maven Enforcer Plugin", 0 ); |
72 | 0 | append( sb, "The Loving Iron Fist of Maven", 1 ); |
73 | 0 | append( sb, "", 0 ); |
74 | |
|
75 | 0 | if ( goal == null || goal.length() <= 0 ) |
76 | |
{ |
77 | 0 | append( sb, "This plugin has 4 goals:", 0 ); |
78 | 0 | append( sb, "", 0 ); |
79 | |
} |
80 | |
|
81 | 0 | if ( goal == null || goal.length() <= 0 || "display-info".equals( goal ) ) |
82 | |
{ |
83 | 0 | append( sb, "enforcer:display-info", 0 ); |
84 | 0 | append( sb, "This goal displays the current platform information.", 1 ); |
85 | 0 | append( sb, "", 0 ); |
86 | 0 | if ( detail ) |
87 | |
{ |
88 | 0 | append( sb, "Available parameters:", 1 ); |
89 | 0 | append( sb, "", 0 ); |
90 | |
} |
91 | |
} |
92 | |
|
93 | 0 | if ( goal == null || goal.length() <= 0 || "enforce".equals( goal ) ) |
94 | |
{ |
95 | 0 | append( sb, "enforcer:enforce", 0 ); |
96 | 0 | append( sb, "This goal executes the defined enforcer-rules once per module.", 1 ); |
97 | 0 | append( sb, "", 0 ); |
98 | 0 | if ( detail ) |
99 | |
{ |
100 | 0 | append( sb, "Available parameters:", 1 ); |
101 | 0 | append( sb, "", 0 ); |
102 | |
|
103 | 0 | append( sb, "fail (Default: true)", 2 ); |
104 | 0 | append( sb, "Flag to fail the build if a version check fails.", 3 ); |
105 | 0 | append( sb, "Expression: ${enforcer.fail}", 3 ); |
106 | 0 | append( sb, "", 0 ); |
107 | |
|
108 | 0 | append( sb, "failFast (Default: false)", 2 ); |
109 | 0 | append( sb, "Fail on the first rule that doesn\'t pass", 3 ); |
110 | 0 | append( sb, "Expression: ${enforcer.failFast}", 3 ); |
111 | 0 | append( sb, "", 0 ); |
112 | |
|
113 | 0 | append( sb, "ignoreCache (Default: false)", 2 ); |
114 | 0 | append( sb, "Use this flag to disable rule result caching. This will cause all rules to execute on each project even if the rule indicates it can safely be cached.", 3 ); |
115 | 0 | append( sb, "Expression: ${enforcer.ignoreCache}", 3 ); |
116 | 0 | append( sb, "", 0 ); |
117 | |
|
118 | 0 | append( sb, "rules", 2 ); |
119 | 0 | append( sb, "Array of objects that implement the EnforcerRule interface to execute.", 3 ); |
120 | 0 | append( sb, "Required: Yes", 3 ); |
121 | 0 | append( sb, "", 0 ); |
122 | |
|
123 | 0 | append( sb, "skip (Default: false)", 2 ); |
124 | 0 | append( sb, "Flag to easily skip all checks", 3 ); |
125 | 0 | append( sb, "Expression: ${enforcer.skip}", 3 ); |
126 | 0 | append( sb, "", 0 ); |
127 | |
} |
128 | |
} |
129 | |
|
130 | 0 | if ( goal == null || goal.length() <= 0 || "enforce-once".equals( goal ) ) |
131 | |
{ |
132 | 0 | append( sb, "enforcer:enforce-once", 0 ); |
133 | 0 | append( sb, "This goal has been deprecated.", 1 ); |
134 | 0 | append( sb, "", 0 ); |
135 | 0 | if ( detail ) |
136 | |
{ |
137 | 0 | append( sb, "Available parameters:", 1 ); |
138 | 0 | append( sb, "", 0 ); |
139 | |
|
140 | 0 | append( sb, "fail (Default: true)", 2 ); |
141 | 0 | append( sb, "Flag to fail the build if a version check fails.", 3 ); |
142 | 0 | append( sb, "Expression: ${enforcer.fail}", 3 ); |
143 | 0 | append( sb, "", 0 ); |
144 | |
|
145 | 0 | append( sb, "failFast (Default: false)", 2 ); |
146 | 0 | append( sb, "Fail on the first rule that doesn\'t pass", 3 ); |
147 | 0 | append( sb, "Expression: ${enforcer.failFast}", 3 ); |
148 | 0 | append( sb, "", 0 ); |
149 | |
|
150 | 0 | append( sb, "ignoreCache (Default: false)", 2 ); |
151 | 0 | append( sb, "Use this flag to disable rule result caching. This will cause all rules to execute on each project even if the rule indicates it can safely be cached.", 3 ); |
152 | 0 | append( sb, "Expression: ${enforcer.ignoreCache}", 3 ); |
153 | 0 | append( sb, "", 0 ); |
154 | |
|
155 | 0 | append( sb, "rules", 2 ); |
156 | 0 | append( sb, "Array of objects that implement the EnforcerRule interface to execute.", 3 ); |
157 | 0 | append( sb, "Required: Yes", 3 ); |
158 | 0 | append( sb, "", 0 ); |
159 | |
|
160 | 0 | append( sb, "skip (Default: false)", 2 ); |
161 | 0 | append( sb, "Flag to easily skip all checks", 3 ); |
162 | 0 | append( sb, "Expression: ${enforcer.skip}", 3 ); |
163 | 0 | append( sb, "", 0 ); |
164 | |
} |
165 | |
} |
166 | |
|
167 | 0 | if ( goal == null || goal.length() <= 0 || "help".equals( goal ) ) |
168 | |
{ |
169 | 0 | append( sb, "enforcer:help", 0 ); |
170 | 0 | append( sb, "Display help information on maven-enforcer-plugin.\nCall\n\u00a0\u00a0mvn\u00a0enforcer:help\u00a0-Ddetail=true\u00a0-Dgoal=<goal-name>\nto display parameter details.", 1 ); |
171 | 0 | append( sb, "", 0 ); |
172 | 0 | if ( detail ) |
173 | |
{ |
174 | 0 | append( sb, "Available parameters:", 1 ); |
175 | 0 | append( sb, "", 0 ); |
176 | |
|
177 | 0 | append( sb, "detail (Default: false)", 2 ); |
178 | 0 | append( sb, "If true, display all settable properties for each goal.", 3 ); |
179 | 0 | append( sb, "Expression: ${detail}", 3 ); |
180 | 0 | append( sb, "", 0 ); |
181 | |
|
182 | 0 | append( sb, "goal", 2 ); |
183 | 0 | append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 3 ); |
184 | 0 | append( sb, "Expression: ${goal}", 3 ); |
185 | 0 | append( sb, "", 0 ); |
186 | |
|
187 | 0 | append( sb, "indentSize (Default: 2)", 2 ); |
188 | 0 | append( sb, "The number of spaces per indentation level, should be positive.", 3 ); |
189 | 0 | append( sb, "Expression: ${indentSize}", 3 ); |
190 | 0 | append( sb, "", 0 ); |
191 | |
|
192 | 0 | append( sb, "lineLength (Default: 80)", 2 ); |
193 | 0 | append( sb, "The maximum length of a display line, should be positive.", 3 ); |
194 | 0 | append( sb, "Expression: ${lineLength}", 3 ); |
195 | 0 | append( sb, "", 0 ); |
196 | |
} |
197 | |
} |
198 | |
|
199 | 0 | if ( getLog().isInfoEnabled() ) |
200 | |
{ |
201 | 0 | getLog().info( sb.toString() ); |
202 | |
} |
203 | 0 | } |
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
private static String repeat( String str, int repeat ) |
215 | |
{ |
216 | 0 | StringBuffer buffer = new StringBuffer( repeat * str.length() ); |
217 | |
|
218 | 0 | for ( int i = 0; i < repeat; i++ ) |
219 | |
{ |
220 | 0 | buffer.append( str ); |
221 | |
} |
222 | |
|
223 | 0 | return buffer.toString(); |
224 | |
} |
225 | |
|
226 | |
|
227 | |
|
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
private void append( StringBuffer sb, String description, int indent ) |
235 | |
{ |
236 | 0 | for ( Iterator it = toLines( description, indent, indentSize, lineLength ).iterator(); it.hasNext(); ) |
237 | |
{ |
238 | 0 | sb.append( it.next().toString() ).append( '\n' ); |
239 | |
} |
240 | 0 | } |
241 | |
|
242 | |
|
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
|
250 | |
|
251 | |
|
252 | |
private static List toLines( String text, int indent, int indentSize, int lineLength ) |
253 | |
{ |
254 | 0 | List lines = new ArrayList(); |
255 | |
|
256 | 0 | String ind = repeat( "\t", indent ); |
257 | 0 | String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" ); |
258 | 0 | for ( int i = 0; i < plainLines.length; i++ ) |
259 | |
{ |
260 | 0 | toLines( lines, ind + plainLines[i], indentSize, lineLength ); |
261 | |
} |
262 | |
|
263 | 0 | return lines; |
264 | |
} |
265 | |
|
266 | |
|
267 | |
|
268 | |
|
269 | |
|
270 | |
|
271 | |
|
272 | |
|
273 | |
|
274 | |
private static void toLines( List lines, String line, int indentSize, int lineLength ) |
275 | |
{ |
276 | 0 | int lineIndent = getIndentLevel( line ); |
277 | 0 | StringBuffer buf = new StringBuffer( 256 ); |
278 | 0 | String[] tokens = line.split( " +" ); |
279 | 0 | for ( int i = 0; i < tokens.length; i++ ) |
280 | |
{ |
281 | 0 | String token = tokens[i]; |
282 | 0 | if ( i > 0 ) |
283 | |
{ |
284 | 0 | if ( buf.length() + token.length() >= lineLength ) |
285 | |
{ |
286 | 0 | lines.add( buf.toString() ); |
287 | 0 | buf.setLength( 0 ); |
288 | 0 | buf.append( repeat( " ", lineIndent * indentSize ) ); |
289 | |
} |
290 | |
else |
291 | |
{ |
292 | 0 | buf.append( ' ' ); |
293 | |
} |
294 | |
} |
295 | 0 | for ( int j = 0; j < token.length(); j++ ) |
296 | |
{ |
297 | 0 | char c = token.charAt( j ); |
298 | 0 | if ( c == '\t' ) |
299 | |
{ |
300 | 0 | buf.append( repeat( " ", indentSize - buf.length() % indentSize ) ); |
301 | |
} |
302 | 0 | else if ( c == '\u00A0' ) |
303 | |
{ |
304 | 0 | buf.append( ' ' ); |
305 | |
} |
306 | |
else |
307 | |
{ |
308 | 0 | buf.append( c ); |
309 | |
} |
310 | |
} |
311 | |
} |
312 | 0 | lines.add( buf.toString() ); |
313 | 0 | } |
314 | |
|
315 | |
|
316 | |
|
317 | |
|
318 | |
|
319 | |
|
320 | |
|
321 | |
private static int getIndentLevel( String line ) |
322 | |
{ |
323 | 0 | int level = 0; |
324 | 0 | for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ ) |
325 | |
{ |
326 | 0 | level++; |
327 | |
} |
328 | 0 | for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ ) |
329 | |
{ |
330 | 0 | if ( line.charAt( i ) == '\t' ) |
331 | |
{ |
332 | 0 | level++; |
333 | 0 | break; |
334 | |
} |
335 | |
} |
336 | 0 | return level; |
337 | |
} |
338 | |
} |