GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — [MNG-6797] Remember if Maven model problems were encountered. by wilx · Pull Request #298 · apache/maven Conversation
|
| * This indicates whether there were any problems detected when building Maven model. | ||
| * @return true if there were problems, false otherwise | ||
| */ | ||
| public boolean isProblems() { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
That really hurts because the plural implies that you have a collection of problem, and not a boolean value. Moreover, third person singular with a plural reads horribly.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
As fas as I understand you want to memorize state. Can you provide an IT why this is necessary/benefit?
IME as someone who maintains Maven projects, people often introduce issues like that and they do not care to fix them unless their build breaks. Remembering in MavenSession that there were problems with the Maven model will allow me to write Maven Enforcer plugin rule that will read that and will fail the build.
I also fail to see how problems are detected, you only changed the signature of the method.
See org.apache.maven.graph.DefaultGraphBuilder#collectProjects. It prints the collected Maven model problems.
That really hurts because the plural implies that you have a collection of problem, and not a boolean value. Moreover, third person singular with a plural reads horribly.
I am open to suggestions for better name. I have only propagated the problems variable name upwards. One thing, I would like to keep the isX or getX for the getter as that would allow me, I believe, to use something like this ReflectionValueExtractor.evaluate("problems", session, false); to retrieve it in the Enforce rule easily, I hope.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Resolve #8485 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Verdict:
This PR adds a problems boolean to MavenSession to track whether model problems were encountered during project collection (MNG-6797). The intent is to let plugins like the Enforcer fail builds on model warnings.
However, the PR is nearly 7 years old and the codebase has been fundamentally restructured since it was opened.
| # | Severity | File | Details |
|---|---|---|---|
| 1 | 🔴 High | DefaultGraphBuilder.java |
Method deleted — The collectProjects(List, List, MavenExecutionRequest) method this PR modifies no longer exists on master. It was refactored in MNG-7646 to delegate to strategy classes (PomlessCollectionStrategy, MultiModuleCollectionStrategy, RequestPomCollectionStrategy). The PR cannot merge. |
| 2 | 🔴 High | MavenSession.java |
File moved — Path changed from maven-core/ to impl/maven-core/ by MNG-8346. Merge state is CONFLICTING. |
| 3 | 🟡 Medium | MavenSession.java:270 |
Naming — isProblems() is grammatically awkward. The Java convention for presence semantics is hasProblems() or hasModelProblems(). |
If MNG-6797 is still relevant:
ProblemCollector<BuilderProblem>, ModelBuilderException)The PR in its current form cannot be merged and would require a complete rewrite.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of Guillaume Nodet
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Reviewed 3 PRs: apache#1437 (COMMENT), apache#1435 (COMMENT, bug found), apache#298 (COMMENT). 33 total reviews posted. ~26 PRs remaining. Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This nearly 7-year-old PR (opened November 2019) cannot merge in its current form. The target code has been both relocated and fundamentally refactored.
The collectProjects(List<MavenProject>, List<File>, MavenExecutionRequest) method in DefaultGraphBuilder was refactored in MNG-7646 — project collection now delegates to strategy classes (PomlessCollectionStrategy, MultiModuleCollectionStrategy, RequestPomCollectionStrategy). The code this PR modifies is gone.
Both files moved from maven-core/ to impl/maven-core/ by MNG-8346. Merge state is CONFLICTING.
isProblems() was flagged by reviewer michael-o as reading awkwardly. hasModelProblems() or hasProblems() would follow Java bean conventions. Acknowledged but never fixed.
michael-o requested an IT demonstrating the benefit. Never provided.
If MNG-6797 is still relevant, a fresh implementation is needed against the current strategy-based architecture, ideally leveraging Maven 4's structured problem reporting (ProblemCollector, ModelBuilderException) rather than a bare boolean flag on MavenSession.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of gnodet
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Remember in MavenSession if Maven model problems were detected in DefaultGraphBuilder.
74923d1 to
28e9658
Compare
|
I forgot I even did this. Rebased. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
https://github.com/wilx/maven/actions/runs/30470388455/job/90640967247 looks like infrastructure problem. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Ping @michael-o Current thoughts about this one? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
The rebase fine. @wilx Can you please briefly summarize how you want to put this into use? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I want to create a Maven Enforcer rule that will inspect the presence of the model problems and will fail the build if there are problems. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sounds reasonable. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
a boolean flag seems insufficient for this purpose. The model problems themselves should be exposed to plugins that want to read them. I'd prefer to avoid half-measures. Is there a more complete approach possible here?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
A boolean is sufficient to implement the Enforcer rule. I do not have a use case for it but I agree that having access to the problem items might be useful. However, because I want to be able to use the Enforcer rules both with 3.10.x and 4.x Maven, there are some design problems:
What else could we do instead? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Is org.apache.maven.model.building.ModelProblem not deprecated in 3.x? If so this might need different code in 3.x and 4.x, not a simple backport. What is the replacement for ModelProblem in 4.x? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The PR correctly targets maven-3.10.x where both MavenSession.java and DefaultGraphBuilder.java still live under maven-core/ and collectProjects() still exists in its current form — so prior reviews claiming the code was gone were wrong (those reviewed against master, not the 3.10.x target branch). The approach here is sound in principle.
Two issues need to be addressed before merge:
modelProblems (medium)getProjectsForMavenReactor() has two code paths. The PR only instruments the POM path:
// POM path — correctly instrumented List<File> files = Arrays.asList(request.getPom().getAbsoluteFile()); boolean problems = collectProjects(projects, files, request); session.setModelProblems(problems); return projects;
The pomless early-return path (request.getPom() == null) falls through without ever calling setModelProblems(), leaving the session field at false. In practice this is a niche edge case (pomless builds use a bundled standalone POM), but if that standalone project ever has problems they'd be silently missed. Add session.setModelProblems(false) before the early return projects;, or better, hoist the setModelProblems() call to the common return point after restructuring to avoid two returns.
setModelProblems(false) can reset a true value (low — fixable with ||=)setModelProblems(boolean) is a direct setter — it can overwrite a previously-set true if called multiple times. In the current call graph this is safe (one call per session build), but the API is misleading. Prefer an additive setter:
public void addModelProblems() { this.modelProblems = true; }
or at minimum document the single-call contract explicitly. As-is, a plugin that calls session.setModelProblems(false) by mistake can silently clear the flag.
ModelProblem and deprecated 4.x equivalents) is valid. The boolean approach works for the stated Enforcer use case. Committers should decide whether this is a blocker.problems = true from logger.isWarnEnabled() in collectProjects() is a genuine correctness improvement from the original code — problems were previously silently missed when warn logging was disabled.@since 3.10.0 tags are appropriate.This review was generated by an AI agent, Hermès on behalf of @gnodet.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| List<File> files = Arrays.asList(request.getPom().getAbsoluteFile()); | ||
| collectProjects(projects, files, request); | ||
| boolean problems = collectProjects(projects, files, request); | ||
| session.setModelProblems(problems); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
request.getPom() == null (around line 333) never calls setModelProblems(), leaving the session at false even if the standalone project has problems. This line is only reached when a POM file is present.
Add session.setModelProblems(false) before the early return projects; in the pomless branch, or restructure to have a single return point so setModelProblems() is always called.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| this.modelProblems = modelProblems; | ||
| } | ||
|
|
||
| public RepositorySystemSession getRepositorySession() { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
setModelProblems(boolean) accepts false, meaning it can clear a previously-set true. The API contract should either be documented as "call at most once per build" or changed to an additive setter:
| public RepositorySystemSession getRepositorySession() { | |
| public void setModelProblems() { | |
| this.modelProblems = true; | |
| } |
This makes the flag monotonic and prevents accidental resets by callers passing false.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I have a change that I forgot to push that exposes the list of the problems. However, the code and data structures are different in 4.x and 3.x. So this would require split of or at least knowledge by the Enforcer rule to accommodate both. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The upgrade from boolean to List<ModelProblem> directly addresses @elharo's CHANGES_REQUESTED concern — the full problem list is now exposed, not just a flag. That is a meaningful improvement and closes the most significant blocker from the previous round.
Two issues remain:
setModelProblems() (medium — same gap as before)From my previous review: the request.getPom() == null early-return branch in getProjectsForMavenReactor() returns without calling setModelProblems(), leaving modelProblems as Collections.emptyList() even if the standalone project has problems.
The new commits did not touch that branch. The fix is straightforward:
// We have no POM file. // if (request.getPom() == null) { ModelSource modelSource = new UrlModelSource(DefaultMaven.class.getResource("project/standalone.xml")); MavenProject project = projectBuilder .build(modelSource, request.getProjectBuildingRequest()) .getProject(); project.setExecutionRoot(true); projects.add(project); request.setProjectPresent(false); session.setModelProblems(Collections.emptyList()); // explicit — pomless builds have no model problems return projects; }
(Or restructure to a single return point.)
The three new tests in DefaultGraphBuilderTest all go through the POM path (request.setPom(new File("pom.xml"))). None exercises request.getPom() == null. Given that finding #1 is specifically about that branch, a test reproducing it would be valuable.
List<ModelProblem> API change. Passing null now throws NPE (documented), and the defensive copy prevents external mutation. ✅List<ModelProblem>. ✅This review was generated by an AI agent, Hermès on behalf of @gnodet.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| List<File> files = Arrays.asList(request.getPom().getAbsoluteFile()); | ||
| collectProjects(projects, files, request); | ||
| session.setModelProblems(collectProjects(projects, files, request)); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
setModelProblems().
The request.getPom() == null branch (lines ~333–341) returns early without setting model problems on the session. Since modelProblems defaults to Collections.emptyList(), a pomless build that encounters problems silently exposes an empty list. Add session.setModelProblems(Collections.emptyList()) before that early return projects; (an empty list is correct for the standalone POM case — it only needs to be an explicit call to make the intent clear and to make the contract testable).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Do we need this? Nobody can use Enforcer from the default POM in POMless execution, AFAIK.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
You're right — withdrawing that finding. In a pomless execution, the build uses Maven's internal standalone POM (DefaultMaven.class.getResource("project/standalone.xml")), which is a fixed resource. Since Enforcer rules must be configured in the project POM, there is no way to configure an Enforcer rule in a pomless build. The pomless path can never trigger the proposed Enforcer rule, making an explicit setModelProblems() call there purely academic. The remaining open issue (from my last review) is the test coverage gap for that branch, but given the use case doesn't exist, even that is low priority.
This comment was generated by an AI agent, Hermès on behalf of @gnodet.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Prototype rule: apache/maven-enforcer#1030 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Whoever holds "req for change" on this PR, pls re-review. I scheduled it for 3.10. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
We'd need a similar PR for the Maven 4 API.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.