1 package de.akquinet.innovation.play.maven;
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, "de.akquinet.innovation.play2:play2-maven-plugin:1.2.1", 0 );
69 append( sb, "", 0 );
70
71 append( sb, "play2-maven-plugin", 0 );
72 append( sb, "A Maven Plugin to build Play2 Application", 1 );
73 append( sb, "", 0 );
74
75 if ( goal == null || goal.length() <= 0 )
76 {
77 append( sb, "This plugin has 9 goals:", 0 );
78 append( sb, "", 0 );
79 }
80
81 if ( goal == null || goal.length() <= 0 || "clean".equals( goal ) )
82 {
83 append( sb, "play2:clean", 0 );
84 append( sb, "Clean the project.", 1 );
85 append( sb, "", 0 );
86 if ( detail )
87 {
88 append( sb, "Available parameters:", 1 );
89 append( sb, "", 0 );
90
91 append( sb, "cleanLibFolder (Default: true)", 2 );
92 append( sb, "Set to false to avoid to clean the lib folder..", 3 );
93 append( sb, "", 0 );
94
95 append( sb, "lib (Default: lib)", 2 );
96 append( sb, "Where are the dependencies copied.", 3 );
97 append( sb, "", 0 );
98
99 append( sb, "play2Home", 2 );
100 append( sb, "The PLAY2_HOME path is taken from this setting, if not found as a Java system property (-DPLAY2_HOME). Refers to the PLAY2_HOME environment variable by default. So that means that the PLAY2_HOME can be given using:\n1.\tA system variable defined by the system or with -DPLAY2_HOME=...\n2.\tThe play2Home configuration property\n3.\tThe PLAY2_HOME environment property\n", 3 );
101 append( sb, "Expression: ${env.PLAY2_HOME}", 3 );
102 append( sb, "", 0 );
103
104 append( sb, "timeout (Default: -1)", 2 );
105 append( sb, "Sets a timeout to the play invocation (in milliseconds). If not set (or set to -1, the plugin waits until the underlying play process completes. If set, the plugin kills the underlying play process when the timeout is reached, and it fails the build.", 3 );
106 append( sb, "Expression: ${play2timeout}", 3 );
107 append( sb, "", 0 );
108 }
109 }
110
111 if ( goal == null || goal.length() <= 0 || "compile".equals( goal ) )
112 {
113 append( sb, "play2:compile", 0 );
114 append( sb, "Compile the Play application", 1 );
115 append( sb, "", 0 );
116 if ( detail )
117 {
118 append( sb, "Available parameters:", 1 );
119 append( sb, "", 0 );
120
121 append( sb, "play2Home", 2 );
122 append( sb, "The PLAY2_HOME path is taken from this setting, if not found as a Java system property (-DPLAY2_HOME). Refers to the PLAY2_HOME environment variable by default. So that means that the PLAY2_HOME can be given using:\n1.\tA system variable defined by the system or with -DPLAY2_HOME=...\n2.\tThe play2Home configuration property\n3.\tThe PLAY2_HOME environment property\n", 3 );
123 append( sb, "Expression: ${env.PLAY2_HOME}", 3 );
124 append( sb, "", 0 );
125
126 append( sb, "timeout (Default: -1)", 2 );
127 append( sb, "Sets a timeout to the play invocation (in milliseconds). If not set (or set to -1, the plugin waits until the underlying play process completes. If set, the plugin kills the underlying play process when the timeout is reached, and it fails the build.", 3 );
128 append( sb, "Expression: ${play2timeout}", 3 );
129 append( sb, "", 0 );
130 }
131 }
132
133 if ( goal == null || goal.length() <= 0 || "copy-dependencies".equals( goal ) )
134 {
135 append( sb, "play2:copy-dependencies", 0 );
136 append( sb, "Copy project dependencies to the lib folder.", 1 );
137 append( sb, "", 0 );
138 if ( detail )
139 {
140 append( sb, "Available parameters:", 1 );
141 append( sb, "", 0 );
142
143 append( sb, "lib (Default: lib)", 2 );
144 append( sb, "Where are the dependencies copied.", 3 );
145 append( sb, "", 0 );
146 }
147 }
148
149 if ( goal == null || goal.length() <= 0 || "debug".equals( goal ) )
150 {
151 append( sb, "play2:debug", 0 );
152 append( sb, "Launch the Play application in debug mode (play debug run)", 1 );
153 append( sb, "", 0 );
154 if ( detail )
155 {
156 append( sb, "Available parameters:", 1 );
157 append( sb, "", 0 );
158
159 append( sb, "play2Home", 2 );
160 append( sb, "The PLAY2_HOME path is taken from this setting, if not found as a Java system property (-DPLAY2_HOME). Refers to the PLAY2_HOME environment variable by default. So that means that the PLAY2_HOME can be given using:\n1.\tA system variable defined by the system or with -DPLAY2_HOME=...\n2.\tThe play2Home configuration property\n3.\tThe PLAY2_HOME environment property\n", 3 );
161 append( sb, "Expression: ${env.PLAY2_HOME}", 3 );
162 append( sb, "", 0 );
163
164 append( sb, "timeout (Default: -1)", 2 );
165 append( sb, "Sets a timeout to the play invocation (in milliseconds). If not set (or set to -1, the plugin waits until the underlying play process completes. If set, the plugin kills the underlying play process when the timeout is reached, and it fails the build.", 3 );
166 append( sb, "Expression: ${play2timeout}", 3 );
167 append( sb, "", 0 );
168 }
169 }
170
171 if ( goal == null || goal.length() <= 0 || "help".equals( goal ) )
172 {
173 append( sb, "play2:help", 0 );
174 append( sb, "Display help information on play2-maven-plugin.\nCall\n\u00a0\u00a0mvn\u00a0play2:help\u00a0-Ddetail=true\u00a0-Dgoal=<goal-name>\nto display parameter details.", 1 );
175 append( sb, "", 0 );
176 if ( detail )
177 {
178 append( sb, "Available parameters:", 1 );
179 append( sb, "", 0 );
180
181 append( sb, "detail (Default: false)", 2 );
182 append( sb, "If true, display all settable properties for each goal.", 3 );
183 append( sb, "Expression: ${detail}", 3 );
184 append( sb, "", 0 );
185
186 append( sb, "goal", 2 );
187 append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 3 );
188 append( sb, "Expression: ${goal}", 3 );
189 append( sb, "", 0 );
190
191 append( sb, "indentSize (Default: 2)", 2 );
192 append( sb, "The number of spaces per indentation level, should be positive.", 3 );
193 append( sb, "Expression: ${indentSize}", 3 );
194 append( sb, "", 0 );
195
196 append( sb, "lineLength (Default: 80)", 2 );
197 append( sb, "The maximum length of a display line, should be positive.", 3 );
198 append( sb, "Expression: ${lineLength}", 3 );
199 append( sb, "", 0 );
200 }
201 }
202
203 if ( goal == null || goal.length() <= 0 || "install-play".equals( goal ) )
204 {
205 append( sb, "play2:install-play", 0 );
206 append( sb, "Download and install a Play! distribution.", 1 );
207 append( sb, "", 0 );
208 if ( detail )
209 {
210 append( sb, "Available parameters:", 1 );
211 append( sb, "", 0 );
212
213 append( sb, "play2basedir (Default: ${project.build.directory})", 2 );
214 append( sb, "The directory where automatically installed Play! distributions are extracted. It\'s highly recommended that you set this configuration parameter to a directory of your choice. If not set its defaulted to project build directory. It means that a clean command will first downoad and install specified Play! distribution and then wipe it. After that next plugin goal will download and install again. It\'s not optimal but provides a default behavior that works. If set the plugin will download Play! distribution in this directory and extract them inside it.", 3 );
215 append( sb, "Expression: ${play2basedir}", 3 );
216 append( sb, "", 0 );
217
218 append( sb, "play2version", 2 );
219 append( sb, "Defines a Play! version to automatically install. If not set, PLAY2_HOME detection takes place and Play! is not automatically installed. If set the plugin will download and install specified Play! distribution. See the play2basedir configuration paramenter to set an install directory.", 3 );
220 append( sb, "Expression: ${play2version}", 3 );
221 append( sb, "", 0 );
222 }
223 }
224
225 if ( goal == null || goal.length() <= 0 || "package".equals( goal ) )
226 {
227 append( sb, "play2:package", 0 );
228 append( sb, "Package the Play application. The application is packaged as a Jar file. It is also possible to create the distribution package (zip).", 1 );
229 append( sb, "", 0 );
230 if ( detail )
231 {
232 append( sb, "Available parameters:", 1 );
233 append( sb, "", 0 );
234
235 append( sb, "attachDist (Default: true)", 2 );
236 append( sb, "Enables or disables the attachment of the distribution file as an artifact to this project. This option has no impact if the distribution is not built.", 3 );
237 append( sb, "", 0 );
238
239 append( sb, "buildDist (Default: true)", 2 );
240 append( sb, "Enables or disables the packaging of the whole distribution. The distribution is an autonomous archive containing all the files required to run the play application. Play 2 module can disable the distribution packaging.", 3 );
241 append( sb, "", 0 );
242
243 append( sb, "classifier", 2 );
244 append( sb, "Output file classifier.", 3 );
245 append( sb, "", 0 );
246
247 append( sb, "deleteDist (Default: true)", 2 );
248 append( sb, "Enables or disables the deletion of the dist folder after having packaged the application and copied the distribution file to target. It allows keeping the base directory cleaner.", 3 );
249 append( sb, "", 0 );
250
251 append( sb, "play2Home", 2 );
252 append( sb, "The PLAY2_HOME path is taken from this setting, if not found as a Java system property (-DPLAY2_HOME). Refers to the PLAY2_HOME environment variable by default. So that means that the PLAY2_HOME can be given using:\n1.\tA system variable defined by the system or with -DPLAY2_HOME=...\n2.\tThe play2Home configuration property\n3.\tThe PLAY2_HOME environment property\n", 3 );
253 append( sb, "Expression: ${env.PLAY2_HOME}", 3 );
254 append( sb, "", 0 );
255
256 append( sb, "timeout (Default: -1)", 2 );
257 append( sb, "Sets a timeout to the play invocation (in milliseconds). If not set (or set to -1, the plugin waits until the underlying play process completes. If set, the plugin kills the underlying play process when the timeout is reached, and it fails the build.", 3 );
258 append( sb, "Expression: ${play2timeout}", 3 );
259 append( sb, "", 0 );
260 }
261 }
262
263 if ( goal == null || goal.length() <= 0 || "run".equals( goal ) )
264 {
265 append( sb, "play2:run", 0 );
266 append( sb, "Launch the Play application", 1 );
267 append( sb, "", 0 );
268 if ( detail )
269 {
270 append( sb, "Available parameters:", 1 );
271 append( sb, "", 0 );
272
273 append( sb, "play2Home", 2 );
274 append( sb, "The PLAY2_HOME path is taken from this setting, if not found as a Java system property (-DPLAY2_HOME). Refers to the PLAY2_HOME environment variable by default. So that means that the PLAY2_HOME can be given using:\n1.\tA system variable defined by the system or with -DPLAY2_HOME=...\n2.\tThe play2Home configuration property\n3.\tThe PLAY2_HOME environment property\n", 3 );
275 append( sb, "Expression: ${env.PLAY2_HOME}", 3 );
276 append( sb, "", 0 );
277
278 append( sb, "timeout (Default: -1)", 2 );
279 append( sb, "Sets a timeout to the play invocation (in milliseconds). If not set (or set to -1, the plugin waits until the underlying play process completes. If set, the plugin kills the underlying play process when the timeout is reached, and it fails the build.", 3 );
280 append( sb, "Expression: ${play2timeout}", 3 );
281 append( sb, "", 0 );
282 }
283 }
284
285 if ( goal == null || goal.length() <= 0 || "test".equals( goal ) )
286 {
287 append( sb, "play2:test", 0 );
288 append( sb, "Run the test of the Play application. The tests are run using play test", 1 );
289 append( sb, "", 0 );
290 if ( detail )
291 {
292 append( sb, "Available parameters:", 1 );
293 append( sb, "", 0 );
294
295 append( sb, "play2Home", 2 );
296 append( sb, "The PLAY2_HOME path is taken from this setting, if not found as a Java system property (-DPLAY2_HOME). Refers to the PLAY2_HOME environment variable by default. So that means that the PLAY2_HOME can be given using:\n1.\tA system variable defined by the system or with -DPLAY2_HOME=...\n2.\tThe play2Home configuration property\n3.\tThe PLAY2_HOME environment property\n", 3 );
297 append( sb, "Expression: ${env.PLAY2_HOME}", 3 );
298 append( sb, "", 0 );
299
300 append( sb, "skip (Default: false)", 2 );
301 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 );
302 append( sb, "Expression: ${maven.test.skip}", 3 );
303 append( sb, "", 0 );
304
305 append( sb, "skipTests (Default: false)", 2 );
306 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 );
307 append( sb, "Expression: ${skipTests}", 3 );
308 append( sb, "", 0 );
309
310 append( sb, "testFailureIgnore (Default: false)", 2 );
311 append( sb, "Set this to \'true\' to ignore a failure during testing. Its use is NOT RECOMMENDED, but quite convenient on occasion.", 3 );
312 append( sb, "Expression: ${maven.test.failure.ignore}", 3 );
313 append( sb, "", 0 );
314
315 append( sb, "timeout (Default: -1)", 2 );
316 append( sb, "Sets a timeout to the play invocation (in milliseconds). If not set (or set to -1, the plugin waits until the underlying play process completes. If set, the plugin kills the underlying play process when the timeout is reached, and it fails the build.", 3 );
317 append( sb, "Expression: ${play2timeout}", 3 );
318 append( sb, "", 0 );
319 }
320 }
321
322 if ( getLog().isInfoEnabled() )
323 {
324 getLog().info( sb.toString() );
325 }
326 }
327
328
329
330
331
332
333
334
335
336
337 private static String repeat( String str, int repeat )
338 {
339 StringBuffer buffer = new StringBuffer( repeat * str.length() );
340
341 for ( int i = 0; i < repeat; i++ )
342 {
343 buffer.append( str );
344 }
345
346 return buffer.toString();
347 }
348
349
350
351
352
353
354
355
356
357 private void append( StringBuffer sb, String description, int indent )
358 {
359 for ( Iterator it = toLines( description, indent, indentSize, lineLength ).iterator(); it.hasNext(); )
360 {
361 sb.append( it.next().toString() ).append( '\n' );
362 }
363 }
364
365
366
367
368
369
370
371
372
373
374
375 private static List toLines( String text, int indent, int indentSize, int lineLength )
376 {
377 List lines = new ArrayList();
378
379 String ind = repeat( "\t", indent );
380 String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" );
381 for ( int i = 0; i < plainLines.length; i++ )
382 {
383 toLines( lines, ind + plainLines[i], indentSize, lineLength );
384 }
385
386 return lines;
387 }
388
389
390
391
392
393
394
395
396
397 private static void toLines( List lines, String line, int indentSize, int lineLength )
398 {
399 int lineIndent = getIndentLevel( line );
400 StringBuffer buf = new StringBuffer( 256 );
401 String[] tokens = line.split( " +" );
402 for ( int i = 0; i < tokens.length; i++ )
403 {
404 String token = tokens[i];
405 if ( i > 0 )
406 {
407 if ( buf.length() + token.length() >= lineLength )
408 {
409 lines.add( buf.toString() );
410 buf.setLength( 0 );
411 buf.append( repeat( " ", lineIndent * indentSize ) );
412 }
413 else
414 {
415 buf.append( ' ' );
416 }
417 }
418 for ( int j = 0; j < token.length(); j++ )
419 {
420 char c = token.charAt( j );
421 if ( c == '\t' )
422 {
423 buf.append( repeat( " ", indentSize - buf.length() % indentSize ) );
424 }
425 else if ( c == '\u00A0' )
426 {
427 buf.append( ' ' );
428 }
429 else
430 {
431 buf.append( c );
432 }
433 }
434 }
435 lines.add( buf.toString() );
436 }
437
438
439
440
441
442
443
444 private static int getIndentLevel( String line )
445 {
446 int level = 0;
447 for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ )
448 {
449 level++;
450 }
451 for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ )
452 {
453 if ( line.charAt( i ) == '\t' )
454 {
455 level++;
456 break;
457 }
458 }
459 return level;
460 }
461 }