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 84e1d2e..553af0e 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
@@ -47,6 +47,7 @@ import org.apache.maven.plugins.annotations.Execute;
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 META-INF/maven/plugin.xml 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 META-INF/maven/plugin.xml gives accurate since only with Maven-3.4.0+
- * (see MNG-6109).
- * For cases where missing since 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;
}
/**
diff --git a/maven-plugin-plugin/src/main/java/org/apache/maven/plugins/plugin/descriptor/MNG6109PluginDescriptorBuilder.java b/maven-plugin-plugin/src/main/java/org/apache/maven/plugins/plugin/descriptor/MNG6109PluginDescriptorBuilder.java
new file mode 100644
index 0000000..0ebe92d
--- /dev/null
+++ b/maven-plugin-plugin/src/main/java/org/apache/maven/plugins/plugin/descriptor/MNG6109PluginDescriptorBuilder.java
@@ -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;
+ }
+}