Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNG-8229] CI Friendly versions confuse model pool #1690

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not change the behaviour, right ? What's the point ?

Copy link
Contributor

@gnodet gnodet Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it does change the behaviour, as if there's a single version, it will always be used, even if there's a version mismatch. I think that's wrong.
Multiple versions of the same GA inside a reactor is a supported (albeit rare) use case.
If the model pool is being filled, we can't rely on the existence of a single version (while the second may not have been read yet).

}

private String getVersion(Model model) {
Expand Down