View Javadoc

1   package org.apache.maven.plugin.antrun;
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-antrun-plugin.<br/> Call <pre>  mvn antrun:help -Ddetail=true -Dgoal=&lt;goal-name&gt;</pre> to display parameter details.
12   *
13   * @version generated on Mon Oct 31 20:24:41 EDT 2011
14   * @author org.apache.maven.tools.plugin.generator.PluginHelpGenerator (version 2.8)
15   * @goal help
16   * @requiresProject false
17   * @threadSafe
18   */
19  @SuppressWarnings( "all" )
20  public class HelpMojo
21      extends AbstractMojo
22  {
23      /**
24       * If <code>true</code>, display all settable properties for each goal.
25       * 
26       * @parameter expression="${detail}" default-value="false"
27       */
28      private boolean detail;
29  
30      /**
31       * The name of the goal for which to show help. If unspecified, all goals will be displayed.
32       * 
33       * @parameter expression="${goal}"
34       */
35      private java.lang.String goal;
36  
37      /**
38       * The maximum length of a display line, should be positive.
39       * 
40       * @parameter expression="${lineLength}" default-value="80"
41       */
42      private int lineLength;
43  
44      /**
45       * The number of spaces per indentation level, should be positive.
46       * 
47       * @parameter expression="${indentSize}" default-value="2"
48       */
49      private int indentSize;
50  
51  
52      /** {@inheritDoc} */
53      public void execute()
54          throws MojoExecutionException
55      {
56          if ( lineLength <= 0 )
57          {
58              getLog().warn( "The parameter 'lineLength' should be positive, using '80' as default." );
59              lineLength = 80;
60          }
61          if ( indentSize <= 0 )
62          {
63              getLog().warn( "The parameter 'indentSize' should be positive, using '2' as default." );
64              indentSize = 2;
65          }
66  
67          StringBuffer sb = new StringBuffer();
68  
69          append( sb, "org.apache.maven.plugins:maven-antrun-plugin:1.7", 0 );
70          append( sb, "", 0 );
71  
72          append( sb, "Maven AntRun Plugin", 0 );
73          append( sb, "Runs Ant scripts embedded in the POM", 1 );
74          append( sb, "", 0 );
75  
76          if ( goal == null || goal.length() <= 0 )
77          {
78              append( sb, "This plugin has 2 goals:", 0 );
79              append( sb, "", 0 );
80          }
81  
82          if ( goal == null || goal.length() <= 0 || "help".equals( goal ) )
83          {
84              append( sb, "antrun:help", 0 );
85              append( sb, "Display help information on maven-antrun-plugin.\nCall\n\u00a0\u00a0mvn\u00a0antrun:help\u00a0-Ddetail=true\u00a0-Dgoal=<goal-name>\nto display parameter details.", 1 );
86              append( sb, "", 0 );
87              if ( detail )
88              {
89                  append( sb, "Available parameters:", 1 );
90                  append( sb, "", 0 );
91  
92                  append( sb, "detail (Default: false)", 2 );
93                  append( sb, "If true, display all settable properties for each goal.", 3 );
94                  append( sb, "Expression: ${detail}", 3 );
95                  append( sb, "", 0 );
96  
97                  append( sb, "goal", 2 );
98                  append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 3 );
99                  append( sb, "Expression: ${goal}", 3 );
100                 append( sb, "", 0 );
101 
102                 append( sb, "indentSize (Default: 2)", 2 );
103                 append( sb, "The number of spaces per indentation level, should be positive.", 3 );
104                 append( sb, "Expression: ${indentSize}", 3 );
105                 append( sb, "", 0 );
106 
107                 append( sb, "lineLength (Default: 80)", 2 );
108                 append( sb, "The maximum length of a display line, should be positive.", 3 );
109                 append( sb, "Expression: ${lineLength}", 3 );
110                 append( sb, "", 0 );
111             }
112         }
113 
114         if ( goal == null || goal.length() <= 0 || "run".equals( goal ) )
115         {
116             append( sb, "antrun:run", 0 );
117             append( sb, "Maven AntRun Mojo.\nThis plugin provides the capability of calling Ant tasks from a POM by running the nested ant tasks inside the <tasks/> parameter. It is encouraged to move the actual tasks to a separate build.xml file and call that file with an <ant/> task.", 1 );
118             append( sb, "", 0 );
119             if ( detail )
120             {
121                 append( sb, "Available parameters:", 1 );
122                 append( sb, "", 0 );
123 
124                 append( sb, "customTaskPrefix", 2 );
125                 append( sb, "The xml tag prefix to use for the built in Ant tasks. This prefix needs to be prepended to each task referenced in the antrun target config. For example, a prefix of \'mvn\' means that the attachartifact task is referenced by \'<mvn:attachartifact>\' The default value of an empty string means that no prefix is used for the tasks.", 3 );
126                 append( sb, "", 0 );
127 
128                 append( sb, "exportAntProperties (Default: false)", 2 );
129                 append( sb, "Specifies whether the Ant properties should be propagated to the Maven properties.", 3 );
130                 append( sb, "", 0 );
131 
132                 append( sb, "failOnError (Default: true)", 2 );
133                 append( sb, "Specifies whether a failure in the ant build leads to a failure of the Maven build. If this value is \'true\', the Maven build will proceed even if the ant build fails. If it is \'false\', then the Maven build fails if the ant build fails.", 3 );
134                 append( sb, "", 0 );
135 
136                 append( sb, "propertyPrefix", 2 );
137                 append( sb, "String to prepend to project and dependency property names.", 3 );
138                 append( sb, "", 0 );
139 
140                 append( sb, "skip (Default: false)", 2 );
141                 append( sb, "Specifies whether the Antrun execution should be skipped.", 3 );
142                 append( sb, "Expression: ${maven.antrun.skip}", 3 );
143                 append( sb, "", 0 );
144 
145                 append( sb, "sourceRoot", 2 );
146                 append( sb, "Deprecated. Use the build-helper-maven-plugin to bind source directories", 3 );
147                 append( sb, "", 0 );
148                 append( sb, "This folder is added to the list of those folders containing source to be compiled. Use this if your ant script generates source code.", 3 );
149                 append( sb, "Expression: ${sourceRoot}", 3 );
150                 append( sb, "", 0 );
151 
152                 append( sb, "target", 2 );
153                 append( sb, "The XML for the Ant target. You can add anything you can add between <target> and </target> in a build.xml.", 3 );
154                 append( sb, "", 0 );
155 
156                 append( sb, "tasks", 2 );
157                 append( sb, "Deprecated. Use target instead", 3 );
158                 append( sb, "", 0 );
159                 append( sb, "The XML for the Ant task. You can add anything you can add between <target> and </target> in a build.xml.", 3 );
160                 append( sb, "", 0 );
161 
162                 append( sb, "testSourceRoot", 2 );
163                 append( sb, "Deprecated. Use the build-helper-maven-plugin to bind test source directories", 3 );
164                 append( sb, "", 0 );
165                 append( sb, "This folder is added to the list of those folders containing source to be compiled for testing. Use this if your ant script generates test source code.", 3 );
166                 append( sb, "Expression: ${testSourceRoot}", 3 );
167                 append( sb, "", 0 );
168 
169                 append( sb, "versionsPropertyName (Default: maven.project.dependencies.versions)", 2 );
170                 append( sb, "The name of a property containing the list of all dependency versions. This is used for the removing the versions from the filenames.", 3 );
171                 append( sb, "", 0 );
172             }
173         }
174 
175         if ( getLog().isInfoEnabled() )
176         {
177             getLog().info( sb.toString() );
178         }
179     }
180 
181     /**
182      * <p>Repeat a String <code>n</code> times to form a new string.</p>
183      *
184      * @param str String to repeat
185      * @param repeat number of times to repeat str
186      * @return String with repeated String
187      * @throws NegativeArraySizeException if <code>repeat < 0</code>
188      * @throws NullPointerException if str is <code>null</code>
189      */
190     private static String repeat( String str, int repeat )
191     {
192         StringBuffer buffer = new StringBuffer( repeat * str.length() );
193 
194         for ( int i = 0; i < repeat; i++ )
195         {
196             buffer.append( str );
197         }
198 
199         return buffer.toString();
200     }
201 
202     /** 
203      * Append a description to the buffer by respecting the indentSize and lineLength parameters.
204      * <b>Note</b>: The last character is always a new line.
205      * 
206      * @param sb The buffer to append the description, not <code>null</code>.
207      * @param description The description, not <code>null</code>.
208      * @param indent The base indentation level of each line, must not be negative.
209      */
210     private void append( StringBuffer sb, String description, int indent )
211     {
212         for ( Iterator it = toLines( description, indent, indentSize, lineLength ).iterator(); it.hasNext(); )
213         {
214             sb.append( it.next().toString() ).append( '\n' );
215         }
216     }
217 
218     /** 
219      * Splits the specified text into lines of convenient display length.
220      * 
221      * @param text The text to split into lines, must not be <code>null</code>.
222      * @param indent The base indentation level of each line, must not be negative.
223      * @param indentSize The size of each indentation, must not be negative.
224      * @param lineLength The length of the line, must not be negative.
225      * @return The sequence of display lines, never <code>null</code>.
226      * @throws NegativeArraySizeException if <code>indent < 0</code>
227      */
228     private static List toLines( String text, int indent, int indentSize, int lineLength )
229     {
230         List<String> lines = new ArrayList<String>();
231 
232         String ind = repeat( "\t", indent );
233         String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" );
234         for ( int i = 0; i < plainLines.length; i++ )
235         {
236             toLines( lines, ind + plainLines[i], indentSize, lineLength );
237         }
238 
239         return lines;
240     }
241 
242     /** 
243      * Adds the specified line to the output sequence, performing line wrapping if necessary.
244      * 
245      * @param lines The sequence of display lines, must not be <code>null</code>.
246      * @param line The line to add, must not be <code>null</code>.
247      * @param indentSize The size of each indentation, must not be negative.
248      * @param lineLength The length of the line, must not be negative.
249      */
250     private static void toLines( List<String> lines, String line, int indentSize, int lineLength )
251     {
252         int lineIndent = getIndentLevel( line );
253         StringBuffer buf = new StringBuffer( 256 );
254         String[] tokens = line.split( " +" );
255         for ( int i = 0; i < tokens.length; i++ )
256         {
257             String token = tokens[i];
258             if ( i > 0 )
259             {
260                 if ( buf.length() + token.length() >= lineLength )
261                 {
262                     lines.add( buf.toString() );
263                     buf.setLength( 0 );
264                     buf.append( repeat( " ", lineIndent * indentSize ) );
265                 }
266                 else
267                 {
268                     buf.append( ' ' );
269                 }
270             }
271             for ( int j = 0; j < token.length(); j++ )
272             {
273                 char c = token.charAt( j );
274                 if ( c == '\t' )
275                 {
276                     buf.append( repeat( " ", indentSize - buf.length() % indentSize ) );
277                 }
278                 else if ( c == '\u00A0' )
279                 {
280                     buf.append( ' ' );
281                 }
282                 else
283                 {
284                     buf.append( c );
285                 }
286             }
287         }
288         lines.add( buf.toString() );
289     }
290 
291     /** 
292      * Gets the indentation level of the specified line.
293      * 
294      * @param line The line whose indentation level should be retrieved, must not be <code>null</code>.
295      * @return The indentation level of the line.
296      */
297     private static int getIndentLevel( String line )
298     {
299         int level = 0;
300         for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ )
301         {
302             level++;
303         }
304         for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ )
305         {
306             if ( line.charAt( i ) == '\t' )
307             {
308                 level++;
309                 break;
310             }
311         }
312         return level;
313     }
314 }