Skip to content

Commit

Permalink
Fix ISE with plugins aggregate report when reactor projects contains …
Browse files Browse the repository at this point in the history
…the same plugin declaration multiple time with different versions (#1024)

Signed-off-by: Olivier Lamy <olamy@apache.org>
  • Loading branch information
olamy authored Nov 16, 2023
1 parent 2fd9c32 commit 1136bf4
Show file tree
Hide file tree
Showing 10 changed files with 255 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public Map<Dependency, ArtifactVersions> getDependencyVersions() {
return dependencyVersions;
}

public void addDependencyVersions(Map<Dependency, ArtifactVersions> dependencyVersions) {
this.dependencyVersions.putAll(dependencyVersions);
}

/**
* Returns true if a new version of the artifact fulfilling the criteria (whether to include snapshots) can be found
*
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -23,4 +24,11 @@ public static <K, V> Map<K, V> filter(Map<K, V> map, Function<V, Boolean> predic
.filter(e -> predicate.apply(e.getValue()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}

public static <K, V> Map<K, V> filter(
Map<K, V> map, Function<V, Boolean> predicate, BinaryOperator<V> mergeFunction) {
return map.entrySet().stream()
.filter(e -> predicate.apply(e.getValue()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, mergeFunction));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#invoker.goals=clean install
invoker.goals=-Pdependency-updates-reports validate validate
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<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-aggregate-plugn-multiple-versions-same-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<groupId>localhost</groupId>
<artifactId>module-a1</artifactId>
<packaging>pom</packaging>

<dependencies>

<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>1.1.2</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<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-aggregate-plugn-multiple-versions-same-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<groupId>localhost</groupId>
<artifactId>module-a2</artifactId>
<packaging>pom</packaging>

<dependencies>

<dependency>
<groupId>localhost</groupId>
<artifactId>module-a1</artifactId>
<version>${project.version}</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<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-aggregate-plugn-multiple-versions-same-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<groupId>localhost</groupId>
<artifactId>module-a3</artifactId>
<packaging>pom</packaging>

<dependencies>

<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>1.1.2</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.6.0</version>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<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-aggregate-plugn-multiple-versions-same-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<groupId>localhost</groupId>
<artifactId>module-a4</artifactId>
<packaging>pom</packaging>

<dependencies>

<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>1.1.2</version>
</dependency>

</dependencies>

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

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<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>dummy-parent</artifactId>
<version>1.0</version>
</parent>

<groupId>localhost</groupId>
<artifactId>it-aggregate-plugn-multiple-versions-same-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>use-reactor basic test</name>

<modules>
<module>module-a1</module>
<module>module-a2</module>
<module>module-a3</module>
<module>module-a4</module>
</modules>

<profiles>
<profile>
<id>dependency-updates-reports</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>root-report</id>
<goals>
<goal>dependency-updates-aggregate-report</goal>
<goal>plugin-updates-aggregate-report</goal>
</goals>
<phase>validate</phase>
<configuration>
<formats>
<format>html</format>
</formats>
<onlyProjectDependencies>false</onlyProjectDependencies>
<onlyUpgradable>true</onlyUpgradable>
<ruleSet>
<rules>
<rule>
<!-- ignore maven alpha/beta releases -->
<groupId>org.apache.maven</groupId>
<ignoreVersions>
<ignoreVersion>
<type>regex</type>
<version>.+-(alpha|beta).?[0-9]+</version>
</ignoreVersion>
</ignoreVersions>
</rule>
</rules>
</ruleSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<PluginUpdatesDetails> merger = (pluginUpdatesDetails, pluginUpdatesDetails2) -> {
pluginUpdatesDetails.addDependencyVersions(pluginUpdatesDetails2.getDependencyVersions());
return pluginUpdatesDetails;
};
pluginUpdates = filter(pluginUpdates, p -> !p.isEmpty(allowSnapshots), merger);
pluginManagementUpdates = filter(pluginManagementUpdates, p -> !p.isEmpty(allowSnapshots));
}

Expand Down

0 comments on commit 1136bf4

Please sign in to comment.