View Javadoc

1   package org.apache.maven.plugin.ear;
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-ear-plugin.<br/> Call <pre>  mvn ear:help -Ddetail=true -Dgoal=&lt;goal-name&gt;</pre> to display parameter details.
12   *
13   * @version generated on Mon Jun 06 10:03:22 CEST 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-ear-plugin:2.6", 0 );
69          append( sb, "", 0 );
70  
71          append( sb, "Maven EAR Plugin", 0 );
72          append( sb, "Generates a J2EE Enterprise Archive (EAR) file.", 1 );
73          append( sb, "", 0 );
74  
75          if ( goal == null || goal.length() <= 0 )
76          {
77              append( sb, "This plugin has 3 goals:", 0 );
78              append( sb, "", 0 );
79          }
80  
81          if ( goal == null || goal.length() <= 0 || "ear".equals( goal ) )
82          {
83              append( sb, "ear:ear", 0 );
84              append( sb, "Builds J2EE Enterprise Archive (EAR) files.", 1 );
85              append( sb, "", 0 );
86              if ( detail )
87              {
88                  append( sb, "Available parameters:", 1 );
89                  append( sb, "", 0 );
90  
91                  append( sb, "applicationXml", 2 );
92                  append( sb, "The location of a custom application.xml file to be used within the ear file.", 3 );
93                  append( sb, "", 0 );
94  
95                  append( sb, "archive", 2 );
96                  append( sb, "The archive configuration to use. See Maven Archiver Reference.", 3 );
97                  append( sb, "", 0 );
98  
99                  append( sb, "artifactTypeMappings", 2 );
100                 append( sb, "The artifact type mappings.", 3 );
101                 append( sb, "", 0 );
102 
103                 append( sb, "classifier", 2 );
104                 append( sb, "Classifier to add to the artifact generated. If given, the artifact will be an attachment instead.", 3 );
105                 append( sb, "", 0 );
106 
107                 append( sb, "defaultLibBundleDir", 2 );
108                 append( sb, "The default bundle dir for libraries.", 3 );
109                 append( sb, "", 0 );
110 
111                 append( sb, "earSourceDirectory (Default: ${basedir}/src/main/application)", 2 );
112                 append( sb, "Single directory for extra files to include in the EAR.", 3 );
113                 append( sb, "Required: Yes", 3 );
114                 append( sb, "", 0 );
115 
116                 append( sb, "earSourceExcludes", 2 );
117                 append( sb, "The comma separated list of tokens to exclude from the EAR.", 3 );
118                 append( sb, "", 0 );
119 
120                 append( sb, "earSourceIncludes (Default: **)", 2 );
121                 append( sb, "The comma separated list of tokens to include in the EAR.", 3 );
122                 append( sb, "", 0 );
123 
124                 append( sb, "encoding (Default: UTF-8)", 2 );
125                 append( sb, "Character encoding for the auto-generated deployment file(s).", 3 );
126                 append( sb, "", 0 );
127 
128                 append( sb, "escapedBackslashesInFilePath (Default: false)", 2 );
129                 append( sb, "To escape interpolated value with windows path c:\\foo\\bar will be replaced with c:\\\\foo\\\\bar", 3 );
130                 append( sb, "Expression: ${maven.ear.escapedBackslashesInFilePath}", 3 );
131                 append( sb, "", 0 );
132 
133                 append( sb, "escapeString", 2 );
134                 append( sb, "Expression preceded with the String won\'t be interpolated \\${foo} will be replaced with ${foo}", 3 );
135                 append( sb, "Expression: ${maven.ear.escapeString}", 3 );
136                 append( sb, "", 0 );
137 
138                 append( sb, "fileNameMapping", 2 );
139                 append( sb, "The file name mapping to use for all dependencies included in the EAR file.", 3 );
140                 append( sb, "", 0 );
141 
142                 append( sb, "filtering (Default: false)", 2 );
143                 append( sb, "Specify that the ear sources should be filtered.", 3 );
144                 append( sb, "", 0 );
145 
146                 append( sb, "filters", 2 );
147                 append( sb, "Filters (property files) to include during the interpolation of the pom.xml.", 3 );
148                 append( sb, "", 0 );
149 
150                 append( sb, "finalName (Default: ${project.build.finalName})", 2 );
151                 append( sb, "The name of the EAR file to generate.", 3 );
152                 append( sb, "Required: Yes", 3 );
153                 append( sb, "", 0 );
154 
155                 append( sb, "generatedDescriptorLocation (Default: ${project.build.directory})", 2 );
156                 append( sb, "Directory where the deployment descriptor file(s) will be auto-generated.", 3 );
157                 append( sb, "", 0 );
158 
159                 append( sb, "includeLibInApplicationXml (Default: false)", 2 );
160                 append( sb, "Should libraries be added in application.xml", 3 );
161                 append( sb, "", 0 );
162 
163                 append( sb, "jboss", 2 );
164                 append( sb, "The JBoss specific configuration.", 3 );
165                 append( sb, "", 0 );
166 
167                 append( sb, "mainArtifactId", 2 );
168                 append( sb, "The id to use to define the main artifact (e.g. the artifact without a classifier) when there is multiple candidates.", 3 );
169                 append( sb, "", 0 );
170 
171                 append( sb, "manifestFile", 2 );
172                 append( sb, "The location of the manifest file to be used within the ear file. If not value if specified, the default location in the workDirectory is taken. If the file does not exist, a manifest will be generated automatically.", 3 );
173                 append( sb, "", 0 );
174 
175                 append( sb, "modules", 2 );
176                 append( sb, "The ear modules configuration.", 3 );
177                 append( sb, "", 0 );
178 
179                 append( sb, "nonFilteredFileExtensions", 2 );
180                 append( sb, "A list of file extensions that should not be filtered if filtering is enabled.", 3 );
181                 append( sb, "", 0 );
182 
183                 append( sb, "outputDirectory (Default: ${project.build.directory})", 2 );
184                 append( sb, "The directory for the generated EAR.", 3 );
185                 append( sb, "Required: Yes", 3 );
186                 append( sb, "", 0 );
187 
188                 append( sb, "resourcesDir", 2 );
189                 append( sb, "Deprecated. please use earSourceDirectory instead", 3 );
190                 append( sb, "", 0 );
191                 append( sb, "The directory to get the resources from.", 3 );
192                 append( sb, "", 0 );
193 
194                 append( sb, "unpackTypes", 2 );
195                 append( sb, "The comma separated list of artifact\'s type(s) to unpack by default.", 3 );
196                 append( sb, "", 0 );
197 
198                 append( sb, "version (Default: 1.3)", 2 );
199                 append( sb, "The version of the application.xml to generate. Valid values are 1.3, 1.4, 5 and 6.", 3 );
200                 append( sb, "", 0 );
201 
202                 append( sb, "workDirectory (Default: ${project.build.directory}/${project.build.finalName})", 2 );
203                 append( sb, "Directory that resources are copied to during the build.", 3 );
204                 append( sb, "Required: Yes", 3 );
205                 append( sb, "", 0 );
206             }
207         }
208 
209         if ( goal == null || goal.length() <= 0 || "generate-application-xml".equals( goal ) )
210         {
211             append( sb, "ear:generate-application-xml", 0 );
212             append( sb, "A Mojo that generates the EAR deployment descriptor file(s).", 1 );
213             append( sb, "", 0 );
214             if ( detail )
215             {
216                 append( sb, "Available parameters:", 1 );
217                 append( sb, "", 0 );
218 
219                 append( sb, "applicationName", 2 );
220                 append( sb, "Application name of the application to be used when the application.xml file is auto-generated. Since JavaEE6.", 3 );
221                 append( sb, "", 0 );
222 
223                 append( sb, "artifactTypeMappings", 2 );
224                 append( sb, "The artifact type mappings.", 3 );
225                 append( sb, "", 0 );
226 
227                 append( sb, "defaultLibBundleDir", 2 );
228                 append( sb, "The default bundle dir for libraries.", 3 );
229                 append( sb, "", 0 );
230 
231                 append( sb, "description (Default: ${project.description})", 2 );
232                 append( sb, "Description of the application to be used when the application.xml file is auto-generated.", 3 );
233                 append( sb, "", 0 );
234 
235                 append( sb, "displayName (Default: ${project.artifactId})", 2 );
236                 append( sb, "Display name of the application to be used when the application.xml file is auto-generated.", 3 );
237                 append( sb, "", 0 );
238 
239                 append( sb, "encoding (Default: UTF-8)", 2 );
240                 append( sb, "Character encoding for the auto-generated deployment file(s).", 3 );
241                 append( sb, "", 0 );
242 
243                 append( sb, "fileNameMapping", 2 );
244                 append( sb, "The file name mapping to use for all dependencies included in the EAR file.", 3 );
245                 append( sb, "", 0 );
246 
247                 append( sb, "generateApplicationXml (Default: true)", 2 );
248                 append( sb, "Whether the application.xml should be generated or not.", 3 );
249                 append( sb, "", 0 );
250 
251                 append( sb, "generatedDescriptorLocation (Default: ${project.build.directory})", 2 );
252                 append( sb, "Directory where the deployment descriptor file(s) will be auto-generated.", 3 );
253                 append( sb, "", 0 );
254 
255                 append( sb, "generateModuleId (Default: false)", 2 );
256                 append( sb, "Whether a module ID should be generated if none is specified.", 3 );
257                 append( sb, "", 0 );
258 
259                 append( sb, "includeLibInApplicationXml (Default: false)", 2 );
260                 append( sb, "Should libraries be added in application.xml", 3 );
261                 append( sb, "", 0 );
262 
263                 append( sb, "initializeInOrder", 2 );
264                 append( sb, "Defines the value of the initialize in order element to be used when the application.xml file is auto-generated. When set to true, modules must be initialized in the order they\'re listed in this deployment descriptor, with the exception of application client modules, which can be initialized in any order. If initialize-in-order is not set or set to false, the order of initialization is unspecified and may be product-dependent. Since JavaEE6.", 3 );
265                 append( sb, "", 0 );
266 
267                 append( sb, "jboss", 2 );
268                 append( sb, "The JBoss specific configuration.", 3 );
269                 append( sb, "", 0 );
270 
271                 append( sb, "mainArtifactId", 2 );
272                 append( sb, "The id to use to define the main artifact (e.g. the artifact without a classifier) when there is multiple candidates.", 3 );
273                 append( sb, "", 0 );
274 
275                 append( sb, "modules", 2 );
276                 append( sb, "The ear modules configuration.", 3 );
277                 append( sb, "", 0 );
278 
279                 append( sb, "security", 2 );
280                 append( sb, "The security-roles to be added to the auto-generated application.xml file.", 3 );
281                 append( sb, "", 0 );
282 
283                 append( sb, "version (Default: 1.3)", 2 );
284                 append( sb, "The version of the application.xml to generate. Valid values are 1.3, 1.4, 5 and 6.", 3 );
285                 append( sb, "", 0 );
286 
287                 append( sb, "workDirectory (Default: ${project.build.directory}/${project.build.finalName})", 2 );
288                 append( sb, "Directory that resources are copied to during the build.", 3 );
289                 append( sb, "Required: Yes", 3 );
290                 append( sb, "", 0 );
291             }
292         }
293 
294         if ( goal == null || goal.length() <= 0 || "help".equals( goal ) )
295         {
296             append( sb, "ear:help", 0 );
297             append( sb, "Display help information on maven-ear-plugin.\nCall\n\u00a0\u00a0mvn\u00a0ear:help\u00a0-Ddetail=true\u00a0-Dgoal=<goal-name>\nto display parameter details.", 1 );
298             append( sb, "", 0 );
299             if ( detail )
300             {
301                 append( sb, "Available parameters:", 1 );
302                 append( sb, "", 0 );
303 
304                 append( sb, "detail (Default: false)", 2 );
305                 append( sb, "If true, display all settable properties for each goal.", 3 );
306                 append( sb, "Expression: ${detail}", 3 );
307                 append( sb, "", 0 );
308 
309                 append( sb, "goal", 2 );
310                 append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 3 );
311                 append( sb, "Expression: ${goal}", 3 );
312                 append( sb, "", 0 );
313 
314                 append( sb, "indentSize (Default: 2)", 2 );
315                 append( sb, "The number of spaces per indentation level, should be positive.", 3 );
316                 append( sb, "Expression: ${indentSize}", 3 );
317                 append( sb, "", 0 );
318 
319                 append( sb, "lineLength (Default: 80)", 2 );
320                 append( sb, "The maximum length of a display line, should be positive.", 3 );
321                 append( sb, "Expression: ${lineLength}", 3 );
322                 append( sb, "", 0 );
323             }
324         }
325 
326         if ( getLog().isInfoEnabled() )
327         {
328             getLog().info( sb.toString() );
329         }
330     }
331 
332     /**
333      * <p>Repeat a String <code>n</code> times to form a new string.</p>
334      *
335      * @param str String to repeat
336      * @param repeat number of times to repeat str
337      * @return String with repeated String
338      * @throws NegativeArraySizeException if <code>repeat < 0</code>
339      * @throws NullPointerException if str is <code>null</code>
340      */
341     private static String repeat( String str, int repeat )
342     {
343         StringBuffer buffer = new StringBuffer( repeat * str.length() );
344 
345         for ( int i = 0; i < repeat; i++ )
346         {
347             buffer.append( str );
348         }
349 
350         return buffer.toString();
351     }
352 
353     /** 
354      * Append a description to the buffer by respecting the indentSize and lineLength parameters.
355      * <b>Note</b>: The last character is always a new line.
356      * 
357      * @param sb The buffer to append the description, not <code>null</code>.
358      * @param description The description, not <code>null</code>.
359      * @param indent The base indentation level of each line, must not be negative.
360      */
361     private void append( StringBuffer sb, String description, int indent )
362     {
363         for ( Iterator it = toLines( description, indent, indentSize, lineLength ).iterator(); it.hasNext(); )
364         {
365             sb.append( it.next().toString() ).append( '\n' );
366         }
367     }
368 
369     /** 
370      * Splits the specified text into lines of convenient display length.
371      * 
372      * @param text The text to split into lines, must not be <code>null</code>.
373      * @param indent The base indentation level of each line, must not be negative.
374      * @param indentSize The size of each indentation, must not be negative.
375      * @param lineLength The length of the line, must not be negative.
376      * @return The sequence of display lines, never <code>null</code>.
377      * @throws NegativeArraySizeException if <code>indent < 0</code>
378      */
379     private static List toLines( String text, int indent, int indentSize, int lineLength )
380     {
381         List lines = new ArrayList();
382 
383         String ind = repeat( "\t", indent );
384         String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" );
385         for ( int i = 0; i < plainLines.length; i++ )
386         {
387             toLines( lines, ind + plainLines[i], indentSize, lineLength );
388         }
389 
390         return lines;
391     }
392 
393     /** 
394      * Adds the specified line to the output sequence, performing line wrapping if necessary.
395      * 
396      * @param lines The sequence of display lines, must not be <code>null</code>.
397      * @param line The line to add, must not be <code>null</code>.
398      * @param indentSize The size of each indentation, must not be negative.
399      * @param lineLength The length of the line, must not be negative.
400      */
401     private static void toLines( List lines, String line, int indentSize, int lineLength )
402     {
403         int lineIndent = getIndentLevel( line );
404         StringBuffer buf = new StringBuffer( 256 );
405         String[] tokens = line.split( " +" );
406         for ( int i = 0; i < tokens.length; i++ )
407         {
408             String token = tokens[i];
409             if ( i > 0 )
410             {
411                 if ( buf.length() + token.length() >= lineLength )
412                 {
413                     lines.add( buf.toString() );
414                     buf.setLength( 0 );
415                     buf.append( repeat( " ", lineIndent * indentSize ) );
416                 }
417                 else
418                 {
419                     buf.append( ' ' );
420                 }
421             }
422             for ( int j = 0; j < token.length(); j++ )
423             {
424                 char c = token.charAt( j );
425                 if ( c == '\t' )
426                 {
427                     buf.append( repeat( " ", indentSize - buf.length() % indentSize ) );
428                 }
429                 else if ( c == '\u00A0' )
430                 {
431                     buf.append( ' ' );
432                 }
433                 else
434                 {
435                     buf.append( c );
436                 }
437             }
438         }
439         lines.add( buf.toString() );
440     }
441 
442     /** 
443      * Gets the indentation level of the specified line.
444      * 
445      * @param line The line whose indentation level should be retrieved, must not be <code>null</code>.
446      * @return The indentation level of the line.
447      */
448     private static int getIndentLevel( String line )
449     {
450         int level = 0;
451         for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ )
452         {
453             level++;
454         }
455         for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ )
456         {
457             if ( line.charAt( i ) == '\t' )
458             {
459                 level++;
460                 break;
461             }
462         }
463         return level;
464     }
465 }