From 6af5d83644c70ce286cdf09876d17974b1975ff1 Mon Sep 17 00:00:00 2001 From: Andrzej Jarmoniuk Date: Thu, 29 Dec 2022 21:45:27 +0100 Subject: [PATCH] Resolves #550: New parameter to DisplayPluginUpdatesMojo: processUnboundPlugins - if true, will show updates to plugins defined in parent poms, which have no version in the current pom - false by default to retain backwards compatibility --- .../invoker.properties | 18 +++++++++ .../parent.xml | 38 +++++++++++++++++++ .../pom.xml | 26 +++++++++++++ .../verify.groovy | 21 ++++++++++ .../versions/DisplayPluginUpdatesMojo.java | 18 +++++++-- 5 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 versions-maven-plugin/src/it/it-display-plugin-updates-issue-533/invoker.properties create mode 100644 versions-maven-plugin/src/it/it-display-plugin-updates-issue-533/parent.xml create mode 100644 versions-maven-plugin/src/it/it-display-plugin-updates-issue-533/pom.xml create mode 100644 versions-maven-plugin/src/it/it-display-plugin-updates-issue-533/verify.groovy diff --git a/versions-maven-plugin/src/it/it-display-plugin-updates-issue-533/invoker.properties b/versions-maven-plugin/src/it/it-display-plugin-updates-issue-533/invoker.properties new file mode 100644 index 000000000..69d411734 --- /dev/null +++ b/versions-maven-plugin/src/it/it-display-plugin-updates-issue-533/invoker.properties @@ -0,0 +1,18 @@ +# +# Copyright MojoHaus and Contributors +# +# Licensed 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 = ${project.groupId}:${project.artifactId}:${project.version}:display-plugin-updates -N +invoker.mavenOpts = -DprocessUnboundPlugins=true -Dversions.outputFile=output.txt -DoutputEncoding=UTF-8 diff --git a/versions-maven-plugin/src/it/it-display-plugin-updates-issue-533/parent.xml b/versions-maven-plugin/src/it/it-display-plugin-updates-issue-533/parent.xml new file mode 100644 index 000000000..f53c9378f --- /dev/null +++ b/versions-maven-plugin/src/it/it-display-plugin-updates-issue-533/parent.xml @@ -0,0 +1,38 @@ + + + + 4.0.0 + + localhost + it-display-plugin-updates-issue-550-parent + 1.0 + pom + + + + + + org.apache.maven.plugins + maven-jar-plugin + 3.0.0 + + + + + + diff --git a/versions-maven-plugin/src/it/it-display-plugin-updates-issue-533/pom.xml b/versions-maven-plugin/src/it/it-display-plugin-updates-issue-533/pom.xml new file mode 100644 index 000000000..434eab734 --- /dev/null +++ b/versions-maven-plugin/src/it/it-display-plugin-updates-issue-533/pom.xml @@ -0,0 +1,26 @@ + + 4.0.0 + + + localhost + it-display-plugin-updates-issue-550-parent + 1.0 + parent.xml + + + it-display-plugin-updates-issue-550 + 1.0 + pom + + + + + + maven-jar-plugin + + + + + + diff --git a/versions-maven-plugin/src/it/it-display-plugin-updates-issue-533/verify.groovy b/versions-maven-plugin/src/it/it-display-plugin-updates-issue-533/verify.groovy new file mode 100644 index 000000000..88307c751 --- /dev/null +++ b/versions-maven-plugin/src/it/it-display-plugin-updates-issue-533/verify.groovy @@ -0,0 +1,21 @@ +/* + * Copyright MojoHaus and Contributors + * + * Licensed 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, 'output.txt').text + .replaceAll('\r', '') + .contains('The following plugin updates are available:\n' + + ' maven-jar-plugin ................................... 3.0.0 -> 3.3.0') diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayPluginUpdatesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayPluginUpdatesMojo.java index cbe735071..a5dc70231 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayPluginUpdatesMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayPluginUpdatesMojo.java @@ -64,6 +64,7 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuilder; import org.apache.maven.project.ProjectBuildingException; @@ -145,6 +146,17 @@ public class DisplayPluginUpdatesMojo extends AbstractVersionsDisplayMojo { */ protected final ProjectBuilder projectBuilder; + /** + *

If set to {@code true}, will also display updates to plugins where no version is specified + * in the current POM, but whose version is specified in the parent or the "superpom".

+ *

It might not always be possible to update these plugins, + * thus the default value of this parameter is {@code false}

. + * + * @since 2.15.0 + */ + @Parameter(property = "processUnboundPlugins", defaultValue = "false") + protected boolean processUnboundPlugins; + // --------------------- GETTER / SETTER METHODS --------------------- @Inject @@ -350,11 +362,11 @@ public void execute() throws MojoExecutionException, MojoFailureException { } boolean versionSpecifiedInCurrentPom = pluginsWithVersionsSpecified.contains(coords); - if (!versionSpecifiedInCurrentPom && parentPlugins.containsKey(coords)) { + if (!versionSpecifiedInCurrentPom && !processUnboundPlugins && parentPlugins.containsKey(coords)) { getLog().debug("Skip " + coords + ", version " + version + " is defined in parent POM."); + getLog().debug("Use the \"processUnboundPlugins\" parameter to see these updates."); continue; } - getLog().debug("Checking " + coords + " for updates newer than " + version); String effectiveVersion = version; @@ -447,7 +459,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { getLog().debug("[" + coords + "].artifactVersion=" + artifactVersion); getLog().debug("[" + coords + "].effectiveVersion=" + effectiveVersion); getLog().debug("[" + coords + "].specified=" + versionSpecifiedInCurrentPom); - if (version == null || !versionSpecifiedInCurrentPom) { + if (version == null || (!processUnboundPlugins && !versionSpecifiedInCurrentPom)) { version = superPomPluginManagement.get(coords); getLog().debug("[" + coords + "].superPom.version=" + version);