Apply configured styles after auto-detected styles; tighten parser visibility - #1116
Conversation
With openrewrite/rewrite#6761 changing style merging to "last wins" semantics, configured styles must be applied after auto-detected styles so they take precedence. Previously configured styles were set on the parser (applied first) and auto-detected styles were added after parsing (applied last), meaning auto-detected styles would unintentionally override user configuration. Remove the now-unnecessary styles parameter from MavenMojoProjectParser#listSourceFiles and instead apply both auto-detected and configured styles in the correct order within AbstractRewriteBaseRunMojo.
|
Would also need to see adjustments downstream in the CLI. |
| .styles(styles) | ||
| .logCompilationWarningsAndErrors(false); | ||
|
|
||
| // todo, add styles from autoDetect |
There was a problem hiding this comment.
| // todo, add styles from autoDetect |
| return listSourceFiles(mavenProject, maven, projectProvenance, Arrays.asList(MAIN, TEST), ctx); | ||
| } | ||
|
|
||
| public Stream<SourceFile> listSourceFiles(MavenProject mavenProject, Xml.@Nullable Document maven, List<Marker> projectProvenance, List<MavenScope> scopes, |
There was a problem hiding this comment.
This method is used by the CLI, and removing the styles here would cause problems there.
There was a problem hiding this comment.
There's some weird interplay here between the Maven plugin detecting styles after and separate from listSourceFiles, whereas the CLI only calls listSourceFiles and itself in a limited capacity loads styles.
Would we need to detect styles as part of listSourceFiles perhaps, and remove the duplicate logic in the CLI? Any ideas here Sam since this follows on from your earlier work?
There was a problem hiding this comment.
Yeah we should make things consistent between the CLI, gradle plugins, and maven plugins. I believe there is some inconsistency with how styles are treated / autodetected in the CLI and between the two plugins. There is likely some redundancy.
|
Heard we might sever the reuse of rewrite-maven-plugin in the Moderne CLI, so might just wait for that to land before making changes here, as it will be easier if there's no backwards compatibility across projects. |
|
This PR is stale because it has been open for 90 days with no activity. Remove |
|
@copilot resolve the merge conflicts in this pull request |
Resolved and pushed in commit |
The Moderne CLI no longer reuses rewrite-maven-plugin, so the parsing methods that were public solely for that reuse can be tightened. Only listSourceFiles(MavenProject, ctx) needs package visibility for the Mojo; the remaining overloads, generateProvenance, parseMaven, and buildSettings are now private, and POM_CACHE is private static.
âĶ 6.41.0 to 6.42.0 [skip ci] Bumps [org.openrewrite.maven:rewrite-maven-plugin](https://github.com/openrewrite/rewrite-maven-plugin) from 6.41.0 to 6.42.0. Release notes *Sourced from [org.openrewrite.maven:rewrite-maven-plugin's releases](https://github.com/openrewrite/rewrite-maven-plugin/releases).* > 6.42.0 > ------ > > What's Changed > -------------- > > * chore(ci): bump rtCamp/action-slack-notify from 2.3.3 to 2.4.0 by [`@âdependabot`](https://github.com/dependabot)[bot] in [openrewrite/rewrite-maven-plugin#1162](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1162) > * chore(ci): bump org.openrewrite:rewrite-bom from 8.84.0 to 8.84.4 by [`@âdependabot`](https://github.com/dependabot)[bot] in [openrewrite/rewrite-maven-plugin#1163](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1163) > * Change the MavenPomCache init logic by [`@âgreg-at-moderne`](https://github.com/greg-at-moderne) in [openrewrite/rewrite-maven-plugin#1164](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1164) > * Remove .context files by [`@âtimtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-maven-plugin#1165](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1165) > * Switch to packages.nuxeo.com in BasicIT by [`@âgreg-at-moderne`](https://github.com/greg-at-moderne) in [openrewrite/rewrite-maven-plugin#1167](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1167) > * chore(ci): bump io.micrometer:micrometer-core from 1.16.5 to 1.17.0 by [`@âdependabot`](https://github.com/dependabot)[bot] in [openrewrite/rewrite-maven-plugin#1166](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1166) > * Apply configured styles after auto-detected styles; tighten parser visibility by [`@âtimtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-maven-plugin#1116](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1116) > > **Full Changelog**: <openrewrite/rewrite-maven-plugin@v6.41.0...v6.42.0> Commits * [`64b0e5f`](openrewrite/rewrite-maven-plugin@64b0e5f) [maven-release-plugin] prepare release v6.42.0 * [`d360daa`](openrewrite/rewrite-maven-plugin@d360daa) Bump rewrite.version property * [`dbe81d4`](openrewrite/rewrite-maven-plugin@dbe81d4) Apply configured styles after auto-detected styles; tighten parser visibility... * [`c4cc317`](openrewrite/rewrite-maven-plugin@c4cc317) chore(ci): bump io.micrometer:micrometer-core from 1.16.5 to 1.17.0 ([#1166](https://redirect.github.com/openrewrite/rewrite-maven-plugin/issues/1166)) * [`af2ae2f`](openrewrite/rewrite-maven-plugin@af2ae2f) Switch to packages.nuxeo.com ([#1167](https://redirect.github.com/openrewrite/rewrite-maven-plugin/issues/1167)) * [`1f337f0`](openrewrite/rewrite-maven-plugin@1f337f0) Bump rewrite.version property * [`c6d8097`](openrewrite/rewrite-maven-plugin@c6d8097) git-ignore .context/ * [`cfd5b08`](openrewrite/rewrite-maven-plugin@cfd5b08) Remove .context files ([#1165](https://redirect.github.com/openrewrite/rewrite-maven-plugin/issues/1165)) * [`962cc40`](openrewrite/rewrite-maven-plugin@962cc40) Change the MavenPomCache init logic ([#1164](https://redirect.github.com/openrewrite/rewrite-maven-plugin/issues/1164)) * [`45c5bd6`](openrewrite/rewrite-maven-plugin@45c5bd6) chore(ci): bump org.openrewrite:rewrite-bom from 8.84.0 to 8.84.4 ([#1163](https://redirect.github.com/openrewrite/rewrite-maven-plugin/issues/1163)) * Additional commits viewable in [compare view](openrewrite/rewrite-maven-plugin@v6.41.0...v6.42.0)
Apply configured styles after auto-detected styles
AbstractRewriteBaseRunMojo, in the correct order: auto-detected first, configured last.stylesparameter fromMavenMojoProjectParser#listSourceFiles.Tighten
MavenMojoProjectParservisibilityThe Moderne CLI no longer reuses rewrite-maven-plugin, so the parsing methods that were
publicsolely for that reuse can be tightened. OnlylistSourceFiles(MavenProject, ctx)still needs package visibility (for the Mojo); the rest are nowprivate:listSourceFiles(...)overloads âprivate(kept the(MavenProject, ctx)entry point package-private)generateProvenance(...)âprivateparseMaven(...)(both overloads) âprivatebuildSettings()âprivatePOM_CACHEâprivate static