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