Skip to content

Commit

Permalink
Resolves mojohaus#550: New parameter to DisplayPluginUpdatesMojo: pro…
Browse files Browse the repository at this point in the history
…cessUnboundPlugins

- 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
  • Loading branch information
jarmoniuk authored and slawekjaranowski committed Jan 4, 2023
1 parent c14ee91 commit 6af5d83
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!--
~ 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>localhost</groupId>
<artifactId>it-display-plugin-updates-issue-550-parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>localhost</groupId>
<artifactId>it-display-plugin-updates-issue-550-parent</artifactId>
<version>1.0</version>
<relativePath>parent.xml</relativePath>
</parent>

<artifactId>it-display-plugin-updates-issue-550</artifactId>
<version>1.0</version>
<packaging>pom</packaging>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -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')
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -145,6 +146,17 @@ public class DisplayPluginUpdatesMojo extends AbstractVersionsDisplayMojo {
*/
protected final ProjectBuilder projectBuilder;

/**
* <p>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".</p>
* <p>It might not always be possible to update these plugins,
* thus the default value of this parameter is {@code false}</p>.
*
* @since 2.15.0
*/
@Parameter(property = "processUnboundPlugins", defaultValue = "false")
protected boolean processUnboundPlugins;

// --------------------- GETTER / SETTER METHODS ---------------------

@Inject
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 6af5d83

Please sign in to comment.