View Javadoc

1   package org.apache.maven.plugin.deploy;
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-deploy-plugin.<br/> Call <pre>  mvn deploy:help -Ddetail=true -Dgoal=&lt;goal-name&gt;</pre> to display parameter details.
12   *
13   * @version generated on Mon May 09 15:50:27 CDT 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-deploy-plugin:2.6", 0 );
69          append( sb, "", 0 );
70  
71          append( sb, "Maven Deploy Plugin", 0 );
72          append( sb, "Uploads the project artifacts to the internal remote repository.", 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 || "deploy".equals( goal ) )
82          {
83              append( sb, "deploy:deploy", 0 );
84              append( sb, "Deploys an artifact to remote repository.", 1 );
85              append( sb, "", 0 );
86              if ( detail )
87              {
88                  append( sb, "Available parameters:", 1 );
89                  append( sb, "", 0 );
90  
91                  append( sb, "altDeploymentRepository", 2 );
92                  append( sb, "Specifies an alternative repository to which the project artifacts should be deployed ( other than those specified in <distributionManagement> ).\nFormat: id::layout::url", 3 );
93                  append( sb, "Expression: ${altDeploymentRepository}", 3 );
94                  append( sb, "", 0 );
95  
96                  append( sb, "skip (Default: false)", 2 );
97                  append( sb, "Set this to \'true\' to bypass artifact deploy", 3 );
98                  append( sb, "Expression: ${maven.deploy.skip}", 3 );
99                  append( sb, "", 0 );
100 
101                 append( sb, "updateReleaseInfo (Default: false)", 2 );
102                 append( sb, "Parameter used to update the metadata to make the artifact as release.", 3 );
103                 append( sb, "Expression: ${updateReleaseInfo}", 3 );
104                 append( sb, "", 0 );
105             }
106         }
107 
108         if ( goal == null || goal.length() <= 0 || "deploy-file".equals( goal ) )
109         {
110             append( sb, "deploy:deploy-file", 0 );
111             append( sb, "Installs the artifact in the remote repository.", 1 );
112             append( sb, "", 0 );
113             if ( detail )
114             {
115                 append( sb, "Available parameters:", 1 );
116                 append( sb, "", 0 );
117 
118                 append( sb, "artifactId", 2 );
119                 append( sb, "ArtifactId of the artifact to be deployed. Retrieved from POM file if specified.", 3 );
120                 append( sb, "Expression: ${artifactId}", 3 );
121                 append( sb, "", 0 );
122 
123                 append( sb, "classifier", 2 );
124                 append( sb, "Add classifier to the artifact", 3 );
125                 append( sb, "Expression: ${classifier}", 3 );
126                 append( sb, "", 0 );
127 
128                 append( sb, "description", 2 );
129                 append( sb, "Description passed to a generated POM file (in case of generatePom=true)", 3 );
130                 append( sb, "Expression: ${generatePom.description}", 3 );
131                 append( sb, "", 0 );
132 
133                 append( sb, "file", 2 );
134                 append( sb, "File to be deployed.", 3 );
135                 append( sb, "Required: Yes", 3 );
136                 append( sb, "Expression: ${file}", 3 );
137                 append( sb, "", 0 );
138 
139                 append( sb, "generatePom (Default: true)", 2 );
140                 append( sb, "Upload a POM for this artifact. Will generate a default POM if none is supplied with the pomFile argument.", 3 );
141                 append( sb, "Expression: ${generatePom}", 3 );
142                 append( sb, "", 0 );
143 
144                 append( sb, "groupId", 2 );
145                 append( sb, "GroupId of the artifact to be deployed. Retrieved from POM file if specified.", 3 );
146                 append( sb, "Expression: ${groupId}", 3 );
147                 append( sb, "", 0 );
148 
149                 append( sb, "javadoc", 2 );
150                 append( sb, "The bundled API docs for the artifact.", 3 );
151                 append( sb, "Expression: ${javadoc}", 3 );
152                 append( sb, "", 0 );
153 
154                 append( sb, "packaging", 2 );
155                 append( sb, "Type of the artifact to be deployed. Retrieved from POM file if specified. Defaults to file extension if not specified via command line or POM.", 3 );
156                 append( sb, "Expression: ${packaging}", 3 );
157                 append( sb, "", 0 );
158 
159                 append( sb, "pomFile", 2 );
160                 append( sb, "Location of an existing POM file to be deployed alongside the main artifact, given by the ${file} parameter.", 3 );
161                 append( sb, "Expression: ${pomFile}", 3 );
162                 append( sb, "", 0 );
163 
164                 append( sb, "repositoryId (Default: remote-repository)", 2 );
165                 append( sb, "Server Id to map on the <id> under <server> section of settings.xml In most cases, this parameter will be required for authentication.", 3 );
166                 append( sb, "Required: Yes", 3 );
167                 append( sb, "Expression: ${repositoryId}", 3 );
168                 append( sb, "", 0 );
169 
170                 append( sb, "repositoryLayout (Default: default)", 2 );
171                 append( sb, "The type of remote repository layout to deploy to. Try legacy for a Maven 1.x-style repository layout.", 3 );
172                 append( sb, "Expression: ${repositoryLayout}", 3 );
173                 append( sb, "", 0 );
174 
175                 append( sb, "sources", 2 );
176                 append( sb, "The bundled sources for the artifact.", 3 );
177                 append( sb, "Expression: ${sources}", 3 );
178                 append( sb, "", 0 );
179 
180                 append( sb, "uniqueVersion (Default: true)", 2 );
181                 append( sb, "Whether to deploy snapshots with a unique version or not.", 3 );
182                 append( sb, "Expression: ${uniqueVersion}", 3 );
183                 append( sb, "", 0 );
184 
185                 append( sb, "updateReleaseInfo (Default: false)", 2 );
186                 append( sb, "Parameter used to update the metadata to make the artifact as release.", 3 );
187                 append( sb, "Expression: ${updateReleaseInfo}", 3 );
188                 append( sb, "", 0 );
189 
190                 append( sb, "url", 2 );
191                 append( sb, "URL where the artifact will be deployed.\nie ( file:///C:/m2-repo or scp://host.com/path/to/repo )", 3 );
192                 append( sb, "Required: Yes", 3 );
193                 append( sb, "Expression: ${url}", 3 );
194                 append( sb, "", 0 );
195 
196                 append( sb, "version", 2 );
197                 append( sb, "Version of the artifact to be deployed. Retrieved from POM file if specified.", 3 );
198                 append( sb, "Expression: ${version}", 3 );
199                 append( sb, "", 0 );
200             }
201         }
202 
203         if ( goal == null || goal.length() <= 0 || "help".equals( goal ) )
204         {
205             append( sb, "deploy:help", 0 );
206             append( sb, "Display help information on maven-deploy-plugin.\nCall\n\u00a0\u00a0mvn\u00a0deploy:help\u00a0-Ddetail=true\u00a0-Dgoal=<goal-name>\nto display parameter details.", 1 );
207             append( sb, "", 0 );
208             if ( detail )
209             {
210                 append( sb, "Available parameters:", 1 );
211                 append( sb, "", 0 );
212 
213                 append( sb, "detail (Default: false)", 2 );
214                 append( sb, "If true, display all settable properties for each goal.", 3 );
215                 append( sb, "Expression: ${detail}", 3 );
216                 append( sb, "", 0 );
217 
218                 append( sb, "goal", 2 );
219                 append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 3 );
220                 append( sb, "Expression: ${goal}", 3 );
221                 append( sb, "", 0 );
222 
223                 append( sb, "indentSize (Default: 2)", 2 );
224                 append( sb, "The number of spaces per indentation level, should be positive.", 3 );
225                 append( sb, "Expression: ${indentSize}", 3 );
226                 append( sb, "", 0 );
227 
228                 append( sb, "lineLength (Default: 80)", 2 );
229                 append( sb, "The maximum length of a display line, should be positive.", 3 );
230                 append( sb, "Expression: ${lineLength}", 3 );
231                 append( sb, "", 0 );
232             }
233         }
234 
235         if ( getLog().isInfoEnabled() )
236         {
237             getLog().info( sb.toString() );
238         }
239     }
240 
241     /**
242      * <p>Repeat a String <code>n</code> times to form a new string.</p>
243      *
244      * @param str String to repeat
245      * @param repeat number of times to repeat str
246      * @return String with repeated String
247      * @throws NegativeArraySizeException if <code>repeat < 0</code>
248      * @throws NullPointerException if str is <code>null</code>
249      */
250     private static String repeat( String str, int repeat )
251     {
252         StringBuffer buffer = new StringBuffer( repeat * str.length() );
253 
254         for ( int i = 0; i < repeat; i++ )
255         {
256             buffer.append( str );
257         }
258 
259         return buffer.toString();
260     }
261 
262     /** 
263      * Append a description to the buffer by respecting the indentSize and lineLength parameters.
264      * <b>Note</b>: The last character is always a new line.
265      * 
266      * @param sb The buffer to append the description, not <code>null</code>.
267      * @param description The description, not <code>null</code>.
268      * @param indent The base indentation level of each line, must not be negative.
269      */
270     private void append( StringBuffer sb, String description, int indent )
271     {
272         for ( Iterator it = toLines( description, indent, indentSize, lineLength ).iterator(); it.hasNext(); )
273         {
274             sb.append( it.next().toString() ).append( '\n' );
275         }
276     }
277 
278     /** 
279      * Splits the specified text into lines of convenient display length.
280      * 
281      * @param text The text to split into lines, must not be <code>null</code>.
282      * @param indent The base indentation level of each line, must not be negative.
283      * @param indentSize The size of each indentation, must not be negative.
284      * @param lineLength The length of the line, must not be negative.
285      * @return The sequence of display lines, never <code>null</code>.
286      * @throws NegativeArraySizeException if <code>indent < 0</code>
287      */
288     private static List toLines( String text, int indent, int indentSize, int lineLength )
289     {
290         List lines = new ArrayList();
291 
292         String ind = repeat( "\t", indent );
293         String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" );
294         for ( int i = 0; i < plainLines.length; i++ )
295         {
296             toLines( lines, ind + plainLines[i], indentSize, lineLength );
297         }
298 
299         return lines;
300     }
301 
302     /** 
303      * Adds the specified line to the output sequence, performing line wrapping if necessary.
304      * 
305      * @param lines The sequence of display lines, must not be <code>null</code>.
306      * @param line The line to add, must not be <code>null</code>.
307      * @param indentSize The size of each indentation, must not be negative.
308      * @param lineLength The length of the line, must not be negative.
309      */
310     private static void toLines( List lines, String line, int indentSize, int lineLength )
311     {
312         int lineIndent = getIndentLevel( line );
313         StringBuffer buf = new StringBuffer( 256 );
314         String[] tokens = line.split( " +" );
315         for ( int i = 0; i < tokens.length; i++ )
316         {
317             String token = tokens[i];
318             if ( i > 0 )
319             {
320                 if ( buf.length() + token.length() >= lineLength )
321                 {
322                     lines.add( buf.toString() );
323                     buf.setLength( 0 );
324                     buf.append( repeat( " ", lineIndent * indentSize ) );
325                 }
326                 else
327                 {
328                     buf.append( ' ' );
329                 }
330             }
331             for ( int j = 0; j < token.length(); j++ )
332             {
333                 char c = token.charAt( j );
334                 if ( c == '\t' )
335                 {
336                     buf.append( repeat( " ", indentSize - buf.length() % indentSize ) );
337                 }
338                 else if ( c == '\u00A0' )
339                 {
340                     buf.append( ' ' );
341                 }
342                 else
343                 {
344                     buf.append( c );
345                 }
346             }
347         }
348         lines.add( buf.toString() );
349     }
350 
351     /** 
352      * Gets the indentation level of the specified line.
353      * 
354      * @param line The line whose indentation level should be retrieved, must not be <code>null</code>.
355      * @return The indentation level of the line.
356      */
357     private static int getIndentLevel( String line )
358     {
359         int level = 0;
360         for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ )
361         {
362             level++;
363         }
364         for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ )
365         {
366             if ( line.charAt( i ) == '\t' )
367             {
368                 level++;
369                 break;
370             }
371         }
372         return level;
373     }
374 }