View Javadoc

1   package org.apache.maven.plugin.resources;
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   * Display help information on maven-resources-plugin.<br/> Call <pre>  mvn resources:help -Ddetail=true -Dgoal=&lt;goal-name&gt;</pre> to display parameter details.
12   *
13   * @version generated on Thu Feb 24 20:51:30 CET 2011
14   * @author org.apache.maven.tools.plugin.generator.PluginHelpGenerator (version 2.7)
15   * @goal help
16   * @requiresProject false
17   * @threadSafe
18   */
19  public class HelpMojo
20      extends AbstractMojo
21  {
22      /**
23       * If <code>true</code>, display all settable properties for each goal.
24       * 
25       * @parameter expression="${detail}" default-value="false"
26       */
27      private boolean detail;
28  
29      /**
30       * The name of the goal for which to show help. If unspecified, all goals will be displayed.
31       * 
32       * @parameter expression="${goal}"
33       */
34      private java.lang.String goal;
35  
36      /**
37       * The maximum length of a display line, should be positive.
38       * 
39       * @parameter expression="${lineLength}" default-value="80"
40       */
41      private int lineLength;
42  
43      /**
44       * The number of spaces per indentation level, should be positive.
45       * 
46       * @parameter expression="${indentSize}" default-value="2"
47       */
48      private int indentSize;
49  
50  
51      /** {@inheritDoc} */
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-resources-plugin:2.5", 0 );
69          append( sb, "", 0 );
70  
71          append( sb, "Maven Resources Plugin", 0 );
72          append( sb, "The Resources Plugin handles the copying of project resources to the output directory. There are two different kinds of resources: main resources and test resources. The difference is that the main resources are the resources associated to the main source code while the test resources are associated to the test source code. Thus, this allows the separation of resources for the main source code and its unit tests.", 1 );
73          append( sb, "", 0 );
74  
75          if ( goal == null || goal.length() <= 0 )
76          {
77              append( sb, "This plugin has 4 goals:", 0 );
78              append( sb, "", 0 );
79          }
80  
81          if ( goal == null || goal.length() <= 0 || "copy-resources".equals( goal ) )
82          {
83              append( sb, "resources:copy-resources", 0 );
84              append( sb, "Copy resources of the configured plugin attribute resources", 1 );
85              append( sb, "", 0 );
86              if ( detail )
87              {
88                  append( sb, "Available parameters:", 1 );
89                  append( sb, "", 0 );
90  
91                  append( sb, "delimiters", 2 );
92                  append( sb, "Set of delimiters for expressions to filter within the resources. These delimiters are specified in the form \'beginToken*endToken\'. If no \'*\' is given, the delimiter is assumed to be the same for start and end.\n\nSo, the default filtering delimiters might be specified as:\n\n<delimiters>\n\u00a0\u00a0<delimiter>${*}</delimiter>\n\u00a0\u00a0<delimiter>@</delimiter>\n</delimiters>\n\nSince the \'@\' delimiter is the same on both ends, we don\'t need to specify \'@*@\' (though we can).\n", 3 );
93                  append( sb, "", 0 );
94  
95                  append( sb, "encoding (Default: ${project.build.sourceEncoding})", 2 );
96                  append( sb, "The character encoding scheme to be applied when filtering resources.", 3 );
97                  append( sb, "Expression: ${encoding}", 3 );
98                  append( sb, "", 0 );
99  
100                 append( sb, "escapeString", 2 );
101                 append( sb, "Expression preceded with the String won\'t be interpolated \\${foo} will be replaced with ${foo}", 3 );
102                 append( sb, "Expression: ${maven.resources.escapeString}", 3 );
103                 append( sb, "", 0 );
104 
105                 append( sb, "escapeWindowsPaths (Default: true)", 2 );
106                 append( sb, "Whether to escape backslashes and colons in windows-style paths.", 3 );
107                 append( sb, "Expression: ${maven.resources.escapeWindowsPaths}", 3 );
108                 append( sb, "", 0 );
109 
110                 append( sb, "filters", 2 );
111                 append( sb, "The list of extra filter properties files to be used along with System properties, project properties, and filter properties files specified in the POM build/filters section, which should be used for the filtering during the current mojo execution.\nNormally, these will be configured from a plugin\'s execution section, to provide a different set of filters for a particular execution. For instance, starting in Maven 2.2.0, you have the option of configuring executions with the id\'s default-resources and default-testResources to supply different configurations for the two different types of resources. By supplying extraFilters configurations, you can separate which filters are used for which type of resource.", 3 );
112                 append( sb, "", 0 );
113 
114                 append( sb, "includeEmptyDirs (Default: false)", 2 );
115                 append( sb, "Copy any empty directories included in the Ressources.", 3 );
116                 append( sb, "Expression: ${maven.resources.includeEmptyDirs}", 3 );
117                 append( sb, "", 0 );
118 
119                 append( sb, "mavenFilteringHints", 2 );
120                 append( sb, "List of plexus components hint which implements MavenResourcesFiltering.filterResources(). They will be executed after the resources copying/filtering.\n", 3 );
121                 append( sb, "", 0 );
122 
123                 append( sb, "nonFilteredFileExtensions", 2 );
124                 append( sb, "Additional file extensions to not apply filtering (already defined are : jpg, jpeg, gif, bmp, png)", 3 );
125                 append( sb, "", 0 );
126 
127                 append( sb, "outputDirectory", 2 );
128                 append( sb, "The output directory into which to copy the resources.", 3 );
129                 append( sb, "Required: Yes", 3 );
130                 append( sb, "", 0 );
131 
132                 append( sb, "overwrite (Default: false)", 2 );
133                 append( sb, "Overwrite existing files even if the destination files are newer.", 3 );
134                 append( sb, "Expression: ${maven.resources.overwrite}", 3 );
135                 append( sb, "", 0 );
136 
137                 append( sb, "resources", 2 );
138                 append( sb, "The list of resources we want to transfer. See the Maven Model for a description of how to code the resources element.", 3 );
139                 append( sb, "Required: Yes", 3 );
140                 append( sb, "", 0 );
141 
142                 append( sb, "supportMultiLineFiltering (Default: false)", 2 );
143                 append( sb, "stop searching endToken at the end of line", 3 );
144                 append( sb, "Expression: ${maven.resources.supportMultiLineFiltering}", 3 );
145                 append( sb, "", 0 );
146 
147                 append( sb, "useBuildFilters (Default: true)", 2 );
148                 append( sb, "If false, don\'t use the filters specified in the build/filters section of the POM when processing resources in this mojo execution.\nSee also: ResourcesMojo.buildFilters and ResourcesMojo.filters", 3 );
149                 append( sb, "", 0 );
150 
151                 append( sb, "useDefaultDelimiters (Default: true)", 2 );
152                 append( sb, "(no description available)", 3 );
153                 append( sb, "", 0 );
154             }
155         }
156 
157         if ( goal == null || goal.length() <= 0 || "help".equals( goal ) )
158         {
159             append( sb, "resources:help", 0 );
160             append( sb, "Display help information on maven-resources-plugin.\nCall\n\u00a0\u00a0mvn\u00a0resources:help\u00a0-Ddetail=true\u00a0-Dgoal=<goal-name>\nto display parameter details.", 1 );
161             append( sb, "", 0 );
162             if ( detail )
163             {
164                 append( sb, "Available parameters:", 1 );
165                 append( sb, "", 0 );
166 
167                 append( sb, "detail (Default: false)", 2 );
168                 append( sb, "If true, display all settable properties for each goal.", 3 );
169                 append( sb, "Expression: ${detail}", 3 );
170                 append( sb, "", 0 );
171 
172                 append( sb, "goal", 2 );
173                 append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 3 );
174                 append( sb, "Expression: ${goal}", 3 );
175                 append( sb, "", 0 );
176 
177                 append( sb, "indentSize (Default: 2)", 2 );
178                 append( sb, "The number of spaces per indentation level, should be positive.", 3 );
179                 append( sb, "Expression: ${indentSize}", 3 );
180                 append( sb, "", 0 );
181 
182                 append( sb, "lineLength (Default: 80)", 2 );
183                 append( sb, "The maximum length of a display line, should be positive.", 3 );
184                 append( sb, "Expression: ${lineLength}", 3 );
185                 append( sb, "", 0 );
186             }
187         }
188 
189         if ( goal == null || goal.length() <= 0 || "resources".equals( goal ) )
190         {
191             append( sb, "resources:resources", 0 );
192             append( sb, "Copy resources for the main source code to the main output directory. Always uses the project.build.resources element to specify the resources to copy.", 1 );
193             append( sb, "", 0 );
194             if ( detail )
195             {
196                 append( sb, "Available parameters:", 1 );
197                 append( sb, "", 0 );
198 
199                 append( sb, "delimiters", 2 );
200                 append( sb, "Set of delimiters for expressions to filter within the resources. These delimiters are specified in the form \'beginToken*endToken\'. If no \'*\' is given, the delimiter is assumed to be the same for start and end.\n\nSo, the default filtering delimiters might be specified as:\n\n<delimiters>\n\u00a0\u00a0<delimiter>${*}</delimiter>\n\u00a0\u00a0<delimiter>@</delimiter>\n</delimiters>\n\nSince the \'@\' delimiter is the same on both ends, we don\'t need to specify \'@*@\' (though we can).\n", 3 );
201                 append( sb, "", 0 );
202 
203                 append( sb, "encoding (Default: ${project.build.sourceEncoding})", 2 );
204                 append( sb, "The character encoding scheme to be applied when filtering resources.", 3 );
205                 append( sb, "Expression: ${encoding}", 3 );
206                 append( sb, "", 0 );
207 
208                 append( sb, "escapeString", 2 );
209                 append( sb, "Expression preceded with the String won\'t be interpolated \\${foo} will be replaced with ${foo}", 3 );
210                 append( sb, "Expression: ${maven.resources.escapeString}", 3 );
211                 append( sb, "", 0 );
212 
213                 append( sb, "escapeWindowsPaths (Default: true)", 2 );
214                 append( sb, "Whether to escape backslashes and colons in windows-style paths.", 3 );
215                 append( sb, "Expression: ${maven.resources.escapeWindowsPaths}", 3 );
216                 append( sb, "", 0 );
217 
218                 append( sb, "filters", 2 );
219                 append( sb, "The list of extra filter properties files to be used along with System properties, project properties, and filter properties files specified in the POM build/filters section, which should be used for the filtering during the current mojo execution.\nNormally, these will be configured from a plugin\'s execution section, to provide a different set of filters for a particular execution. For instance, starting in Maven 2.2.0, you have the option of configuring executions with the id\'s default-resources and default-testResources to supply different configurations for the two different types of resources. By supplying extraFilters configurations, you can separate which filters are used for which type of resource.", 3 );
220                 append( sb, "", 0 );
221 
222                 append( sb, "includeEmptyDirs (Default: false)", 2 );
223                 append( sb, "Copy any empty directories included in the Ressources.", 3 );
224                 append( sb, "Expression: ${maven.resources.includeEmptyDirs}", 3 );
225                 append( sb, "", 0 );
226 
227                 append( sb, "mavenFilteringHints", 2 );
228                 append( sb, "List of plexus components hint which implements MavenResourcesFiltering.filterResources(). They will be executed after the resources copying/filtering.\n", 3 );
229                 append( sb, "", 0 );
230 
231                 append( sb, "nonFilteredFileExtensions", 2 );
232                 append( sb, "Additional file extensions to not apply filtering (already defined are : jpg, jpeg, gif, bmp, png)", 3 );
233                 append( sb, "", 0 );
234 
235                 append( sb, "outputDirectory (Default: ${project.build.outputDirectory})", 2 );
236                 append( sb, "The output directory into which to copy the resources.", 3 );
237                 append( sb, "Required: Yes", 3 );
238                 append( sb, "", 0 );
239 
240                 append( sb, "overwrite (Default: false)", 2 );
241                 append( sb, "Overwrite existing files even if the destination files are newer.", 3 );
242                 append( sb, "Expression: ${maven.resources.overwrite}", 3 );
243                 append( sb, "", 0 );
244 
245                 append( sb, "supportMultiLineFiltering (Default: false)", 2 );
246                 append( sb, "stop searching endToken at the end of line", 3 );
247                 append( sb, "Expression: ${maven.resources.supportMultiLineFiltering}", 3 );
248                 append( sb, "", 0 );
249 
250                 append( sb, "useBuildFilters (Default: true)", 2 );
251                 append( sb, "If false, don\'t use the filters specified in the build/filters section of the POM when processing resources in this mojo execution.\nSee also: ResourcesMojo.buildFilters and ResourcesMojo.filters", 3 );
252                 append( sb, "", 0 );
253 
254                 append( sb, "useDefaultDelimiters (Default: true)", 2 );
255                 append( sb, "(no description available)", 3 );
256                 append( sb, "", 0 );
257             }
258         }
259 
260         if ( goal == null || goal.length() <= 0 || "testResources".equals( goal ) )
261         {
262             append( sb, "resources:testResources", 0 );
263             append( sb, "Copy resources for the test source code to the test output directory. Always uses the project.build.testResources element to specify the resources to copy.", 1 );
264             append( sb, "", 0 );
265             if ( detail )
266             {
267                 append( sb, "Available parameters:", 1 );
268                 append( sb, "", 0 );
269 
270                 append( sb, "delimiters", 2 );
271                 append( sb, "Set of delimiters for expressions to filter within the resources. These delimiters are specified in the form \'beginToken*endToken\'. If no \'*\' is given, the delimiter is assumed to be the same for start and end.\n\nSo, the default filtering delimiters might be specified as:\n\n<delimiters>\n\u00a0\u00a0<delimiter>${*}</delimiter>\n\u00a0\u00a0<delimiter>@</delimiter>\n</delimiters>\n\nSince the \'@\' delimiter is the same on both ends, we don\'t need to specify \'@*@\' (though we can).\n", 3 );
272                 append( sb, "", 0 );
273 
274                 append( sb, "encoding (Default: ${project.build.sourceEncoding})", 2 );
275                 append( sb, "The character encoding scheme to be applied when filtering resources.", 3 );
276                 append( sb, "Expression: ${encoding}", 3 );
277                 append( sb, "", 0 );
278 
279                 append( sb, "escapeString", 2 );
280                 append( sb, "Expression preceded with the String won\'t be interpolated \\${foo} will be replaced with ${foo}", 3 );
281                 append( sb, "Expression: ${maven.resources.escapeString}", 3 );
282                 append( sb, "", 0 );
283 
284                 append( sb, "escapeWindowsPaths (Default: true)", 2 );
285                 append( sb, "Whether to escape backslashes and colons in windows-style paths.", 3 );
286                 append( sb, "Expression: ${maven.resources.escapeWindowsPaths}", 3 );
287                 append( sb, "", 0 );
288 
289                 append( sb, "filters", 2 );
290                 append( sb, "The list of extra filter properties files to be used along with System properties, project properties, and filter properties files specified in the POM build/filters section, which should be used for the filtering during the current mojo execution.\nNormally, these will be configured from a plugin\'s execution section, to provide a different set of filters for a particular execution. For instance, starting in Maven 2.2.0, you have the option of configuring executions with the id\'s default-resources and default-testResources to supply different configurations for the two different types of resources. By supplying extraFilters configurations, you can separate which filters are used for which type of resource.", 3 );
291                 append( sb, "", 0 );
292 
293                 append( sb, "includeEmptyDirs (Default: false)", 2 );
294                 append( sb, "Copy any empty directories included in the Ressources.", 3 );
295                 append( sb, "Expression: ${maven.resources.includeEmptyDirs}", 3 );
296                 append( sb, "", 0 );
297 
298                 append( sb, "mavenFilteringHints", 2 );
299                 append( sb, "List of plexus components hint which implements MavenResourcesFiltering.filterResources(). They will be executed after the resources copying/filtering.\n", 3 );
300                 append( sb, "", 0 );
301 
302                 append( sb, "nonFilteredFileExtensions", 2 );
303                 append( sb, "Additional file extensions to not apply filtering (already defined are : jpg, jpeg, gif, bmp, png)", 3 );
304                 append( sb, "", 0 );
305 
306                 append( sb, "outputDirectory", 2 );
307                 append( sb, "The output directory into which to copy the resources.", 3 );
308                 append( sb, "Required: Yes", 3 );
309                 append( sb, "Expression: ${project.build.testOutputDirectory}", 3 );
310                 append( sb, "", 0 );
311 
312                 append( sb, "overwrite (Default: false)", 2 );
313                 append( sb, "Overwrite existing files even if the destination files are newer.", 3 );
314                 append( sb, "Expression: ${maven.resources.overwrite}", 3 );
315                 append( sb, "", 0 );
316 
317                 append( sb, "supportMultiLineFiltering (Default: false)", 2 );
318                 append( sb, "stop searching endToken at the end of line", 3 );
319                 append( sb, "Expression: ${maven.resources.supportMultiLineFiltering}", 3 );
320                 append( sb, "", 0 );
321 
322                 append( sb, "useBuildFilters (Default: true)", 2 );
323                 append( sb, "If false, don\'t use the filters specified in the build/filters section of the POM when processing resources in this mojo execution.\nSee also: ResourcesMojo.buildFilters and ResourcesMojo.filters", 3 );
324                 append( sb, "", 0 );
325 
326                 append( sb, "useDefaultDelimiters (Default: true)", 2 );
327                 append( sb, "(no description available)", 3 );
328                 append( sb, "", 0 );
329             }
330         }
331 
332         if ( getLog().isInfoEnabled() )
333         {
334             getLog().info( sb.toString() );
335         }
336     }
337 
338     /**
339      * <p>Repeat a String <code>n</code> times to form a new string.</p>
340      *
341      * @param str String to repeat
342      * @param repeat number of times to repeat str
343      * @return String with repeated String
344      * @throws NegativeArraySizeException if <code>repeat < 0</code>
345      * @throws NullPointerException if str is <code>null</code>
346      */
347     private static String repeat( String str, int repeat )
348     {
349         StringBuffer buffer = new StringBuffer( repeat * str.length() );
350 
351         for ( int i = 0; i < repeat; i++ )
352         {
353             buffer.append( str );
354         }
355 
356         return buffer.toString();
357     }
358 
359     /** 
360      * Append a description to the buffer by respecting the indentSize and lineLength parameters.
361      * <b>Note</b>: The last character is always a new line.
362      * 
363      * @param sb The buffer to append the description, not <code>null</code>.
364      * @param description The description, not <code>null</code>.
365      * @param indent The base indentation level of each line, must not be negative.
366      */
367     private void append( StringBuffer sb, String description, int indent )
368     {
369         for ( Iterator it = toLines( description, indent, indentSize, lineLength ).iterator(); it.hasNext(); )
370         {
371             sb.append( it.next().toString() ).append( '\n' );
372         }
373     }
374 
375     /** 
376      * Splits the specified text into lines of convenient display length.
377      * 
378      * @param text The text to split into lines, must not be <code>null</code>.
379      * @param indent The base indentation level of each line, must not be negative.
380      * @param indentSize The size of each indentation, must not be negative.
381      * @param lineLength The length of the line, must not be negative.
382      * @return The sequence of display lines, never <code>null</code>.
383      * @throws NegativeArraySizeException if <code>indent < 0</code>
384      */
385     private static List toLines( String text, int indent, int indentSize, int lineLength )
386     {
387         List lines = new ArrayList();
388 
389         String ind = repeat( "\t", indent );
390         String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" );
391         for ( int i = 0; i < plainLines.length; i++ )
392         {
393             toLines( lines, ind + plainLines[i], indentSize, lineLength );
394         }
395 
396         return lines;
397     }
398 
399     /** 
400      * Adds the specified line to the output sequence, performing line wrapping if necessary.
401      * 
402      * @param lines The sequence of display lines, must not be <code>null</code>.
403      * @param line The line to add, must not be <code>null</code>.
404      * @param indentSize The size of each indentation, must not be negative.
405      * @param lineLength The length of the line, must not be negative.
406      */
407     private static void toLines( List lines, String line, int indentSize, int lineLength )
408     {
409         int lineIndent = getIndentLevel( line );
410         StringBuffer buf = new StringBuffer( 256 );
411         String[] tokens = line.split( " +" );
412         for ( int i = 0; i < tokens.length; i++ )
413         {
414             String token = tokens[i];
415             if ( i > 0 )
416             {
417                 if ( buf.length() + token.length() >= lineLength )
418                 {
419                     lines.add( buf.toString() );
420                     buf.setLength( 0 );
421                     buf.append( repeat( " ", lineIndent * indentSize ) );
422                 }
423                 else
424                 {
425                     buf.append( ' ' );
426                 }
427             }
428             for ( int j = 0; j < token.length(); j++ )
429             {
430                 char c = token.charAt( j );
431                 if ( c == '\t' )
432                 {
433                     buf.append( repeat( " ", indentSize - buf.length() % indentSize ) );
434                 }
435                 else if ( c == '\u00A0' )
436                 {
437                     buf.append( ' ' );
438                 }
439                 else
440                 {
441                     buf.append( c );
442                 }
443             }
444         }
445         lines.add( buf.toString() );
446     }
447 
448     /** 
449      * Gets the indentation level of the specified line.
450      * 
451      * @param line The line whose indentation level should be retrieved, must not be <code>null</code>.
452      * @return The indentation level of the line.
453      */
454     private static int getIndentLevel( String line )
455     {
456         int level = 0;
457         for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ )
458         {
459             level++;
460         }
461         for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ )
462         {
463             if ( line.charAt( i ) == '\t' )
464             {
465                 level++;
466                 break;
467             }
468         }
469         return level;
470     }
471 }