rewrite
rewrite copied to clipboard
Gradle Plugin/Openrewrite should skip files anntoated with javax.annotation.Generated
What problem are you trying to solve?
Avoiding updating generated java files. e.g. Those generated by XJC
Describe the solution you'd like
Skip classes/files annotated with https://docs.oracle.com/en/java/javase/17/docs/api/java.compiler/javax/annotation/processing/Generated.html
https://docs.oracle.com/javase/8/docs/technotes/tools/unix/xjc.html
Have you considered any alternatives or workarounds?
Directory skipping but this is build dependent and prone to additional issues.
Additional context
Are you interested in [contributing this feature to OpenRewrite]
Yes
Hi! Thanks for the suggestion and offer to help. As a bit of context let me link you to how for instance the Maven plugin handles generated sources, as that might factor in here as well: https://github.com/openrewrite/rewrite-maven-plugin/blob/09fe6c413311aba7ae160bd4e6e8b38f1d41bad6/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java#L428-L433
You'll notice that generated sources get a org.openrewrite.marker.Generated
marker attached to them, which then later excludes them from showing changes:
https://github.com/openrewrite/rewrite/blob/c3270d00822efef1f4a0bc175ac417ffea8d9c8a/rewrite-core/src/main/java/org/openrewrite/scheduling/RecipeRunCycle.java#L172-L176
https://github.com/openrewrite/rewrite/blob/c3270d00822efef1f4a0bc175ac417ffea8d9c8a/rewrite-core/src/main/java/org/openrewrite/internal/InMemoryLargeSourceSet.java#L111-L113
It appears we don't yet take javax.annotation.Generated
into account, but I could see a point being made to also add our internal generated marker to classes annotated as generated. Would you want to help explore that option?
That seems pretty straightforward. I assume you would want to use reflection to test or are you okay taking a dependency on the generated class directly?
Great to hear; elsewhere we use FindAnnotations.find
to find annotations on LST elements, with those dependencies only necessary on the projects themselves, not for the recipe development.
https://github.com/openrewrite/rewrite/blob/c3270d00822efef1f4a0bc175ac417ffea8d9c8a/rewrite-java/src/main/java/org/openrewrite/java/ExtractInterface.java#L135