1 | |
package org.apache.maven.plugins.surefire.report; |
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 | |
@SuppressWarnings( "all" ) |
20 | 0 | public class HelpMojo |
21 | |
extends AbstractMojo |
22 | |
{ |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
private boolean detail; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
private java.lang.String goal; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
private int lineLength; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
private int indentSize; |
50 | |
|
51 | |
|
52 | |
|
53 | |
public void execute() |
54 | |
throws MojoExecutionException |
55 | |
{ |
56 | 0 | if ( lineLength <= 0 ) |
57 | |
{ |
58 | 0 | getLog().warn( "The parameter 'lineLength' should be positive, using '80' as default." ); |
59 | 0 | lineLength = 80; |
60 | |
} |
61 | 0 | if ( indentSize <= 0 ) |
62 | |
{ |
63 | 0 | getLog().warn( "The parameter 'indentSize' should be positive, using '2' as default." ); |
64 | 0 | indentSize = 2; |
65 | |
} |
66 | |
|
67 | 0 | StringBuffer sb = new StringBuffer(); |
68 | |
|
69 | 0 | append( sb, "org.apache.maven.plugins:maven-surefire-report-plugin:2.14.1", 0 ); |
70 | 0 | append( sb, "", 0 ); |
71 | |
|
72 | 0 | append( sb, "Maven Surefire Report Plugin", 0 ); |
73 | 0 | append( sb, "Surefire is a test framework project.", 1 ); |
74 | 0 | append( sb, "", 0 ); |
75 | |
|
76 | 0 | if ( goal == null || goal.length() <= 0 ) |
77 | |
{ |
78 | 0 | append( sb, "This plugin has 4 goals:", 0 ); |
79 | 0 | append( sb, "", 0 ); |
80 | |
} |
81 | |
|
82 | 0 | if ( goal == null || goal.length() <= 0 || "failsafe-report-only".equals( goal ) ) |
83 | |
{ |
84 | 0 | append( sb, "surefire-report:failsafe-report-only", 0 ); |
85 | 0 | append( sb, "Creates a nicely formatted Failsafe Test Report in html format. This goal does not run the tests, it only builds the reports. See http://jira.codehaus.org/browse/SUREFIRE-257", 1 ); |
86 | 0 | append( sb, "", 0 ); |
87 | 0 | if ( detail ) |
88 | |
{ |
89 | 0 | append( sb, "Available parameters:", 1 ); |
90 | 0 | append( sb, "", 0 ); |
91 | |
|
92 | 0 | append( sb, "aggregate (Default: false)", 2 ); |
93 | 0 | append( sb, "Whether to build an aggregated report at the root, or build individual reports.", 3 ); |
94 | 0 | append( sb, "Expression: ${aggregate}", 3 ); |
95 | 0 | append( sb, "", 0 ); |
96 | |
|
97 | 0 | append( sb, "alwaysGenerateFailsafeReport (Default: false)", 2 ); |
98 | 0 | append( sb, "If set to true the failsafe report will be generated even when there are no failsafe result files. Defaults to false to preserve legacy behaviour pre 2.10", 3 ); |
99 | 0 | append( sb, "Expression: ${alwaysGenerateFailsafeReport}", 3 ); |
100 | 0 | append( sb, "", 0 ); |
101 | |
|
102 | 0 | append( sb, "linkXRef (Default: true)", 2 ); |
103 | 0 | append( sb, "Whether to link the XRef if found.", 3 ); |
104 | 0 | append( sb, "Expression: ${linkXRef}", 3 ); |
105 | 0 | append( sb, "", 0 ); |
106 | |
|
107 | 0 | append( sb, "outputDirectory", 2 ); |
108 | 0 | append( sb, "Location where generated html will be created.", 3 ); |
109 | 0 | append( sb, "Expression: ${project.reporting.outputDirectory}", 3 ); |
110 | 0 | append( sb, "", 0 ); |
111 | |
|
112 | 0 | append( sb, "outputName (Default: failsafe-report)", 2 ); |
113 | 0 | append( sb, "The filename to use for the report.", 3 ); |
114 | 0 | append( sb, "Required: Yes", 3 ); |
115 | 0 | append( sb, "Expression: ${outputName}", 3 ); |
116 | 0 | append( sb, "", 0 ); |
117 | |
|
118 | 0 | append( sb, "project", 2 ); |
119 | 0 | append( sb, "Maven Project", 3 ); |
120 | 0 | append( sb, "Required: Yes", 3 ); |
121 | 0 | append( sb, "Expression: ${project}", 3 ); |
122 | 0 | append( sb, "", 0 ); |
123 | |
|
124 | 0 | append( sb, "reportsDirectories", 2 ); |
125 | 0 | append( sb, "Directories containing the XML Report files that will be parsed and rendered to HTML format.", 3 ); |
126 | 0 | append( sb, "", 0 ); |
127 | |
|
128 | 0 | append( sb, "reportsDirectory", 2 ); |
129 | 0 | append( sb, "(Deprecated, use reportsDirectories) This directory contains the XML Report files that will be parsed and rendered to HTML format.", 3 ); |
130 | 0 | append( sb, "", 0 ); |
131 | |
|
132 | 0 | append( sb, "showSuccess (Default: true)", 2 ); |
133 | 0 | append( sb, "If set to false, only failures are shown.", 3 ); |
134 | 0 | append( sb, "Required: Yes", 3 ); |
135 | 0 | append( sb, "Expression: ${showSuccess}", 3 ); |
136 | 0 | append( sb, "", 0 ); |
137 | |
|
138 | 0 | append( sb, "skipFailsafeReport (Default: false)", 2 ); |
139 | 0 | append( sb, "If set to true the failsafe report generation will be skipped.", 3 ); |
140 | 0 | append( sb, "Expression: ${skipFailsafeReport}", 3 ); |
141 | 0 | append( sb, "", 0 ); |
142 | |
|
143 | 0 | append( sb, "xrefLocation (Default: ${project.reporting.outputDirectory}/xref-test)", 2 ); |
144 | 0 | append( sb, "Location of the Xrefs to link.", 3 ); |
145 | 0 | append( sb, "", 0 ); |
146 | |
} |
147 | |
} |
148 | |
|
149 | 0 | if ( goal == null || goal.length() <= 0 || "help".equals( goal ) ) |
150 | |
{ |
151 | 0 | append( sb, "surefire-report:help", 0 ); |
152 | 0 | append( sb, "Display help information on maven-surefire-report-plugin.\nCall\n\u00a0\u00a0mvn\u00a0surefire-report:help\u00a0-Ddetail=true\u00a0-Dgoal=<goal-name>\nto display parameter details.", 1 ); |
153 | 0 | append( sb, "", 0 ); |
154 | 0 | if ( detail ) |
155 | |
{ |
156 | 0 | append( sb, "Available parameters:", 1 ); |
157 | 0 | append( sb, "", 0 ); |
158 | |
|
159 | 0 | append( sb, "detail (Default: false)", 2 ); |
160 | 0 | append( sb, "If true, display all settable properties for each goal.", 3 ); |
161 | 0 | append( sb, "Expression: ${detail}", 3 ); |
162 | 0 | append( sb, "", 0 ); |
163 | |
|
164 | 0 | append( sb, "goal", 2 ); |
165 | 0 | append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 3 ); |
166 | 0 | append( sb, "Expression: ${goal}", 3 ); |
167 | 0 | append( sb, "", 0 ); |
168 | |
|
169 | 0 | append( sb, "indentSize (Default: 2)", 2 ); |
170 | 0 | append( sb, "The number of spaces per indentation level, should be positive.", 3 ); |
171 | 0 | append( sb, "Expression: ${indentSize}", 3 ); |
172 | 0 | append( sb, "", 0 ); |
173 | |
|
174 | 0 | append( sb, "lineLength (Default: 80)", 2 ); |
175 | 0 | append( sb, "The maximum length of a display line, should be positive.", 3 ); |
176 | 0 | append( sb, "Expression: ${lineLength}", 3 ); |
177 | 0 | append( sb, "", 0 ); |
178 | |
} |
179 | |
} |
180 | |
|
181 | 0 | if ( goal == null || goal.length() <= 0 || "report".equals( goal ) ) |
182 | |
{ |
183 | 0 | append( sb, "surefire-report:report", 0 ); |
184 | 0 | append( sb, "Creates a nicely formatted Surefire Test Report in html format.", 1 ); |
185 | 0 | append( sb, "", 0 ); |
186 | 0 | if ( detail ) |
187 | |
{ |
188 | 0 | append( sb, "Available parameters:", 1 ); |
189 | 0 | append( sb, "", 0 ); |
190 | |
|
191 | 0 | append( sb, "aggregate (Default: false)", 2 ); |
192 | 0 | append( sb, "Whether to build an aggregated report at the root, or build individual reports.", 3 ); |
193 | 0 | append( sb, "Expression: ${aggregate}", 3 ); |
194 | 0 | append( sb, "", 0 ); |
195 | |
|
196 | 0 | append( sb, "alwaysGenerateSurefireReport (Default: true)", 2 ); |
197 | 0 | append( sb, "If set to true the surefire report will be generated even when there are no surefire result files. Defaulyts to true to preserve legacy behaviour pre 2.10.", 3 ); |
198 | 0 | append( sb, "Expression: ${alwaysGenerateSurefireReport}", 3 ); |
199 | 0 | append( sb, "", 0 ); |
200 | |
|
201 | 0 | append( sb, "linkXRef (Default: true)", 2 ); |
202 | 0 | append( sb, "Whether to link the XRef if found.", 3 ); |
203 | 0 | append( sb, "Expression: ${linkXRef}", 3 ); |
204 | 0 | append( sb, "", 0 ); |
205 | |
|
206 | 0 | append( sb, "outputDirectory", 2 ); |
207 | 0 | append( sb, "Location where generated html will be created.", 3 ); |
208 | 0 | append( sb, "Expression: ${project.reporting.outputDirectory}", 3 ); |
209 | 0 | append( sb, "", 0 ); |
210 | |
|
211 | 0 | append( sb, "outputName (Default: surefire-report)", 2 ); |
212 | 0 | append( sb, "The filename to use for the report.", 3 ); |
213 | 0 | append( sb, "Required: Yes", 3 ); |
214 | 0 | append( sb, "Expression: ${outputName}", 3 ); |
215 | 0 | append( sb, "", 0 ); |
216 | |
|
217 | 0 | append( sb, "project", 2 ); |
218 | 0 | append( sb, "Maven Project", 3 ); |
219 | 0 | append( sb, "Required: Yes", 3 ); |
220 | 0 | append( sb, "Expression: ${project}", 3 ); |
221 | 0 | append( sb, "", 0 ); |
222 | |
|
223 | 0 | append( sb, "reportsDirectories", 2 ); |
224 | 0 | append( sb, "Directories containing the XML Report files that will be parsed and rendered to HTML format.", 3 ); |
225 | 0 | append( sb, "", 0 ); |
226 | |
|
227 | 0 | append( sb, "reportsDirectory", 2 ); |
228 | 0 | append( sb, "(Deprecated, use reportsDirectories) This directory contains the XML Report files that will be parsed and rendered to HTML format.", 3 ); |
229 | 0 | append( sb, "", 0 ); |
230 | |
|
231 | 0 | append( sb, "showSuccess (Default: true)", 2 ); |
232 | 0 | append( sb, "If set to false, only failures are shown.", 3 ); |
233 | 0 | append( sb, "Required: Yes", 3 ); |
234 | 0 | append( sb, "Expression: ${showSuccess}", 3 ); |
235 | 0 | append( sb, "", 0 ); |
236 | |
|
237 | 0 | append( sb, "skipSurefireReport (Default: false)", 2 ); |
238 | 0 | append( sb, "If set to true the surefire report generation will be skipped.", 3 ); |
239 | 0 | append( sb, "Expression: ${skipSurefireReport}", 3 ); |
240 | 0 | append( sb, "", 0 ); |
241 | |
|
242 | 0 | append( sb, "xrefLocation (Default: ${project.reporting.outputDirectory}/xref-test)", 2 ); |
243 | 0 | append( sb, "Location of the Xrefs to link.", 3 ); |
244 | 0 | append( sb, "", 0 ); |
245 | |
} |
246 | |
} |
247 | |
|
248 | 0 | if ( goal == null || goal.length() <= 0 || "report-only".equals( goal ) ) |
249 | |
{ |
250 | 0 | append( sb, "surefire-report:report-only", 0 ); |
251 | 0 | append( sb, "Creates a nicely formatted Surefire Test Report in html format. This goal does not run the tests, it only builds the reports. This is a workaround for http://jira.codehaus.org/browse/SUREFIRE-257", 1 ); |
252 | 0 | append( sb, "", 0 ); |
253 | 0 | if ( detail ) |
254 | |
{ |
255 | 0 | append( sb, "Available parameters:", 1 ); |
256 | 0 | append( sb, "", 0 ); |
257 | |
|
258 | 0 | append( sb, "aggregate (Default: false)", 2 ); |
259 | 0 | append( sb, "Whether to build an aggregated report at the root, or build individual reports.", 3 ); |
260 | 0 | append( sb, "Expression: ${aggregate}", 3 ); |
261 | 0 | append( sb, "", 0 ); |
262 | |
|
263 | 0 | append( sb, "alwaysGenerateSurefireReport (Default: true)", 2 ); |
264 | 0 | append( sb, "If set to true the surefire report will be generated even when there are no surefire result files. Defaulyts to true to preserve legacy behaviour pre 2.10.", 3 ); |
265 | 0 | append( sb, "Expression: ${alwaysGenerateSurefireReport}", 3 ); |
266 | 0 | append( sb, "", 0 ); |
267 | |
|
268 | 0 | append( sb, "linkXRef (Default: true)", 2 ); |
269 | 0 | append( sb, "Whether to link the XRef if found.", 3 ); |
270 | 0 | append( sb, "Expression: ${linkXRef}", 3 ); |
271 | 0 | append( sb, "", 0 ); |
272 | |
|
273 | 0 | append( sb, "outputDirectory", 2 ); |
274 | 0 | append( sb, "Location where generated html will be created.", 3 ); |
275 | 0 | append( sb, "Expression: ${project.reporting.outputDirectory}", 3 ); |
276 | 0 | append( sb, "", 0 ); |
277 | |
|
278 | 0 | append( sb, "outputName (Default: surefire-report)", 2 ); |
279 | 0 | append( sb, "The filename to use for the report.", 3 ); |
280 | 0 | append( sb, "Required: Yes", 3 ); |
281 | 0 | append( sb, "Expression: ${outputName}", 3 ); |
282 | 0 | append( sb, "", 0 ); |
283 | |
|
284 | 0 | append( sb, "project", 2 ); |
285 | 0 | append( sb, "Maven Project", 3 ); |
286 | 0 | append( sb, "Required: Yes", 3 ); |
287 | 0 | append( sb, "Expression: ${project}", 3 ); |
288 | 0 | append( sb, "", 0 ); |
289 | |
|
290 | 0 | append( sb, "reportsDirectories", 2 ); |
291 | 0 | append( sb, "Directories containing the XML Report files that will be parsed and rendered to HTML format.", 3 ); |
292 | 0 | append( sb, "", 0 ); |
293 | |
|
294 | 0 | append( sb, "reportsDirectory", 2 ); |
295 | 0 | append( sb, "(Deprecated, use reportsDirectories) This directory contains the XML Report files that will be parsed and rendered to HTML format.", 3 ); |
296 | 0 | append( sb, "", 0 ); |
297 | |
|
298 | 0 | append( sb, "showSuccess (Default: true)", 2 ); |
299 | 0 | append( sb, "If set to false, only failures are shown.", 3 ); |
300 | 0 | append( sb, "Required: Yes", 3 ); |
301 | 0 | append( sb, "Expression: ${showSuccess}", 3 ); |
302 | 0 | append( sb, "", 0 ); |
303 | |
|
304 | 0 | append( sb, "skipSurefireReport (Default: false)", 2 ); |
305 | 0 | append( sb, "If set to true the surefire report generation will be skipped.", 3 ); |
306 | 0 | append( sb, "Expression: ${skipSurefireReport}", 3 ); |
307 | 0 | append( sb, "", 0 ); |
308 | |
|
309 | 0 | append( sb, "xrefLocation (Default: ${project.reporting.outputDirectory}/xref-test)", 2 ); |
310 | 0 | append( sb, "Location of the Xrefs to link.", 3 ); |
311 | 0 | append( sb, "", 0 ); |
312 | |
} |
313 | |
} |
314 | |
|
315 | 0 | if ( getLog().isInfoEnabled() ) |
316 | |
{ |
317 | 0 | getLog().info( sb.toString() ); |
318 | |
} |
319 | 0 | } |
320 | |
|
321 | |
|
322 | |
|
323 | |
|
324 | |
|
325 | |
|
326 | |
|
327 | |
|
328 | |
|
329 | |
|
330 | |
private static String repeat( String str, int repeat ) |
331 | |
{ |
332 | 0 | StringBuffer buffer = new StringBuffer( repeat * str.length() ); |
333 | |
|
334 | 0 | for ( int i = 0; i < repeat; i++ ) |
335 | |
{ |
336 | 0 | buffer.append( str ); |
337 | |
} |
338 | |
|
339 | 0 | return buffer.toString(); |
340 | |
} |
341 | |
|
342 | |
|
343 | |
|
344 | |
|
345 | |
|
346 | |
|
347 | |
|
348 | |
|
349 | |
|
350 | |
private void append( StringBuffer sb, String description, int indent ) |
351 | |
{ |
352 | 0 | for ( Iterator it = toLines( description, indent, indentSize, lineLength ).iterator(); it.hasNext(); ) |
353 | |
{ |
354 | 0 | sb.append( it.next().toString() ).append( '\n' ); |
355 | |
} |
356 | 0 | } |
357 | |
|
358 | |
|
359 | |
|
360 | |
|
361 | |
|
362 | |
|
363 | |
|
364 | |
|
365 | |
|
366 | |
|
367 | |
|
368 | |
private static List toLines( String text, int indent, int indentSize, int lineLength ) |
369 | |
{ |
370 | 0 | List<String> lines = new ArrayList<String>(); |
371 | |
|
372 | 0 | String ind = repeat( "\t", indent ); |
373 | 0 | String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" ); |
374 | 0 | for ( int i = 0; i < plainLines.length; i++ ) |
375 | |
{ |
376 | 0 | toLines( lines, ind + plainLines[i], indentSize, lineLength ); |
377 | |
} |
378 | |
|
379 | 0 | return lines; |
380 | |
} |
381 | |
|
382 | |
|
383 | |
|
384 | |
|
385 | |
|
386 | |
|
387 | |
|
388 | |
|
389 | |
|
390 | |
private static void toLines( List<String> lines, String line, int indentSize, int lineLength ) |
391 | |
{ |
392 | 0 | int lineIndent = getIndentLevel( line ); |
393 | 0 | StringBuffer buf = new StringBuffer( 256 ); |
394 | 0 | String[] tokens = line.split( " +" ); |
395 | 0 | for ( int i = 0; i < tokens.length; i++ ) |
396 | |
{ |
397 | 0 | String token = tokens[i]; |
398 | 0 | if ( i > 0 ) |
399 | |
{ |
400 | 0 | if ( buf.length() + token.length() >= lineLength ) |
401 | |
{ |
402 | 0 | lines.add( buf.toString() ); |
403 | 0 | buf.setLength( 0 ); |
404 | 0 | buf.append( repeat( " ", lineIndent * indentSize ) ); |
405 | |
} |
406 | |
else |
407 | |
{ |
408 | 0 | buf.append( ' ' ); |
409 | |
} |
410 | |
} |
411 | 0 | for ( int j = 0; j < token.length(); j++ ) |
412 | |
{ |
413 | 0 | char c = token.charAt( j ); |
414 | 0 | if ( c == '\t' ) |
415 | |
{ |
416 | 0 | buf.append( repeat( " ", indentSize - buf.length() % indentSize ) ); |
417 | |
} |
418 | 0 | else if ( c == '\u00A0' ) |
419 | |
{ |
420 | 0 | buf.append( ' ' ); |
421 | |
} |
422 | |
else |
423 | |
{ |
424 | 0 | buf.append( c ); |
425 | |
} |
426 | |
} |
427 | |
} |
428 | 0 | lines.add( buf.toString() ); |
429 | 0 | } |
430 | |
|
431 | |
|
432 | |
|
433 | |
|
434 | |
|
435 | |
|
436 | |
|
437 | |
private static int getIndentLevel( String line ) |
438 | |
{ |
439 | 0 | int level = 0; |
440 | 0 | for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ ) |
441 | |
{ |
442 | 0 | level++; |
443 | |
} |
444 | 0 | for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ ) |
445 | |
{ |
446 | 0 | if ( line.charAt( i ) == '\t' ) |
447 | |
{ |
448 | 0 | level++; |
449 | 0 | break; |
450 | |
} |
451 | |
} |
452 | 0 | return level; |
453 | |
} |
454 | |
} |