1 | |
package org.apache.maven.plugins.help; |
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-help-plugin:2.1.1", 0 ); |
68 | 0 | append( sb, "", 0 ); |
69 | |
|
70 | 0 | append( sb, "Maven Help Plugin", 0 ); |
71 | 0 | append( sb, "The Maven Help plugin provides goals aimed at helping to make sense out of the build environment. It includes the ability to view the effective POM and settings files, after inheritance and active profiles have been applied, as well as a describe a particular plugin goal to give usage information.", 1 ); |
72 | 0 | append( sb, "", 0 ); |
73 | |
|
74 | 0 | if ( goal == null || goal.length() <= 0 ) |
75 | |
{ |
76 | 0 | append( sb, "This plugin has 9 goals:", 0 ); |
77 | 0 | append( sb, "", 0 ); |
78 | |
} |
79 | |
|
80 | 0 | if ( goal == null || goal.length() <= 0 || "active-profiles".equals( goal ) ) |
81 | |
{ |
82 | 0 | append( sb, "help:active-profiles", 0 ); |
83 | 0 | append( sb, "Displays a list of the profiles which are currently active for this build.", 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, "output", 2 ); |
91 | 0 | append( sb, "Optional parameter to write the output of this help in a given file, instead of writing to the console.\nNote: Could be a relative path.", 3 ); |
92 | 0 | append( sb, "", 0 ); |
93 | |
} |
94 | |
} |
95 | |
|
96 | 0 | if ( goal == null || goal.length() <= 0 || "all-profiles".equals( goal ) ) |
97 | |
{ |
98 | 0 | append( sb, "help:all-profiles", 0 ); |
99 | 0 | append( sb, "Displays a list of available profiles under the current project.\nNote: it will list all profiles for a project. If a profile comes up with a status inactive then there might be a need to set profile activation switches/property.", 1 ); |
100 | 0 | append( sb, "", 0 ); |
101 | 0 | if ( detail ) |
102 | |
{ |
103 | 0 | append( sb, "Available parameters:", 1 ); |
104 | 0 | append( sb, "", 0 ); |
105 | |
|
106 | 0 | append( sb, "output", 2 ); |
107 | 0 | append( sb, "Optional parameter to write the output of this help in a given file, instead of writing to the console.\nNote: Could be a relative path.", 3 ); |
108 | 0 | append( sb, "", 0 ); |
109 | |
} |
110 | |
} |
111 | |
|
112 | 0 | if ( goal == null || goal.length() <= 0 || "describe".equals( goal ) ) |
113 | |
{ |
114 | 0 | append( sb, "help:describe", 0 ); |
115 | 0 | append( sb, "Displays a list of the attributes for a Maven Plugin and/or goals (aka Mojo - Maven plain Old Java Object).", 1 ); |
116 | 0 | append( sb, "", 0 ); |
117 | 0 | if ( detail ) |
118 | |
{ |
119 | 0 | append( sb, "Available parameters:", 1 ); |
120 | 0 | append( sb, "", 0 ); |
121 | |
|
122 | 0 | append( sb, "artifactId", 2 ); |
123 | 0 | append( sb, "The Maven Plugin artifactId to describe.\nNote: Should be used with groupId parameter.", 3 ); |
124 | 0 | append( sb, "", 0 ); |
125 | |
|
126 | 0 | append( sb, "cmd", 2 ); |
127 | 0 | append( sb, "A Maven command like a single goal or a single phase following the Maven command line:\nmvn [options] [<goal(s)>] [<phase(s)>]", 3 ); |
128 | 0 | append( sb, "", 0 ); |
129 | |
|
130 | 0 | append( sb, "detail (Default: false)", 2 ); |
131 | 0 | append( sb, "This flag specifies that a detailed (verbose) list of goal (Mojo) information should be given.", 3 ); |
132 | 0 | append( sb, "", 0 ); |
133 | |
|
134 | 0 | append( sb, "goal", 2 ); |
135 | 0 | append( sb, "The goal name of a Mojo to describe within the specified Maven Plugin. If this parameter is specified, only the corresponding goal (Mojo) will be described, rather than the whole Plugin.", 3 ); |
136 | 0 | append( sb, "", 0 ); |
137 | |
|
138 | 0 | append( sb, "groupId", 2 ); |
139 | 0 | append( sb, "The Maven Plugin groupId to describe.\nNote: Should be used with artifactId parameter.", 3 ); |
140 | 0 | append( sb, "", 0 ); |
141 | |
|
142 | 0 | append( sb, "medium (Default: true)", 2 ); |
143 | 0 | append( sb, "This flag specifies that a medium list of goal (Mojo) information should be given.", 3 ); |
144 | 0 | append( sb, "", 0 ); |
145 | |
|
146 | 0 | append( sb, "minimal (Default: false)", 2 ); |
147 | 0 | append( sb, "This flag specifies that a minimal list of goal (Mojo) information should be given.", 3 ); |
148 | 0 | append( sb, "", 0 ); |
149 | |
|
150 | 0 | append( sb, "output", 2 ); |
151 | 0 | append( sb, "Optional parameter to write the output of this help in a given file, instead of writing to the console.\nNote: Could be a relative path.", 3 ); |
152 | 0 | append( sb, "", 0 ); |
153 | |
|
154 | 0 | append( sb, "plugin", 2 ); |
155 | 0 | append( sb, "The Maven Plugin to describe. This must be specified in one of three ways:\n\n1.\tplugin-prefix, i.e. \'help\'\n2.\tgroupId:artifactId, i.e. \'org.apache.maven.plugins:maven-help-plugin\'\n3.\tgroupId:artifactId:version, i.e. \'org.apache.maven.plugins:maven-help-plugin:2.0\'\n", 3 ); |
156 | 0 | append( sb, "", 0 ); |
157 | |
|
158 | 0 | append( sb, "version", 2 ); |
159 | 0 | append( sb, "The Maven Plugin version to describe.\nNote: Should be used with groupId/artifactId parameters.", 3 ); |
160 | 0 | append( sb, "", 0 ); |
161 | |
} |
162 | |
} |
163 | |
|
164 | 0 | if ( goal == null || goal.length() <= 0 || "effective-pom".equals( goal ) ) |
165 | |
{ |
166 | 0 | append( sb, "help:effective-pom", 0 ); |
167 | 0 | append( sb, "Displays the effective POM as an XML for this build, with the active profiles factored in.", 1 ); |
168 | 0 | append( sb, "", 0 ); |
169 | 0 | if ( detail ) |
170 | |
{ |
171 | 0 | append( sb, "Available parameters:", 1 ); |
172 | 0 | append( sb, "", 0 ); |
173 | |
|
174 | 0 | append( sb, "output", 2 ); |
175 | 0 | append( sb, "Optional parameter to write the output of this help in a given file, instead of writing to the console.\nNote: Could be a relative path.", 3 ); |
176 | 0 | append( sb, "", 0 ); |
177 | |
} |
178 | |
} |
179 | |
|
180 | 0 | if ( goal == null || goal.length() <= 0 || "effective-settings".equals( goal ) ) |
181 | |
{ |
182 | 0 | append( sb, "help:effective-settings", 0 ); |
183 | 0 | append( sb, "Displays the calculated settings as XML for this project, given any profile enhancement and the inheritance of the global settings into the user-level settings.", 1 ); |
184 | 0 | append( sb, "", 0 ); |
185 | 0 | if ( detail ) |
186 | |
{ |
187 | 0 | append( sb, "Available parameters:", 1 ); |
188 | 0 | append( sb, "", 0 ); |
189 | |
|
190 | 0 | append( sb, "output", 2 ); |
191 | 0 | append( sb, "Optional parameter to write the output of this help in a given file, instead of writing to the console.\nNote: Could be a relative path.", 3 ); |
192 | 0 | append( sb, "", 0 ); |
193 | |
|
194 | 0 | append( sb, "showPasswords (Default: false)", 2 ); |
195 | 0 | append( sb, "For security reasons, all passwords are hidden by default. Set this to true to show all passwords.", 3 ); |
196 | 0 | append( sb, "", 0 ); |
197 | |
} |
198 | |
} |
199 | |
|
200 | 0 | if ( goal == null || goal.length() <= 0 || "evaluate".equals( goal ) ) |
201 | |
{ |
202 | 0 | append( sb, "help:evaluate", 0 ); |
203 | 0 | append( sb, "Evaluates Maven expressions given by the user in an interactive mode.", 1 ); |
204 | 0 | append( sb, "", 0 ); |
205 | 0 | if ( detail ) |
206 | |
{ |
207 | 0 | append( sb, "Available parameters:", 1 ); |
208 | 0 | append( sb, "", 0 ); |
209 | |
|
210 | 0 | append( sb, "artifact", 2 ); |
211 | 0 | append( sb, "An artifact for evaluating Maven expressions.\nNote: Should respect the Maven format, i.e. groupId:artifactId[:version][:classifier].", 3 ); |
212 | 0 | append( sb, "", 0 ); |
213 | |
|
214 | 0 | append( sb, "expression", 2 ); |
215 | 0 | append( sb, "An expression to evaluate instead of prompting. Note that this must not include the surrounding ${...}.", 3 ); |
216 | 0 | append( sb, "", 0 ); |
217 | |
} |
218 | |
} |
219 | |
|
220 | 0 | if ( goal == null || goal.length() <= 0 || "expressions".equals( goal ) ) |
221 | |
{ |
222 | 0 | append( sb, "help:expressions", 0 ); |
223 | 0 | append( sb, "Displays the supported Plugin expressions used by Maven.", 1 ); |
224 | 0 | append( sb, "", 0 ); |
225 | 0 | if ( detail ) |
226 | |
{ |
227 | 0 | append( sb, "Available parameters:", 1 ); |
228 | 0 | append( sb, "", 0 ); |
229 | |
|
230 | 0 | append( sb, "output", 2 ); |
231 | 0 | append( sb, "Optional parameter to write the output of this help in a given file, instead of writing to the console.\nNote: Could be a relative path.", 3 ); |
232 | 0 | append( sb, "", 0 ); |
233 | |
} |
234 | |
} |
235 | |
|
236 | 0 | if ( goal == null || goal.length() <= 0 || "help".equals( goal ) ) |
237 | |
{ |
238 | 0 | append( sb, "help:help", 0 ); |
239 | 0 | append( sb, "Display help information on maven-help-plugin.\nCall\n\u00a0\u00a0mvn\u00a0help:help\u00a0-Ddetail=true\u00a0-Dgoal=<goal-name>\nto display parameter details.", 1 ); |
240 | 0 | append( sb, "", 0 ); |
241 | 0 | if ( detail ) |
242 | |
{ |
243 | 0 | append( sb, "Available parameters:", 1 ); |
244 | 0 | append( sb, "", 0 ); |
245 | |
|
246 | 0 | append( sb, "detail (Default: false)", 2 ); |
247 | 0 | append( sb, "If true, display all settable properties for each goal.", 3 ); |
248 | 0 | append( sb, "", 0 ); |
249 | |
|
250 | 0 | append( sb, "goal", 2 ); |
251 | 0 | append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 3 ); |
252 | 0 | append( sb, "", 0 ); |
253 | |
|
254 | 0 | append( sb, "indentSize (Default: 2)", 2 ); |
255 | 0 | append( sb, "The number of spaces per indentation level, should be positive.", 3 ); |
256 | 0 | append( sb, "", 0 ); |
257 | |
|
258 | 0 | append( sb, "lineLength (Default: 80)", 2 ); |
259 | 0 | append( sb, "The maximum length of a display line, should be positive.", 3 ); |
260 | 0 | append( sb, "", 0 ); |
261 | |
} |
262 | |
} |
263 | |
|
264 | 0 | if ( goal == null || goal.length() <= 0 || "system".equals( goal ) ) |
265 | |
{ |
266 | 0 | append( sb, "help:system", 0 ); |
267 | 0 | append( sb, "Displays a list of the platform details like system properties and environment variables.", 1 ); |
268 | 0 | append( sb, "", 0 ); |
269 | 0 | if ( detail ) |
270 | |
{ |
271 | 0 | append( sb, "Available parameters:", 1 ); |
272 | 0 | append( sb, "", 0 ); |
273 | |
|
274 | 0 | append( sb, "output", 2 ); |
275 | 0 | append( sb, "Optional parameter to write the output of this help in a given file, instead of writing to the console.\nNote: Could be a relative path.", 3 ); |
276 | 0 | append( sb, "", 0 ); |
277 | |
} |
278 | |
} |
279 | |
|
280 | 0 | if ( getLog().isInfoEnabled() ) |
281 | |
{ |
282 | 0 | getLog().info( sb.toString() ); |
283 | |
} |
284 | 0 | } |
285 | |
|
286 | |
|
287 | |
|
288 | |
|
289 | |
|
290 | |
|
291 | |
|
292 | |
|
293 | |
|
294 | |
|
295 | |
private static String repeat( String str, int repeat ) |
296 | |
{ |
297 | 0 | StringBuffer buffer = new StringBuffer( repeat * str.length() ); |
298 | |
|
299 | 0 | for ( int i = 0; i < repeat; i++ ) |
300 | |
{ |
301 | 0 | buffer.append( str ); |
302 | |
} |
303 | |
|
304 | 0 | return buffer.toString(); |
305 | |
} |
306 | |
|
307 | |
|
308 | |
|
309 | |
|
310 | |
|
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
private void append( StringBuffer sb, String description, int indent ) |
316 | |
{ |
317 | 0 | for ( Iterator it = toLines( description, indent, indentSize, lineLength ).iterator(); it.hasNext(); ) |
318 | |
{ |
319 | 0 | sb.append( it.next().toString() ).append( '\n' ); |
320 | |
} |
321 | 0 | } |
322 | |
|
323 | |
|
324 | |
|
325 | |
|
326 | |
|
327 | |
|
328 | |
|
329 | |
|
330 | |
|
331 | |
|
332 | |
|
333 | |
private static List toLines( String text, int indent, int indentSize, int lineLength ) |
334 | |
{ |
335 | 0 | List lines = new ArrayList(); |
336 | |
|
337 | 0 | String ind = repeat( "\t", indent ); |
338 | 0 | String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" ); |
339 | 0 | for ( int i = 0; i < plainLines.length; i++ ) |
340 | |
{ |
341 | 0 | toLines( lines, ind + plainLines[i], indentSize, lineLength ); |
342 | |
} |
343 | |
|
344 | 0 | return lines; |
345 | |
} |
346 | |
|
347 | |
|
348 | |
|
349 | |
|
350 | |
|
351 | |
|
352 | |
|
353 | |
|
354 | |
|
355 | |
private static void toLines( List lines, String line, int indentSize, int lineLength ) |
356 | |
{ |
357 | 0 | int lineIndent = getIndentLevel( line ); |
358 | 0 | StringBuffer buf = new StringBuffer( 256 ); |
359 | 0 | String[] tokens = line.split( " +" ); |
360 | 0 | for ( int i = 0; i < tokens.length; i++ ) |
361 | |
{ |
362 | 0 | String token = tokens[i]; |
363 | 0 | if ( i > 0 ) |
364 | |
{ |
365 | 0 | if ( buf.length() + token.length() >= lineLength ) |
366 | |
{ |
367 | 0 | lines.add( buf.toString() ); |
368 | 0 | buf.setLength( 0 ); |
369 | 0 | buf.append( repeat( " ", lineIndent * indentSize ) ); |
370 | |
} |
371 | |
else |
372 | |
{ |
373 | 0 | buf.append( ' ' ); |
374 | |
} |
375 | |
} |
376 | 0 | for ( int j = 0; j < token.length(); j++ ) |
377 | |
{ |
378 | 0 | char c = token.charAt( j ); |
379 | 0 | if ( c == '\t' ) |
380 | |
{ |
381 | 0 | buf.append( repeat( " ", indentSize - buf.length() % indentSize ) ); |
382 | |
} |
383 | 0 | else if ( c == '\u00A0' ) |
384 | |
{ |
385 | 0 | buf.append( ' ' ); |
386 | |
} |
387 | |
else |
388 | |
{ |
389 | 0 | buf.append( c ); |
390 | |
} |
391 | |
} |
392 | |
} |
393 | 0 | lines.add( buf.toString() ); |
394 | 0 | } |
395 | |
|
396 | |
|
397 | |
|
398 | |
|
399 | |
|
400 | |
|
401 | |
|
402 | |
private static int getIndentLevel( String line ) |
403 | |
{ |
404 | 0 | int level = 0; |
405 | 0 | for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ ) |
406 | |
{ |
407 | 0 | level++; |
408 | |
} |
409 | 0 | for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ ) |
410 | |
{ |
411 | 0 | if ( line.charAt( i ) == '\t' ) |
412 | |
{ |
413 | 0 | level++; |
414 | 0 | break; |
415 | |
} |
416 | |
} |
417 | 0 | return level; |
418 | |
} |
419 | |
} |