You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by cs...@apache.org on 2024/08/29 22:04:44 UTC

(maven) 01/01: [MNG-8229] CI Friendly versions confuse model pool

This is an automated email from the ASF dual-hosted git repository.

cstamas pushed a commit to branch MNG-8229
in repository https://gitbox.apache.org/repos/asf/maven.git

commit a9221f7af10f467db5dda8756a0e7b5b7056cb3a
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Fri Aug 30 00:03:06 2024 +0200

    [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
---
 .../org/apache/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 183132a5e3..a249ebf142 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<Model> 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) {