1 package org.apache.maven.plugin.surefire;
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 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 if ( lineLength <= 0 )
56 {
57 getLog().warn( "The parameter 'lineLength' should be positive, using '80' as default." );
58 lineLength = 80;
59 }
60 if ( indentSize <= 0 )
61 {
62 getLog().warn( "The parameter 'indentSize' should be positive, using '2' as default." );
63 indentSize = 2;
64 }
65
66 StringBuffer sb = new StringBuffer();
67
68 append( sb, "org.apache.maven.plugins:maven-surefire-plugin:2.9", 0 );
69 append( sb, "", 0 );
70
71 append( sb, "Maven Surefire Plugin", 0 );
72 append( sb, "Surefire is a test framework project.", 1 );
73 append( sb, "", 0 );
74
75 if ( goal == null || goal.length() <= 0 )
76 {
77 append( sb, "This plugin has 2 goals:", 0 );
78 append( sb, "", 0 );
79 }
80
81 if ( goal == null || goal.length() <= 0 || "help".equals( goal ) )
82 {
83 append( sb, "surefire:help", 0 );
84 append( sb, "Display help information on maven-surefire-plugin.\nCall\n\u00a0\u00a0mvn\u00a0surefire:help\u00a0-Ddetail=true\u00a0-Dgoal=<goal-name>\nto display parameter details.", 1 );
85 append( sb, "", 0 );
86 if ( detail )
87 {
88 append( sb, "Available parameters:", 1 );
89 append( sb, "", 0 );
90
91 append( sb, "detail (Default: false)", 2 );
92 append( sb, "If true, display all settable properties for each goal.", 3 );
93 append( sb, "Expression: ${detail}", 3 );
94 append( sb, "", 0 );
95
96 append( sb, "goal", 2 );
97 append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 3 );
98 append( sb, "Expression: ${goal}", 3 );
99 append( sb, "", 0 );
100
101 append( sb, "indentSize (Default: 2)", 2 );
102 append( sb, "The number of spaces per indentation level, should be positive.", 3 );
103 append( sb, "Expression: ${indentSize}", 3 );
104 append( sb, "", 0 );
105
106 append( sb, "lineLength (Default: 80)", 2 );
107 append( sb, "The maximum length of a display line, should be positive.", 3 );
108 append( sb, "Expression: ${lineLength}", 3 );
109 append( sb, "", 0 );
110 }
111 }
112
113 if ( goal == null || goal.length() <= 0 || "test".equals( goal ) )
114 {
115 append( sb, "surefire:test", 0 );
116 append( sb, "Run tests using Surefire.", 1 );
117 append( sb, "", 0 );
118 if ( detail )
119 {
120 append( sb, "Available parameters:", 1 );
121 append( sb, "", 0 );
122
123 append( sb, "additionalClasspathElements", 2 );
124 append( sb, "Additional elements to be appended to the classpath.", 3 );
125 append( sb, "", 0 );
126
127 append( sb, "argLine", 2 );
128 append( sb, "Arbitrary JVM options to set on the command line.", 3 );
129 append( sb, "Expression: ${argLine}", 3 );
130 append( sb, "", 0 );
131
132 append( sb, "basedir (Default: ${basedir})", 2 );
133 append( sb, "The base directory of the project being tested. This can be obtained in your unit test via System.getProperty(\'basedir\').", 3 );
134 append( sb, "", 0 );
135
136 append( sb, "childDelegation (Default: false)", 2 );
137 append( sb, "When false it makes tests run using the standard classloader delegation instead of the default Maven isolated classloader. Only used when forking (forkMode is not \'none\').\nSetting it to false helps with some problems caused by conflicts between xml parsers in the classpath and the Java 5 provider parser.", 3 );
138 append( sb, "Expression: ${childDelegation}", 3 );
139 append( sb, "", 0 );
140
141 append( sb, "classesDirectory (Default: ${project.build.outputDirectory})", 2 );
142 append( sb, "The directory containing generated classes of the project being tested. This will be included after the test classes in the test classpath.", 3 );
143 append( sb, "", 0 );
144
145 append( sb, "classpathDependencyExcludes", 2 );
146 append( sb, "List of dependencies to exclude from the test classpath. Each dependency string must follow the format groupId:artifactId. For example: org.acme:project-a", 3 );
147 append( sb, "", 0 );
148
149 append( sb, "classpathDependencyScopeExclude", 2 );
150 append( sb, "A dependency scope to exclude from the test classpath. The scope can be one of the following scopes:\n-\tcompile - system, provided, compile\n-\truntime - compile, runtime\n-\ttest - system, provided, compile, runtime, test\n", 3 );
151 append( sb, "", 0 );
152
153 append( sb, "debugForkedProcess", 2 );
154 append( sb, "Attach a debugger to the forked JVM. If set to \'true\', the process will suspend and wait for a debugger to attach on port 5005. If set to some other string, that string will be appended to the argLine, allowing you to configure arbitrary debuggability options (without overwriting the other options specified through the argLine parameter).", 3 );
155 append( sb, "Expression: ${maven.surefire.debug}", 3 );
156 append( sb, "", 0 );
157
158 append( sb, "disableXmlReport (Default: false)", 2 );
159 append( sb, "Flag to disable the generation of report files in xml format.", 3 );
160 append( sb, "Expression: ${disableXmlReport}", 3 );
161 append( sb, "", 0 );
162
163 append( sb, "enableAssertions (Default: true)", 2 );
164 append( sb, "By default, Surefire enables JVM assertions for the execution of your test cases. To disable the assertions, set this flag to \'false\'.", 3 );
165 append( sb, "Expression: ${enableAssertions}", 3 );
166 append( sb, "", 0 );
167
168 append( sb, "environmentVariables", 2 );
169 append( sb, "Additional environment variables to set on the command line.", 3 );
170 append( sb, "", 0 );
171
172 append( sb, "excludedGroups", 2 );
173 append( sb, "(TestNG only) Excluded groups. Any methods/classes/etc with one of the groups specified in this list will specifically not be run.\nThis parameter is ignored if the suiteXmlFiles parameter is specified.", 3 );
174 append( sb, "Expression: ${excludedGroups}", 3 );
175 append( sb, "", 0 );
176
177 append( sb, "excludes", 2 );
178 append( sb, "A list of <exclude> elements specifying the tests (by pattern) that should be excluded in testing. When not specified and when the test parameter is not specified, the default excludes will be \n<excludes>\n\u00a0<exclude>**/*$*</exclude>\n</excludes>\n(which excludes all inner classes).\nThis parameter is ignored if the TestNG suiteXmlFiles parameter is specified.", 3 );
179 append( sb, "", 0 );
180
181 append( sb, "failIfNoTests", 2 );
182 append( sb, "Set this to \'true\' to cause a failure if there are no tests to run. Defaults to \'false\'.", 3 );
183 append( sb, "Expression: ${failIfNoTests}", 3 );
184 append( sb, "", 0 );
185
186 append( sb, "forkedProcessTimeoutInSeconds", 2 );
187 append( sb, "Kill the forked test process after a certain number of seconds. If set to 0, wait forever for the process, never timing out.", 3 );
188 append( sb, "Expression: ${surefire.timeout}", 3 );
189 append( sb, "", 0 );
190
191 append( sb, "forkMode (Default: once)", 2 );
192 append( sb, "Option to specify the forking mode. Can be \'never\', \'once\' or \'always\'. \'none\' and \'pertest\' are also accepted for backwards compatibility. \'always\' forks for each test-class.", 3 );
193 append( sb, "Expression: ${forkMode}", 3 );
194 append( sb, "", 0 );
195
196 append( sb, "groups", 2 );
197 append( sb, "(TestNG only) Groups for this test. Only classes/methods/etc decorated with one of the groups specified here will be included in test run, if specified.\nThis parameter is ignored if the suiteXmlFiles parameter is specified.", 3 );
198 append( sb, "Expression: ${groups}", 3 );
199 append( sb, "", 0 );
200
201 append( sb, "includes", 2 );
202 append( sb, "A list of <include> elements specifying the tests (by pattern) that should be included in testing. When not specified and when the test parameter is not specified, the default includes will be \n<includes>\n\u00a0<include>**/Test*.java</include>\n\u00a0<include>**/*Test.java</include>\n\u00a0<include>**/*TestCase.java</include>\n</includes>\nThis parameter is ignored if the TestNG suiteXmlFiles parameter is specified.", 3 );
203 append( sb, "", 0 );
204
205 append( sb, "junitArtifactName (Default: junit:junit)", 2 );
206 append( sb, "Allows you to specify the name of the JUnit artifact. If not set, junit:junit will be used.", 3 );
207 append( sb, "Expression: ${junitArtifactName}", 3 );
208 append( sb, "", 0 );
209
210 append( sb, "jvm", 2 );
211 append( sb, "Option to specify the jvm (or path to the java executable) to use with the forking options. For the default, the jvm will be a new instance of the same VM as the one used to run Maven. JVM settings are not inherited from MAVEN_OPTS.", 3 );
212 append( sb, "Expression: ${jvm}", 3 );
213 append( sb, "", 0 );
214
215 append( sb, "objectFactory", 2 );
216 append( sb, "(TestNG only) Define the factory class used to create all test instances.", 3 );
217 append( sb, "Expression: ${objectFactory}", 3 );
218 append( sb, "", 0 );
219
220 append( sb, "parallel", 2 );
221 append( sb, "(TestNG only) When you use the parallel attribute, TestNG will try to run all your test methods in separate threads, except for methods that depend on each other, which will be run in the same thread in order to respect their order of execution. (JUnit 4.7 provider) Supports values \'classes\'/\'methods\'/\'both\' to run in separate threads, as controlled by threadCount.", 3 );
222 append( sb, "Expression: ${parallel}", 3 );
223 append( sb, "", 0 );
224
225 append( sb, "perCoreThreadCount (Default: true)", 2 );
226 append( sb, "(JUnit 4.7 provider) Indicates that threadCount is per cpu core.", 3 );
227 append( sb, "Expression: ${perCoreThreadCount}", 3 );
228 append( sb, "", 0 );
229
230 append( sb, "printSummary (Default: true)", 2 );
231 append( sb, "Option to print summary of test suites or just print the test cases that have errors.", 3 );
232 append( sb, "Expression: ${surefire.printSummary}", 3 );
233 append( sb, "", 0 );
234
235 append( sb, "properties", 2 );
236 append( sb, "List of properties for configuring all TestNG related configurations. This is the new preferred method of configuring TestNG.", 3 );
237 append( sb, "", 0 );
238
239 append( sb, "redirectTestOutputToFile (Default: false)", 2 );
240 append( sb, "Set this to \'true\' to redirect the unit test standard output to a file (found in reportsDirectory/testName-output.txt).", 3 );
241 append( sb, "Expression: ${maven.test.redirectTestOutputToFile}", 3 );
242 append( sb, "", 0 );
243
244 append( sb, "remoteRepositories", 2 );
245 append( sb, "The remote plugin repositories declared in the POM.", 3 );
246 append( sb, "Expression: ${project.pluginArtifactRepositories}", 3 );
247 append( sb, "", 0 );
248
249 append( sb, "reportFormat (Default: brief)", 2 );
250 append( sb, "Selects the formatting for the test report to be generated. Can be set as \'brief\' or \'plain\'.", 3 );
251 append( sb, "Expression: ${surefire.reportFormat}", 3 );
252 append( sb, "", 0 );
253
254 append( sb, "reportsDirectory (Default: ${project.build.directory}/surefire-reports)", 2 );
255 append( sb, "Base directory where all reports are written to.", 3 );
256 append( sb, "", 0 );
257
258 append( sb, "runOrder (Default: filesystem)", 2 );
259 append( sb, "Defines the order the tests will be run in. Supported values are \'alphabetical\', \'reversealphabetical\', \'random\', \'hourly\' (alphabetical on even hours, reverse alphabetical on odd hours) and \'filesystem\'. Odd/Even for hourly is determined at the time the of scanning the classpath, meaning it could change during a multi-module build.", 3 );
260 append( sb, "", 0 );
261
262 append( sb, "skip (Default: false)", 2 );
263 append( sb, "Set this to \'true\' to bypass unit tests entirely. Its use is NOT RECOMMENDED, especially if you enable it using the \'maven.test.skip\' property, because maven.test.skip disables both running the tests and compiling the tests. Consider using the skipTests parameter instead.", 3 );
264 append( sb, "Expression: ${maven.test.skip}", 3 );
265 append( sb, "", 0 );
266
267 append( sb, "skipExec", 2 );
268 append( sb, "Deprecated. Use skipTests instead.", 3 );
269 append( sb, "", 0 );
270 append( sb, "This old parameter is just like skipTests, but bound to the old property \'maven.test.skip.exec\'.", 3 );
271 append( sb, "Expression: ${maven.test.skip.exec}", 3 );
272 append( sb, "", 0 );
273
274 append( sb, "skipTests (Default: false)", 2 );
275 append( sb, "Set this to \'true\' to skip running tests, but still compile them. Its use is NOT RECOMMENDED, but quite convenient on occasion.", 3 );
276 append( sb, "Expression: ${skipTests}", 3 );
277 append( sb, "", 0 );
278
279 append( sb, "suiteXmlFiles", 2 );
280 append( sb, "(TestNG only) List of <suiteXmlFile> elements specifying TestNG suite xml file locations. Note that suiteXmlFiles is incompatible with several other parameters of this plugin, like includes/excludes.\nThis parameter is ignored if the test parameter is specified (allowing you to run a single test instead of an entire suite).", 3 );
281 append( sb, "", 0 );
282
283 append( sb, "systemProperties", 2 );
284 append( sb, "Deprecated. Use systemPropertyVariables instead.", 3 );
285 append( sb, "", 0 );
286 append( sb, "List of System properties to pass to the JUnit tests.", 3 );
287 append( sb, "", 0 );
288
289 append( sb, "systemPropertiesFile", 2 );
290 append( sb, "List of System properties, loaded from a file, to pass to the JUnit tests.", 3 );
291 append( sb, "", 0 );
292
293 append( sb, "systemPropertyVariables", 2 );
294 append( sb, "List of System properties to pass to the JUnit tests.", 3 );
295 append( sb, "", 0 );
296
297 append( sb, "test", 2 );
298 append( sb, "Specify this parameter to run individual tests by file name, overriding the includes/excludes parameters. Each pattern you specify here will be used to create an include pattern formatted like **/${test}.java, so you can just type \'-Dtest=MyTest\' to run a single test called \'foo/MyTest.java\'.\nThis parameter overrides the includes/excludes parameters, and the TestNG suiteXmlFiles parameter. since 2.7.3 You can execute a limited number of method in the test with adding #myMethod or #my*ethod. Si type \'-Dtest=MyTest#myMethod\' supported for junit 4.x and testNg", 3 );
299 append( sb, "Expression: ${test}", 3 );
300 append( sb, "", 0 );
301
302 append( sb, "testClassesDirectory (Default: ${project.build.testOutputDirectory})", 2 );
303 append( sb, "The directory containing generated test classes of the project being tested. This will be included at the beginning of the test classpath. *", 3 );
304 append( sb, "", 0 );
305
306 append( sb, "testFailureIgnore (Default: false)", 2 );
307 append( sb, "Set this to \'true\' to ignore a failure during testing. Its use is NOT RECOMMENDED, but quite convenient on occasion.", 3 );
308 append( sb, "Expression: ${maven.test.failure.ignore}", 3 );
309 append( sb, "", 0 );
310
311 append( sb, "testNGArtifactName (Default: org.testng:testng)", 2 );
312 append( sb, "Allows you to specify the name of the TestNG artifact. If not set, org.testng:testng will be used.", 3 );
313 append( sb, "Expression: ${testNGArtifactName}", 3 );
314 append( sb, "", 0 );
315
316 append( sb, "testSourceDirectory (Default: ${project.build.testSourceDirectory})", 2 );
317 append( sb, "The test source directory containing test class sources.", 3 );
318 append( sb, "Required: Yes", 3 );
319 append( sb, "", 0 );
320
321 append( sb, "threadCount", 2 );
322 append( sb, "(TestNG/JUnit 4.7 provider only) The attribute thread-count allows you to specify how many threads should be allocated for this execution. Only makes sense to use in conjunction with the parallel parameter.", 3 );
323 append( sb, "Expression: ${threadCount}", 3 );
324 append( sb, "", 0 );
325
326 append( sb, "trimStackTrace (Default: true)", 2 );
327 append( sb, "Whether to trim the stack trace in the reports to just the lines within the test, or show the full trace.", 3 );
328 append( sb, "Expression: ${trimStackTrace}", 3 );
329 append( sb, "", 0 );
330
331 append( sb, "useFile (Default: true)", 2 );
332 append( sb, "Option to generate a file test report or just output the test report to the console.", 3 );
333 append( sb, "Expression: ${surefire.useFile}", 3 );
334 append( sb, "", 0 );
335
336 append( sb, "useManifestOnlyJar (Default: true)", 2 );
337 append( sb, "By default, Surefire forks your tests using a manifest-only JAR; set this parameter to \'false\' to force it to launch your tests with a plain old Java classpath. (See http://maven.apache.org/plugins/maven-surefire-plugin/examples/class-loading.html for a more detailed explanation of manifest-only JARs and their benefits.) Beware, setting this to \'false\' may cause your tests to fail on Windows if your classpath is too long.", 3 );
338 append( sb, "Expression: ${surefire.useManifestOnlyJar}", 3 );
339 append( sb, "", 0 );
340
341 append( sb, "useSystemClassLoader (Default: true)", 2 );
342 append( sb, "Option to pass dependencies to the system\'s classloader instead of using an isolated class loader when forking. Prevents problems with JDKs which implement the service provider lookup mechanism by using the system\'s classloader.", 3 );
343 append( sb, "Expression: ${surefire.useSystemClassLoader}", 3 );
344 append( sb, "", 0 );
345
346 append( sb, "useUnlimitedThreads (Default: false)", 2 );
347 append( sb, "(JUnit 4.7 provider) Indicates that the thread pool will be unlimited. The parallel parameter and the actual number of classes/methods will decide. Setting this to \'true\' effectively disables perCoreThreadCount and threadCount. Defaults to \'false\'.", 3 );
348 append( sb, "Expression: ${useUnlimitedThreads}", 3 );
349 append( sb, "", 0 );
350
351 append( sb, "workingDirectory", 2 );
352 append( sb, "Command line working directory.", 3 );
353 append( sb, "Expression: ${basedir}", 3 );
354 append( sb, "", 0 );
355 }
356 }
357
358 if ( getLog().isInfoEnabled() )
359 {
360 getLog().info( sb.toString() );
361 }
362 }
363
364
365
366
367
368
369
370
371
372
373 private static String repeat( String str, int repeat )
374 {
375 StringBuffer buffer = new StringBuffer( repeat * str.length() );
376
377 for ( int i = 0; i < repeat; i++ )
378 {
379 buffer.append( str );
380 }
381
382 return buffer.toString();
383 }
384
385
386
387
388
389
390
391
392
393 private void append( StringBuffer sb, String description, int indent )
394 {
395 for ( Iterator it = toLines( description, indent, indentSize, lineLength ).iterator(); it.hasNext(); )
396 {
397 sb.append( it.next().toString() ).append( '\n' );
398 }
399 }
400
401
402
403
404
405
406
407
408
409
410
411 private static List toLines( String text, int indent, int indentSize, int lineLength )
412 {
413 List lines = new ArrayList();
414
415 String ind = repeat( "\t", indent );
416 String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" );
417 for ( int i = 0; i < plainLines.length; i++ )
418 {
419 toLines( lines, ind + plainLines[i], indentSize, lineLength );
420 }
421
422 return lines;
423 }
424
425
426
427
428
429
430
431
432
433 private static void toLines( List lines, String line, int indentSize, int lineLength )
434 {
435 int lineIndent = getIndentLevel( line );
436 StringBuffer buf = new StringBuffer( 256 );
437 String[] tokens = line.split( " +" );
438 for ( int i = 0; i < tokens.length; i++ )
439 {
440 String token = tokens[i];
441 if ( i > 0 )
442 {
443 if ( buf.length() + token.length() >= lineLength )
444 {
445 lines.add( buf.toString() );
446 buf.setLength( 0 );
447 buf.append( repeat( " ", lineIndent * indentSize ) );
448 }
449 else
450 {
451 buf.append( ' ' );
452 }
453 }
454 for ( int j = 0; j < token.length(); j++ )
455 {
456 char c = token.charAt( j );
457 if ( c == '\t' )
458 {
459 buf.append( repeat( " ", indentSize - buf.length() % indentSize ) );
460 }
461 else if ( c == '\u00A0' )
462 {
463 buf.append( ' ' );
464 }
465 else
466 {
467 buf.append( c );
468 }
469 }
470 }
471 lines.add( buf.toString() );
472 }
473
474
475
476
477
478
479
480 private static int getIndentLevel( String line )
481 {
482 int level = 0;
483 for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ )
484 {
485 level++;
486 }
487 for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ )
488 {
489 if ( line.charAt( i ) == '\t' )
490 {
491 level++;
492 break;
493 }
494 }
495 return level;
496 }
497 }