You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2022/07/14 16:25:28 UTC

[maven-plugin-tools] branch MPLUGIN-407 created (now 366240ca)

This is an automated email from the ASF dual-hosted git repository.

sjaranowski pushed a change to branch MPLUGIN-407
in repository https://gitbox.apache.org/repos/asf/maven-plugin-tools.git


      at 366240ca [MPLUGIN-407] Remove duplicate code from PluginReport

This branch includes the following new commits:

     new 366240ca [MPLUGIN-407] Remove duplicate code from PluginReport

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-plugin-tools] 01/01: [MPLUGIN-407] Remove duplicate code from PluginReport

Posted by sj...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sjaranowski pushed a commit to branch MPLUGIN-407
in repository https://gitbox.apache.org/repos/asf/maven-plugin-tools.git

commit 366240ca3d6949bb45435c4582b8110ce223f324
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Thu Jul 14 18:25:10 2022 +0200

    [MPLUGIN-407] Remove duplicate code from PluginReport
---
 .../apache/maven/plugin/plugin/PluginReport.java   | 104 ++-------------------
 1 file changed, 7 insertions(+), 97 deletions(-)

diff --git a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java
index 14f839ac..01c75a06 100644
--- a/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java
+++ b/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java
@@ -20,12 +20,11 @@ package org.apache.maven.plugin.plugin;
  */
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.Reader;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Iterator;
-import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -33,9 +32,7 @@ import java.util.ResourceBundle;
 
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.doxia.sink.Sink;
-import org.apache.maven.doxia.siterenderer.Renderer;
 import org.apache.maven.model.Plugin;
-import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
 import org.apache.maven.plugin.descriptor.MojoDescriptor;
 import org.apache.maven.plugin.descriptor.PluginDescriptor;
 import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
@@ -52,13 +49,11 @@ import org.apache.maven.reporting.MavenReportException;
 import org.apache.maven.rtinfo.RuntimeInformation;
 import org.apache.maven.tools.plugin.DefaultPluginToolsRequest;
 import org.apache.maven.tools.plugin.PluginToolsRequest;
-import org.apache.maven.tools.plugin.extractor.ExtractionException;
 import org.apache.maven.tools.plugin.generator.GeneratorException;
 import org.apache.maven.tools.plugin.generator.GeneratorUtils;
 import org.apache.maven.tools.plugin.generator.PluginXdocGenerator;
 import org.apache.maven.tools.plugin.scanner.MojoScanner;
 import org.apache.maven.tools.plugin.util.PluginUtils;
-import org.codehaus.plexus.component.repository.ComponentDependency;
 import org.codehaus.plexus.configuration.PlexusConfigurationException;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.XmlStreamReader;
@@ -83,18 +78,6 @@ public class PluginReport
     @Parameter( defaultValue = "${project.build.directory}/generated-site/xdoc" )
     private File outputDirectory;
 
-    /**
-     * Doxia Site Renderer.
-     */
-    @Component
-    private Renderer siteRenderer;
-
-    /**
-     * The Maven Project.
-     */
-    @Parameter( defaultValue = "${project}", readonly = true )
-    private MavenProject project;
-
     /**
      * Mojo scanner tools.
      */
@@ -215,15 +198,6 @@ public class PluginReport
                     readonly = true )
     private File pluginXmlFile;
 
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    protected Renderer getSiteRenderer()
-    {
-        return siteRenderer;
-    }
-
     /**
      * {@inheritDoc}
      */
@@ -234,15 +208,6 @@ public class PluginReport
         return project.getReporting().getOutputDirectory();
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    protected MavenProject getProject()
-    {
-        return project;
-    }
-
     /**
      * {@inheritDoc}
      */
@@ -259,10 +224,6 @@ public class PluginReport
     protected void executeReport( Locale locale )
         throws MavenReportException
     {
-        if ( !canGenerateReport() )
-        {
-            return;
-        }
         if ( skip || skipReport )
         {
             getLog().info( "Maven Plugin Plugin Report generation skipped." );
@@ -276,7 +237,7 @@ public class PluginReport
 
         // Write the overview
         PluginOverviewRenderer r =
-            new PluginOverviewRenderer( project, requirements, getSink(), 
+            new PluginOverviewRenderer( getProject(), requirements, getSink(),
                     pluginDescriptor, locale, hasExtensionsToLoad );
         r.render();
     }
@@ -286,66 +247,15 @@ public class PluginReport
     {
         PluginDescriptorBuilder builder = getPluginDescriptorBuilder();
 
-        try ( Reader input = new XmlStreamReader( new FileInputStream( pluginXmlFile ) ) )
+        try ( Reader input = new XmlStreamReader( Files.newInputStream( pluginXmlFile.toPath() ) ) )
         {
             return builder.build( input );
         }
         catch ( IOException | PlexusConfigurationException e )
         {
-            getLog().debug( "Failed to read " + pluginXmlFile + ", fall back to mojoScanner" );
-        }
-
-        // Copy from AbstractGeneratorMojo#execute()
-        String defaultGoalPrefix = PluginDescriptor.getGoalPrefixFromArtifactId( project.getArtifactId() );
-        if ( goalPrefix == null )
-        {
-            goalPrefix = defaultGoalPrefix;
-        }
-        else
-        {
-            getLog().warn( "\n\nGoal prefix is specified as: '" + goalPrefix + "'. Maven currently expects it to be '"
-                               + defaultGoalPrefix + "'.\n" );
+            throw new MavenReportException( "Error extracting plugin descriptor from " + pluginXmlFile, e );
         }
 
-        // TODO: could use this more, eg in the writing of the plugin descriptor!
-        PluginDescriptor pluginDescriptor = new PluginDescriptor();
-
-        pluginDescriptor.setGroupId( project.getGroupId() );
-
-        pluginDescriptor.setArtifactId( project.getArtifactId() );
-
-        pluginDescriptor.setVersion( project.getVersion() );
-
-        pluginDescriptor.setGoalPrefix( goalPrefix );
-
-        try
-        {
-            List<ComponentDependency> deps = GeneratorUtils.toComponentDependencies( project.getArtifacts() );
-            pluginDescriptor.setDependencies( deps );
-
-            PluginToolsRequest request = new DefaultPluginToolsRequest( project, pluginDescriptor );
-            request.setEncoding( encoding );
-            request.setSkipErrorNoDescriptorsFound( true );
-            request.setDependencies( new LinkedHashSet<>( project.getArtifacts() ) );
-            request.setLocal( this.local );
-            request.setRemoteRepos( this.remoteRepos );
-
-            try
-            {
-                mojoScanner.populatePluginDescriptor( request );
-            }
-            catch ( InvalidPluginDescriptorException e )
-            {
-                // this is OK, it happens to lifecycle plugins. Allow generation to proceed.
-                getLog().debug( "Plugin without mojos.", e );
-            }
-        }
-        catch ( ExtractionException e )
-        {
-            throw new MavenReportException( "Error extracting plugin descriptor: \'" + e.getLocalizedMessage() + "\'",
-                                            e );
-        }
-        return pluginDescriptor;
     }
 
     /**
@@ -415,8 +325,8 @@ public class PluginReport
             File outputDir = outputDirectory;
             outputDir.mkdirs();
 
-            PluginXdocGenerator generator = new PluginXdocGenerator( project, locale );
-            PluginToolsRequest pluginToolsRequest = new DefaultPluginToolsRequest( project, pluginDescriptor );
+            PluginXdocGenerator generator = new PluginXdocGenerator( getProject(), locale );
+            PluginToolsRequest pluginToolsRequest = new DefaultPluginToolsRequest( getProject(), pluginDescriptor );
             generator.execute( outputDir, pluginToolsRequest );
         }
         catch ( GeneratorException e )
@@ -488,7 +398,7 @@ public class PluginReport
          * {@inheritDoc}
          */
         @Override
-        @SuppressWarnings( { "unchecked", "rawtypes" } )
+        @SuppressWarnings( { "rawtypes" } )
         public void renderBody()
         {
             startSection( getTitle() );