openrewrite / rewrite-maven-plugin

OpenRewrite's Maven plugin.
https://openrewrite.github.io/rewrite-maven-plugin/plugin-info.html
Apache License 2.0
130 stars 68 forks source link

Feature request : aggregate applied recipes in a multi module project and print them at the end #328

Closed yeikel closed 2 years ago

yeikel commented 2 years ago

I am running mvn rewrite:run from the root directory of a multi module project. Doing so produces a log such as

[WARNING] Changes have been made to module/src/main/java/Java.java by: [WARNING] org.openrewrite.java.logging.ParameterizedLogging

The problem is that when there are multiple modules, the logs are printed after the build of each module finishes

As my build prints many logs, it is very difficult and tedious to navigate the logs per module to find the recipes applied

It would be better if we could aggregate this and print it at the end of the build

An ideal output would look like this :

[WARNING] Changes have been made to module1/path by
[WARNING]     org.openrewrite.java.logging.ParameterizedLogging
[WARNING] Changes have been made to module2/path by
[WARNING]     org.openrewrite.java.cleanup.MinimumSwitchCases
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for multimodule 0.0.0-SNAPSHOT:
[INFO] 
[INFO] module1 ........................................... SUCCESS [ 16.625 s]
[INFO] module2 .......................................... SUCCESS [ 20.884 s]
[INFO] module3 .............................. SUCCESS [ 34.173 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:32 min (Wall Clock)
[INFO] Finished at: 2022-04-08T12:54:51-04:00
tkvangorder commented 2 years ago

This seems reasonable, we might be able to achieve this with a shutdown hook.

tkvangorder commented 2 years ago

@yeikel This has been addressed in #349 .

We defer the running of the plugin, until the last project, parse source files from each module (in reactor order) and then run the recipe across all source files. The patch file is always generated in the root project.

murdos commented 2 years ago

Hi. I'm currently using the snapshot version of the maven plugin, and I'm not really found of this new behavior. It doesn't really fit the maven way of doing things IMO. For example there's no ending test report on a multi-module project for surefire and failsafe plugin, you'll check the log of each module. And if I want to check only changes made to a module, I don't have a way to see only the report for this module. It also doesn't really work well in IntelliJ which only shows log of a module when you select it: whereas I launched rewrite:run on the root of the project, selection a submodule will only show resources and compilation logs, but trace of rewrite.

tkvangorder commented 2 years ago

@murdos I have added a configuration flag that will allow you to run on a per-module basis:

See https://github.com/openrewrite/rewrite-maven-plugin/pull/360

Note the new configuration flag runPerSubmodule :

            <plugin>
                <groupId>org.openrewrite.maven</groupId>
                <artifactId>rewrite-maven-plugin</artifactId>
                <version>4.24.0-SNAPSHOT</version>
                <configuration>
                    <runPerSubmodule>true</runPerSubmodule>
                    <activeRecipes>
                        <recipe>org.openrewrite.java.cleanup.AddSerialVersionUidToSerializable</recipe>
                    </activeRecipes>
                </configuration>
            </plugin>

The default for this flag is false, so you will need to explicitly set this flag to revert to the previous behavior.

Thanks for the feedback!

murdos commented 2 years ago

@tkvangorder : thanks for taking my input in consideration! I was reading other issues like #349 that led to https://github.com/openrewrite/rewrite-maven-plugin/pull/359 and I should admit that I don't the issue with #349 event when reading https://github.com/openrewrite/rewrite-maven-plugin/issues/349#issuecomment-1118024408

Now there's currently a big pitfall with running only once per multi-module project: you don't take into account that each module may have configured the maven plugin differently, including using specific recipes. To demonstrate and check that I've configured this multi-module project: https://github.com/murdos/piggymetrics/commit/38812ecda75e518baec2bf8f3107f07c552f8d51 org.openrewrite.java.format.AutoFormat is only configured in submodule turbine-stream-service, however it's applied in the whole project:

[WARNING] Changes have been made to statistics-service/src/test/java/com/piggymetrics/statistics/client/ExchangeRatesClientTest.java by: [WARNING] org.openrewrite.java.format.AutoFormat [WARNING] Changes have been made to notification-service/src/main/java/com/piggymetrics/notification/repository/converter/FrequencyWriterConverter.java by: [WARNING] org.openrewrite.java.format.AutoFormat

tkvangorder commented 2 years ago

Yes, I totally understand. This issue was a request from one of our design partners. The model of applying the recipe at the top level of the project and then operating on sources across all submodules is closer to parity with what is done in the Gradle plugin and how recipes are executed on the SaaS.