Fix updating of maven model when parent pom was updated previously in same cycle#5051
Fix updating of maven model when parent pom was updated previously in same cycle#5051mryan43 wants to merge 35 commits intoopenrewrite:mainfrom
Conversation
…ionResult + UpdateMavenModel - Only update project poms in ExecutionContext when UpdateMavenModel runs - Resolve updated maven model before maven visitor visits a document - Added minimal test to showcase issue caused by projectPoms not being shared between MavenResolutionResults - WIP: a few tests fail. Also resolution of updated maven model can be improved to run only when a previous recipe actually made a change. Also not 100% sure about new implementation of MavenResolutionResult#parentPomIsProjectPom
rewrite-maven/src/main/java/org/openrewrite/maven/tree/MavenResolutionResult.java
Show resolved
Hide resolved
…x-maven-model-update
- Fix setProjectPoms in ExecutionContext
…x-maven-model-update
…uments if a parent pom from the project was updated. - Fix: fix for maven download error messages in poms
…loader for non-maven contexts
|
Thanks a lot @mryan43 ! Tagging Knut for review as he proposed something similar for constructors just today. |
…ToParentThenRemoveRedundantDependencyTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
…x-maven-model-update
|
Hi @mryan43, looks neat! I will have a detailed look tomorrow in the morning 📓 |
|
PR is ready for another round of review. PS: Huge thank you for all the work everyone has put in this PR so far ! |
# Conflicts: # rewrite-maven/src/main/java/org/openrewrite/maven/internal/MavenPomDownloader.java
…x-maven-model-update
|
Merged origin/main into this branch, please approve again for CI. This PR is still awaiting a re-review after comments were addressed. |
|
Hi @mryan43 as you see from the number of participants, updating I apologize for the delay and late intervention. I hope you can use your incredible skill and motivation to find a better solution with us. |
|
I would also like to challenge the idea that the Pom class represents a LST element.
For all those reasons... I think only XML documents and tags can be considered LST elements in the current implementation. |
|
You are right, Poms are not actually LST elements for the reasons you mention. There is also no technical reason why LST elements can't be stored in the ExecutionContext. Sometimes that can be the best way to achieve something. The reason we discourage storing LSTs in the ExecutionContext is that these can consume a lot of memory, especially if they have type attribution attached to them as in the case of Java. In the case of Maven the MavenResolutionResult can also consume quite a lot of memory due to all the transitive dependencies. I am not sure how much of that is attributed to the Pom objects, but I think it should probably be OK and I don't really see any other option anyway. |
|
Also note that while using the InMemoryLargeSourceSet for recipe execution this isn't a problem, because all LST are already loaded into memory anyway and thus adding a reference to the ExecutionContext doesn't occupy any additional memory. With the Moderne SaaS and CLI the situation is different as they support processing huge repos by not loading all LSTs at once into memory. By carrying LSTs forward in the ExecutionContext the memory of those LSTs can never be released. |
|
Thanks a lot for clarifying those concerns ! I was wondering if there exists any mechanism other than the |
|
The only alternative I can come up with is if we would register something like a |
|
I'm not convinced that we can find a better solution without heavily refactoring the whole maven module... The question remains about what should happen to this PR. |
|
@mryan43 What about my proposal with a transformer function? Would that end up capturing a lot of objects from the LST model in the lambda or is it a lot of work to refactor? I haven't looked at the changes very closely and it is a bit hard to tell from a distance. |
|
I can add an interface with an implementation that contains the full Pom object and replaces it. Then downstream closed source product maintainers can replace it by whatever they want. Would that work for you ? This would be similar to how the ExecutionContext vs InMemoryExecutionContext works |
|
This PR is stale because it has been open for 90 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
|
How can we progress on this? Ultimately, when a recipe is crawling over a child pom, we need all the parent metadata to be up to date. I even tried multi-cycle as a quick hack to make things work, but it didn't. I didn't really dig into why, but I seem to recall some caching. Is the function approach mentioned here being discussed? |



What's changed?
What's your motivation?
See added test for a very simple real-life scenario.
I also believe that this PR could fix a number of similar issues with many different combinations of recipes, such as this one for example : #4949
Have you considered any alternatives or workarounds?
Checklist