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
12
13
14
15
16
17
18
19 public class HelpMojo
20 extends AbstractMojo
21 {
22
23
24
25
26
27 private boolean detail;
28
29
30
31
32
33
34 private java.lang.String goal;
35
36
37
38
39
40
41 private int lineLength;
42
43
44
45
46
47
48 private int indentSize;
49
50
51
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
243
244
245
246
247
248
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
264
265
266
267
268
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
280
281
282
283
284
285
286
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
304
305
306
307
308
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
353
354
355
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 }