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 | 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-surefire-report-plugin:2.8", 0 ); |
69 | 0 | append( sb, "", 0 ); |
70 | |
|
71 | 0 | append( sb, "Maven Surefire Report Plugin", 0 ); |
72 | 0 | append( sb, "Surefire is a test framework project.", 1 ); |
73 | 0 | append( sb, "", 0 ); |
74 | |
|
75 | 0 | if ( goal == null || goal.length() <= 0 ) |
76 | |
{ |
77 | 0 | append( sb, "This plugin has 3 goals:", 0 ); |
78 | 0 | append( sb, "", 0 ); |
79 | |
} |
80 | |
|
81 | 0 | if ( goal == null || goal.length() <= 0 || "help".equals( goal ) ) |
82 | |
{ |
83 | 0 | append( sb, "surefire-report:help", 0 ); |
84 | 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 ); |
85 | 0 | append( sb, "", 0 ); |
86 | 0 | if ( detail ) |
87 | |
{ |
88 | 0 | append( sb, "Available parameters:", 1 ); |
89 | 0 | append( sb, "", 0 ); |
90 | |
|
91 | 0 | append( sb, "detail (Default: false)", 2 ); |
92 | 0 | append( sb, "If true, display all settable properties for each goal.", 3 ); |
93 | 0 | append( sb, "Expression: ${detail}", 3 ); |
94 | 0 | append( sb, "", 0 ); |
95 | |
|
96 | 0 | append( sb, "goal", 2 ); |
97 | 0 | append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 3 ); |
98 | 0 | append( sb, "Expression: ${goal}", 3 ); |
99 | 0 | append( sb, "", 0 ); |
100 | |
|
101 | 0 | append( sb, "indentSize (Default: 2)", 2 ); |
102 | 0 | append( sb, "The number of spaces per indentation level, should be positive.", 3 ); |
103 | 0 | append( sb, "Expression: ${indentSize}", 3 ); |
104 | 0 | append( sb, "", 0 ); |
105 | |
|
106 | 0 | append( sb, "lineLength (Default: 80)", 2 ); |
107 | 0 | append( sb, "The maximum length of a display line, should be positive.", 3 ); |
108 | 0 | append( sb, "Expression: ${lineLength}", 3 ); |
109 | 0 | append( sb, "", 0 ); |
110 | |
} |
111 | |
} |
112 | |
|
113 | 0 | if ( goal == null || goal.length() <= 0 || "report".equals( goal ) ) |
114 | |
{ |
115 | 0 | append( sb, "surefire-report:report", 0 ); |
116 | 0 | append( sb, "Creates a nicely formatted Surefire Test Report in html format.", 1 ); |
117 | 0 | append( sb, "", 0 ); |
118 | 0 | if ( detail ) |
119 | |
{ |
120 | 0 | append( sb, "Available parameters:", 1 ); |
121 | 0 | append( sb, "", 0 ); |
122 | |
|
123 | 0 | append( sb, "aggregate (Default: false)", 2 ); |
124 | 0 | append( sb, "Whether to build an aggregated report at the root, or build individual reports.", 3 ); |
125 | 0 | append( sb, "Expression: ${aggregate}", 3 ); |
126 | 0 | append( sb, "", 0 ); |
127 | |
|
128 | 0 | append( sb, "linkXRef (Default: true)", 2 ); |
129 | 0 | append( sb, "Whether to link the XRef if found.", 3 ); |
130 | 0 | append( sb, "Expression: ${linkXRef}", 3 ); |
131 | 0 | append( sb, "", 0 ); |
132 | |
|
133 | 0 | append( sb, "outputDirectory", 2 ); |
134 | 0 | append( sb, "Location where generated html will be created.", 3 ); |
135 | 0 | append( sb, "Expression: ${project.reporting.outputDirectory}", 3 ); |
136 | 0 | append( sb, "", 0 ); |
137 | |
|
138 | 0 | append( sb, "outputName (Default: surefire-report)", 2 ); |
139 | 0 | append( sb, "The filename to use for the report.", 3 ); |
140 | 0 | append( sb, "Required: Yes", 3 ); |
141 | 0 | append( sb, "Expression: ${outputName}", 3 ); |
142 | 0 | append( sb, "", 0 ); |
143 | |
|
144 | 0 | append( sb, "project", 2 ); |
145 | 0 | append( sb, "Maven Project", 3 ); |
146 | 0 | append( sb, "Required: Yes", 3 ); |
147 | 0 | append( sb, "Expression: ${project}", 3 ); |
148 | 0 | append( sb, "", 0 ); |
149 | |
|
150 | 0 | append( sb, "reportsDirectories", 2 ); |
151 | 0 | append( sb, "Directories containing the XML Report files that will be parsed and rendered to HTML format.", 3 ); |
152 | 0 | append( sb, "", 0 ); |
153 | |
|
154 | 0 | append( sb, "reportsDirectory", 2 ); |
155 | 0 | append( sb, "(Deprecated, use reportsDirectories) This directory contains the XML Report files that will be parsed and rendered to HTML format.", 3 ); |
156 | 0 | append( sb, "", 0 ); |
157 | |
|
158 | 0 | append( sb, "showSuccess (Default: true)", 2 ); |
159 | 0 | append( sb, "If set to false, only failures are shown.", 3 ); |
160 | 0 | append( sb, "Required: Yes", 3 ); |
161 | 0 | append( sb, "Expression: ${showSuccess}", 3 ); |
162 | 0 | append( sb, "", 0 ); |
163 | |
|
164 | 0 | append( sb, "xrefLocation (Default: ${project.reporting.outputDirectory}/xref-test)", 2 ); |
165 | 0 | append( sb, "Location of the Xrefs to link.", 3 ); |
166 | 0 | append( sb, "", 0 ); |
167 | |
} |
168 | |
} |
169 | |
|
170 | 0 | if ( goal == null || goal.length() <= 0 || "report-only".equals( goal ) ) |
171 | |
{ |
172 | 0 | append( sb, "surefire-report:report-only", 0 ); |
173 | 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 ); |
174 | 0 | append( sb, "", 0 ); |
175 | 0 | if ( detail ) |
176 | |
{ |
177 | 0 | append( sb, "Available parameters:", 1 ); |
178 | 0 | append( sb, "", 0 ); |
179 | |
|
180 | 0 | append( sb, "aggregate (Default: false)", 2 ); |
181 | 0 | append( sb, "Whether to build an aggregated report at the root, or build individual reports.", 3 ); |
182 | 0 | append( sb, "Expression: ${aggregate}", 3 ); |
183 | 0 | append( sb, "", 0 ); |
184 | |
|
185 | 0 | append( sb, "linkXRef (Default: true)", 2 ); |
186 | 0 | append( sb, "Whether to link the XRef if found.", 3 ); |
187 | 0 | append( sb, "Expression: ${linkXRef}", 3 ); |
188 | 0 | append( sb, "", 0 ); |
189 | |
|
190 | 0 | append( sb, "outputDirectory", 2 ); |
191 | 0 | append( sb, "Location where generated html will be created.", 3 ); |
192 | 0 | append( sb, "Expression: ${project.reporting.outputDirectory}", 3 ); |
193 | 0 | append( sb, "", 0 ); |
194 | |
|
195 | 0 | append( sb, "outputName (Default: surefire-report)", 2 ); |
196 | 0 | append( sb, "The filename to use for the report.", 3 ); |
197 | 0 | append( sb, "Required: Yes", 3 ); |
198 | 0 | append( sb, "Expression: ${outputName}", 3 ); |
199 | 0 | append( sb, "", 0 ); |
200 | |
|
201 | 0 | append( sb, "project", 2 ); |
202 | 0 | append( sb, "Maven Project", 3 ); |
203 | 0 | append( sb, "Required: Yes", 3 ); |
204 | 0 | append( sb, "Expression: ${project}", 3 ); |
205 | 0 | append( sb, "", 0 ); |
206 | |
|
207 | 0 | append( sb, "reportsDirectories", 2 ); |
208 | 0 | append( sb, "Directories containing the XML Report files that will be parsed and rendered to HTML format.", 3 ); |
209 | 0 | append( sb, "", 0 ); |
210 | |
|
211 | 0 | append( sb, "reportsDirectory", 2 ); |
212 | 0 | append( sb, "(Deprecated, use reportsDirectories) This directory contains the XML Report files that will be parsed and rendered to HTML format.", 3 ); |
213 | 0 | append( sb, "", 0 ); |
214 | |
|
215 | 0 | append( sb, "showSuccess (Default: true)", 2 ); |
216 | 0 | append( sb, "If set to false, only failures are shown.", 3 ); |
217 | 0 | append( sb, "Required: Yes", 3 ); |
218 | 0 | append( sb, "Expression: ${showSuccess}", 3 ); |
219 | 0 | append( sb, "", 0 ); |
220 | |
|
221 | 0 | append( sb, "xrefLocation (Default: ${project.reporting.outputDirectory}/xref-test)", 2 ); |
222 | 0 | append( sb, "Location of the Xrefs to link.", 3 ); |
223 | 0 | append( sb, "", 0 ); |
224 | |
} |
225 | |
} |
226 | |
|
227 | 0 | if ( getLog().isInfoEnabled() ) |
228 | |
{ |
229 | 0 | getLog().info( sb.toString() ); |
230 | |
} |
231 | 0 | } |
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
private static String repeat( String str, int repeat ) |
243 | |
{ |
244 | 0 | StringBuffer buffer = new StringBuffer( repeat * str.length() ); |
245 | |
|
246 | 0 | for ( int i = 0; i < repeat; i++ ) |
247 | |
{ |
248 | 0 | buffer.append( str ); |
249 | |
} |
250 | |
|
251 | 0 | return buffer.toString(); |
252 | |
} |
253 | |
|
254 | |
|
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | |
|
260 | |
|
261 | |
|
262 | |
private void append( StringBuffer sb, String description, int indent ) |
263 | |
{ |
264 | 0 | for ( Iterator it = toLines( description, indent, indentSize, lineLength ).iterator(); it.hasNext(); ) |
265 | |
{ |
266 | 0 | sb.append( it.next().toString() ).append( '\n' ); |
267 | |
} |
268 | 0 | } |
269 | |
|
270 | |
|
271 | |
|
272 | |
|
273 | |
|
274 | |
|
275 | |
|
276 | |
|
277 | |
|
278 | |
|
279 | |
|
280 | |
private static List toLines( String text, int indent, int indentSize, int lineLength ) |
281 | |
{ |
282 | 0 | List lines = new ArrayList(); |
283 | |
|
284 | 0 | String ind = repeat( "\t", indent ); |
285 | 0 | String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" ); |
286 | 0 | for ( int i = 0; i < plainLines.length; i++ ) |
287 | |
{ |
288 | 0 | toLines( lines, ind + plainLines[i], indentSize, lineLength ); |
289 | |
} |
290 | |
|
291 | 0 | return lines; |
292 | |
} |
293 | |
|
294 | |
|
295 | |
|
296 | |
|
297 | |
|
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
private static void toLines( List lines, String line, int indentSize, int lineLength ) |
303 | |
{ |
304 | 0 | int lineIndent = getIndentLevel( line ); |
305 | 0 | StringBuffer buf = new StringBuffer( 256 ); |
306 | 0 | String[] tokens = line.split( " +" ); |
307 | 0 | for ( int i = 0; i < tokens.length; i++ ) |
308 | |
{ |
309 | 0 | String token = tokens[i]; |
310 | 0 | if ( i > 0 ) |
311 | |
{ |
312 | 0 | if ( buf.length() + token.length() >= lineLength ) |
313 | |
{ |
314 | 0 | lines.add( buf.toString() ); |
315 | 0 | buf.setLength( 0 ); |
316 | 0 | buf.append( repeat( " ", lineIndent * indentSize ) ); |
317 | |
} |
318 | |
else |
319 | |
{ |
320 | 0 | buf.append( ' ' ); |
321 | |
} |
322 | |
} |
323 | 0 | for ( int j = 0; j < token.length(); j++ ) |
324 | |
{ |
325 | 0 | char c = token.charAt( j ); |
326 | 0 | if ( c == '\t' ) |
327 | |
{ |
328 | 0 | buf.append( repeat( " ", indentSize - buf.length() % indentSize ) ); |
329 | |
} |
330 | 0 | else if ( c == '\u00A0' ) |
331 | |
{ |
332 | 0 | buf.append( ' ' ); |
333 | |
} |
334 | |
else |
335 | |
{ |
336 | 0 | buf.append( c ); |
337 | |
} |
338 | |
} |
339 | |
} |
340 | 0 | lines.add( buf.toString() ); |
341 | 0 | } |
342 | |
|
343 | |
|
344 | |
|
345 | |
|
346 | |
|
347 | |
|
348 | |
|
349 | |
private static int getIndentLevel( String line ) |
350 | |
{ |
351 | 0 | int level = 0; |
352 | 0 | for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ ) |
353 | |
{ |
354 | 0 | level++; |
355 | |
} |
356 | 0 | for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ ) |
357 | |
{ |
358 | 0 | if ( line.charAt( i ) == '\t' ) |
359 | |
{ |
360 | 0 | level++; |
361 | 0 | break; |
362 | |
} |
363 | |
} |
364 | 0 | return level; |
365 | |
} |
366 | |
} |