You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2017/01/14 13:39:47 UTC

svn commit: r1778770 - in /maven/plugin-tools/trunk/maven-plugin-plugin/src/main/java/org/apache/maven: plugin/plugin/PluginReport.java plugins/ plugins/plugin/ plugins/plugin/descriptor/ plugins/plugin/descriptor/MNG6109PluginDescriptorBuilder.java

Author: rfscholte
Date: Sat Jan 14 13:39:47 2017
New Revision: 1778770

URL: http://svn.apache.org/viewvc?rev=1778770&view=rev
Log:
[MPLUGIN-319] @since values ignored in report
New strategy where we don't need a parameter anymore (who would change it?)

Added:
    maven/plugin-tools/trunk/maven-plugin-plugin/src/main/java/org/apache/maven/plugins/
    maven/plugin-tools/trunk/maven-plugin-plugin/src/main/java/org/apache/maven/plugins/plugin/
    maven/plugin-tools/trunk/maven-plugin-plugin/src/main/java/org/apache/maven/plugins/plugin/descriptor/
    maven/plugin-tools/trunk/maven-plugin-plugin/src/main/java/org/apache/maven/plugins/plugin/descriptor/MNG6109PluginDescriptorBuilder.java
Modified:
    maven/plugin-tools/trunk/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java

Modified: maven/plugin-tools/trunk/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java
URL: http://svn.apache.org/viewvc/maven/plugin-tools/trunk/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java?rev=1778770&r1=1778769&r2=1778770&view=diff
==============================================================================
--- maven/plugin-tools/trunk/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java (original)
+++ maven/plugin-tools/trunk/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/PluginReport.java Sat Jan 14 13:39:47 2017
@@ -47,6 +47,7 @@ import org.apache.maven.plugins.annotati
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.plugin.descriptor.MNG6109PluginDescriptorBuilder;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.reporting.AbstractMavenReport;
 import org.apache.maven.reporting.AbstractMavenReportRenderer;
@@ -195,18 +196,6 @@ public class PluginReport
      */
     @Component
     private RuntimeInformation rtInfo;
-    
-    /**
-     * Maven version range where <code>META-INF/maven/plugin.xml</code> should be used to get plugin info:
-     * when running with a Maven version not in the range, plugin info is extracted directly from plugin source.
-     * Reading <code>META-INF/maven/plugin.xml</code> gives accurate <code>since</code> only with Maven-3.4.0+
-     * (see MNG-6109).
-     * For cases where missing <code>since</code> info is not an issue, this version range spec can be changed
-     * to avoid extracting info from plugin source once again.
-     * @since 3.5.1
-     */
-    @Parameter( defaultValue = "(3.3.9,)" )
-    private String usePluginXmlMavenVersionRange;
 
     /**
      * {@inheritDoc}
@@ -271,26 +260,20 @@ public class PluginReport
     private PluginDescriptor extractPluginDescriptor()
         throws MavenReportException
     {
-        if ( !usePluginXml() )
+        PluginDescriptorBuilder builder = getPluginDescriptorBuilder();
+        
+        try
         {
-            getLog().debug( "Mojo configured to avoid plugin.xml (MNG-6109): fall back to mojoScanner" );
+            return builder.build( new FileReader( new File( project.getBuild().getOutputDirectory(),
+                                                            "META-INF/maven/plugin.xml" ) ) );
         }
-        else
+        catch ( FileNotFoundException e )
         {
-            PluginDescriptorBuilder builder = new PluginDescriptorBuilder();
-            try
-            {
-                return builder.build( new FileReader( new File( project.getBuild().getOutputDirectory(),
-                                                                "META-INF/maven/plugin.xml" ) ) );
-            }
-            catch ( FileNotFoundException e )
-            {
-                getLog().debug( "Failed to read META-INF/maven/plugin.xml, fall back to mojoScanner" );
-            }
-            catch ( PlexusConfigurationException e )
-            {
-                getLog().debug( "Failed to read META-INF/maven/plugin.xml, fall back to mojoScanner" );
-            }
+            getLog().debug( "Failed to read META-INF/maven/plugin.xml, fall back to mojoScanner" );
+        }
+        catch ( PlexusConfigurationException e )
+        {
+            getLog().debug( "Failed to read META-INF/maven/plugin.xml, fall back to mojoScanner" );
         }
 
         // Copy from AbstractGeneratorMojo#execute()
@@ -348,23 +331,35 @@ public class PluginReport
     }
 
     /**
-     * Check if META-INF/maven/plugin.xml should be used (as expected initially) or not (because of Maven
-     * MNG-6109 bug that won't give accurate since info when reading plugin.xml).
-     * @return true if runing Maven version is in configured usePluginXmlMavenVersionRange range
+     * Return the pluginDescriptorBuilder to use based on the Maven version: either use the original from the 
+     * maven-plugin-api or a patched version for Maven versions before the MNG-6109 fix 
+     * (because of Maven MNG-6109 bug that won't give accurate 'since' info when reading plugin.xml).
+     * 
+     * @return the proper pluginDescriptorBuilder
      * @see https://issues.apache.org/jira/browse/MNG-6109
      * @see https://issues.apache.org/jira/browse/MPLUGIN-319
      */
-    private boolean usePluginXml()
+    private PluginDescriptorBuilder getPluginDescriptorBuilder()
     {
+        PluginDescriptorBuilder pluginDescriptorBuilder;
         try
         {
-            VersionRange versionRange = VersionRange.createFromVersionSpec( usePluginXmlMavenVersionRange );
-            return versionRange.containsVersion( rtInfo.getApplicationVersion() );
+            VersionRange versionRange = VersionRange.createFromVersionSpec( "(3.3.9,)" );
+            if ( versionRange.containsVersion( rtInfo.getApplicationVersion() ) )
+            {
+                pluginDescriptorBuilder = new PluginDescriptorBuilder();
+            }
+            else
+            {
+                pluginDescriptorBuilder = new MNG6109PluginDescriptorBuilder();
+            }
         }
         catch ( InvalidVersionSpecificationException e )
         {
-            return false;
+            return new MNG6109PluginDescriptorBuilder();
         }
+        
+        return pluginDescriptorBuilder;
     }
 
     /**

Added: maven/plugin-tools/trunk/maven-plugin-plugin/src/main/java/org/apache/maven/plugins/plugin/descriptor/MNG6109PluginDescriptorBuilder.java
URL: http://svn.apache.org/viewvc/maven/plugin-tools/trunk/maven-plugin-plugin/src/main/java/org/apache/maven/plugins/plugin/descriptor/MNG6109PluginDescriptorBuilder.java?rev=1778770&view=auto
==============================================================================
--- maven/plugin-tools/trunk/maven-plugin-plugin/src/main/java/org/apache/maven/plugins/plugin/descriptor/MNG6109PluginDescriptorBuilder.java (added)
+++ maven/plugin-tools/trunk/maven-plugin-plugin/src/main/java/org/apache/maven/plugins/plugin/descriptor/MNG6109PluginDescriptorBuilder.java Sat Jan 14 13:39:47 2017
@@ -0,0 +1,61 @@
+package org.apache.maven.plugins.plugin.descriptor;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.plugin.descriptor.MojoDescriptor;
+import org.apache.maven.plugin.descriptor.PluginDescriptor;
+import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
+import org.codehaus.plexus.configuration.PlexusConfigurationException;
+
+/**
+ * Reads the plugin descriptor and adds the fix for MNG-6109 when using Maven-3.3.9 and before.
+ * Class can be removed once Maven 3.5.0 is the prerequisite for this plugin.
+ * 
+ * @author Robert Scholte
+ * @since 3.5.1
+ */
+public class MNG6109PluginDescriptorBuilder extends PluginDescriptorBuilder
+{
+
+    @Override
+    public MojoDescriptor buildComponentDescriptor( PlexusConfiguration c, PluginDescriptor pluginDescriptor )
+        throws PlexusConfigurationException
+    {
+        MojoDescriptor mojoDescriptor = super.buildComponentDescriptor( c, pluginDescriptor );
+        
+        // ----------------------------------------------------------------------
+        // Parameters
+        // ----------------------------------------------------------------------
+
+        PlexusConfiguration[] parameterConfigurations = c.getChild( "parameters" ).getChildren( "parameter" );
+
+        for ( PlexusConfiguration d : parameterConfigurations )
+        {
+            String parameterName = d.getChild( "name" ).getValue();
+            
+            String parameterSince = d.getChild( "since" ).getValue();
+            
+            mojoDescriptor.getParameterMap().get( parameterName ).setSince( parameterSince );
+        }
+        
+        return mojoDescriptor;
+    }
+}



Re: svn commit: r1778770 - in /maven/plugin-tools/trunk/maven-plugin-plugin/src/main/java/org/apache/maven: plugin/plugin/PluginReport.java plugins/ plugins/plugin/ plugins/plugin/descriptor/ plugins/plugin/descriptor/MNG6109PluginDescriptorBuilder.java

Posted by Hervé BOUTEMY <he...@free.fr>.
grrrrreat!
I like it :)

Regards,

Hervé

Le samedi 14 janvier 2017, 13:39:47 CET rfscholte@apache.org a écrit :
> Author: rfscholte
> Date: Sat Jan 14 13:39:47 2017
> New Revision: 1778770
> 
> URL: http://svn.apache.org/viewvc?rev=1778770&view=rev
> Log:
> [MPLUGIN-319] @since values ignored in report
> New strategy where we don't need a parameter anymore (who would change it?)
> 
> Added:
>    
> maven/plugin-tools/trunk/maven-plugin-plugin/src/main/java/org/apache/maven
> /plugins/
> maven/plugin-tools/trunk/maven-plugin-plugin/src/main/java/org/apache/maven
> /plugins/plugin/
> maven/plugin-tools/trunk/maven-plugin-plugin/src/main/java/org/apache/maven
> /plugins/plugin/descriptor/
> maven/plugin-tools/trunk/maven-plugin-plugin/src/main/java/org/apache/maven
> /plugins/plugin/descriptor/MNG6109PluginDescriptorBuilder.java Modified:
>    
> maven/plugin-tools/trunk/maven-plugin-plugin/src/main/java/org/apache/maven
> /plugin/plugin/PluginReport.java
> 
> Modified:
> maven/plugin-tools/trunk/maven-plugin-plugin/src/main/java/org/apache/maven
> /plugin/plugin/PluginReport.java URL:
> http://svn.apache.org/viewvc/maven/plugin-tools/trunk/maven-plugin-plugin/s
> rc/main/java/org/apache/maven/plugin/plugin/PluginReport.java?rev=1778770&r1
> =1778769&r2=1778770&view=diff
> ===========================================================================
> === ---
> maven/plugin-tools/trunk/maven-plugin-plugin/src/main/java/org/apache/maven
> /plugin/plugin/PluginReport.java (original) +++
> maven/plugin-tools/trunk/maven-plugin-plugin/src/main/java/org/apache/maven
> /plugin/plugin/PluginReport.java Sat Jan 14 13:39:47 2017 @@ -47,6 +47,7 @@
> import org.apache.maven.plugins.annotati
>  import org.apache.maven.plugins.annotations.LifecyclePhase;
>  import org.apache.maven.plugins.annotations.Mojo;
>  import org.apache.maven.plugins.annotations.Parameter;
> +import
> org.apache.maven.plugins.plugin.descriptor.MNG6109PluginDescriptorBuilder;
> import org.apache.maven.project.MavenProject;
>  import org.apache.maven.reporting.AbstractMavenReport;
>  import org.apache.maven.reporting.AbstractMavenReportRenderer;
> @@ -195,18 +196,6 @@ public class PluginReport
>       */
>      @Component
>      private RuntimeInformation rtInfo;
> -
> -    /**
> -     * Maven version range where <code>META-INF/maven/plugin.xml</code>
> should be used to get plugin info: -     * when running with a Maven
> version not in the range, plugin info is extracted directly from plugin
> source. -     * Reading <code>META-INF/maven/plugin.xml</code> gives
> accurate <code>since</code> only with Maven-3.4.0+ -     * (see MNG-6109).
> -     * For cases where missing <code>since</code> info is not an issue,
> this version range spec can be changed -     * to avoid extracting info
> from plugin source once again.
> -     * @since 3.5.1
> -     */
> -    @Parameter( defaultValue = "(3.3.9,)" )
> -    private String usePluginXmlMavenVersionRange;
> 
>      /**
>       * {@inheritDoc}
> @@ -271,26 +260,20 @@ public class PluginReport
>      private PluginDescriptor extractPluginDescriptor()
>          throws MavenReportException
>      {
> -        if ( !usePluginXml() )
> +        PluginDescriptorBuilder builder = getPluginDescriptorBuilder();
> +
> +        try
>          {
> -            getLog().debug( "Mojo configured to avoid plugin.xml
> (MNG-6109): fall back to mojoScanner" ); +            return builder.build(
> new FileReader( new File( project.getBuild().getOutputDirectory(), +       
>                                                    
> "META-INF/maven/plugin.xml" ) ) ); }
> -        else
> +        catch ( FileNotFoundException e )
>          {
> -            PluginDescriptorBuilder builder = new
> PluginDescriptorBuilder(); -            try
> -            {
> -                return builder.build( new FileReader( new File(
> project.getBuild().getOutputDirectory(), -                                 
>                               "META-INF/maven/plugin.xml" ) ) ); -         
>   }
> -            catch ( FileNotFoundException e )
> -            {
> -                getLog().debug( "Failed to read META-INF/maven/plugin.xml,
> fall back to mojoScanner" ); -            }
> -            catch ( PlexusConfigurationException e )
> -            {
> -                getLog().debug( "Failed to read META-INF/maven/plugin.xml,
> fall back to mojoScanner" ); -            }
> +            getLog().debug( "Failed to read META-INF/maven/plugin.xml, fall
> back to mojoScanner" ); +        }
> +        catch ( PlexusConfigurationException e )
> +        {
> +            getLog().debug( "Failed to read META-INF/maven/plugin.xml, fall
> back to mojoScanner" ); }
> 
>          // Copy from AbstractGeneratorMojo#execute()
> @@ -348,23 +331,35 @@ public class PluginReport
>      }
> 
>      /**
> -     * Check if META-INF/maven/plugin.xml should be used (as expected
> initially) or not (because of Maven -     * MNG-6109 bug that won't give
> accurate since info when reading plugin.xml). -     * @return true if
> runing Maven version is in configured usePluginXmlMavenVersionRange range +
>     * Return the pluginDescriptorBuilder to use based on the Maven version:
> either use the original from the +     * maven-plugin-api or a patched
> version for Maven versions before the MNG-6109 fix +     * (because of
> Maven MNG-6109 bug that won't give accurate 'since' info when reading
> plugin.xml). +     *
> +     * @return the proper pluginDescriptorBuilder
>       * @see https://issues.apache.org/jira/browse/MNG-6109
>       * @see https://issues.apache.org/jira/browse/MPLUGIN-319
>       */
> -    private boolean usePluginXml()
> +    private PluginDescriptorBuilder getPluginDescriptorBuilder()
>      {
> +        PluginDescriptorBuilder pluginDescriptorBuilder;
>          try
>          {
> -            VersionRange versionRange = VersionRange.createFromVersionSpec(
> usePluginXmlMavenVersionRange ); -            return
> versionRange.containsVersion( rtInfo.getApplicationVersion() ); +          
>  VersionRange versionRange = VersionRange.createFromVersionSpec( "(3.3.9,)"
> ); +            if ( versionRange.containsVersion(
> rtInfo.getApplicationVersion() ) ) +            {
> +                pluginDescriptorBuilder = new PluginDescriptorBuilder();
> +            }
> +            else
> +            {
> +                pluginDescriptorBuilder = new
> MNG6109PluginDescriptorBuilder(); +            }
>          }
>          catch ( InvalidVersionSpecificationException e )
>          {
> -            return false;
> +            return new MNG6109PluginDescriptorBuilder();
>          }
> +
> +        return pluginDescriptorBuilder;
>      }
> 
>      /**
> 
> Added:
> maven/plugin-tools/trunk/maven-plugin-plugin/src/main/java/org/apache/maven
> /plugins/plugin/descriptor/MNG6109PluginDescriptorBuilder.java URL:
> http://svn.apache.org/viewvc/maven/plugin-tools/trunk/maven-plugin-plugin/s
> rc/main/java/org/apache/maven/plugins/plugin/descriptor/MNG6109PluginDescrip
> torBuilder.java?rev=1778770&view=auto
> ===========================================================================
> === ---
> maven/plugin-tools/trunk/maven-plugin-plugin/src/main/java/org/apache/maven
> /plugins/plugin/descriptor/MNG6109PluginDescriptorBuilder.java (added) +++
> maven/plugin-tools/trunk/maven-plugin-plugin/src/main/java/org/apache/maven
> /plugins/plugin/descriptor/MNG6109PluginDescriptorBuilder.java Sat Jan 14
> 13:39:47 2017 @@ -0,0 +1,61 @@
> +package org.apache.maven.plugins.plugin.descriptor;
> +
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements.  See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership.  The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (the
> + * "License"); you may not use this file except in compliance
> + * with the License.  You may obtain a copy of the License at
> + *
> + *   http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied.  See the License for the
> + * specific language governing permissions and limitations
> + * under the License.
> + */
> +
> +import org.apache.maven.plugin.descriptor.MojoDescriptor;
> +import org.apache.maven.plugin.descriptor.PluginDescriptor;
> +import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
> +import org.codehaus.plexus.configuration.PlexusConfiguration;
> +import org.codehaus.plexus.configuration.PlexusConfigurationException;
> +
> +/**
> + * Reads the plugin descriptor and adds the fix for MNG-6109 when using
> Maven-3.3.9 and before. + * Class can be removed once Maven 3.5.0 is the
> prerequisite for this plugin. + *
> + * @author Robert Scholte
> + * @since 3.5.1
> + */
> +public class MNG6109PluginDescriptorBuilder extends PluginDescriptorBuilder
> +{
> +
> +    @Override
> +    public MojoDescriptor buildComponentDescriptor( PlexusConfiguration c,
> PluginDescriptor pluginDescriptor ) +        throws
> PlexusConfigurationException
> +    {
> +        MojoDescriptor mojoDescriptor = super.buildComponentDescriptor( c,
> pluginDescriptor ); +
> +        //
> ---------------------------------------------------------------------- +   
>     // Parameters
> +        //
> ---------------------------------------------------------------------- +
> +        PlexusConfiguration[] parameterConfigurations = c.getChild(
> "parameters" ).getChildren( "parameter" ); +
> +        for ( PlexusConfiguration d : parameterConfigurations )
> +        {
> +            String parameterName = d.getChild( "name" ).getValue();
> +
> +            String parameterSince = d.getChild( "since" ).getValue();
> +
> +            mojoDescriptor.getParameterMap().get( parameterName ).setSince(
> parameterSince ); +        }
> +
> +        return mojoDescriptor;
> +    }
> +}



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org