From 8e71800afc9ea5ab653c5d70133f328dce476eb6 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 17 Nov 2023 09:01:35 +1000 Subject: [PATCH] Fix ISE with plugins aggregate report when reactor projects contains the same plugin declaration multiple time with different versions Signed-off-by: Olivier Lamy --- .../versions/api/PluginUpdatesDetails.java | 4 ++ .../mojo/versions/utils/MiscUtils.java | 8 +++ .../invoker.properties | 2 + .../module-a1/pom.xml | 34 +++++++++ .../module-a2/pom.xml | 34 +++++++++ .../module-a3/pom.xml | 35 ++++++++++ .../module-a4/pom.xml | 35 ++++++++++ .../pom.xml | 70 +++++++++++++++++++ .../verify.groovy | 26 +++++++ .../AbstractPluginUpdatesReportMojo.java | 8 ++- 10 files changed, 255 insertions(+), 1 deletion(-) create mode 100644 versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/invoker.properties create mode 100644 versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/module-a1/pom.xml create mode 100644 versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/module-a2/pom.xml create mode 100644 versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/module-a3/pom.xml create mode 100644 versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/module-a4/pom.xml create mode 100644 versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/pom.xml create mode 100644 versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/verify.groovy diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/api/PluginUpdatesDetails.java b/versions-common/src/main/java/org/codehaus/mojo/versions/api/PluginUpdatesDetails.java index ca7b3cbe73..7d55ac04f1 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/api/PluginUpdatesDetails.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/api/PluginUpdatesDetails.java @@ -51,6 +51,10 @@ public Map getDependencyVersions() { return dependencyVersions; } + public void addDependencyVersions(Map dependencyVersions) { + this.dependencyVersions.putAll(dependencyVersions); + } + /** * Returns true if a new version of the artifact fulfilling the criteria (whether to include snapshots) can be found * diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/utils/MiscUtils.java b/versions-common/src/main/java/org/codehaus/mojo/versions/utils/MiscUtils.java index fb50f51c67..984794ed6a 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/utils/MiscUtils.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/utils/MiscUtils.java @@ -1,6 +1,7 @@ package org.codehaus.mojo.versions.utils; import java.util.Map; +import java.util.function.BinaryOperator; import java.util.function.Function; import java.util.stream.Collectors; @@ -23,4 +24,11 @@ public static Map filter(Map map, Function predic .filter(e -> predicate.apply(e.getValue())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } + + public static Map filter( + Map map, Function predicate, BinaryOperator mergeFunction) { + return map.entrySet().stream() + .filter(e -> predicate.apply(e.getValue())) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, mergeFunction)); + } } diff --git a/versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/invoker.properties b/versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/invoker.properties new file mode 100644 index 0000000000..2cff9c9dc7 --- /dev/null +++ b/versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/invoker.properties @@ -0,0 +1,2 @@ +#invoker.goals=clean install +invoker.goals=-Pdependency-updates-reports validate validate diff --git a/versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/module-a1/pom.xml b/versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/module-a1/pom.xml new file mode 100644 index 0000000000..19046a1e5b --- /dev/null +++ b/versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/module-a1/pom.xml @@ -0,0 +1,34 @@ + + 4.0.0 + + + localhost + it-aggregate-plugn-multiple-versions-same-plugin + 1.0-SNAPSHOT + + + localhost + module-a1 + pom + + + + + localhost + dummy-api + 1.1.2 + + + + + + + + maven-assembly-plugin + 2.2 + + + + + diff --git a/versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/module-a2/pom.xml b/versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/module-a2/pom.xml new file mode 100644 index 0000000000..ee6e32fa03 --- /dev/null +++ b/versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/module-a2/pom.xml @@ -0,0 +1,34 @@ + + 4.0.0 + + + localhost + it-aggregate-plugn-multiple-versions-same-plugin + 1.0-SNAPSHOT + + + localhost + module-a2 + pom + + + + + localhost + module-a1 + ${project.version} + + + + + + + + maven-assembly-plugin + 3.3.0 + + + + + diff --git a/versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/module-a3/pom.xml b/versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/module-a3/pom.xml new file mode 100644 index 0000000000..5f3ebce935 --- /dev/null +++ b/versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/module-a3/pom.xml @@ -0,0 +1,35 @@ + + 4.0.0 + + + localhost + it-aggregate-plugn-multiple-versions-same-plugin + 1.0-SNAPSHOT + + + localhost + module-a3 + pom + + + + + localhost + dummy-api + 1.1.2 + + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.6.0 + + + + + diff --git a/versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/module-a4/pom.xml b/versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/module-a4/pom.xml new file mode 100644 index 0000000000..1c3e9aed80 --- /dev/null +++ b/versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/module-a4/pom.xml @@ -0,0 +1,35 @@ + + 4.0.0 + + + localhost + it-aggregate-plugn-multiple-versions-same-plugin + 1.0-SNAPSHOT + + + localhost + module-a4 + pom + + + + + localhost + dummy-api + 1.1.2 + + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.0.0 + + + + + diff --git a/versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/pom.xml b/versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/pom.xml new file mode 100644 index 0000000000..404ff0e4a1 --- /dev/null +++ b/versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/pom.xml @@ -0,0 +1,70 @@ + + 4.0.0 + + + localhost + dummy-parent + 1.0 + + + localhost + it-aggregate-plugn-multiple-versions-same-plugin + 1.0-SNAPSHOT + pom + use-reactor basic test + + + module-a1 + module-a2 + module-a3 + module-a4 + + + + + dependency-updates-reports + + + + org.codehaus.mojo + versions-maven-plugin + @project.version@ + + + root-report + + dependency-updates-aggregate-report + plugin-updates-aggregate-report + + validate + + + html + + false + true + + + + + org.apache.maven + + + regex + .+-(alpha|beta).?[0-9]+ + + + + + + + + + + + + + + + diff --git a/versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/verify.groovy b/versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/verify.groovy new file mode 100644 index 0000000000..b47711ca60 --- /dev/null +++ b/versions-maven-plugin/src/it/it-aggregate-plugn-multiple-versions-same-plugin/verify.groovy @@ -0,0 +1,26 @@ +/* + * 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. + */ + +def dependenciesUpgradeReport = new File( basedir, 'target/site/dependency-updates-aggregate-report.html') + +assert dependenciesUpgradeReport.exists() + +def pluginsUpgradeReport = new File( basedir, 'target/site/dependency-updates-aggregate-report.html') + +assert pluginsUpgradeReport.exists() \ No newline at end of file diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractPluginUpdatesReportMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractPluginUpdatesReportMojo.java index 738ccd1bb8..a2d53e545d 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractPluginUpdatesReportMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractPluginUpdatesReportMojo.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.Set; import java.util.TreeSet; +import java.util.function.BinaryOperator; import org.apache.maven.doxia.sink.Sink; import org.apache.maven.model.Plugin; @@ -131,7 +132,12 @@ protected void doGenerateReport(Locale locale, Sink sink) throws MavenReportExce getHelper().lookupPluginsUpdates(pluginManagement.stream(), getAllowSnapshots()); if (onlyUpgradable) { - pluginUpdates = filter(pluginUpdates, p -> !p.isEmpty(allowSnapshots)); + + BinaryOperator merger = (pluginUpdatesDetails, pluginUpdatesDetails2) -> { + pluginUpdatesDetails.addDependencyVersions(pluginUpdatesDetails2.getDependencyVersions()); + return pluginUpdatesDetails; + }; + pluginUpdates = filter(pluginUpdates, p -> !p.isEmpty(allowSnapshots), merger); pluginManagementUpdates = filter(pluginManagementUpdates, p -> !p.isEmpty(allowSnapshots)); }