1 | |
package org.apache.maven.plugin.plugin; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import org.apache.maven.artifact.Artifact; |
23 | |
import org.apache.maven.artifact.repository.ArtifactRepository; |
24 | |
import org.apache.maven.doxia.sink.Sink; |
25 | |
import org.apache.maven.doxia.siterenderer.Renderer; |
26 | |
import org.apache.maven.model.Plugin; |
27 | |
import org.apache.maven.model.ReportPlugin; |
28 | |
import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; |
29 | |
import org.apache.maven.plugin.descriptor.MojoDescriptor; |
30 | |
import org.apache.maven.plugin.descriptor.PluginDescriptor; |
31 | |
import org.apache.maven.plugins.annotations.Component; |
32 | |
import org.apache.maven.plugins.annotations.Execute; |
33 | |
import org.apache.maven.plugins.annotations.LifecyclePhase; |
34 | |
import org.apache.maven.plugins.annotations.Mojo; |
35 | |
import org.apache.maven.plugins.annotations.Parameter; |
36 | |
import org.apache.maven.project.MavenProject; |
37 | |
import org.apache.maven.reporting.AbstractMavenReport; |
38 | |
import org.apache.maven.reporting.AbstractMavenReportRenderer; |
39 | |
import org.apache.maven.reporting.MavenReportException; |
40 | |
import org.apache.maven.tools.plugin.DefaultPluginToolsRequest; |
41 | |
import org.apache.maven.tools.plugin.PluginToolsRequest; |
42 | |
import org.apache.maven.tools.plugin.extractor.ExtractionException; |
43 | |
import org.apache.maven.tools.plugin.generator.GeneratorException; |
44 | |
import org.apache.maven.tools.plugin.generator.GeneratorUtils; |
45 | |
import org.apache.maven.tools.plugin.generator.PluginXdocGenerator; |
46 | |
import org.apache.maven.tools.plugin.scanner.MojoScanner; |
47 | |
import org.apache.maven.tools.plugin.util.PluginUtils; |
48 | |
import org.codehaus.plexus.util.StringUtils; |
49 | |
import org.codehaus.plexus.util.xml.Xpp3Dom; |
50 | |
|
51 | |
import java.io.File; |
52 | |
import java.util.ArrayList; |
53 | |
import java.util.Iterator; |
54 | |
import java.util.List; |
55 | |
import java.util.Locale; |
56 | |
import java.util.Map; |
57 | |
import java.util.ResourceBundle; |
58 | |
import java.util.Set; |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
@Mojo( name = "report", threadSafe = true ) |
69 | |
@Execute( phase = LifecyclePhase.PROCESS_CLASSES ) |
70 | 0 | public class PluginReport |
71 | |
extends AbstractMavenReport |
72 | |
{ |
73 | |
|
74 | |
|
75 | |
|
76 | |
@Parameter( defaultValue = "${project.build.directory}/generated-site/xdoc" ) |
77 | |
private File outputDirectory; |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
@Component |
83 | |
private Renderer siteRenderer; |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
@Component |
89 | |
private MavenProject project; |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
@Component |
95 | |
protected MojoScanner mojoScanner; |
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
@Parameter( property = "encoding", defaultValue = "${project.build.sourceEncoding}" ) |
103 | |
private String encoding; |
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
@Parameter |
124 | |
private Requirements requirements; |
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
@Parameter( property = "goalPrefix" ) |
143 | |
protected String goalPrefix; |
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
@Parameter( defaultValue = "false", property = "maven.plugin.skip" ) |
151 | |
private boolean skip; |
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
@Parameter( defaultValue = "false", property = "maven.plugin.report.skip" ) |
159 | |
private boolean skipReport; |
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
@Parameter( defaultValue = "${project.artifacts}", required = true, readonly = true ) |
167 | |
protected Set<Artifact> dependencies; |
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
|
173 | |
|
174 | |
@Parameter( defaultValue = "${project.remoteArtifactRepositories}", required = true, readonly = true ) |
175 | |
protected List<ArtifactRepository> remoteRepos; |
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
@Parameter( defaultValue = "${localRepository}", required = true, readonly = true ) |
183 | |
protected ArtifactRepository local; |
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
protected Renderer getSiteRenderer() |
189 | |
{ |
190 | 0 | return siteRenderer; |
191 | |
} |
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
protected String getOutputDirectory() |
197 | |
{ |
198 | 0 | return outputDirectory.getPath(); |
199 | |
} |
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
protected MavenProject getProject() |
205 | |
{ |
206 | 0 | return project; |
207 | |
} |
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
public boolean canGenerateReport() |
213 | |
{ |
214 | 0 | return "maven-plugin".equals( project.getPackaging() ); |
215 | |
} |
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
@SuppressWarnings( "unchecked" ) |
221 | |
protected void executeReport( Locale locale ) |
222 | |
throws MavenReportException |
223 | |
{ |
224 | 0 | if ( !canGenerateReport() ) |
225 | |
{ |
226 | 0 | return; |
227 | |
} |
228 | 0 | if ( skip || skipReport ) |
229 | |
{ |
230 | 0 | getLog().info( "Maven Plugin Plugin Report generation skipped." ); |
231 | 0 | return; |
232 | |
} |
233 | |
|
234 | |
|
235 | 0 | String defaultGoalPrefix = PluginDescriptor.getGoalPrefixFromArtifactId( project.getArtifactId() ); |
236 | 0 | if ( goalPrefix == null ) |
237 | |
{ |
238 | 0 | goalPrefix = defaultGoalPrefix; |
239 | |
} |
240 | |
else |
241 | |
{ |
242 | 0 | getLog().warn( "\n\nGoal prefix is specified as: '" + goalPrefix + "'. Maven currently expects it to be '" |
243 | |
+ defaultGoalPrefix + "'.\n" ); |
244 | |
} |
245 | |
|
246 | |
|
247 | 0 | PluginDescriptor pluginDescriptor = new PluginDescriptor(); |
248 | |
|
249 | 0 | pluginDescriptor.setGroupId( project.getGroupId() ); |
250 | |
|
251 | 0 | pluginDescriptor.setArtifactId( project.getArtifactId() ); |
252 | |
|
253 | 0 | pluginDescriptor.setVersion( project.getVersion() ); |
254 | |
|
255 | 0 | pluginDescriptor.setGoalPrefix( goalPrefix ); |
256 | |
|
257 | |
try |
258 | |
{ |
259 | 0 | pluginDescriptor.setDependencies( GeneratorUtils.toComponentDependencies( project.getRuntimeDependencies() ) ); |
260 | |
|
261 | 0 | PluginToolsRequest request = new DefaultPluginToolsRequest( project, pluginDescriptor ); |
262 | 0 | request.setEncoding( encoding ); |
263 | 0 | request.setSkipErrorNoDescriptorsFound( true ); |
264 | 0 | request.setDependencies( dependencies ); |
265 | 0 | request.setLocal( this.local ); |
266 | 0 | request.setRemoteRepos( this.remoteRepos ); |
267 | |
|
268 | |
|
269 | |
try |
270 | |
{ |
271 | 0 | mojoScanner.populatePluginDescriptor( request ); |
272 | |
} |
273 | 0 | catch ( InvalidPluginDescriptorException e ) |
274 | |
{ |
275 | |
|
276 | 0 | getLog().debug( "Plugin without mojos.", e ); |
277 | |
|
278 | 0 | } |
279 | |
|
280 | |
|
281 | 0 | generatePluginDocumentation( pluginDescriptor, locale ); |
282 | |
|
283 | |
|
284 | 0 | PluginOverviewRenderer r = |
285 | |
new PluginOverviewRenderer( project, requirements, getSink(), pluginDescriptor, locale ); |
286 | 0 | r.render(); |
287 | |
} |
288 | |
|
289 | 0 | catch ( ExtractionException e ) |
290 | |
{ |
291 | 0 | throw new MavenReportException( "Error extracting plugin descriptor: \'" + e.getLocalizedMessage() + "\'", |
292 | |
e ); |
293 | 0 | } |
294 | 0 | } |
295 | |
|
296 | |
|
297 | |
|
298 | |
|
299 | |
public String getDescription( Locale locale ) |
300 | |
{ |
301 | 0 | return getBundle( locale ).getString( "report.plugin.description" ); |
302 | |
} |
303 | |
|
304 | |
|
305 | |
|
306 | |
|
307 | |
public String getName( Locale locale ) |
308 | |
{ |
309 | 0 | return getBundle( locale ).getString( "report.plugin.name" ); |
310 | |
} |
311 | |
|
312 | |
|
313 | |
|
314 | |
|
315 | |
public String getOutputName() |
316 | |
{ |
317 | 0 | return "plugin-info"; |
318 | |
} |
319 | |
|
320 | |
|
321 | |
|
322 | |
|
323 | |
|
324 | |
|
325 | |
private void generatePluginDocumentation( PluginDescriptor pluginDescriptor, Locale locale ) |
326 | |
throws MavenReportException |
327 | |
{ |
328 | |
try |
329 | |
{ |
330 | 0 | File outputDir = new File( getOutputDirectory() ); |
331 | 0 | outputDir.mkdirs(); |
332 | |
|
333 | 0 | PluginXdocGenerator generator = new PluginXdocGenerator( project, locale ); |
334 | 0 | PluginToolsRequest pluginToolsRequest = new DefaultPluginToolsRequest( project, pluginDescriptor ); |
335 | 0 | generator.execute( outputDir, pluginToolsRequest ); |
336 | |
} |
337 | 0 | catch ( GeneratorException e ) |
338 | |
{ |
339 | 0 | throw new MavenReportException( "Error writing plugin documentation", e ); |
340 | 0 | } |
341 | |
|
342 | 0 | } |
343 | |
|
344 | |
|
345 | |
|
346 | |
|
347 | |
|
348 | |
protected static ResourceBundle getBundle( Locale locale ) |
349 | |
{ |
350 | 0 | return ResourceBundle.getBundle( "plugin-report", locale, PluginReport.class.getClassLoader() ); |
351 | |
} |
352 | |
|
353 | |
|
354 | |
|
355 | |
|
356 | |
|
357 | 0 | static class PluginOverviewRenderer |
358 | |
extends AbstractMavenReportRenderer |
359 | |
{ |
360 | |
private final MavenProject project; |
361 | |
|
362 | |
private final Requirements requirements; |
363 | |
|
364 | |
private final PluginDescriptor pluginDescriptor; |
365 | |
|
366 | |
private final Locale locale; |
367 | |
|
368 | |
|
369 | |
|
370 | |
|
371 | |
|
372 | |
|
373 | |
|
374 | |
|
375 | |
public PluginOverviewRenderer( MavenProject project, Requirements requirements, Sink sink, |
376 | |
PluginDescriptor pluginDescriptor, Locale locale ) |
377 | |
{ |
378 | 0 | super( sink ); |
379 | |
|
380 | 0 | this.project = project; |
381 | |
|
382 | 0 | this.requirements = ( requirements == null ? new Requirements() : requirements ); |
383 | |
|
384 | 0 | this.pluginDescriptor = pluginDescriptor; |
385 | |
|
386 | 0 | this.locale = locale; |
387 | 0 | } |
388 | |
|
389 | |
|
390 | |
|
391 | |
|
392 | |
public String getTitle() |
393 | |
{ |
394 | 0 | return getBundle( locale ).getString( "report.plugin.title" ); |
395 | |
} |
396 | |
|
397 | |
|
398 | |
|
399 | |
|
400 | |
@SuppressWarnings( { "unchecked", "rawtypes" } ) |
401 | |
public void renderBody() |
402 | |
{ |
403 | 0 | startSection( getTitle() ); |
404 | |
|
405 | 0 | if ( !( pluginDescriptor.getMojos() != null && pluginDescriptor.getMojos().size() > 0 ) ) |
406 | |
{ |
407 | 0 | paragraph( getBundle( locale ).getString( "report.plugin.goals.nogoal" ) ); |
408 | 0 | endSection(); |
409 | 0 | return; |
410 | |
} |
411 | |
|
412 | 0 | paragraph( getBundle( locale ).getString( "report.plugin.goals.intro" ) ); |
413 | |
|
414 | 0 | boolean hasMavenReport = false; |
415 | 0 | for ( Iterator<MojoDescriptor> i = pluginDescriptor.getMojos().iterator(); i.hasNext(); ) |
416 | |
{ |
417 | 0 | MojoDescriptor mojo = i.next(); |
418 | |
|
419 | 0 | if ( GeneratorUtils.isMavenReport( mojo.getImplementation(), project ) ) |
420 | |
{ |
421 | 0 | hasMavenReport = true; |
422 | |
} |
423 | 0 | } |
424 | |
|
425 | 0 | startTable(); |
426 | |
|
427 | 0 | String goalColumnName = getBundle( locale ).getString( "report.plugin.goals.column.goal" ); |
428 | 0 | String isMavenReport = getBundle( locale ).getString( "report.plugin.goals.column.isMavenReport" ); |
429 | 0 | String descriptionColumnName = getBundle( locale ).getString( "report.plugin.goals.column.description" ); |
430 | 0 | if ( hasMavenReport ) |
431 | |
{ |
432 | 0 | tableHeader( new String[]{ goalColumnName, isMavenReport, descriptionColumnName } ); |
433 | |
} |
434 | |
else |
435 | |
{ |
436 | 0 | tableHeader( new String[]{ goalColumnName, descriptionColumnName } ); |
437 | |
} |
438 | |
|
439 | 0 | List<MojoDescriptor> mojos = new ArrayList<MojoDescriptor>(); |
440 | 0 | mojos.addAll( pluginDescriptor.getMojos() ); |
441 | 0 | PluginUtils.sortMojos( mojos ); |
442 | 0 | for ( MojoDescriptor mojo : mojos ) |
443 | |
{ |
444 | 0 | String goalName = mojo.getFullGoalName(); |
445 | |
|
446 | |
|
447 | |
|
448 | |
|
449 | |
|
450 | 0 | String goalDocumentationLink = "./" + mojo.getGoal() + "-mojo.html"; |
451 | |
|
452 | |
String description; |
453 | 0 | if ( StringUtils.isNotEmpty( mojo.getDeprecated() ) ) |
454 | |
{ |
455 | 0 | description = |
456 | |
"<strong>" + getBundle( locale ).getString( "report.plugin.goal.deprecated" ) + "</strong> " |
457 | |
+ GeneratorUtils.makeHtmlValid( mojo.getDeprecated() ); |
458 | |
} |
459 | 0 | else if ( StringUtils.isNotEmpty( mojo.getDescription() ) ) |
460 | |
{ |
461 | 0 | description = GeneratorUtils.makeHtmlValid( mojo.getDescription() ); |
462 | |
} |
463 | |
else |
464 | |
{ |
465 | 0 | description = getBundle( locale ).getString( "report.plugin.goal.nodescription" ); |
466 | |
} |
467 | |
|
468 | 0 | sink.tableRow(); |
469 | 0 | tableCell( createLinkPatternedText( goalName, goalDocumentationLink ) ); |
470 | 0 | if ( hasMavenReport ) |
471 | |
{ |
472 | 0 | if ( GeneratorUtils.isMavenReport( mojo.getImplementation(), project ) ) |
473 | |
{ |
474 | 0 | sink.tableCell(); |
475 | 0 | sink.text( getBundle( locale ).getString( "report.plugin.isReport" ) ); |
476 | 0 | sink.tableCell_(); |
477 | |
} |
478 | |
else |
479 | |
{ |
480 | 0 | sink.tableCell(); |
481 | 0 | sink.text( getBundle( locale ).getString( "report.plugin.isNotReport" ) ); |
482 | 0 | sink.tableCell_(); |
483 | |
} |
484 | |
} |
485 | 0 | tableCell( description, true ); |
486 | 0 | sink.tableRow_(); |
487 | 0 | } |
488 | |
|
489 | 0 | endTable(); |
490 | |
|
491 | 0 | startSection( getBundle( locale ).getString( "report.plugin.systemrequirements" ) ); |
492 | |
|
493 | 0 | paragraph( getBundle( locale ).getString( "report.plugin.systemrequirements.intro" ) ); |
494 | |
|
495 | 0 | startTable(); |
496 | |
|
497 | 0 | String maven = discoverMavenRequirement( project, requirements ); |
498 | 0 | sink.tableRow(); |
499 | 0 | tableCell( getBundle( locale ).getString( "report.plugin.systemrequirements.maven" ) ); |
500 | 0 | tableCell( ( maven != null |
501 | |
? maven |
502 | |
: getBundle( locale ).getString( "report.plugin.systemrequirements.nominimum" ) ) ); |
503 | 0 | sink.tableRow_(); |
504 | |
|
505 | 0 | String jdk = discoverJdkRequirement( project, requirements ); |
506 | 0 | sink.tableRow(); |
507 | 0 | tableCell( getBundle( locale ).getString( "report.plugin.systemrequirements.jdk" ) ); |
508 | 0 | tableCell( |
509 | |
( jdk != null ? jdk : getBundle( locale ).getString( "report.plugin.systemrequirements.nominimum" ) ) ); |
510 | 0 | sink.tableRow_(); |
511 | |
|
512 | 0 | sink.tableRow(); |
513 | 0 | tableCell( getBundle( locale ).getString( "report.plugin.systemrequirements.memory" ) ); |
514 | 0 | tableCell( ( StringUtils.isNotEmpty( requirements.getMemory() ) |
515 | |
? requirements.getMemory() |
516 | |
: getBundle( locale ).getString( "report.plugin.systemrequirements.nominimum" ) ) ); |
517 | 0 | sink.tableRow_(); |
518 | |
|
519 | 0 | sink.tableRow(); |
520 | 0 | tableCell( getBundle( locale ).getString( "report.plugin.systemrequirements.diskspace" ) ); |
521 | 0 | tableCell( ( StringUtils.isNotEmpty( requirements.getDiskSpace() ) |
522 | |
? requirements.getDiskSpace() |
523 | |
: getBundle( locale ).getString( "report.plugin.systemrequirements.nominimum" ) ) ); |
524 | 0 | sink.tableRow_(); |
525 | |
|
526 | 0 | if ( requirements.getOthers() != null && requirements.getOthers().size() > 0 ) |
527 | |
{ |
528 | 0 | for ( Iterator it = requirements.getOthers().keySet().iterator(); it.hasNext(); ) |
529 | |
{ |
530 | 0 | String key = it.next().toString(); |
531 | |
|
532 | 0 | sink.tableRow(); |
533 | 0 | tableCell( key ); |
534 | 0 | tableCell( ( StringUtils.isNotEmpty( requirements.getOthers().getProperty( key ) ) |
535 | |
? requirements.getOthers().getProperty( key ) |
536 | |
: getBundle( locale ).getString( "report.plugin.systemrequirements.nominimum" ) ) ); |
537 | 0 | sink.tableRow_(); |
538 | 0 | } |
539 | |
} |
540 | 0 | endTable(); |
541 | |
|
542 | 0 | endSection(); |
543 | |
|
544 | 0 | renderUsageSection( hasMavenReport ); |
545 | |
|
546 | 0 | endSection(); |
547 | 0 | } |
548 | |
|
549 | |
|
550 | |
|
551 | |
|
552 | |
|
553 | |
|
554 | |
private void renderUsageSection( boolean hasMavenReport ) |
555 | |
{ |
556 | 0 | startSection( getBundle( locale ).getString( "report.plugin.usage" ) ); |
557 | |
|
558 | |
|
559 | 0 | sink.paragraph(); |
560 | 0 | text( getBundle( locale ).getString( "report.plugin.usage.intro" ) ); |
561 | 0 | sink.paragraph_(); |
562 | |
|
563 | 0 | StringBuilder sb = new StringBuilder(); |
564 | 0 | sb.append( "<project>" ).append( '\n' ); |
565 | 0 | sb.append( " ..." ).append( '\n' ); |
566 | 0 | sb.append( " <build>" ).append( '\n' ); |
567 | 0 | sb.append( |
568 | |
" <!-- " + getBundle( locale ).getString( "report.plugin.usage.pluginManagement" ) + " -->" ).append( |
569 | |
'\n' ); |
570 | 0 | sb.append( " <pluginManagement>" ).append( '\n' ); |
571 | 0 | sb.append( " <plugins>" ).append( '\n' ); |
572 | 0 | sb.append( " <plugin>" ).append( '\n' ); |
573 | 0 | sb.append( " <groupId>" ).append( pluginDescriptor.getGroupId() ).append( "</groupId>" ).append( |
574 | |
'\n' ); |
575 | 0 | sb.append( " <artifactId>" ).append( pluginDescriptor.getArtifactId() ).append( |
576 | |
"</artifactId>" ).append( '\n' ); |
577 | 0 | sb.append( " <version>" ).append( pluginDescriptor.getVersion() ).append( "</version>" ).append( |
578 | |
'\n' ); |
579 | 0 | sb.append( " </plugin>" ).append( '\n' ); |
580 | 0 | sb.append( " ..." ).append( '\n' ); |
581 | 0 | sb.append( " </plugins>" ).append( '\n' ); |
582 | 0 | sb.append( " </pluginManagement>" ).append( '\n' ); |
583 | 0 | sb.append( " <!-- " + getBundle( locale ).getString( "report.plugin.usage.plugins" ) + " -->" ).append( |
584 | |
'\n' ); |
585 | 0 | sb.append( " <plugins>" ).append( '\n' ); |
586 | 0 | sb.append( " <plugin>" ).append( '\n' ); |
587 | 0 | sb.append( " <groupId>" ).append( pluginDescriptor.getGroupId() ).append( "</groupId>" ).append( |
588 | |
'\n' ); |
589 | 0 | sb.append( " <artifactId>" ).append( pluginDescriptor.getArtifactId() ).append( |
590 | |
"</artifactId>" ).append( '\n' ); |
591 | 0 | sb.append( " <version>" ).append( pluginDescriptor.getVersion() ).append( "</version>" ).append( |
592 | |
'\n' ); |
593 | 0 | sb.append( " </plugin>" ).append( '\n' ); |
594 | 0 | sb.append( " ..." ).append( '\n' ); |
595 | 0 | sb.append( " </plugins>" ).append( '\n' ); |
596 | 0 | sb.append( " </build>" ).append( '\n' ); |
597 | |
|
598 | 0 | if ( hasMavenReport ) |
599 | |
{ |
600 | 0 | sb.append( " ..." ).append( '\n' ); |
601 | 0 | sb.append( |
602 | |
" <!-- " + getBundle( locale ).getString( "report.plugin.usage.reporting" ) + " -->" ).append( |
603 | |
'\n' ); |
604 | 0 | sb.append( " <reporting>" ).append( '\n' ); |
605 | 0 | sb.append( " <plugins>" ).append( '\n' ); |
606 | 0 | sb.append( " <plugin>" ).append( '\n' ); |
607 | 0 | sb.append( " <groupId>" ).append( pluginDescriptor.getGroupId() ).append( "</groupId>" ).append( |
608 | |
'\n' ); |
609 | 0 | sb.append( " <artifactId>" ).append( pluginDescriptor.getArtifactId() ).append( |
610 | |
"</artifactId>" ).append( '\n' ); |
611 | 0 | sb.append( " <version>" ).append( pluginDescriptor.getVersion() ).append( "</version>" ).append( |
612 | |
'\n' ); |
613 | 0 | sb.append( " </plugin>" ).append( '\n' ); |
614 | 0 | sb.append( " ..." ).append( '\n' ); |
615 | 0 | sb.append( " </plugins>" ).append( '\n' ); |
616 | 0 | sb.append( " </reporting>" ).append( '\n' ); |
617 | |
} |
618 | |
|
619 | 0 | sb.append( " ..." ).append( '\n' ); |
620 | 0 | sb.append( "</project>" ).append( '\n' ); |
621 | |
|
622 | 0 | verbatimText( sb.toString() ); |
623 | |
|
624 | 0 | sink.paragraph(); |
625 | 0 | linkPatternedText( getBundle( locale ).getString( "report.plugin.configuration.end" ) ); |
626 | 0 | sink.paragraph_(); |
627 | |
|
628 | 0 | endSection(); |
629 | 0 | } |
630 | |
|
631 | |
|
632 | |
|
633 | |
|
634 | |
|
635 | |
|
636 | |
|
637 | |
|
638 | |
|
639 | |
private static String discoverMavenRequirement( MavenProject project, Requirements requirements ) |
640 | |
{ |
641 | 0 | String maven = requirements.getMaven(); |
642 | 0 | if ( maven == null ) |
643 | |
{ |
644 | 0 | maven = ( project.getPrerequisites() != null ? project.getPrerequisites().getMaven() : null ); |
645 | |
} |
646 | 0 | if ( maven == null ) |
647 | |
{ |
648 | 0 | maven = "2.0"; |
649 | |
} |
650 | |
|
651 | 0 | return maven; |
652 | |
} |
653 | |
|
654 | |
|
655 | |
|
656 | |
|
657 | |
|
658 | |
|
659 | |
|
660 | |
|
661 | |
|
662 | |
|
663 | |
|
664 | |
private static String discoverJdkRequirement( MavenProject project, Requirements requirements ) |
665 | |
{ |
666 | 0 | String jdk = requirements.getJdk(); |
667 | 0 | if ( jdk == null ) |
668 | |
{ |
669 | 0 | jdk = discoverJdkRequirementFromPlugins( project.getBuild().getPluginsAsMap() ); |
670 | |
} |
671 | 0 | if ( jdk == null && project.getPluginManagement() != null ) |
672 | |
{ |
673 | 0 | jdk = discoverJdkRequirementFromPlugins( project.getPluginManagement().getPluginsAsMap() ); |
674 | |
} |
675 | 0 | if ( jdk == null ) |
676 | |
{ |
677 | 0 | jdk = "Unknown"; |
678 | |
} |
679 | |
|
680 | 0 | return jdk; |
681 | |
} |
682 | |
|
683 | |
|
684 | |
|
685 | |
|
686 | |
|
687 | |
@SuppressWarnings( "rawtypes" ) |
688 | |
private static String discoverJdkRequirementFromPlugins( Map pluginsAsMap ) |
689 | |
{ |
690 | 0 | if ( pluginsAsMap == null ) |
691 | |
{ |
692 | 0 | return null; |
693 | |
} |
694 | |
|
695 | 0 | String jdk = null; |
696 | 0 | String backupJdk = null; |
697 | 0 | for ( Iterator it = pluginsAsMap.keySet().iterator(); it.hasNext(); ) |
698 | |
{ |
699 | 0 | String key = it.next().toString(); |
700 | |
|
701 | 0 | if ( !key.equals( "org.apache.maven.plugins:maven-compiler-plugin" ) ) |
702 | |
{ |
703 | 0 | continue; |
704 | |
} |
705 | |
|
706 | 0 | Object value = pluginsAsMap.get( key ); |
707 | 0 | Xpp3Dom pluginConf = null; |
708 | |
|
709 | 0 | backupJdk = "Default version for maven-compiler-plugin"; |
710 | 0 | if ( value instanceof Plugin ) |
711 | |
{ |
712 | 0 | Plugin plugin = (Plugin) value; |
713 | 0 | backupJdk = "Default target for maven-compiler-plugin version " + plugin.getVersion(); |
714 | 0 | pluginConf = (Xpp3Dom) plugin.getConfiguration(); |
715 | |
} |
716 | |
|
717 | 0 | if ( value instanceof ReportPlugin ) |
718 | |
{ |
719 | 0 | ReportPlugin reportPlugin = (ReportPlugin) value; |
720 | 0 | backupJdk = "Default target for maven-compiler-plugin version " + reportPlugin.getVersion(); |
721 | 0 | pluginConf = (Xpp3Dom) reportPlugin.getConfiguration(); |
722 | |
} |
723 | |
|
724 | 0 | if ( pluginConf == null ) |
725 | |
{ |
726 | 0 | continue; |
727 | |
} |
728 | |
|
729 | 0 | if ( pluginConf.getChild( "target" ) == null ) |
730 | |
{ |
731 | 0 | continue; |
732 | |
} |
733 | |
|
734 | 0 | jdk = pluginConf.getChild( "target" ).getValue(); |
735 | 0 | } |
736 | |
|
737 | 0 | if ( jdk == null ) |
738 | |
{ |
739 | 0 | return backupJdk; |
740 | |
} |
741 | |
else |
742 | |
{ |
743 | 0 | return jdk; |
744 | |
} |
745 | |
} |
746 | |
} |
747 | |
} |