Skip to content

Prevent cross-scope source files from being parsed as PlainText - #1123

Merged
timtebeek merged 4 commits into
mainfrom
pstreef/fix-scoped-plaintext
Mar 18, 2026
Merged

timtebeek merged 4 commits into
mainfrom
pstreef/fix-scoped-plaintext

Conversation

@pstreef

@pstreef pstreef commented Mar 17, 2026 •

Copy link
Copy Markdown
Contributor

Problem

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 PlainTextParser claims 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 listSourceFiles flows, since processMainSources eagerly walks resource directories before processTestSources has added test source paths to alreadyParsed.

Solution

Before each scope's resource loop, pre-populate alreadyParsed with the other scope's source file paths (Java, Kotlin, Groovy). This ensures OmniParser skips source files that will be properly parsed by the other scope.

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
pstreef force-pushed the pstreef/fix-scoped-plaintext branch from a26d9df to 84d9f61 Compare March 17, 2026 15:38
@timtebeek

Copy link
Copy Markdown
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:
d9ced30#diff-b74cafb3bb2091d675d11745dfcb80fa5c3777709a69f416025366ba7aead259L219

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.
@timtebeek timtebeek self-assigned this Mar 18, 2026
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
timtebeek marked this pull request as ready for review March 18, 2026 14:29
@timtebeek
timtebeek merged commit 753abba into main Mar 18, 2026
1 check passed
@timtebeek
timtebeek deleted the pstreef/fix-scoped-plaintext branch March 18, 2026 16:09
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Mar 18, 2026
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)
  
[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility\_score?dependency-name=org.openrewrite.maven:rewrite-maven-plugin&package-manager=maven&previous-version=6.32.0&new-version=6.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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants