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 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
@SuppressWarnings( "all" ) |
20 | 0 | public class HelpMojo |
21 | |
extends AbstractMojo |
22 | |
{ |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
private boolean detail; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
private java.lang.String goal; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
private int lineLength; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
private int indentSize; |
50 | |
|
51 | |
|
52 | |
|
53 | |
public void execute() |
54 | |
throws MojoExecutionException |
55 | |
{ |
56 | 0 | if ( lineLength <= 0 ) |
57 | |
{ |
58 | 0 | getLog().warn( "The parameter 'lineLength' should be positive, using '80' as default." ); |
59 | 0 | lineLength = 80; |
60 | |
} |
61 | 0 | if ( indentSize <= 0 ) |
62 | |
{ |
63 | 0 | getLog().warn( "The parameter 'indentSize' should be positive, using '2' as default." ); |
64 | 0 | indentSize = 2; |
65 | |
} |
66 | |
|
67 | 0 | StringBuffer sb = new StringBuffer(); |
68 | |
|
69 | 0 | append( sb, "org.apache.maven.plugins:maven-antrun-plugin:1.7", 0 ); |
70 | 0 | append( sb, "", 0 ); |
71 | |
|
72 | 0 | append( sb, "Maven AntRun Plugin", 0 ); |
73 | 0 | append( sb, "Runs Ant scripts embedded in the POM", 1 ); |
74 | 0 | append( sb, "", 0 ); |
75 | |
|
76 | 0 | if ( goal == null || goal.length() <= 0 ) |
77 | |
{ |
78 | 0 | append( sb, "This plugin has 2 goals:", 0 ); |
79 | 0 | append( sb, "", 0 ); |
80 | |
} |
81 | |
|
82 | 0 | if ( goal == null || goal.length() <= 0 || "help".equals( goal ) ) |
83 | |
{ |
84 | 0 | append( sb, "antrun:help", 0 ); |
85 | 0 | 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 | 0 | append( sb, "", 0 ); |
87 | 0 | if ( detail ) |
88 | |
{ |
89 | 0 | append( sb, "Available parameters:", 1 ); |
90 | 0 | append( sb, "", 0 ); |
91 | |
|
92 | 0 | append( sb, "detail (Default: false)", 2 ); |
93 | 0 | append( sb, "If true, display all settable properties for each goal.", 3 ); |
94 | 0 | append( sb, "Expression: ${detail}", 3 ); |
95 | 0 | append( sb, "", 0 ); |
96 | |
|
97 | 0 | append( sb, "goal", 2 ); |
98 | 0 | append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 3 ); |
99 | 0 | append( sb, "Expression: ${goal}", 3 ); |
100 | 0 | append( sb, "", 0 ); |
101 | |
|
102 | 0 | append( sb, "indentSize (Default: 2)", 2 ); |
103 | 0 | append( sb, "The number of spaces per indentation level, should be positive.", 3 ); |
104 | 0 | append( sb, "Expression: ${indentSize}", 3 ); |
105 | 0 | append( sb, "", 0 ); |
106 | |
|
107 | 0 | append( sb, "lineLength (Default: 80)", 2 ); |
108 | 0 | append( sb, "The maximum length of a display line, should be positive.", 3 ); |
109 | 0 | append( sb, "Expression: ${lineLength}", 3 ); |
110 | 0 | append( sb, "", 0 ); |
111 | |
} |
112 | |
} |
113 | |
|
114 | 0 | if ( goal == null || goal.length() <= 0 || "run".equals( goal ) ) |
115 | |
{ |
116 | 0 | append( sb, "antrun:run", 0 ); |
117 | 0 | 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 | 0 | append( sb, "", 0 ); |
119 | 0 | if ( detail ) |
120 | |
{ |
121 | 0 | append( sb, "Available parameters:", 1 ); |
122 | 0 | append( sb, "", 0 ); |
123 | |
|
124 | 0 | append( sb, "customTaskPrefix", 2 ); |
125 | 0 | 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 | 0 | append( sb, "", 0 ); |
127 | |
|
128 | 0 | append( sb, "exportAntProperties (Default: false)", 2 ); |
129 | 0 | append( sb, "Specifies whether the Ant properties should be propagated to the Maven properties.", 3 ); |
130 | 0 | append( sb, "", 0 ); |
131 | |
|
132 | 0 | append( sb, "failOnError (Default: true)", 2 ); |
133 | 0 | 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 | 0 | append( sb, "", 0 ); |
135 | |
|
136 | 0 | append( sb, "propertyPrefix", 2 ); |
137 | 0 | append( sb, "String to prepend to project and dependency property names.", 3 ); |
138 | 0 | append( sb, "", 0 ); |
139 | |
|
140 | 0 | append( sb, "skip (Default: false)", 2 ); |
141 | 0 | append( sb, "Specifies whether the Antrun execution should be skipped.", 3 ); |
142 | 0 | append( sb, "Expression: ${maven.antrun.skip}", 3 ); |
143 | 0 | append( sb, "", 0 ); |
144 | |
|
145 | 0 | append( sb, "sourceRoot", 2 ); |
146 | 0 | append( sb, "Deprecated. Use the build-helper-maven-plugin to bind source directories", 3 ); |
147 | 0 | append( sb, "", 0 ); |
148 | 0 | 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 | 0 | append( sb, "Expression: ${sourceRoot}", 3 ); |
150 | 0 | append( sb, "", 0 ); |
151 | |
|
152 | 0 | append( sb, "target", 2 ); |
153 | 0 | 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 | 0 | append( sb, "", 0 ); |
155 | |
|
156 | 0 | append( sb, "tasks", 2 ); |
157 | 0 | append( sb, "Deprecated. Use target instead", 3 ); |
158 | 0 | append( sb, "", 0 ); |
159 | 0 | 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 | 0 | append( sb, "", 0 ); |
161 | |
|
162 | 0 | append( sb, "testSourceRoot", 2 ); |
163 | 0 | append( sb, "Deprecated. Use the build-helper-maven-plugin to bind test source directories", 3 ); |
164 | 0 | append( sb, "", 0 ); |
165 | 0 | 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 | 0 | append( sb, "Expression: ${testSourceRoot}", 3 ); |
167 | 0 | append( sb, "", 0 ); |
168 | |
|
169 | 0 | append( sb, "versionsPropertyName (Default: maven.project.dependencies.versions)", 2 ); |
170 | 0 | 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 | 0 | append( sb, "", 0 ); |
172 | |
} |
173 | |
} |
174 | |
|
175 | 0 | if ( getLog().isInfoEnabled() ) |
176 | |
{ |
177 | 0 | getLog().info( sb.toString() ); |
178 | |
} |
179 | 0 | } |
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
private static String repeat( String str, int repeat ) |
191 | |
{ |
192 | 0 | StringBuffer buffer = new StringBuffer( repeat * str.length() ); |
193 | |
|
194 | 0 | for ( int i = 0; i < repeat; i++ ) |
195 | |
{ |
196 | 0 | buffer.append( str ); |
197 | |
} |
198 | |
|
199 | 0 | return buffer.toString(); |
200 | |
} |
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
private void append( StringBuffer sb, String description, int indent ) |
211 | |
{ |
212 | 0 | for ( Iterator it = toLines( description, indent, indentSize, lineLength ).iterator(); it.hasNext(); ) |
213 | |
{ |
214 | 0 | sb.append( it.next().toString() ).append( '\n' ); |
215 | |
} |
216 | 0 | } |
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | |
|
226 | |
|
227 | |
|
228 | |
private static List toLines( String text, int indent, int indentSize, int lineLength ) |
229 | |
{ |
230 | 0 | List<String> lines = new ArrayList<String>(); |
231 | |
|
232 | 0 | String ind = repeat( "\t", indent ); |
233 | 0 | String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" ); |
234 | 0 | for ( int i = 0; i < plainLines.length; i++ ) |
235 | |
{ |
236 | 0 | toLines( lines, ind + plainLines[i], indentSize, lineLength ); |
237 | |
} |
238 | |
|
239 | 0 | return lines; |
240 | |
} |
241 | |
|
242 | |
|
243 | |
|
244 | |
|
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
|
250 | |
private static void toLines( List<String> lines, String line, int indentSize, int lineLength ) |
251 | |
{ |
252 | 0 | int lineIndent = getIndentLevel( line ); |
253 | 0 | StringBuffer buf = new StringBuffer( 256 ); |
254 | 0 | String[] tokens = line.split( " +" ); |
255 | 0 | for ( int i = 0; i < tokens.length; i++ ) |
256 | |
{ |
257 | 0 | String token = tokens[i]; |
258 | 0 | if ( i > 0 ) |
259 | |
{ |
260 | 0 | if ( buf.length() + token.length() >= lineLength ) |
261 | |
{ |
262 | 0 | lines.add( buf.toString() ); |
263 | 0 | buf.setLength( 0 ); |
264 | 0 | buf.append( repeat( " ", lineIndent * indentSize ) ); |
265 | |
} |
266 | |
else |
267 | |
{ |
268 | 0 | buf.append( ' ' ); |
269 | |
} |
270 | |
} |
271 | 0 | for ( int j = 0; j < token.length(); j++ ) |
272 | |
{ |
273 | 0 | char c = token.charAt( j ); |
274 | 0 | if ( c == '\t' ) |
275 | |
{ |
276 | 0 | buf.append( repeat( " ", indentSize - buf.length() % indentSize ) ); |
277 | |
} |
278 | 0 | else if ( c == '\u00A0' ) |
279 | |
{ |
280 | 0 | buf.append( ' ' ); |
281 | |
} |
282 | |
else |
283 | |
{ |
284 | 0 | buf.append( c ); |
285 | |
} |
286 | |
} |
287 | |
} |
288 | 0 | lines.add( buf.toString() ); |
289 | 0 | } |
290 | |
|
291 | |
|
292 | |
|
293 | |
|
294 | |
|
295 | |
|
296 | |
|
297 | |
private static int getIndentLevel( String line ) |
298 | |
{ |
299 | 0 | int level = 0; |
300 | 0 | for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ ) |
301 | |
{ |
302 | 0 | level++; |
303 | |
} |
304 | 0 | for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ ) |
305 | |
{ |
306 | 0 | if ( line.charAt( i ) == '\t' ) |
307 | |
{ |
308 | 0 | level++; |
309 | 0 | break; |
310 | |
} |
311 | |
} |
312 | 0 | return level; |
313 | |
} |
314 | |
} |