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 | 0 | public class HelpMojo |
18 | |
extends AbstractMojo |
19 | |
{ |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
private boolean detail; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
private java.lang.String goal; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
private int lineLength; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
private int indentSize; |
47 | |
|
48 | |
|
49 | |
|
50 | |
public void execute() |
51 | |
throws MojoExecutionException |
52 | |
{ |
53 | 0 | StringBuffer sb = new StringBuffer(); |
54 | |
|
55 | 0 | append( sb, "org.apache.maven.plugins:maven-deploy-plugin:2.4", 0 ); |
56 | 0 | append( sb, "", 0 ); |
57 | |
|
58 | 0 | append( sb, "Maven Deploy Plugin 2.4", 0 ); |
59 | 0 | append( sb, "Maven Plugins", 1 ); |
60 | 0 | append( sb, "", 0 ); |
61 | |
|
62 | 0 | if ( goal == null || goal.length() <= 0 ) |
63 | |
{ |
64 | 0 | append( sb, "This plugin has 3 goals:", 0 ); |
65 | 0 | append( sb, "", 0 ); |
66 | |
} |
67 | |
|
68 | 0 | if ( goal == null || goal.length() <= 0 || "deploy".equals( goal ) ) |
69 | |
{ |
70 | 0 | append( sb, "deploy:deploy", 0 ); |
71 | 0 | append( sb, "Deploys an artifact to remote repository.", 1 ); |
72 | 0 | append( sb, "", 0 ); |
73 | 0 | if ( detail ) |
74 | |
{ |
75 | 0 | append( sb, "Available parameters:", 1 ); |
76 | 0 | append( sb, "", 0 ); |
77 | |
|
78 | 0 | append( sb, "altDeploymentRepository", 2 ); |
79 | 0 | 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 ); |
80 | 0 | append( sb, "", 0 ); |
81 | |
|
82 | 0 | append( sb, "skip (Default: false)", 2 ); |
83 | 0 | append( sb, "Set this to \'true\' to bypass artifact deploy", 3 ); |
84 | 0 | append( sb, "", 0 ); |
85 | |
|
86 | 0 | append( sb, "updateReleaseInfo (Default: false)", 2 ); |
87 | 0 | append( sb, "Parameter used to update the metadata to make the artifact as release.", 3 ); |
88 | 0 | append( sb, "", 0 ); |
89 | |
} |
90 | |
} |
91 | |
|
92 | 0 | if ( goal == null || goal.length() <= 0 || "deploy-file".equals( goal ) ) |
93 | |
{ |
94 | 0 | append( sb, "deploy:deploy-file", 0 ); |
95 | 0 | append( sb, "Installs the artifact in the remote repository.", 1 ); |
96 | 0 | append( sb, "", 0 ); |
97 | 0 | if ( detail ) |
98 | |
{ |
99 | 0 | append( sb, "Available parameters:", 1 ); |
100 | 0 | append( sb, "", 0 ); |
101 | |
|
102 | 0 | append( sb, "artifactId", 2 ); |
103 | 0 | append( sb, "ArtifactId of the artifact to be deployed. Retrieved from POM file if specified.", 3 ); |
104 | 0 | append( sb, "", 0 ); |
105 | |
|
106 | 0 | append( sb, "classifier", 2 ); |
107 | 0 | append( sb, "Add classifier to the artifact", 3 ); |
108 | 0 | append( sb, "", 0 ); |
109 | |
|
110 | 0 | append( sb, "description", 2 ); |
111 | 0 | append( sb, "Description passed to a generated POM file (in case of generatePom=true)", 3 ); |
112 | 0 | append( sb, "", 0 ); |
113 | |
|
114 | 0 | append( sb, "file", 2 ); |
115 | 0 | append( sb, "File to be deployed.", 3 ); |
116 | 0 | append( sb, "", 0 ); |
117 | |
|
118 | 0 | append( sb, "generatePom (Default: true)", 2 ); |
119 | 0 | append( sb, "Upload a POM for this artifact. Will generate a default POM if none is supplied with the pomFile argument.", 3 ); |
120 | 0 | append( sb, "", 0 ); |
121 | |
|
122 | 0 | append( sb, "groupId", 2 ); |
123 | 0 | append( sb, "GroupId of the artifact to be deployed. Retrieved from POM file if specified.", 3 ); |
124 | 0 | append( sb, "", 0 ); |
125 | |
|
126 | 0 | append( sb, "packaging", 2 ); |
127 | 0 | append( sb, "Type of the artifact to be deployed. Retrieved from POM file if specified.", 3 ); |
128 | 0 | append( sb, "", 0 ); |
129 | |
|
130 | 0 | append( sb, "pomFile", 2 ); |
131 | 0 | append( sb, "Location of an existing POM file to be deployed alongside the main artifact, given by the ${file} parameter.", 3 ); |
132 | 0 | append( sb, "", 0 ); |
133 | |
|
134 | 0 | append( sb, "repositoryId (Default: remote-repository)", 2 ); |
135 | 0 | 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 ); |
136 | 0 | append( sb, "", 0 ); |
137 | |
|
138 | 0 | append( sb, "repositoryLayout (Default: default)", 2 ); |
139 | 0 | append( sb, "The type of remote repository layout to deploy to. Try legacy for a Maven 1.x-style repository layout.", 3 ); |
140 | 0 | append( sb, "", 0 ); |
141 | |
|
142 | 0 | append( sb, "uniqueVersion (Default: true)", 2 ); |
143 | 0 | append( sb, "Whether to deploy snapshots with a unique version or not.", 3 ); |
144 | 0 | append( sb, "", 0 ); |
145 | |
|
146 | 0 | append( sb, "url", 2 ); |
147 | 0 | append( sb, "URL where the artifact will be deployed.\nie ( file://C:\\m2-repo or scp://host.com/path/to/repo )", 3 ); |
148 | 0 | append( sb, "", 0 ); |
149 | |
|
150 | 0 | append( sb, "version", 2 ); |
151 | 0 | append( sb, "Version of the artifact to be deployed. Retrieved from POM file if specified.", 3 ); |
152 | 0 | append( sb, "", 0 ); |
153 | |
} |
154 | |
} |
155 | |
|
156 | 0 | if ( goal == null || goal.length() <= 0 || "help".equals( goal ) ) |
157 | |
{ |
158 | 0 | append( sb, "deploy:help", 0 ); |
159 | 0 | append( sb, "Display help information on maven-deploy-plugin. Call\n\u00a0\u00a0mvn\u00a0deploy:help\u00a0-Ddetail=true\u00a0-Dgoal=<goal-name>\nto display parameter details.", 1 ); |
160 | 0 | append( sb, "", 0 ); |
161 | 0 | if ( detail ) |
162 | |
{ |
163 | 0 | append( sb, "Available parameters:", 1 ); |
164 | 0 | append( sb, "", 0 ); |
165 | |
|
166 | 0 | append( sb, "detail (Default: false)", 2 ); |
167 | 0 | append( sb, "If true, display all settable properties for each goal.", 3 ); |
168 | 0 | append( sb, "", 0 ); |
169 | |
|
170 | 0 | append( sb, "goal", 2 ); |
171 | 0 | append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 3 ); |
172 | 0 | append( sb, "", 0 ); |
173 | |
|
174 | 0 | append( sb, "lineLength (Default: 80)", 2 ); |
175 | 0 | append( sb, "The maximum length of a display line.", 3 ); |
176 | 0 | append( sb, "", 0 ); |
177 | |
|
178 | 0 | append( sb, "indentSize (Default: 2)", 2 ); |
179 | 0 | append( sb, "The number of spaces per indentation level.", 3 ); |
180 | 0 | append( sb, "", 0 ); |
181 | |
} |
182 | |
} |
183 | |
|
184 | 0 | if ( getLog().isInfoEnabled() ) |
185 | |
{ |
186 | 0 | getLog().info( sb.toString() ); |
187 | |
} |
188 | 0 | } |
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
private static String repeat( String str, int repeat ) |
200 | |
{ |
201 | 0 | StringBuffer buffer = new StringBuffer( repeat * str.length() ); |
202 | |
|
203 | 0 | for ( int i = 0; i < repeat; i++ ) |
204 | |
{ |
205 | 0 | buffer.append( str ); |
206 | |
} |
207 | |
|
208 | 0 | return buffer.toString(); |
209 | |
} |
210 | |
|
211 | |
private void append( StringBuffer sb, String description, int indent ) |
212 | |
{ |
213 | 0 | for ( Iterator it = toLines( description, indent ).iterator(); it.hasNext(); ) |
214 | |
{ |
215 | 0 | sb.append( it.next().toString() ).append( '\n' ); |
216 | |
} |
217 | 0 | } |
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
private List toLines( String text, int indent ) |
227 | |
{ |
228 | 0 | List lines = new ArrayList(); |
229 | |
|
230 | 0 | String ind = repeat( "\t", indent ); |
231 | 0 | String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" ); |
232 | 0 | for ( int i = 0; i < plainLines.length; i++ ) |
233 | |
{ |
234 | 0 | toLines( lines, ind + plainLines[i] ); |
235 | |
} |
236 | |
|
237 | 0 | return lines; |
238 | |
} |
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | |
|
245 | |
|
246 | |
private void toLines( List lines, String line ) |
247 | |
{ |
248 | 0 | int lineIndent = getIndentLevel( line ); |
249 | 0 | StringBuffer buf = new StringBuffer( 256 ); |
250 | 0 | String[] tokens = line.split( " +" ); |
251 | 0 | for ( int i = 0; i < tokens.length; i++ ) |
252 | |
{ |
253 | 0 | String token = tokens[i]; |
254 | 0 | if ( i > 0 ) |
255 | |
{ |
256 | 0 | if ( buf.length() + token.length() >= lineLength ) |
257 | |
{ |
258 | 0 | lines.add( buf.toString() ); |
259 | 0 | buf.setLength( 0 ); |
260 | 0 | buf.append( repeat( " ", lineIndent * indentSize ) ); |
261 | |
} |
262 | |
else |
263 | |
{ |
264 | 0 | buf.append( ' ' ); |
265 | |
} |
266 | |
} |
267 | 0 | for ( int j = 0; j < token.length(); j++ ) |
268 | |
{ |
269 | 0 | char c = token.charAt( j ); |
270 | 0 | if ( c == '\t' ) |
271 | |
{ |
272 | 0 | buf.append( repeat( " ", indentSize - buf.length() % indentSize ) ); |
273 | |
} |
274 | 0 | else if ( c == '\u00A0' ) |
275 | |
{ |
276 | 0 | buf.append( ' ' ); |
277 | |
} |
278 | |
else |
279 | |
{ |
280 | 0 | buf.append( c ); |
281 | |
} |
282 | |
} |
283 | |
} |
284 | 0 | lines.add( buf.toString() ); |
285 | 0 | } |
286 | |
|
287 | |
|
288 | |
|
289 | |
|
290 | |
|
291 | |
|
292 | |
|
293 | |
private static int getIndentLevel( String line ) |
294 | |
{ |
295 | 0 | int level = 0; |
296 | 0 | for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ ) |
297 | |
{ |
298 | 0 | level++; |
299 | |
} |
300 | 0 | for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ ) |
301 | |
{ |
302 | 0 | if ( line.charAt( i ) == '\t' ) |
303 | |
{ |
304 | 0 | level++; |
305 | 0 | break; |
306 | |
} |
307 | |
} |
308 | 0 | return level; |
309 | |
} |
310 | |
} |