From 89a82c2963245f526fbe0ad8db075a6c35160a25 Mon Sep 17 00:00:00 2001 From: Robert Scholte Date: Sun, 20 Nov 2016 14:42:29 +0000 Subject: [PATCH] [MPLUGIN-319] @since values ignored in report Only use plugin.xml for M3.4.0 and above due to MNG-6109 git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@1770562 13f79535-47bb-0310-9956-ffa450edef68 --- .../invoker.properties | 18 ++++ .../src/it/mplugin-329_report-since/pom.xml | 86 +++++++++++++++++++ .../src/main/java/org/MyMojo.java | 67 +++++++++++++++ .../it/mplugin-329_report-since/verify.groovy | 27 ++++++ .../src/it/plugin-info-jdk/pom.xml | 4 + .../maven/plugin/plugin/PluginReport.java | 78 ++++++++++++----- 6 files changed, 257 insertions(+), 23 deletions(-) create mode 100644 maven-plugin-plugin/src/it/mplugin-329_report-since/invoker.properties create mode 100644 maven-plugin-plugin/src/it/mplugin-329_report-since/pom.xml create mode 100644 maven-plugin-plugin/src/it/mplugin-329_report-since/src/main/java/org/MyMojo.java create mode 100644 maven-plugin-plugin/src/it/mplugin-329_report-since/verify.groovy diff --git a/maven-plugin-plugin/src/it/mplugin-329_report-since/invoker.properties b/maven-plugin-plugin/src/it/mplugin-329_report-since/invoker.properties new file mode 100644 index 0000000..1f02de5 --- /dev/null +++ b/maven-plugin-plugin/src/it/mplugin-329_report-since/invoker.properties @@ -0,0 +1,18 @@ +# 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. + +invoker.goals = clean plugin:report diff --git a/maven-plugin-plugin/src/it/mplugin-329_report-since/pom.xml b/maven-plugin-plugin/src/it/mplugin-329_report-since/pom.xml new file mode 100644 index 0000000..628999d --- /dev/null +++ b/maven-plugin-plugin/src/it/mplugin-329_report-since/pom.xml @@ -0,0 +1,86 @@ + + + + + + 4.0.0 + + org.apache.maven.plugins.its.plugin + report-since + 1.0-SNAPSHOT + maven-plugin + + + UTF-8 + + + + + org.apache.maven + maven-plugin-api + 2.0 + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + + org.apache.maven.plugins + maven-plugin-plugin + @project.version@ + + + org.apache.maven.plugins + maven-site-plugin + @sitePluginVersion@ + + + + + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 2.4 + + + + index + + + + + + org.apache.maven.plugins + maven-plugin-plugin + @project.version@ + + + + diff --git a/maven-plugin-plugin/src/it/mplugin-329_report-since/src/main/java/org/MyMojo.java b/maven-plugin-plugin/src/it/mplugin-329_report-since/src/main/java/org/MyMojo.java new file mode 100644 index 0000000..915a2db --- /dev/null +++ b/maven-plugin-plugin/src/it/mplugin-329_report-since/src/main/java/org/MyMojo.java @@ -0,0 +1,67 @@ +package org; + +/* + * 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.AbstractMojo; + +/** + * Does nothing. + * + * @goal noop + * @phase process-sources + * @requiresDependencyResolution test + * @requiresDirectInvocation true + * @requiresOnline + * @inheritByDefault false + * @execute phase="compile" + * @aggregator + * @since 1.0 + * + * @deprecated You don't use test goals, do you? + */ +public class MyMojo + extends AbstractMojo +{ + + /** + * This is a test. + * + * @parameter + * @required + */ + @SuppressWarnings( "unused" ) + private String required; + + /** + * This is a test. + * + * @parameter expression="${string}" default-value="${project.version}/" + * @deprecated Just testing. + * @since 1.1 + */ + @SuppressWarnings( "unused" ) + private String string; + + public void execute() + { + // intentional do nothing + } + +} diff --git a/maven-plugin-plugin/src/it/mplugin-329_report-since/verify.groovy b/maven-plugin-plugin/src/it/mplugin-329_report-since/verify.groovy new file mode 100644 index 0000000..294a0c0 --- /dev/null +++ b/maven-plugin-plugin/src/it/mplugin-329_report-since/verify.groovy @@ -0,0 +1,27 @@ + +/* + * 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. + */ +assert new File( basedir, 'target/generated-site' ).exists() + +content = new File( basedir, 'target/generated-site/xdoc/noop-mojo.xml' ).text + +assert content.contains( '
  • Since: 1.0
  • ' ) +assert content.contains( '
  • Since: 1.1
  • ' ) + +return true \ No newline at end of file diff --git a/maven-plugin-plugin/src/it/plugin-info-jdk/pom.xml b/maven-plugin-plugin/src/it/plugin-info-jdk/pom.xml index a184f45..5404a98 100644 --- a/maven-plugin-plugin/src/it/plugin-info-jdk/pom.xml +++ b/maven-plugin-plugin/src/it/plugin-info-jdk/pom.xml @@ -90,6 +90,10 @@ under the License. org.apache.maven.plugins maven-plugin-plugin @project.version@ + + + [2.0,) + 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 4bc7a58..8c085fe 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 @@ -19,10 +19,24 @@ package org.apache.maven.plugin.plugin; * under the License. */ +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.ResourceBundle; +import java.util.Set; + import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; +import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.doxia.sink.Sink; import org.apache.maven.doxia.siterenderer.Renderer; +import org.apache.maven.execution.RuntimeInformation; import org.apache.maven.model.Plugin; import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; import org.apache.maven.plugin.descriptor.MojoDescriptor; @@ -50,17 +64,6 @@ import org.codehaus.plexus.configuration.PlexusConfigurationException; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.Xpp3Dom; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.ResourceBundle; -import java.util.Set; - /** * Generates the Plugin's documentation report: plugin-info.html plugin overview page, * and one goal-mojo.html per goal. @@ -186,6 +189,19 @@ public class PluginReport */ @Parameter( defaultValue = "${localRepository}", required = true, readonly = true ) protected ArtifactRepository local; + + /** + * @since 3.5.1 + */ + @Component + private RuntimeInformation rtInfo; + + /** + * By default pluginXml should be read with Maven-3.4.0+ (MNG-6109) + * For some integration-tests this is not an issue, they can reduce this spec. + */ + @Parameter( readonly = true ) + private String pluginXmlSpec = "(3.3.9,)"; /** * {@inheritDoc} @@ -250,19 +266,22 @@ public class PluginReport private PluginDescriptor extractPluginDescriptor() throws MavenReportException { - PluginDescriptorBuilder builder = new PluginDescriptorBuilder(); - try + if ( usePluginXml() ) { - 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" ); + 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" ); + } } // Copy from AbstractGeneratorMojo#execute() @@ -319,6 +338,19 @@ public class PluginReport return pluginDescriptor; } + private boolean usePluginXml() + { + try + { + VersionRange versionRange = VersionRange.createFromVersionSpec( pluginXmlSpec ); + return versionRange.containsVersion( rtInfo.getApplicationVersion() ); + } + catch ( InvalidVersionSpecificationException e ) + { + return false; + } + } + /** * {@inheritDoc} */