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 17:02:26 UTC

[maven-plugin-tools] branch MPLUGIN-407 updated (5eb17de4 -> 3886aee7)

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


 discard 5eb17de4 [MPLUGIN-407] Remove duplicate code from PluginReport
     new 3886aee7 [MPLUGIN-407] Remove duplicate code from PluginReport

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (5eb17de4)
            \
             N -- N -- N   refs/heads/MPLUGIN-407 (3886aee7)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

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.


Summary of changes:
 .../apache/maven/plugin/plugin/PluginReport.java   | 31 +++++-----------------
 1 file changed, 6 insertions(+), 25 deletions(-)


[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 3886aee7323bcaf174b391d26be3dd320ab68632
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   | 133 ++-------------------
 1 file changed, 12 insertions(+), 121 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 0ef02e59..66e52050 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,22 +20,18 @@ 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;
 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 +48,10 @@ 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,29 +76,14 @@ 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.
-     */
-    @Component
-    protected MojoScanner mojoScanner;
-
     /**
      * The file encoding of the source files.
      *
+     * @deprecated not used in report
+     *
      * @since 2.7
      */
+    @Deprecated
     @Parameter( property = "encoding", defaultValue = "${project.build.sourceEncoding}" )
     private String encoding;
 
@@ -151,8 +129,11 @@ public class PluginReport
      * (There is a special case for maven-plugin-plugin: it is mapped to 'plugin')
      * </p>
      *
+     * @deprecated not used in report
+     *
      * @since 2.4
      */
+    @Deprecated
     @Parameter( property = "goalPrefix" )
     protected String goalPrefix;
 
@@ -181,22 +162,6 @@ public class PluginReport
     @Parameter( defaultValue = "false", property = "maven.plugin.report.hasExtensionsToLoad" )
     private boolean hasExtensionsToLoad;
 
-    /**
-     * List of Remote Repositories used by the resolver
-     *
-     * @since 3.0
-     */
-    @Parameter( defaultValue = "${project.remoteArtifactRepositories}", required = true, readonly = true )
-    protected List<ArtifactRepository> remoteRepos;
-
-    /**
-     * Location of the local repository.
-     *
-     * @since 3.0
-     */
-    @Parameter( defaultValue = "${localRepository}", required = true, readonly = true )
-    protected ArtifactRepository local;
-    
     /**
      * @since 3.5.1
      */
@@ -212,15 +177,6 @@ public class PluginReport
                     readonly = true )
     private File pluginXmlFile;
 
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    protected Renderer getSiteRenderer()
-    {
-        return siteRenderer;
-    }
-
     /**
      * {@inheritDoc}
      */
@@ -231,15 +187,6 @@ public class PluginReport
         return project.getReporting().getOutputDirectory();
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    protected MavenProject getProject()
-    {
-        return project;
-    }
-
     /**
      * {@inheritDoc}
      */
@@ -256,10 +203,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." );
@@ -273,7 +216,7 @@ public class PluginReport
 
         // Write the overview
         PluginOverviewRenderer r =
-            new PluginOverviewRenderer( project, requirements, getSink(), 
+            new PluginOverviewRenderer( getProject(), requirements, getSink(),
                     pluginDescriptor, locale, hasExtensionsToLoad );
         r.render();
     }
@@ -283,66 +226,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" );
+            throw new MavenReportException( "Error extracting plugin descriptor from " + pluginXmlFile, e );
         }
 
-        // 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" );
-        }
-
-        // 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;
     }
 
     /**
@@ -412,8 +304,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 )
@@ -485,7 +377,6 @@ public class PluginReport
          * {@inheritDoc}
          */
         @Override
-        @SuppressWarnings( { "unchecked", "rawtypes" } )
         public void renderBody()
         {
             startSection( getTitle() );