Skip parsing generated sources; use compiled classes instead#1142
Skip parsing generated sources; use compiled classes instead#1142
Conversation
…nstead Generated sources under the build directory (e.g. target/generated-sources/) were being fully parsed into LSTs only to be filtered out afterward. Since getCompileClasspathElements() already includes target/classes with the compiled .class files for these sources, type attribution works without parsing them. This adds filterGeneratedSourceRoots() to exclude source roots under the build directory before scanning for source files, avoiding unnecessary parsing work for projects that heavily use code generation (protobuf, MapStruct, annotation processors, etc.). Closes #667
| List<String> mainSourceRoots = filterGeneratedSourceRoots(mavenProject, mavenProject.getExecutionProject().getCompileSourceRoots()); | ||
| List<String> testSourceRoots = filterGeneratedSourceRoots(mavenProject, mavenProject.getExecutionProject().getTestCompileSourceRoots()); |
There was a problem hiding this comment.
Won't this result in the files being present in the model as PlainText? Maybe we should -- like the Gradle plugin -- filter out at the end? Avoiding parsing them ahead of time is useful as well though.
There was a problem hiding this comment.
You're right, thanks! Changed the approach slightly to still claim the sources through parsedPaths, but not parse them in processMainSources and processTestSources. That should then still achieve the goals set out on #667 for efficiency, without affecting functionality.
Restore unfiltered source roots for parsedPaths pre-population so that OmniParser does not pick up generated .java files as PlainText. The filtering of generated source roots is still applied in processMainSources and processTestSources to skip expensive language parsing, and the buildDirectory filter at the end acts as a safety net.
shanman190
left a comment
There was a problem hiding this comment.
Should we just add this to the isExcluded check on L241? That could probably be converted to a filter like we did in the Gradle plugin.
Move the build directory filter from processMainSources/processTestSources into the unified isExcluded check, matching the Gradle plugin's approach. Generated sources are now excluded in one place alongside user exclusions and gitignore checks, while filterGeneratedSourceRoots still skips expensive language parsing upfront.
…unchanged Move the buildDirectory exclusion out of isExcluded and into the call site at L241 as an inline check, keeping isExcluded's signature and tests unchanged. Remove build directory unit tests that no longer apply to isExcluded directly.
There was a problem hiding this comment.
optional: We could simplify this to a .filter(sourceFile -> !isExcluded(repository, exclusionMatchers, sourceFile.getSourcePath()) && !source.getSourcePath().startsWith(buildDirectory))
… 6.34.0 to 6.38.0 [skip ci] Bumps [org.openrewrite.maven:rewrite-maven-plugin](https://github.com/openrewrite/rewrite-maven-plugin) from 6.34.0 to 6.38.0. Release notes *Sourced from [org.openrewrite.maven:rewrite-maven-plugin's releases](https://github.com/openrewrite/rewrite-maven-plugin/releases).* > 6.38.0 > ------ > > **Full Changelog**: <openrewrite/rewrite-maven-plugin@v6.37.0...v6.38.0> > > 6.37.0 > ------ > > What's Changed > -------------- > > * Fix GHSA-6fmv-xxpf-w3cw: pin plexus-utils 3.6.1 and suppress false positive by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-maven-plugin#1138](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1138) > * Validate DEVELOCITY\_ACCESS\_KEY format before build by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-maven-plugin#1141](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1141) > * Add Slack notification for scheduled CI failures by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-maven-plugin#1140](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1140) > * Resolve Maven user properties (-D) in YAML configuration by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-maven-plugin#1139](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1139) > * Skip parsing generated sources; use compiled classes instead by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-maven-plugin#1142](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1142) > * chore(ci): bump org.owasp:dependency-check-maven from 12.2.0 to 12.2.1 by [`@dependabot`](https://github.com/dependabot)[bot] in [openrewrite/rewrite-maven-plugin#1143](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1143) > * Fix plexus-utils CVE-2025-67030 suppression by [`@Jenson3210`](https://github.com/Jenson3210) in [openrewrite/rewrite-maven-plugin#1144](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1144) > * Move dependency-check-maven plugin from reporting to build by [`@Jenson3210`](https://github.com/Jenson3210) in [openrewrite/rewrite-maven-plugin#1145](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1145) > * chore(ci): bump actions/upload-pages-artifact from 4 to 5 by [`@dependabot`](https://github.com/dependabot)[bot] in [openrewrite/rewrite-maven-plugin#1146](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1146) > * chore(ci): bump io.micrometer:micrometer-core from 1.16.4 to 1.16.5 by [`@dependabot`](https://github.com/dependabot)[bot] in [openrewrite/rewrite-maven-plugin#1148](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1148) > * chore(ci): bump maven-dependencies.version from 3.9.14 to 3.9.15 by [`@dependabot`](https://github.com/dependabot)[bot] in [openrewrite/rewrite-maven-plugin#1147](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1147) > > **Full Changelog**: <openrewrite/rewrite-maven-plugin@v6.36.0...v6.37.0> > > 6.36.0 > ------ > > **Full Changelog**: <openrewrite/rewrite-maven-plugin@v6.35.1...v6.36.0> > > 6.35.1 > ------ > > What's Changed > -------------- > > * Fix datatable\_export test for updated CSV column headers by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-maven-plugin#1132](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1132) > * chore(ci): bump actions/configure-pages from 5 to 6 by [`@dependabot`](https://github.com/dependabot)[bot] in [openrewrite/rewrite-maven-plugin#1129](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1129) > * chore(ci): bump actions/deploy-pages from 4 to 5 by [`@dependabot`](https://github.com/dependabot)[bot] in [openrewrite/rewrite-maven-plugin#1130](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1130) > * Fix files falsely marked as changed by migration recipes by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-maven-plugin#1134](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1134) > * Pass null properties when resolvePropertiesInYaml=false by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-maven-plugin#1133](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1133) > * Fix isExcluded gitignore handling using shared GitIgnore utility by [`@pdelagrave`](https://github.com/pdelagrave) in [openrewrite/rewrite-maven-plugin#1135](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1135) > * bump vulnerabilities by [`@Jenson3210`](https://github.com/Jenson3210) in [openrewrite/rewrite-maven-plugin#1136](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1136) > > New Contributors > ---------------- > > * [`@pdelagrave`](https://github.com/pdelagrave) made their first contribution in [openrewrite/rewrite-maven-plugin#1135](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1135) > > **Full Changelog**: <openrewrite/rewrite-maven-plugin@v6.35.0...v6.35.1> > > 6.35.0 > ------ > > What's Changed > -------------- > > * Add optional version input to publish workflow by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-maven-plugin#1124](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1124) > * Use CsvDataTableStore for data table export by [`@jkschneider`](https://github.com/jkschneider) in [openrewrite/rewrite-maven-plugin#1125](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1125) > * chore(ci): bump com.fasterxml.jackson:jackson-bom from 2.17.3 to 2.21.2 by [`@dependabot`](https://github.com/dependabot)[bot] in [openrewrite/rewrite-maven-plugin#1126](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1126) > * Load proxy settings from Maven settings.xml by [`@timtebeek`](https://github.com/timtebeek) in [openrewrite/rewrite-maven-plugin#1127](https://redirect.github.com/openrewrite/rewrite-maven-plugin/pull/1127) > > **Full Changelog**: <openrewrite/rewrite-maven-plugin@v6.34.0...v6.35.0> Commits * [`4fe065c`](openrewrite/rewrite-maven-plugin@4fe065c) [maven-release-plugin] prepare release v6.38.0 * [`446bc8a`](openrewrite/rewrite-maven-plugin@446bc8a) Bump rewrite.version property * [`f3d983c`](openrewrite/rewrite-maven-plugin@f3d983c) Bump rewrite.version property * [`b5565ff`](openrewrite/rewrite-maven-plugin@b5565ff) Bump rewrite.version property * [`b7d7640`](openrewrite/rewrite-maven-plugin@b7d7640) [maven-release-plugin] prepare for next development iteration * [`caecb2f`](openrewrite/rewrite-maven-plugin@caecb2f) [maven-release-plugin] prepare release v6.37.0 * [`68bab02`](openrewrite/rewrite-maven-plugin@68bab02) Bump rewrite.version property * [`841ed61`](openrewrite/rewrite-maven-plugin@841ed61) chore(ci): bump maven-dependencies.version from 3.9.14 to 3.9.15 ([#1147](https://redirect.github.com/openrewrite/rewrite-maven-plugin/issues/1147)) * [`4b191ed`](openrewrite/rewrite-maven-plugin@4b191ed) chore(ci): bump io.micrometer:micrometer-core from 1.16.4 to 1.16.5 ([#1148](https://redirect.github.com/openrewrite/rewrite-maven-plugin/issues/1148)) * [`e8cb166`](openrewrite/rewrite-maven-plugin@e8cb166) chore(ci): bump actions/upload-pages-artifact from 4 to 5 ([#1146](https://redirect.github.com/openrewrite/rewrite-maven-plugin/issues/1146)) * Additional commits viewable in [compare view](openrewrite/rewrite-maven-plugin@v6.34.0...v6.38.0)
Summary
Generated sources under the build directory (e.g.
target/generated-sources/) were being fully parsed into LSTs only to be filtered out afterwardSince
getCompileClasspathElements()already includestarget/classeswith the compiled.classfiles, type attribution works without parsing the generated sourcesAdds
filterGeneratedSourceRoots()to exclude source roots under the build directory before scanning, applied consistently inprocessMainSources(),processTestSources(), and theparsedPathspre-populationThis improves performance for projects that heavily use code generation (protobuf, MapStruct, annotation processors, etc.)
Closes Do not parse generated sources as source files, but only as compiled classes #667
Impact on related issues
GeneratedSourcemarker, which is orthogonal to this change.ParseError#649 — Maven PolyglotParseError. Unrelated; that issue is about non-standard POM files, not source file handling.Test plan