-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not add Kotlin and Groovy sources from build/
to LST
#322
Conversation
I suspect that we're actually including all types of generated sources that are produced by various plugins as they will appear within the source files from What should probably be being done is a filter operation when collecting all of the unparsed sources and excluding them when they are contained within |
Thanks for the hint! Noticed we only had that pattern for Java; now also for Kotlin & Groovy + Kotlin multi platform. Should help I think, although it's a bit cumbersome to test. |
@@ -737,7 +739,7 @@ public Stream<SourceFile> parse(Project subproject, Set<Path> alreadyParsed, Exe | |||
.flatMap(jp -> jp.parse(javaPaths, baseDir, ctx)) | |||
.map(cu -> { | |||
if (isExcluded(exclusions, cu.getSourcePath()) || | |||
cu.getSourcePath().startsWith(baseDir.relativize(subproject.getLayout().getBuildDirectory().get().getAsFile().toPath()))) { | |||
cu.getSourcePath().startsWith(buildDirPath)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to even be parsing these files at all with OpenRewrite?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we did so for the type attribution; that's at least the comment over on the Maven plugin. Hadn't thought to change that here just yet. Just excluding them after they are parsed to prevent them ending up in the LST themselves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we have so far, yeah, but we also trigger the compile phases in Gradle as well prior to the rewrite tasks, so technically we could put the source set's own output classes onto the parser's classpath to still get the necessary type attribution and bypass parsing the generated types.
Just a thought though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could indeed be a nice improvement to stop ourselves from parsing source files whose LSTs we'll discard anyway, or perhaps even having two sources of the same type information; compiled vs source.
build/
to LST
What's changed?
Reuse the mechanism we added for
protos/build/generated
forbuild/generated-sources
.What's your motivation?
Files like
build-src/build/generated-sources
are parsed into the LST, and modified by recipes. That last part is undesirable, as the diffs would then target files not part of the git repository, and fail to apply from a dryRun fix.patch file.Anything in particular you'd like reviewers to focus on?
There's likely a better way, but I'm having a bit of trouble working that out. Figured open this PR to start the discussion.
Have you considered any alternatives or workarounds?
What I'd done previously in an attempt to exclude these files is add them to Git ignore:
openrewrite/rewrite-recipe-bom@9f5840c
But somehow they are still picked up; I had thought we already excluded files ignored in git.
Any additional context
I know in the Maven plugin we explicitly exclude generated sources, but I'm not immediately seeing an equivalent here.
https://github.com/ammachado/rewrite-maven-plugin/blob/f900a9a6365a4d02c0083dd29e14927d6ffa6576/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java#L425-L430