1 | |
package org.apache.maven.tools.plugin.generator; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.io.File; |
23 | |
import java.io.FileOutputStream; |
24 | |
import java.io.IOException; |
25 | |
import java.io.OutputStreamWriter; |
26 | |
import java.io.PrintWriter; |
27 | |
import java.io.Writer; |
28 | |
import java.text.MessageFormat; |
29 | |
import java.util.ArrayList; |
30 | |
import java.util.Iterator; |
31 | |
import java.util.List; |
32 | |
import java.util.Locale; |
33 | |
import java.util.ResourceBundle; |
34 | |
|
35 | |
import org.apache.maven.plugin.descriptor.MojoDescriptor; |
36 | |
import org.apache.maven.plugin.descriptor.Parameter; |
37 | |
import org.apache.maven.plugin.descriptor.PluginDescriptor; |
38 | |
import org.apache.maven.project.MavenProject; |
39 | |
import org.apache.maven.tools.plugin.DefaultPluginToolsRequest; |
40 | |
import org.apache.maven.tools.plugin.ExtendedMojoDescriptor; |
41 | |
import org.apache.maven.tools.plugin.PluginToolsRequest; |
42 | |
import org.apache.maven.tools.plugin.util.PluginUtils; |
43 | |
import org.codehaus.plexus.util.IOUtil; |
44 | |
import org.codehaus.plexus.util.StringUtils; |
45 | |
import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; |
46 | |
import org.codehaus.plexus.util.xml.XMLWriter; |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
public class PluginXdocGenerator |
53 | |
implements Generator |
54 | |
{ |
55 | |
|
56 | |
private final Locale locale; |
57 | |
|
58 | |
|
59 | |
private final MavenProject project; |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
public PluginXdocGenerator() |
66 | 1 | { |
67 | 1 | this.project = null; |
68 | 1 | this.locale = Locale.ENGLISH; |
69 | 1 | } |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
public PluginXdocGenerator( MavenProject project ) |
77 | 0 | { |
78 | 0 | this.project = project; |
79 | 0 | this.locale = Locale.ENGLISH; |
80 | 0 | } |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
public PluginXdocGenerator( MavenProject project, Locale locale ) |
87 | 0 | { |
88 | 0 | this.project = project; |
89 | 0 | if ( locale == null ) |
90 | |
{ |
91 | 0 | this.locale = Locale.ENGLISH; |
92 | |
} |
93 | |
else |
94 | |
{ |
95 | 0 | this.locale = locale; |
96 | |
} |
97 | 0 | } |
98 | |
|
99 | |
|
100 | |
public void execute( File destinationDirectory, PluginDescriptor pluginDescriptor ) |
101 | |
throws IOException |
102 | |
{ |
103 | 0 | execute( destinationDirectory, new DefaultPluginToolsRequest( project, pluginDescriptor ) ); |
104 | 0 | } |
105 | |
|
106 | |
|
107 | |
public void execute( File destinationDirectory, PluginToolsRequest request ) |
108 | |
throws IOException |
109 | |
{ |
110 | 1 | if ( request.getPluginDescriptor().getMojos() != null ) |
111 | |
{ |
112 | |
for ( @SuppressWarnings( "unchecked" ) |
113 | 1 | Iterator<MojoDescriptor> it = request.getPluginDescriptor().getMojos().iterator(); it.hasNext(); ) |
114 | |
{ |
115 | 1 | MojoDescriptor descriptor = it.next(); |
116 | |
|
117 | 1 | processMojoDescriptor( descriptor, destinationDirectory ); |
118 | 1 | } |
119 | |
} |
120 | 1 | } |
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
protected void processMojoDescriptor( MojoDescriptor mojoDescriptor, File destinationDirectory ) |
128 | |
throws IOException |
129 | |
{ |
130 | 1 | File outputFile = new File( destinationDirectory, getMojoFilename( mojoDescriptor, "xml" ) ); |
131 | 1 | String encoding = "UTF-8"; |
132 | 1 | Writer writer = null; |
133 | |
try |
134 | |
{ |
135 | 1 | writer = new OutputStreamWriter( new FileOutputStream( outputFile ), encoding ); |
136 | |
|
137 | 1 | XMLWriter w = new PrettyPrintXMLWriter( new PrintWriter( writer ), encoding, null ); |
138 | 1 | writeBody( mojoDescriptor, w ); |
139 | |
|
140 | 1 | writer.flush(); |
141 | |
} |
142 | |
finally |
143 | |
{ |
144 | 1 | IOUtil.close( writer ); |
145 | 1 | } |
146 | 1 | } |
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
private String getMojoFilename( MojoDescriptor mojo, String ext ) |
154 | |
{ |
155 | 1 | return mojo.getGoal() + "-mojo." + ext; |
156 | |
} |
157 | |
|
158 | |
|
159 | |
|
160 | |
|
161 | |
|
162 | |
private void writeBody( MojoDescriptor mojoDescriptor, XMLWriter w ) |
163 | |
{ |
164 | 1 | w.startElement( "document" ); |
165 | 1 | w.addAttribute( "xmlns", "http://maven.apache.org/XDOC/2.0" ); |
166 | 1 | w.addAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" ); |
167 | 1 | w.addAttribute( "xsi:schemaLocation", |
168 | |
"http://maven.apache.org/XDOC/2.0 http://maven.apache.org/xsd/xdoc-2.0.xsd" ); |
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | 1 | w.startElement( "properties" ); |
175 | |
|
176 | 1 | w.startElement( "title" ); |
177 | 1 | w.writeText( mojoDescriptor.getFullGoalName() ); |
178 | 1 | w.endElement(); |
179 | |
|
180 | 1 | w.endElement(); |
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | 1 | w.startElement( "body" ); |
187 | |
|
188 | 1 | w.startElement( "section" ); |
189 | |
|
190 | 1 | w.addAttribute( "name", mojoDescriptor.getFullGoalName() ); |
191 | |
|
192 | 1 | writeReportNotice( mojoDescriptor, w ); |
193 | |
|
194 | 1 | w.startElement( "p" ); |
195 | 1 | w.writeMarkup( getString( "pluginxdoc.mojodescriptor.fullname" ) ); |
196 | 1 | w.endElement(); |
197 | 1 | w.startElement( "p" ); |
198 | 1 | w.writeMarkup( mojoDescriptor.getPluginDescriptor().getGroupId() + ":" |
199 | |
+ mojoDescriptor.getPluginDescriptor().getArtifactId() + ":" |
200 | |
+ mojoDescriptor.getPluginDescriptor().getVersion() + ":" + mojoDescriptor.getGoal() ); |
201 | 1 | w.endElement(); |
202 | |
|
203 | 1 | if ( StringUtils.isNotEmpty( mojoDescriptor.getDeprecated() ) ) |
204 | |
{ |
205 | 0 | w.startElement( "p" ); |
206 | 0 | w.writeMarkup( getString( "pluginxdoc.mojodescriptor.deprecated" ) ); |
207 | 0 | w.endElement(); |
208 | 0 | w.startElement( "div" ); |
209 | 0 | w.writeMarkup( PluginUtils.makeHtmlValid( mojoDescriptor.getDeprecated() ) ); |
210 | 0 | w.endElement(); |
211 | |
} |
212 | |
|
213 | 1 | w.startElement( "p" ); |
214 | 1 | w.writeMarkup( getString( "pluginxdoc.description" ) ); |
215 | 1 | w.endElement(); |
216 | 1 | w.startElement( "div" ); |
217 | 1 | if ( StringUtils.isNotEmpty( mojoDescriptor.getDescription() ) ) |
218 | |
{ |
219 | 0 | w.writeMarkup( PluginUtils.makeHtmlValid( mojoDescriptor.getDescription() ) ); |
220 | |
} |
221 | |
else |
222 | |
{ |
223 | 1 | w.writeText( getString( "pluginxdoc.nodescription" ) ); |
224 | |
} |
225 | 1 | w.endElement(); |
226 | |
|
227 | 1 | writeGoalAttributes( mojoDescriptor, w ); |
228 | |
|
229 | 1 | writeGoalParameterTable( mojoDescriptor, w ); |
230 | |
|
231 | 1 | w.endElement(); |
232 | |
|
233 | 1 | w.endElement(); |
234 | |
|
235 | 1 | w.endElement(); |
236 | 1 | } |
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
private void writeReportNotice( MojoDescriptor mojoDescriptor, XMLWriter w ) |
243 | |
{ |
244 | 1 | if ( PluginUtils.isMavenReport( mojoDescriptor.getImplementation(), project ) ) |
245 | |
{ |
246 | 0 | w.startElement( "p" ); |
247 | 0 | w.writeMarkup( getString( "pluginxdoc.mojodescriptor.notice.note" ) ); |
248 | 0 | w.writeText( getString( "pluginxdoc.mojodescriptor.notice.isMavenReport" ) ); |
249 | 0 | w.endElement(); |
250 | |
} |
251 | 1 | } |
252 | |
|
253 | |
|
254 | |
|
255 | |
|
256 | |
|
257 | |
private void writeGoalAttributes( MojoDescriptor mojoDescriptor, XMLWriter w ) |
258 | |
{ |
259 | 1 | w.startElement( "p" ); |
260 | 1 | w.writeMarkup( getString( "pluginxdoc.mojodescriptor.attributes" ) ); |
261 | 1 | w.endElement(); |
262 | |
|
263 | 1 | boolean addedUl = false; |
264 | |
String value; |
265 | 1 | if ( mojoDescriptor.isProjectRequired() ) |
266 | |
{ |
267 | 1 | if ( !addedUl ) |
268 | |
{ |
269 | 1 | w.startElement( "ul" ); |
270 | 1 | addedUl = true; |
271 | |
} |
272 | 1 | w.startElement( "li" ); |
273 | 1 | w.writeMarkup( getString( "pluginxdoc.mojodescriptor.projectRequired" ) ); |
274 | 1 | w.endElement(); |
275 | |
} |
276 | |
|
277 | 1 | if ( mojoDescriptor.isRequiresReports() ) |
278 | |
{ |
279 | 0 | if ( !addedUl ) |
280 | |
{ |
281 | 0 | w.startElement( "ul" ); |
282 | 0 | addedUl = true; |
283 | |
} |
284 | 0 | w.startElement( "li" ); |
285 | 0 | w.writeMarkup( getString( "pluginxdoc.mojodescriptor.reportingMojo" ) ); |
286 | 0 | w.endElement(); |
287 | |
} |
288 | |
|
289 | 1 | if ( mojoDescriptor.isAggregator() ) |
290 | |
{ |
291 | 0 | if ( !addedUl ) |
292 | |
{ |
293 | 0 | w.startElement( "ul" ); |
294 | 0 | addedUl = true; |
295 | |
} |
296 | 0 | w.startElement( "li" ); |
297 | 0 | w.writeMarkup( getString( "pluginxdoc.mojodescriptor.aggregator" ) ); |
298 | 0 | w.endElement(); |
299 | |
} |
300 | |
|
301 | 1 | if ( mojoDescriptor.isDirectInvocationOnly() ) |
302 | |
{ |
303 | 0 | if ( !addedUl ) |
304 | |
{ |
305 | 0 | w.startElement( "ul" ); |
306 | 0 | addedUl = true; |
307 | |
} |
308 | 0 | w.startElement( "li" ); |
309 | 0 | w.writeMarkup( getString( "pluginxdoc.mojodescriptor.directInvocationOnly" ) ); |
310 | 0 | w.endElement(); |
311 | |
} |
312 | |
|
313 | 1 | value = mojoDescriptor.isDependencyResolutionRequired(); |
314 | 1 | if ( StringUtils.isNotEmpty( value ) ) |
315 | |
{ |
316 | 1 | if ( !addedUl ) |
317 | |
{ |
318 | 0 | w.startElement( "ul" ); |
319 | 0 | addedUl = true; |
320 | |
} |
321 | 1 | w.startElement( "li" ); |
322 | 1 | w.writeMarkup( format( "pluginxdoc.mojodescriptor.dependencyResolutionRequired", value ) ); |
323 | 1 | w.endElement(); |
324 | |
} |
325 | |
|
326 | 1 | if ( mojoDescriptor instanceof ExtendedMojoDescriptor ) |
327 | |
{ |
328 | 0 | ExtendedMojoDescriptor extendedMojoDescriptor = (ExtendedMojoDescriptor) mojoDescriptor; |
329 | |
|
330 | 0 | value = extendedMojoDescriptor.getDependencyCollectionRequired(); |
331 | 0 | if ( StringUtils.isNotEmpty( value ) ) |
332 | |
{ |
333 | 0 | if ( !addedUl ) |
334 | |
{ |
335 | 0 | w.startElement( "ul" ); |
336 | 0 | addedUl = true; |
337 | |
} |
338 | 0 | w.startElement( "li" ); |
339 | 0 | w.writeMarkup( format( "pluginxdoc.mojodescriptor.dependencyCollectionRequired", value ) ); |
340 | 0 | w.endElement(); |
341 | |
} |
342 | |
|
343 | 0 | if ( extendedMojoDescriptor.isThreadSafe() ) |
344 | |
{ |
345 | 0 | if ( !addedUl ) |
346 | |
{ |
347 | 0 | w.startElement( "ul" ); |
348 | 0 | addedUl = true; |
349 | |
} |
350 | 0 | w.startElement( "li" ); |
351 | 0 | w.writeMarkup( getString( "pluginxdoc.mojodescriptor.threadSafe" ) ); |
352 | 0 | w.endElement(); |
353 | |
} |
354 | |
|
355 | |
} |
356 | |
|
357 | 1 | value = mojoDescriptor.getSince(); |
358 | 1 | if ( StringUtils.isNotEmpty( value ) ) |
359 | |
{ |
360 | 0 | if ( !addedUl ) |
361 | |
{ |
362 | 0 | w.startElement( "ul" ); |
363 | 0 | addedUl = true; |
364 | |
} |
365 | 0 | w.startElement( "li" ); |
366 | 0 | w.writeMarkup( format( "pluginxdoc.mojodescriptor.since", value ) ); |
367 | 0 | w.endElement(); |
368 | |
} |
369 | |
|
370 | 1 | value = mojoDescriptor.getPhase(); |
371 | 1 | if ( StringUtils.isNotEmpty( value ) ) |
372 | |
{ |
373 | 0 | if ( !addedUl ) |
374 | |
{ |
375 | 0 | w.startElement( "ul" ); |
376 | 0 | addedUl = true; |
377 | |
} |
378 | 0 | w.startElement( "li" ); |
379 | 0 | w.writeMarkup( format( "pluginxdoc.mojodescriptor.phase", value ) ); |
380 | 0 | w.endElement(); |
381 | |
} |
382 | |
|
383 | 1 | value = mojoDescriptor.getExecutePhase(); |
384 | 1 | if ( StringUtils.isNotEmpty( value ) ) |
385 | |
{ |
386 | 0 | if ( !addedUl ) |
387 | |
{ |
388 | 0 | w.startElement( "ul" ); |
389 | 0 | addedUl = true; |
390 | |
} |
391 | 0 | w.startElement( "li" ); |
392 | 0 | w.writeMarkup( format( "pluginxdoc.mojodescriptor.executePhase", value ) ); |
393 | 0 | w.endElement(); |
394 | |
} |
395 | |
|
396 | 1 | value = mojoDescriptor.getExecuteGoal(); |
397 | 1 | if ( StringUtils.isNotEmpty( value ) ) |
398 | |
{ |
399 | 0 | if ( !addedUl ) |
400 | |
{ |
401 | 0 | w.startElement( "ul" ); |
402 | 0 | addedUl = true; |
403 | |
} |
404 | 0 | w.startElement( "li" ); |
405 | 0 | w.writeMarkup( format( "pluginxdoc.mojodescriptor.executeGoal", value ) ); |
406 | 0 | w.endElement(); |
407 | |
} |
408 | |
|
409 | 1 | value = mojoDescriptor.getExecuteLifecycle(); |
410 | 1 | if ( StringUtils.isNotEmpty( value ) ) |
411 | |
{ |
412 | 0 | if ( !addedUl ) |
413 | |
{ |
414 | 0 | w.startElement( "ul" ); |
415 | 0 | addedUl = true; |
416 | |
} |
417 | 0 | w.startElement( "li" ); |
418 | 0 | w.writeMarkup( format( "pluginxdoc.mojodescriptor.executeLifecycle", value ) ); |
419 | 0 | w.endElement(); |
420 | |
} |
421 | |
|
422 | 1 | if ( mojoDescriptor.isOnlineRequired() ) |
423 | |
{ |
424 | 0 | if ( !addedUl ) |
425 | |
{ |
426 | 0 | w.startElement( "ul" ); |
427 | 0 | addedUl = true; |
428 | |
} |
429 | 0 | w.startElement( "li" ); |
430 | 0 | w.writeMarkup( getString( "pluginxdoc.mojodescriptor.onlineRequired" ) ); |
431 | 0 | w.endElement(); |
432 | |
} |
433 | |
|
434 | 1 | if ( !mojoDescriptor.isInheritedByDefault() ) |
435 | |
{ |
436 | 0 | if ( !addedUl ) |
437 | |
{ |
438 | 0 | w.startElement( "ul" ); |
439 | 0 | addedUl = true; |
440 | |
} |
441 | 0 | w.startElement( "li" ); |
442 | 0 | w.writeMarkup( getString( "pluginxdoc.mojodescriptor.inheritedByDefault" ) ); |
443 | 0 | w.endElement(); |
444 | |
} |
445 | |
|
446 | 1 | if ( addedUl ) |
447 | |
{ |
448 | 1 | w.endElement(); |
449 | |
} |
450 | 1 | } |
451 | |
|
452 | |
|
453 | |
|
454 | |
|
455 | |
|
456 | |
private void writeGoalParameterTable( MojoDescriptor mojoDescriptor, XMLWriter w ) |
457 | |
{ |
458 | |
@SuppressWarnings( "unchecked" ) |
459 | 1 | List<Parameter> parameterList = mojoDescriptor.getParameters(); |
460 | |
|
461 | |
|
462 | 1 | List<Parameter> list = filterParameters( parameterList ); |
463 | |
|
464 | 1 | if ( list != null && list.size() > 0 ) |
465 | |
{ |
466 | 1 | writeParameterSummary( mojoDescriptor, list, w ); |
467 | |
|
468 | 1 | writeParameterDetails( mojoDescriptor, list, w ); |
469 | |
} |
470 | |
else |
471 | |
{ |
472 | 0 | w.startElement( "subsection" ); |
473 | 0 | w.addAttribute( "name", getString( "pluginxdoc.mojodescriptor.parameters" ) ); |
474 | |
|
475 | 0 | w.startElement( "p" ); |
476 | 0 | w.writeMarkup( getString( "pluginxdoc.mojodescriptor.noParameter" ) ); |
477 | 0 | w.endElement(); |
478 | |
|
479 | 0 | w.endElement(); |
480 | |
} |
481 | 1 | } |
482 | |
|
483 | |
|
484 | |
|
485 | |
|
486 | |
|
487 | |
private List<Parameter> filterParameters( List<Parameter> parameterList ) |
488 | |
{ |
489 | 1 | List<Parameter> filtered = new ArrayList<Parameter>(); |
490 | |
|
491 | 1 | if ( parameterList != null ) |
492 | |
{ |
493 | 1 | for ( Parameter parameter : parameterList ) |
494 | |
{ |
495 | 1 | if ( parameter.isEditable() ) |
496 | |
{ |
497 | 1 | String expression = parameter.getExpression(); |
498 | |
|
499 | 1 | if ( expression == null || !expression.startsWith( "${component." ) ) |
500 | |
{ |
501 | 1 | filtered.add( parameter ); |
502 | |
} |
503 | 1 | } |
504 | |
} |
505 | |
} |
506 | |
|
507 | 1 | return filtered; |
508 | |
} |
509 | |
|
510 | |
|
511 | |
|
512 | |
|
513 | |
|
514 | |
|
515 | |
private void writeParameterDetails( MojoDescriptor mojoDescriptor, List<Parameter> parameterList, XMLWriter w ) |
516 | |
{ |
517 | 1 | w.startElement( "subsection" ); |
518 | 1 | w.addAttribute( "name", getString( "pluginxdoc.mojodescriptor.parameter.details" ) ); |
519 | |
|
520 | 1 | for ( Iterator<Parameter> parameters = parameterList.iterator(); parameters.hasNext(); ) |
521 | |
{ |
522 | 1 | Parameter parameter = parameters.next(); |
523 | |
|
524 | 1 | w.startElement( "p" ); |
525 | 1 | w.writeMarkup( format( "pluginxdoc.mojodescriptor.parameter.name_internal", parameter.getName() ) ); |
526 | 1 | w.endElement(); |
527 | |
|
528 | 1 | if ( StringUtils.isNotEmpty( parameter.getDeprecated() ) ) |
529 | |
{ |
530 | 0 | w.startElement( "div" ); |
531 | 0 | w.writeMarkup( format( "pluginxdoc.mojodescriptor.parameter.deprecated", |
532 | |
PluginUtils.makeHtmlValid( parameter.getDeprecated() ) ) ); |
533 | 0 | w.endElement(); |
534 | |
} |
535 | |
|
536 | 1 | w.startElement( "div" ); |
537 | 1 | if ( StringUtils.isNotEmpty( parameter.getDescription() ) ) |
538 | |
{ |
539 | 1 | w.writeMarkup( PluginUtils.makeHtmlValid( parameter.getDescription() ) ); |
540 | |
} |
541 | |
else |
542 | |
{ |
543 | 0 | w.writeMarkup( getString( "pluginxdoc.nodescription" ) ); |
544 | |
} |
545 | 1 | w.endElement(); |
546 | |
|
547 | 1 | boolean addedUl = false; |
548 | 1 | if ( !addedUl && StringUtils.isNotEmpty( parameter.getType() ) ) |
549 | |
{ |
550 | 1 | w.startElement( "ul" ); |
551 | 1 | addedUl = true; |
552 | |
} |
553 | 1 | writeDetail( getString( "pluginxdoc.mojodescriptor.parameter.type" ), parameter.getType(), w ); |
554 | |
|
555 | 1 | if ( StringUtils.isNotEmpty( parameter.getSince() ) ) |
556 | |
{ |
557 | 0 | if ( !addedUl ) |
558 | |
{ |
559 | 0 | w.startElement( "ul" ); |
560 | 0 | addedUl = true; |
561 | |
} |
562 | 0 | writeDetail( getString( "pluginxdoc.mojodescriptor.parameter.since" ), parameter.getSince(), w ); |
563 | |
} |
564 | |
else |
565 | |
{ |
566 | 1 | if ( StringUtils.isNotEmpty( mojoDescriptor.getSince() ) ) |
567 | |
{ |
568 | 0 | if ( !addedUl ) |
569 | |
{ |
570 | 0 | w.startElement( "ul" ); |
571 | 0 | addedUl = true; |
572 | |
} |
573 | 0 | writeDetail( getString( "pluginxdoc.mojodescriptor.parameter.since" ), |
574 | |
mojoDescriptor.getSince(), w ); |
575 | |
} |
576 | |
} |
577 | |
|
578 | 1 | if ( parameter.isRequired() ) |
579 | |
{ |
580 | 1 | if ( !addedUl ) |
581 | |
{ |
582 | 0 | w.startElement( "ul" ); |
583 | 0 | addedUl = true; |
584 | |
} |
585 | 1 | writeDetail( getString( "pluginxdoc.mojodescriptor.parameter.required" ), |
586 | |
getString( "pluginxdoc.yes" ), w ); |
587 | |
} |
588 | |
else |
589 | |
{ |
590 | 0 | if ( !addedUl ) |
591 | |
{ |
592 | 0 | w.startElement( "ul" ); |
593 | 0 | addedUl = true; |
594 | |
} |
595 | 0 | writeDetail( getString( "pluginxdoc.mojodescriptor.parameter.required" ), |
596 | |
getString( "pluginxdoc.no" ), w ); |
597 | |
} |
598 | |
|
599 | 1 | if ( !addedUl && StringUtils.isNotEmpty( parameter.getExpression() ) ) |
600 | |
{ |
601 | 0 | w.startElement( "ul" ); |
602 | 0 | addedUl = true; |
603 | |
} |
604 | 1 | writeDetail( getString( "pluginxdoc.mojodescriptor.parameter.expression" ), parameter.getExpression(), w ); |
605 | |
|
606 | 1 | if ( !addedUl && StringUtils.isNotEmpty( parameter.getDefaultValue() ) ) |
607 | |
{ |
608 | 0 | w.startElement( "ul" ); |
609 | 0 | addedUl = true; |
610 | |
} |
611 | 1 | writeDetail( getString( "pluginxdoc.mojodescriptor.parameter.default" ), |
612 | |
escapeXml( parameter.getDefaultValue() ), w ); |
613 | |
|
614 | 1 | if ( addedUl ) |
615 | |
{ |
616 | 1 | w.endElement(); |
617 | |
} |
618 | |
|
619 | 1 | if ( parameters.hasNext() ) |
620 | |
{ |
621 | 0 | w.writeMarkup( "<hr/>" ); |
622 | |
} |
623 | 1 | } |
624 | |
|
625 | 1 | w.endElement(); |
626 | 1 | } |
627 | |
|
628 | |
|
629 | |
|
630 | |
|
631 | |
|
632 | |
|
633 | |
private void writeDetail( String param, String value, XMLWriter w ) |
634 | |
{ |
635 | 4 | if ( StringUtils.isNotEmpty( value ) ) |
636 | |
{ |
637 | 4 | w.startElement( "li" ); |
638 | 4 | w.writeMarkup( format( "pluginxdoc.detail", new String[]{ param, value } ) ); |
639 | 4 | w.endElement(); |
640 | |
} |
641 | 4 | } |
642 | |
|
643 | |
|
644 | |
|
645 | |
|
646 | |
|
647 | |
|
648 | |
private void writeParameterSummary( MojoDescriptor mojoDescriptor, List<Parameter> parameterList, XMLWriter w ) |
649 | |
{ |
650 | 1 | List<Parameter> requiredParams = getParametersByRequired( true, parameterList ); |
651 | 1 | if ( requiredParams.size() > 0 ) |
652 | |
{ |
653 | 1 | writeParameterList( mojoDescriptor, getString( "pluginxdoc.mojodescriptor.requiredParameters" ), |
654 | |
requiredParams, w ); |
655 | |
} |
656 | |
|
657 | 1 | List<Parameter> optionalParams = getParametersByRequired( false, parameterList ); |
658 | 1 | if ( optionalParams.size() > 0 ) |
659 | |
{ |
660 | 0 | writeParameterList( mojoDescriptor, getString( "pluginxdoc.mojodescriptor.optionalParameters" ), |
661 | |
optionalParams, w ); |
662 | |
} |
663 | 1 | } |
664 | |
|
665 | |
|
666 | |
|
667 | |
|
668 | |
|
669 | |
|
670 | |
|
671 | |
private void writeParameterList( MojoDescriptor mojoDescriptor, String title, List<Parameter> parameterList, XMLWriter w ) |
672 | |
{ |
673 | 1 | w.startElement( "subsection" ); |
674 | 1 | w.addAttribute( "name", title ); |
675 | |
|
676 | 1 | w.startElement( "table" ); |
677 | 1 | w.addAttribute( "border", "0" ); |
678 | |
|
679 | 1 | w.startElement( "tr" ); |
680 | 1 | w.startElement( "th" ); |
681 | 1 | w.writeText( getString( "pluginxdoc.mojodescriptor.parameter.name" ) ); |
682 | 1 | w.endElement(); |
683 | 1 | w.startElement( "th" ); |
684 | 1 | w.writeText( getString( "pluginxdoc.mojodescriptor.parameter.type" ) ); |
685 | 1 | w.endElement(); |
686 | 1 | w.startElement( "th" ); |
687 | 1 | w.writeText( getString( "pluginxdoc.mojodescriptor.parameter.since" ) ); |
688 | 1 | w.endElement(); |
689 | 1 | w.startElement( "th" ); |
690 | 1 | w.writeText( getString( "pluginxdoc.mojodescriptor.parameter.description" ) ); |
691 | 1 | w.endElement(); |
692 | 1 | w.endElement(); |
693 | |
|
694 | 1 | for ( Parameter parameter : parameterList ) |
695 | |
{ |
696 | 1 | w.startElement( "tr" ); |
697 | 1 | w.startElement( "td" ); |
698 | 1 | w.writeMarkup( format( "pluginxdoc.mojodescriptor.parameter.name_link", parameter.getName() ) ); |
699 | 1 | w.endElement(); |
700 | 1 | w.startElement( "td" ); |
701 | 1 | int index = parameter.getType().lastIndexOf( "." ); |
702 | 1 | w.writeMarkup( "<code>" + parameter.getType().substring( index + 1 ) + "</code>" ); |
703 | 1 | w.endElement(); |
704 | 1 | w.startElement( "td" ); |
705 | 1 | if ( StringUtils.isNotEmpty( parameter.getSince() ) ) |
706 | |
{ |
707 | 0 | w.writeMarkup( "<code>" + parameter.getSince() + "</code>" ); |
708 | |
} |
709 | |
else |
710 | |
{ |
711 | 1 | if ( StringUtils.isNotEmpty( mojoDescriptor.getSince() ) ) |
712 | |
{ |
713 | 0 | w.writeMarkup( "<code>" + mojoDescriptor.getSince() + "</code>" ); |
714 | |
} |
715 | |
else |
716 | |
{ |
717 | 1 | w.writeMarkup( "<code>-</code>" ); |
718 | |
} |
719 | |
} |
720 | 1 | w.endElement(); |
721 | 1 | w.startElement( "td" ); |
722 | |
String description; |
723 | 1 | if ( StringUtils.isNotEmpty( parameter.getDeprecated() ) ) |
724 | |
{ |
725 | 0 | description = |
726 | |
format( "pluginxdoc.mojodescriptor.parameter.deprecated", |
727 | |
PluginUtils.makeHtmlValid( parameter.getDeprecated() ) ); |
728 | |
} |
729 | 1 | else if ( StringUtils.isNotEmpty( parameter.getDescription() ) ) |
730 | |
{ |
731 | 1 | description = PluginUtils.makeHtmlValid( parameter.getDescription() ); |
732 | |
} |
733 | |
else |
734 | |
{ |
735 | 0 | description = getString( "pluginxdoc.nodescription" ); |
736 | |
} |
737 | 1 | w.writeMarkup( description + "<br/>" ); |
738 | |
|
739 | 1 | if ( StringUtils.isNotEmpty( parameter.getDefaultValue() ) ) |
740 | |
{ |
741 | 1 | w.writeMarkup( format( "pluginxdoc.mojodescriptor.parameter.defaultValue", |
742 | |
escapeXml( parameter.getDefaultValue() ) ) ); |
743 | |
} |
744 | 1 | w.endElement(); |
745 | 1 | w.endElement(); |
746 | 1 | } |
747 | |
|
748 | 1 | w.endElement(); |
749 | 1 | w.endElement(); |
750 | 1 | } |
751 | |
|
752 | |
|
753 | |
|
754 | |
|
755 | |
|
756 | |
|
757 | |
private List<Parameter> getParametersByRequired( boolean required, List<Parameter> parameterList ) |
758 | |
{ |
759 | 2 | List<Parameter> list = new ArrayList<Parameter>(); |
760 | |
|
761 | 2 | for ( Parameter parameter : parameterList ) |
762 | |
{ |
763 | 2 | if ( parameter.isRequired() == required ) |
764 | |
{ |
765 | 1 | list.add( parameter ); |
766 | |
} |
767 | |
} |
768 | |
|
769 | 2 | return list; |
770 | |
} |
771 | |
|
772 | |
|
773 | |
|
774 | |
|
775 | |
|
776 | |
|
777 | |
private ResourceBundle getBundle() |
778 | |
{ |
779 | 24 | return ResourceBundle.getBundle( "pluginxdoc", locale, getClass().getClassLoader() ); |
780 | |
} |
781 | |
|
782 | |
|
783 | |
|
784 | |
|
785 | |
|
786 | |
|
787 | |
private String getString( String key ) |
788 | |
{ |
789 | 24 | return getBundle().getString( key ); |
790 | |
} |
791 | |
|
792 | |
|
793 | |
|
794 | |
|
795 | |
|
796 | |
|
797 | |
|
798 | |
|
799 | |
|
800 | |
private String format( String key, Object arg1 ) |
801 | |
{ |
802 | 4 | return format( key, new Object[] { arg1 } ); |
803 | |
} |
804 | |
|
805 | |
|
806 | |
|
807 | |
|
808 | |
|
809 | |
|
810 | |
|
811 | |
|
812 | |
|
813 | |
private String format( String key, Object[] args ) |
814 | |
{ |
815 | 8 | String pattern = getString( key ); |
816 | |
|
817 | 8 | pattern = StringUtils.replace( pattern, "'", "''" ); |
818 | |
|
819 | 8 | MessageFormat messageFormat = new MessageFormat( "" ); |
820 | 8 | messageFormat.setLocale( locale ); |
821 | 8 | messageFormat.applyPattern( pattern ); |
822 | |
|
823 | 8 | return messageFormat.format( args ); |
824 | |
} |
825 | |
|
826 | |
|
827 | |
|
828 | |
|
829 | |
|
830 | |
private String escapeXml( String text ) |
831 | |
{ |
832 | 2 | if ( text != null ) |
833 | |
{ |
834 | 2 | text = text.replaceAll( "&", "&" ); |
835 | 2 | text = text.replaceAll( "<", "<" ); |
836 | 2 | text = text.replaceAll( ">", ">" ); |
837 | 2 | text = text.replaceAll( "\"", """ ); |
838 | 2 | text = text.replaceAll( "\'", "'" ); |
839 | |
} |
840 | 2 | return text; |
841 | |
} |
842 | |
|
843 | |
} |