openrewrite / rewrite

Automated mass refactoring of source code.
https://docs.openrewrite.org
Apache License 2.0
2.15k stars 320 forks source link

Parse only what's needed to run the recipe #3693

Closed yeikel closed 10 months ago

yeikel commented 10 months ago

What problem are you trying to solve?

While trying to run the org.openrewrite.maven.OrderPomElements recipe, I was hoping that it would only parse and process my pom files and apply the transformations needed

What I noticed however is that it seems to be scanning all the source files instead

[INFO] --- rewrite:5.11.0:run (default-cli) @ ---
[INFO] Using active recipe(s) [org.openrewrite.maven.OrderPomElements]
[INFO] Using active styles(s) []
[INFO] Validating active recipes...
[INFO] Project [parent] Resolving Poms...
[INFO] Project [parent] Parsing source files
[INFO] Project [child project 1] Parsing source files
[INFO] Project [child project 2] Parsing source files
[INFO] Project [child project 3] Parsing source files
[INFO] Project [child project 4] Parsing source files

Describe the solution you'd like

In an ideal world, recipes that do not need to modify Java files like this one only parse what is needed. To process and reformat a few XML files, I'd expect the recipe to run in a few milliseconds at most

Have you considered any alternatives or workarounds?

I am not aware of any alternatives

Additional context

The reason I suspect that this scanned my entire source files is that the build took over 5 minutes to complete when changing a few pom files should not take that long

[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  05:11 min (Wall Clock)
[INFO] Finished at: 2023-11-15T15:37:27-05:00
timtebeek commented 10 months ago

Hi @yeikel ; Thanks for the suggestion! We did this in a distant past, but have stopped doing this as it's nowadays quite common for scanning recipes to operate across file types, for instance only adding a dependency if a particular Java type is used. Such cases make it relatively rare for any recipe to only affect one particular file type, and the logic to track and selectively parse would make this quite complicated quickly. It'll almost certainly have to land in both of the plugins, and since you're using Maven I suggest to close this issue and watch this one for any work towards this: