[MPLUGIN-319] @since values ignored in report
New strategy where we don't need a parameter anymore (who would change it?) git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@1778770 13f79535-47bb-0310-9956-ffa450edef68master
parent
6fda7882f1
commit
bcf94564ba
|
|
@ -47,6 +47,7 @@ import org.apache.maven.plugins.annotations.Execute;
|
||||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||||
import org.apache.maven.plugins.annotations.Mojo;
|
import org.apache.maven.plugins.annotations.Mojo;
|
||||||
import org.apache.maven.plugins.annotations.Parameter;
|
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.project.MavenProject;
|
||||||
import org.apache.maven.reporting.AbstractMavenReport;
|
import org.apache.maven.reporting.AbstractMavenReport;
|
||||||
import org.apache.maven.reporting.AbstractMavenReportRenderer;
|
import org.apache.maven.reporting.AbstractMavenReportRenderer;
|
||||||
|
|
@ -195,18 +196,6 @@ public class PluginReport
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
private RuntimeInformation rtInfo;
|
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}
|
* {@inheritDoc}
|
||||||
|
|
@ -271,26 +260,20 @@ public class PluginReport
|
||||||
private PluginDescriptor extractPluginDescriptor()
|
private PluginDescriptor extractPluginDescriptor()
|
||||||
throws MavenReportException
|
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();
|
getLog().debug( "Failed to read META-INF/maven/plugin.xml, fall back to mojoScanner" );
|
||||||
try
|
}
|
||||||
{
|
catch ( PlexusConfigurationException e )
|
||||||
return builder.build( new FileReader( new File( project.getBuild().getOutputDirectory(),
|
{
|
||||||
"META-INF/maven/plugin.xml" ) ) );
|
getLog().debug( "Failed to read META-INF/maven/plugin.xml, fall back to mojoScanner" );
|
||||||
}
|
|
||||||
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" );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy from AbstractGeneratorMojo#execute()
|
// 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
|
* Return the pluginDescriptorBuilder to use based on the Maven version: either use the original from the
|
||||||
* MNG-6109 bug that won't give accurate since info when reading plugin.xml).
|
* maven-plugin-api or a patched version for Maven versions before the MNG-6109 fix
|
||||||
* @return true if runing Maven version is in configured usePluginXmlMavenVersionRange range
|
* (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/MNG-6109
|
||||||
* @see https://issues.apache.org/jira/browse/MPLUGIN-319
|
* @see https://issues.apache.org/jira/browse/MPLUGIN-319
|
||||||
*/
|
*/
|
||||||
private boolean usePluginXml()
|
private PluginDescriptorBuilder getPluginDescriptorBuilder()
|
||||||
{
|
{
|
||||||
|
PluginDescriptorBuilder pluginDescriptorBuilder;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
VersionRange versionRange = VersionRange.createFromVersionSpec( usePluginXmlMavenVersionRange );
|
VersionRange versionRange = VersionRange.createFromVersionSpec( "(3.3.9,)" );
|
||||||
return versionRange.containsVersion( rtInfo.getApplicationVersion() );
|
if ( versionRange.containsVersion( rtInfo.getApplicationVersion() ) )
|
||||||
|
{
|
||||||
|
pluginDescriptorBuilder = new PluginDescriptorBuilder();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pluginDescriptorBuilder = new MNG6109PluginDescriptorBuilder();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch ( InvalidVersionSpecificationException e )
|
catch ( InvalidVersionSpecificationException e )
|
||||||
{
|
{
|
||||||
return false;
|
return new MNG6109PluginDescriptorBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return pluginDescriptorBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue