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