1 | |
package org.apache.maven.plugin.jar; |
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 | 0 | public class HelpMojo |
19 | |
extends AbstractMojo |
20 | |
{ |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
private boolean detail; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
private java.lang.String goal; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
private int lineLength; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
private int indentSize; |
48 | |
|
49 | |
|
50 | |
|
51 | |
public void execute() |
52 | |
throws MojoExecutionException |
53 | |
{ |
54 | 0 | if ( lineLength <= 0 ) |
55 | |
{ |
56 | 0 | getLog().warn( "The parameter 'lineLength' should be positive, using '80' as default." ); |
57 | 0 | lineLength = 80; |
58 | |
} |
59 | 0 | if ( indentSize <= 0 ) |
60 | |
{ |
61 | 0 | getLog().warn( "The parameter 'indentSize' should be positive, using '2' as default." ); |
62 | 0 | indentSize = 2; |
63 | |
} |
64 | |
|
65 | 0 | StringBuffer sb = new StringBuffer(); |
66 | |
|
67 | 0 | append( sb, "org.apache.maven.plugins:maven-jar-plugin:2.3.1", 0 ); |
68 | 0 | append( sb, "", 0 ); |
69 | |
|
70 | 0 | append( sb, "Maven JAR Plugin", 0 ); |
71 | 0 | append( sb, "Builds a Java Archive (JAR) file from the compiled project classes and resources.", 1 ); |
72 | 0 | append( sb, "", 0 ); |
73 | |
|
74 | 0 | if ( goal == null || goal.length() <= 0 ) |
75 | |
{ |
76 | 0 | append( sb, "This plugin has 5 goals:", 0 ); |
77 | 0 | append( sb, "", 0 ); |
78 | |
} |
79 | |
|
80 | 0 | if ( goal == null || goal.length() <= 0 || "help".equals( goal ) ) |
81 | |
{ |
82 | 0 | append( sb, "jar:help", 0 ); |
83 | 0 | append( sb, "Display help information on maven-jar-plugin.\nCall\n\u00a0\u00a0mvn\u00a0jar:help\u00a0-Ddetail=true\u00a0-Dgoal=<goal-name>\nto display parameter details.", 1 ); |
84 | 0 | append( sb, "", 0 ); |
85 | 0 | if ( detail ) |
86 | |
{ |
87 | 0 | append( sb, "Available parameters:", 1 ); |
88 | 0 | append( sb, "", 0 ); |
89 | |
|
90 | 0 | append( sb, "detail (Default: false)", 2 ); |
91 | 0 | append( sb, "If true, display all settable properties for each goal.", 3 ); |
92 | 0 | append( sb, "", 0 ); |
93 | |
|
94 | 0 | append( sb, "goal", 2 ); |
95 | 0 | append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 3 ); |
96 | 0 | append( sb, "", 0 ); |
97 | |
|
98 | 0 | append( sb, "indentSize (Default: 2)", 2 ); |
99 | 0 | append( sb, "The number of spaces per indentation level, should be positive.", 3 ); |
100 | 0 | append( sb, "", 0 ); |
101 | |
|
102 | 0 | append( sb, "lineLength (Default: 80)", 2 ); |
103 | 0 | append( sb, "The maximum length of a display line, should be positive.", 3 ); |
104 | 0 | append( sb, "", 0 ); |
105 | |
} |
106 | |
} |
107 | |
|
108 | 0 | if ( goal == null || goal.length() <= 0 || "jar".equals( goal ) ) |
109 | |
{ |
110 | 0 | append( sb, "jar:jar", 0 ); |
111 | 0 | append( sb, "Build a JAR from the current project.", 1 ); |
112 | 0 | append( sb, "", 0 ); |
113 | 0 | if ( detail ) |
114 | |
{ |
115 | 0 | append( sb, "Available parameters:", 1 ); |
116 | 0 | append( sb, "", 0 ); |
117 | |
|
118 | 0 | append( sb, "archive", 2 ); |
119 | 0 | append( sb, "The archive configuration to use. See Maven Archiver Reference.", 3 ); |
120 | 0 | append( sb, "", 0 ); |
121 | |
|
122 | 0 | append( sb, "classesDirectory", 2 ); |
123 | 0 | append( sb, "Directory containing the classes and resource files that should be packaged into the JAR.", 3 ); |
124 | 0 | append( sb, "", 0 ); |
125 | |
|
126 | 0 | append( sb, "classifier", 2 ); |
127 | 0 | append( sb, "Classifier to add to the artifact generated. If given, the artifact will be an attachment instead.", 3 ); |
128 | 0 | append( sb, "", 0 ); |
129 | |
|
130 | 0 | append( sb, "excludes", 2 ); |
131 | 0 | append( sb, "List of files to exclude. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.", 3 ); |
132 | 0 | append( sb, "", 0 ); |
133 | |
|
134 | 0 | append( sb, "finalName (Default: ${project.build.finalName})", 2 ); |
135 | 0 | append( sb, "Name of the generated JAR.", 3 ); |
136 | 0 | append( sb, "", 0 ); |
137 | |
|
138 | 0 | append( sb, "forceCreation (Default: false)", 2 ); |
139 | 0 | append( sb, "Whether creating the archive should be forced.", 3 ); |
140 | 0 | append( sb, "", 0 ); |
141 | |
|
142 | 0 | append( sb, "includes", 2 ); |
143 | 0 | append( sb, "List of files to include. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.", 3 ); |
144 | 0 | append( sb, "", 0 ); |
145 | |
|
146 | 0 | append( sb, "outputDirectory", 2 ); |
147 | 0 | append( sb, "Directory containing the generated JAR.", 3 ); |
148 | 0 | append( sb, "", 0 ); |
149 | |
|
150 | 0 | append( sb, "useDefaultManifestFile (Default: false)", 2 ); |
151 | 0 | append( sb, "Set this to true to enable the use of the defaultManifestFile.", 3 ); |
152 | 0 | append( sb, "", 0 ); |
153 | |
} |
154 | |
} |
155 | |
|
156 | 0 | if ( goal == null || goal.length() <= 0 || "sign".equals( goal ) ) |
157 | |
{ |
158 | 0 | append( sb, "jar:sign", 0 ); |
159 | 0 | append( sb, "Deprecated. As of version 2.3, this goal is no longer supported in favor of the dedicated maven-jarsigner-plugin.", 1 ); |
160 | 0 | if ( detail ) |
161 | |
{ |
162 | 0 | append( sb, "", 0 ); |
163 | 0 | append( sb, "Signs a JAR using jarsigner.", 1 ); |
164 | |
} |
165 | 0 | append( sb, "", 0 ); |
166 | 0 | if ( detail ) |
167 | |
{ |
168 | 0 | append( sb, "Available parameters:", 1 ); |
169 | 0 | append( sb, "", 0 ); |
170 | |
|
171 | 0 | append( sb, "alias", 2 ); |
172 | 0 | append( sb, "See options.", 3 ); |
173 | 0 | append( sb, "", 0 ); |
174 | |
|
175 | 0 | append( sb, "classifier", 2 ); |
176 | 0 | append( sb, "Classifier to use for the generated artifact. If not specified, the generated artifact becomes the primary artifact.", 3 ); |
177 | 0 | append( sb, "", 0 ); |
178 | |
|
179 | 0 | append( sb, "finalName", 2 ); |
180 | 0 | append( sb, "Name of the generated JAR (without classifier and extension).", 3 ); |
181 | 0 | append( sb, "", 0 ); |
182 | |
|
183 | 0 | append( sb, "jarPath (Default: ${project.build.directory}/${project.build.finalName}.${project.packaging})", 2 ); |
184 | 0 | append( sb, "Path of the jar to sign. When specified, the finalName is ignored.", 3 ); |
185 | 0 | append( sb, "", 0 ); |
186 | |
|
187 | 0 | append( sb, "keypass", 2 ); |
188 | 0 | append( sb, "See options.", 3 ); |
189 | 0 | append( sb, "", 0 ); |
190 | |
|
191 | 0 | append( sb, "keystore", 2 ); |
192 | 0 | append( sb, "See options.", 3 ); |
193 | 0 | append( sb, "", 0 ); |
194 | |
|
195 | 0 | append( sb, "sigfile", 2 ); |
196 | 0 | append( sb, "See options.", 3 ); |
197 | 0 | append( sb, "", 0 ); |
198 | |
|
199 | 0 | append( sb, "signedjar", 2 ); |
200 | 0 | append( sb, "See options.\n>Not specifying this argument will sign the jar in-place (your original jar is going to be overwritten).\n", 3 ); |
201 | 0 | append( sb, "", 0 ); |
202 | |
|
203 | 0 | append( sb, "skip (Default: false)", 2 ); |
204 | 0 | append( sb, "Set this to true to disable signing. Useful to speed up build process in development environment.", 3 ); |
205 | 0 | append( sb, "", 0 ); |
206 | |
|
207 | 0 | append( sb, "storepass", 2 ); |
208 | 0 | append( sb, "See options.", 3 ); |
209 | 0 | append( sb, "", 0 ); |
210 | |
|
211 | 0 | append( sb, "type", 2 ); |
212 | 0 | append( sb, "See options. The corresponding option in the command line is -storetype.", 3 ); |
213 | 0 | append( sb, "", 0 ); |
214 | |
|
215 | 0 | append( sb, "verbose (Default: false)", 2 ); |
216 | 0 | append( sb, "Enable verbose. See options.", 3 ); |
217 | 0 | append( sb, "", 0 ); |
218 | |
|
219 | 0 | append( sb, "verify (Default: false)", 2 ); |
220 | 0 | append( sb, "Automatically verify a jar after signing it.\n>See options.\n", 3 ); |
221 | 0 | append( sb, "", 0 ); |
222 | |
|
223 | 0 | append( sb, "workingDirectory (Default: ${basedir})", 2 ); |
224 | 0 | append( sb, "The working directory in which the jarsigner executable will be run.", 3 ); |
225 | 0 | append( sb, "", 0 ); |
226 | |
} |
227 | |
} |
228 | |
|
229 | 0 | if ( goal == null || goal.length() <= 0 || "sign-verify".equals( goal ) ) |
230 | |
{ |
231 | 0 | append( sb, "jar:sign-verify", 0 ); |
232 | 0 | append( sb, "Deprecated. As of version 2.3, this goal is no longer supported in favor of the dedicated maven-jarsigner-plugin.", 1 ); |
233 | 0 | if ( detail ) |
234 | |
{ |
235 | 0 | append( sb, "", 0 ); |
236 | 0 | append( sb, "Checks the signature of a signed jar using jarsigner.", 1 ); |
237 | |
} |
238 | 0 | append( sb, "", 0 ); |
239 | 0 | if ( detail ) |
240 | |
{ |
241 | 0 | append( sb, "Available parameters:", 1 ); |
242 | 0 | append( sb, "", 0 ); |
243 | |
|
244 | 0 | append( sb, "checkCerts (Default: false)", 2 ); |
245 | 0 | append( sb, "Check certificates. Requires setVerbose(). See options.", 3 ); |
246 | 0 | append( sb, "", 0 ); |
247 | |
|
248 | 0 | append( sb, "errorWhenNotSigned (Default: true)", 2 ); |
249 | 0 | append( sb, "When true this will make the execute() operation fail, throwing an exception, when verifying a non signed jar. Primarily to keep backwards compatibility with existing code, and allow reusing the bean in unattended operations when set to false.", 3 ); |
250 | 0 | append( sb, "", 0 ); |
251 | |
|
252 | 0 | append( sb, "finalName", 2 ); |
253 | 0 | append( sb, "Name of the generated JAR (without classifier and extension).", 3 ); |
254 | 0 | append( sb, "", 0 ); |
255 | |
|
256 | 0 | append( sb, "jarPath", 2 ); |
257 | 0 | append( sb, "Path of the signed jar. When specified, the finalName is ignored.", 3 ); |
258 | 0 | append( sb, "", 0 ); |
259 | |
|
260 | 0 | append( sb, "verbose (Default: false)", 2 ); |
261 | 0 | append( sb, "Enable verbose See options.", 3 ); |
262 | 0 | append( sb, "", 0 ); |
263 | |
|
264 | 0 | append( sb, "workingDirectory (Default: ${basedir})", 2 ); |
265 | 0 | append( sb, "The working directory in which the jarsigner executable will be run.", 3 ); |
266 | 0 | append( sb, "", 0 ); |
267 | |
} |
268 | |
} |
269 | |
|
270 | 0 | if ( goal == null || goal.length() <= 0 || "test-jar".equals( goal ) ) |
271 | |
{ |
272 | 0 | append( sb, "jar:test-jar", 0 ); |
273 | 0 | append( sb, "Build a JAR of the test classes for the current project.", 1 ); |
274 | 0 | append( sb, "", 0 ); |
275 | 0 | if ( detail ) |
276 | |
{ |
277 | 0 | append( sb, "Available parameters:", 1 ); |
278 | 0 | append( sb, "", 0 ); |
279 | |
|
280 | 0 | append( sb, "archive", 2 ); |
281 | 0 | append( sb, "The archive configuration to use. See Maven Archiver Reference.", 3 ); |
282 | 0 | append( sb, "", 0 ); |
283 | |
|
284 | 0 | append( sb, "excludes", 2 ); |
285 | 0 | append( sb, "List of files to exclude. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.", 3 ); |
286 | 0 | append( sb, "", 0 ); |
287 | |
|
288 | 0 | append( sb, "finalName (Default: ${project.build.finalName})", 2 ); |
289 | 0 | append( sb, "Name of the generated JAR.", 3 ); |
290 | 0 | append( sb, "", 0 ); |
291 | |
|
292 | 0 | append( sb, "forceCreation (Default: false)", 2 ); |
293 | 0 | append( sb, "Whether creating the archive should be forced.", 3 ); |
294 | 0 | append( sb, "", 0 ); |
295 | |
|
296 | 0 | append( sb, "includes", 2 ); |
297 | 0 | append( sb, "List of files to include. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.", 3 ); |
298 | 0 | append( sb, "", 0 ); |
299 | |
|
300 | 0 | append( sb, "outputDirectory", 2 ); |
301 | 0 | append( sb, "Directory containing the generated JAR.", 3 ); |
302 | 0 | append( sb, "", 0 ); |
303 | |
|
304 | 0 | append( sb, "skip", 2 ); |
305 | 0 | append( sb, "Set this to true to bypass unit tests entirely. Its use is NOT RECOMMENDED, but quite convenient on occasion.", 3 ); |
306 | 0 | append( sb, "", 0 ); |
307 | |
|
308 | 0 | append( sb, "testClassesDirectory", 2 ); |
309 | 0 | append( sb, "Directory containing the test classes and resource files that should be packaged into the JAR.", 3 ); |
310 | 0 | append( sb, "", 0 ); |
311 | |
|
312 | 0 | append( sb, "useDefaultManifestFile (Default: false)", 2 ); |
313 | 0 | append( sb, "Set this to true to enable the use of the defaultManifestFile.", 3 ); |
314 | 0 | append( sb, "", 0 ); |
315 | |
} |
316 | |
} |
317 | |
|
318 | 0 | if ( getLog().isInfoEnabled() ) |
319 | |
{ |
320 | 0 | getLog().info( sb.toString() ); |
321 | |
} |
322 | 0 | } |
323 | |
|
324 | |
|
325 | |
|
326 | |
|
327 | |
|
328 | |
|
329 | |
|
330 | |
|
331 | |
|
332 | |
|
333 | |
private static String repeat( String str, int repeat ) |
334 | |
{ |
335 | 0 | StringBuffer buffer = new StringBuffer( repeat * str.length() ); |
336 | |
|
337 | 0 | for ( int i = 0; i < repeat; i++ ) |
338 | |
{ |
339 | 0 | buffer.append( str ); |
340 | |
} |
341 | |
|
342 | 0 | return buffer.toString(); |
343 | |
} |
344 | |
|
345 | |
|
346 | |
|
347 | |
|
348 | |
|
349 | |
|
350 | |
|
351 | |
|
352 | |
|
353 | |
private void append( StringBuffer sb, String description, int indent ) |
354 | |
{ |
355 | 0 | for ( Iterator it = toLines( description, indent, indentSize, lineLength ).iterator(); it.hasNext(); ) |
356 | |
{ |
357 | 0 | sb.append( it.next().toString() ).append( '\n' ); |
358 | |
} |
359 | 0 | } |
360 | |
|
361 | |
|
362 | |
|
363 | |
|
364 | |
|
365 | |
|
366 | |
|
367 | |
|
368 | |
|
369 | |
|
370 | |
|
371 | |
private static List toLines( String text, int indent, int indentSize, int lineLength ) |
372 | |
{ |
373 | 0 | List lines = new ArrayList(); |
374 | |
|
375 | 0 | String ind = repeat( "\t", indent ); |
376 | 0 | String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" ); |
377 | 0 | for ( int i = 0; i < plainLines.length; i++ ) |
378 | |
{ |
379 | 0 | toLines( lines, ind + plainLines[i], indentSize, lineLength ); |
380 | |
} |
381 | |
|
382 | 0 | return lines; |
383 | |
} |
384 | |
|
385 | |
|
386 | |
|
387 | |
|
388 | |
|
389 | |
|
390 | |
|
391 | |
|
392 | |
|
393 | |
private static void toLines( List lines, String line, int indentSize, int lineLength ) |
394 | |
{ |
395 | 0 | int lineIndent = getIndentLevel( line ); |
396 | 0 | StringBuffer buf = new StringBuffer( 256 ); |
397 | 0 | String[] tokens = line.split( " +" ); |
398 | 0 | for ( int i = 0; i < tokens.length; i++ ) |
399 | |
{ |
400 | 0 | String token = tokens[i]; |
401 | 0 | if ( i > 0 ) |
402 | |
{ |
403 | 0 | if ( buf.length() + token.length() >= lineLength ) |
404 | |
{ |
405 | 0 | lines.add( buf.toString() ); |
406 | 0 | buf.setLength( 0 ); |
407 | 0 | buf.append( repeat( " ", lineIndent * indentSize ) ); |
408 | |
} |
409 | |
else |
410 | |
{ |
411 | 0 | buf.append( ' ' ); |
412 | |
} |
413 | |
} |
414 | 0 | for ( int j = 0; j < token.length(); j++ ) |
415 | |
{ |
416 | 0 | char c = token.charAt( j ); |
417 | 0 | if ( c == '\t' ) |
418 | |
{ |
419 | 0 | buf.append( repeat( " ", indentSize - buf.length() % indentSize ) ); |
420 | |
} |
421 | 0 | else if ( c == '\u00A0' ) |
422 | |
{ |
423 | 0 | buf.append( ' ' ); |
424 | |
} |
425 | |
else |
426 | |
{ |
427 | 0 | buf.append( c ); |
428 | |
} |
429 | |
} |
430 | |
} |
431 | 0 | lines.add( buf.toString() ); |
432 | 0 | } |
433 | |
|
434 | |
|
435 | |
|
436 | |
|
437 | |
|
438 | |
|
439 | |
|
440 | |
private static int getIndentLevel( String line ) |
441 | |
{ |
442 | 0 | int level = 0; |
443 | 0 | for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ ) |
444 | |
{ |
445 | 0 | level++; |
446 | |
} |
447 | 0 | for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ ) |
448 | |
{ |
449 | 0 | if ( line.charAt( i ) == '\t' ) |
450 | |
{ |
451 | 0 | level++; |
452 | 0 | break; |
453 | |
} |
454 | |
} |
455 | 0 | return level; |
456 | |
} |
457 | |
} |