Prevent cross-scope source files from being parsed as PlainText - #1123
Merged
Merged
Conversation
processMainSources and processTestSources each iterate resource
directories via getResources()/getTestResources(). When a resource
directory points at ${project.basedir}, OmniParser walks the entire
project tree. Source files belonging to the other scope are not yet
in alreadyParsed, so they get claimed by PlainTextParser. The real
parse in the other scope then produces a duplicate entry, and the
PlainText version shadows the properly typed one — making type
information and annotations invisible to recipes.
Fix: before each scope's resource loop, pre-populate alreadyParsed
with the other scope's source file paths (Java, Kotlin, Groovy).
pstreef
force-pushed
the
pstreef/fix-scoped-plaintext
branch
from
March 17, 2026 15:38
a26d9df to
84d9f61
Compare
Member
|
Hmm; it looks like we pulled forward the resource parsing recently in Previously we only parsed resources after having parsed the sources in main and test: I wonder if we should return to that pattern. /cc @shanman190 |
Move the alreadyParsed pre-population from each scope method into listSourceFiles(), eliminating coupling between processMainSources and processTestSources. Both scopes' source paths are now computed once upfront before either scope method runs.
Rename the Set<Path> variable/parameter from alreadyParsed to parsedPaths since it is now pre-populated before parsing begins. Remove the redundant addAll calls in processMainSources and processTestSources that re-added paths already present from the upfront pre-population.
Verify that source files in both main and test scopes are parsed as Java (not PlainText) when resource directories point at project.basedir. AutoFormat only operates on Java ASTs, so it will not modify files that were incorrectly claimed by PlainTextParser.
timtebeek
marked this pull request as ready for review
March 18, 2026 14:29
mergify Bot
added a commit
to robfrank/linklift
that referenced
this pull request
Mar 19, 2026
… 6.32.0 to 6.34.0 [skip ci] Bumps [org.openrewrite.maven:rewrite-maven-plugin](https://github.com/openrewrite/rewrite-maven-plugin) from 6.32.0 to 6.34.0. Release notes *Sourced from [org.openrewrite.maven:rewrite-maven-plugin's releases](https://github.com/openrewrite/rewrite-maven-plugin/releases).* > 6.34.0 > ------ > > What's Changed > -------------- > > * Add explicit Groovy source file parsing with classpath by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-maven-plugin#1119](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1119) > * chore(ci): bump io.micrometer:micrometer-core from 1.16.3 to 1.16.4 by [`@dependabot`](https://github.com/dependabot)[bot] in [openrewrite/rewrite-maven-plugin#1120](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1120) > * chore(ci): bump maven-dependencies.version from 3.9.13 to 3.9.14 by [`@dependabot`](https://github.com/dependabot)[bot] in [openrewrite/rewrite-maven-plugin#1121](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1121) > * Prevent cross-scope source files from being parsed as PlainText by [`@pstreef`](https://github.com/pstreef) in [openrewrite/rewrite-maven-plugin#1123](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1123) > > New Contributors > ---------------- > > * [`@pstreef`](https://github.com/pstreef) made their first contribution in [openrewrite/rewrite-maven-plugin#1123](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1123) > > **Full Changelog**: <openrewrite/rewrite-maven-plugin@v6.33.0...v6.34.0> > > 6.33.0 > ------ > > What's Changed > -------------- > > * chore(ci): bump maven-dependencies.version from 3.9.12 to 3.9.13 by [`@dependabot`](https://github.com/dependabot)[bot] in [openrewrite/rewrite-maven-plugin#1117](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1117) > > **Full Changelog**: <openrewrite/rewrite-maven-plugin@v6.32.0...v6.33.0> Commits * [`cf0a432`](openrewrite/rewrite-maven-plugin@cf0a432) [maven-release-plugin] prepare release v6.34.0 * [`241454c`](openrewrite/rewrite-maven-plugin@241454c) Bump rewrite.version property * [`753abba`](openrewrite/rewrite-maven-plugin@753abba) Prevent cross-scope source files from being parsed as PlainText ([#1123](https://redirect.github.com/openrewrite/rewrite-maven-plugin/issues/1123)) * [`86478fe`](openrewrite/rewrite-maven-plugin@86478fe) chore(ci): bump maven-dependencies.version from 3.9.13 to 3.9.14 ([#1121](https://redirect.github.com/openrewrite/rewrite-maven-plugin/issues/1121)) * [`9d6cafa`](openrewrite/rewrite-maven-plugin@9d6cafa) chore(ci): bump io.micrometer:micrometer-core from 1.16.3 to 1.16.4 ([#1120](https://redirect.github.com/openrewrite/rewrite-maven-plugin/issues/1120)) * [`30b4ff1`](openrewrite/rewrite-maven-plugin@30b4ff1) Add explicit Groovy source file parsing with classpath ([#1119](https://redirect.github.com/openrewrite/rewrite-maven-plugin/issues/1119)) * [`4e290c4`](openrewrite/rewrite-maven-plugin@4e290c4) Bump rewrite.version property * [`23b08c7`](openrewrite/rewrite-maven-plugin@23b08c7) [maven-release-plugin] prepare for next development iteration * [`b990e73`](openrewrite/rewrite-maven-plugin@b990e73) [maven-release-plugin] prepare release v6.33.0 * [`2d8fd65`](openrewrite/rewrite-maven-plugin@2d8fd65) Bump rewrite.version property * Additional commits viewable in [compare view](openrewrite/rewrite-maven-plugin@v6.32.0...v6.34.0) [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- Dependabot commands and options You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
processMainSourcesandprocessTestSourceseach iterate resource directories viagetResources()/getTestResources(). When a resource directory points at${project.basedir},OmniParserwalks the entire project tree. Source files belonging to the other scope are not yet inalreadyParsed, soPlainTextParserclaims them. The real parse in the other scope then produces a duplicate entry, and the PlainText version shadows the properly typed one — making type information and annotations invisible to recipes.This affects both scoped and non-scoped
listSourceFilesflows, sinceprocessMainSourceseagerly walks resource directories beforeprocessTestSourceshas added test source paths toalreadyParsed.Solution
Before each scope's resource loop, pre-populate
alreadyParsedwith the other scope's source file paths (Java, Kotlin, Groovy). This ensuresOmniParserskips source files that will be properly parsed by the other scope.