From a9221f7af10f467db5dda8756a0e7b5b7056cb3a Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Fri, 30 Aug 2024 00:03:06 +0200 Subject: [PATCH] [MNG-8229] CI Friendly versions confuse model pool Fixing the method (there is one GA inside reactor), but this still does not fix the issue, now it fails elsewhere. The problem in short is CI friendly version and its half-assed solution as model version "suddenly" change from file-activated models to effective ones. --- https://issues.apache.org/jira/browse/MNG-8229 --- .../maven/project/ReactorModelPool.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/project/ReactorModelPool.java b/maven-core/src/main/java/org/apache/maven/project/ReactorModelPool.java index 183132a5e3e8..a249ebf142fb 100644 --- a/maven-core/src/main/java/org/apache/maven/project/ReactorModelPool.java +++ b/maven-core/src/main/java/org/apache/maven/project/ReactorModelPool.java @@ -19,6 +19,7 @@ package org.apache.maven.project; import java.nio.file.Path; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Map; @@ -48,13 +49,20 @@ class ReactorModelPool { * @throws IllegalStateException if version was null and multiple modules share the same groupId + artifactId */ public Model get(String groupId, String artifactId, String version) { - return modelsByGa.getOrDefault(new GAKey(groupId, artifactId), Collections.emptySet()).stream() - .filter(m -> version == null || version.equals(getVersion(m))) - .reduce((a, b) -> { - throw new IllegalStateException( - "Multiple modules with key " + a.getGroupId() + ':' + a.getArtifactId()); - }) - .orElse(null); + Collection models = modelsByGa.getOrDefault(new GAKey(groupId, artifactId), Collections.emptySet()); + if (models.isEmpty()) { + return null; + } else if (models.size() == 1) { + return models.iterator().next(); + } else { + return models.stream() + .filter(m -> version == null || version.equals(getVersion(m))) + .reduce((a, b) -> { + throw new IllegalStateException( + "Multiple modules with key " + a.getGroupId() + ':' + a.getArtifactId()); + }) + .orElse(null); + } } private String getVersion(Model model) {