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