1 | |
package org.apache.maven.plugin.acr; |
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 | 0 | 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 | 0 | if ( lineLength <= 0 ) |
56 | |
{ |
57 | 0 | getLog().warn( "The parameter 'lineLength' should be positive, using '80' as default." ); |
58 | 0 | lineLength = 80; |
59 | |
} |
60 | 0 | if ( indentSize <= 0 ) |
61 | |
{ |
62 | 0 | getLog().warn( "The parameter 'indentSize' should be positive, using '2' as default." ); |
63 | 0 | indentSize = 2; |
64 | |
} |
65 | |
|
66 | 0 | StringBuffer sb = new StringBuffer(); |
67 | |
|
68 | 0 | append( sb, "org.apache.maven.plugins:maven-acr-plugin:1.0", 0 ); |
69 | 0 | append( sb, "", 0 ); |
70 | |
|
71 | 0 | append( sb, "Maven ACR Plugin", 0 ); |
72 | 0 | append( sb, "Generates a J2EE Application Client file.", 1 ); |
73 | 0 | append( sb, "", 0 ); |
74 | |
|
75 | 0 | if ( goal == null || goal.length() <= 0 ) |
76 | |
{ |
77 | 0 | append( sb, "This plugin has 2 goals:", 0 ); |
78 | 0 | append( sb, "", 0 ); |
79 | |
} |
80 | |
|
81 | 0 | if ( goal == null || goal.length() <= 0 || "acr".equals( goal ) ) |
82 | |
{ |
83 | 0 | append( sb, "acr:acr", 0 ); |
84 | 0 | append( sb, "Build a JavaEE Application Client jar file from the current project.", 1 ); |
85 | 0 | append( sb, "", 0 ); |
86 | 0 | if ( detail ) |
87 | |
{ |
88 | 0 | append( sb, "Available parameters:", 1 ); |
89 | 0 | append( sb, "", 0 ); |
90 | |
|
91 | 0 | append( sb, "archive", 2 ); |
92 | 0 | append( sb, "The archive configuration to use. See Maven Archiver Reference.", 3 ); |
93 | 0 | append( sb, "", 0 ); |
94 | |
|
95 | 0 | append( sb, "escapeBackslashesInFilePath (Default: false)", 2 ); |
96 | 0 | append( sb, "To escape interpolated value with windows path. c:\\foo\\bar will be replaced with c:\\\\foo\\\\bar.", 3 ); |
97 | 0 | append( sb, "Expression: ${acr.escapeBackslashesInFilePath}", 3 ); |
98 | 0 | append( sb, "", 0 ); |
99 | |
|
100 | 0 | append( sb, "escapeString", 2 ); |
101 | 0 | append( sb, "An expression preceded with this String won\'t be interpolated. \\${foo} will be replaced with ${foo}.", 3 ); |
102 | 0 | append( sb, "Expression: ${acr.escapeString}", 3 ); |
103 | 0 | append( sb, "", 0 ); |
104 | |
|
105 | 0 | append( sb, "excludes", 2 ); |
106 | 0 | append( sb, "The files and directories to exclude from the main Application Client jar. Usage:\n\n<excludes>\n\u00a0\u00a0<exclude>**/*DevOnly.class</exclude>\n</excludes>\n\nDefault exclusions: META-INF/application-client.xml,", 3 ); |
107 | 0 | append( sb, "", 0 ); |
108 | |
|
109 | 0 | append( sb, "filterDeploymentDescriptor (Default: false)", 2 ); |
110 | 0 | append( sb, "To filter the deployment descriptor.", 3 ); |
111 | 0 | append( sb, "Expression: ${acr.filterDeploymentDescriptor}", 3 ); |
112 | 0 | append( sb, "", 0 ); |
113 | |
|
114 | 0 | append( sb, "filters", 2 ); |
115 | 0 | append( sb, "Filters (properties files) to include during the interpolation of the deployment descriptor.", 3 ); |
116 | 0 | append( sb, "", 0 ); |
117 | |
|
118 | 0 | append( sb, "jarName (Default: ${project.build.finalName})", 2 ); |
119 | 0 | append( sb, "The name of the Application client JAR file to generate.", 3 ); |
120 | 0 | append( sb, "Expression: ${jarName}", 3 ); |
121 | 0 | append( sb, "", 0 ); |
122 | |
|
123 | 0 | append( sb, "outputDirectory (Default: ${project.build.outputDirectory})", 2 ); |
124 | 0 | append( sb, "Directory that resources are copied to during the build.", 3 ); |
125 | 0 | append( sb, "Expression: ${outputDirectory}", 3 ); |
126 | 0 | append( sb, "", 0 ); |
127 | |
} |
128 | |
} |
129 | |
|
130 | 0 | if ( goal == null || goal.length() <= 0 || "help".equals( goal ) ) |
131 | |
{ |
132 | 0 | append( sb, "acr:help", 0 ); |
133 | 0 | append( sb, "Display help information on maven-acr-plugin.\nCall\n\u00a0\u00a0mvn\u00a0acr:help\u00a0-Ddetail=true\u00a0-Dgoal=<goal-name>\nto display parameter details.", 1 ); |
134 | 0 | append( sb, "", 0 ); |
135 | 0 | if ( detail ) |
136 | |
{ |
137 | 0 | append( sb, "Available parameters:", 1 ); |
138 | 0 | append( sb, "", 0 ); |
139 | |
|
140 | 0 | append( sb, "detail (Default: false)", 2 ); |
141 | 0 | append( sb, "If true, display all settable properties for each goal.", 3 ); |
142 | 0 | append( sb, "Expression: ${detail}", 3 ); |
143 | 0 | append( sb, "", 0 ); |
144 | |
|
145 | 0 | append( sb, "goal", 2 ); |
146 | 0 | append( sb, "The name of the goal for which to show help. If unspecified, all goals will be displayed.", 3 ); |
147 | 0 | append( sb, "Expression: ${goal}", 3 ); |
148 | 0 | append( sb, "", 0 ); |
149 | |
|
150 | 0 | append( sb, "indentSize (Default: 2)", 2 ); |
151 | 0 | append( sb, "The number of spaces per indentation level, should be positive.", 3 ); |
152 | 0 | append( sb, "Expression: ${indentSize}", 3 ); |
153 | 0 | append( sb, "", 0 ); |
154 | |
|
155 | 0 | append( sb, "lineLength (Default: 80)", 2 ); |
156 | 0 | append( sb, "The maximum length of a display line, should be positive.", 3 ); |
157 | 0 | append( sb, "Expression: ${lineLength}", 3 ); |
158 | 0 | append( sb, "", 0 ); |
159 | |
} |
160 | |
} |
161 | |
|
162 | 0 | if ( getLog().isInfoEnabled() ) |
163 | |
{ |
164 | 0 | getLog().info( sb.toString() ); |
165 | |
} |
166 | 0 | } |
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
private static String repeat( String str, int repeat ) |
178 | |
{ |
179 | 0 | StringBuffer buffer = new StringBuffer( repeat * str.length() ); |
180 | |
|
181 | 0 | for ( int i = 0; i < repeat; i++ ) |
182 | |
{ |
183 | 0 | buffer.append( str ); |
184 | |
} |
185 | |
|
186 | 0 | return buffer.toString(); |
187 | |
} |
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
private void append( StringBuffer sb, String description, int indent ) |
198 | |
{ |
199 | 0 | for ( Iterator it = toLines( description, indent, indentSize, lineLength ).iterator(); it.hasNext(); ) |
200 | |
{ |
201 | 0 | sb.append( it.next().toString() ).append( '\n' ); |
202 | |
} |
203 | 0 | } |
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | |
private static List toLines( String text, int indent, int indentSize, int lineLength ) |
216 | |
{ |
217 | 0 | List lines = new ArrayList(); |
218 | |
|
219 | 0 | String ind = repeat( "\t", indent ); |
220 | 0 | String[] plainLines = text.split( "(\r\n)|(\r)|(\n)" ); |
221 | 0 | for ( int i = 0; i < plainLines.length; i++ ) |
222 | |
{ |
223 | 0 | toLines( lines, ind + plainLines[i], indentSize, lineLength ); |
224 | |
} |
225 | |
|
226 | 0 | return lines; |
227 | |
} |
228 | |
|
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
private static void toLines( List lines, String line, int indentSize, int lineLength ) |
238 | |
{ |
239 | 0 | int lineIndent = getIndentLevel( line ); |
240 | 0 | StringBuffer buf = new StringBuffer( 256 ); |
241 | 0 | String[] tokens = line.split( " +" ); |
242 | 0 | for ( int i = 0; i < tokens.length; i++ ) |
243 | |
{ |
244 | 0 | String token = tokens[i]; |
245 | 0 | if ( i > 0 ) |
246 | |
{ |
247 | 0 | if ( buf.length() + token.length() >= lineLength ) |
248 | |
{ |
249 | 0 | lines.add( buf.toString() ); |
250 | 0 | buf.setLength( 0 ); |
251 | 0 | buf.append( repeat( " ", lineIndent * indentSize ) ); |
252 | |
} |
253 | |
else |
254 | |
{ |
255 | 0 | buf.append( ' ' ); |
256 | |
} |
257 | |
} |
258 | 0 | for ( int j = 0; j < token.length(); j++ ) |
259 | |
{ |
260 | 0 | char c = token.charAt( j ); |
261 | 0 | if ( c == '\t' ) |
262 | |
{ |
263 | 0 | buf.append( repeat( " ", indentSize - buf.length() % indentSize ) ); |
264 | |
} |
265 | 0 | else if ( c == '\u00A0' ) |
266 | |
{ |
267 | 0 | buf.append( ' ' ); |
268 | |
} |
269 | |
else |
270 | |
{ |
271 | 0 | buf.append( c ); |
272 | |
} |
273 | |
} |
274 | |
} |
275 | 0 | lines.add( buf.toString() ); |
276 | 0 | } |
277 | |
|
278 | |
|
279 | |
|
280 | |
|
281 | |
|
282 | |
|
283 | |
|
284 | |
private static int getIndentLevel( String line ) |
285 | |
{ |
286 | 0 | int level = 0; |
287 | 0 | for ( int i = 0; i < line.length() && line.charAt( i ) == '\t'; i++ ) |
288 | |
{ |
289 | 0 | level++; |
290 | |
} |
291 | 0 | for ( int i = level + 1; i <= level + 4 && i < line.length(); i++ ) |
292 | |
{ |
293 | 0 | if ( line.charAt( i ) == '\t' ) |
294 | |
{ |
295 | 0 | level++; |
296 | 0 | break; |
297 | |
} |
298 | |
} |
299 | 0 | return level; |
300 | |
} |
301 | |
} |