rewrite-maven-plugin icon indicating copy to clipboard operation
rewrite-maven-plugin copied to clipboard

Scan the generated sources but not apply change

Open addozhang opened this issue 9 months ago • 4 comments

What problem are you trying to solve?

Here we have projects that use OAS to define API and generate codes. These generated codes locate at target/generated-sources.

During recipes running, these generated codes will be referred by others sources or used in scanning phase.

Describe the solution you'd like

Scan the generated sources but not apply changes to these generated ones.

Have you considered any alternatives or workarounds?

We may can involve a new Marker like Immutable, and add Marker to generated sources.

During changes apply, skip the sources with this Marker.

Additional context

Are you interested in contributing this feature to OpenRewrite?

Yes, if the feature accepted.

addozhang avatar Mar 26 '25 06:03 addozhang

Hi @addozhang ; Interesting suggestion! If I understand correctly you'd want the generated source to participate in the scanning phase of any ScanningRecipe, but not be visited in the edit phase? Or have their suggested changes discarded?

Right now that would not be possible, as for instance the Maven plugin already filters out generated source LSTs in the parser: https://github.com/openrewrite/rewrite-maven-plugin/blob/b75abb0fcc3d7584b15ea1d2322a950ca53ed396/src/main/java/org/openrewrite/maven/MavenMojoProjectParser.java#L443-L448

Could you describe why you'd want to see this change in a little more detail? You've for now mostly described what you'd like to see, but for a change like this the motivation is important before we'd make such structural changes.

timtebeek avatar Mar 26 '25 16:03 timtebeek

Yes, I see from the source that the plugin reads the generated code but eventually filters it out.

I now want to migrate our project from a commercial framework to springboot. These APIs use OpenAPI to describe the interface that we use OAS Generator to generate controllers for endpoints. Then use openrewrite to generate the implementation of the Controller. Those business logic are described using xml. With xmlst, we implement the logical code in the Controller or Service layer.

I hope my description is clear enough.

addozhang avatar Mar 27 '25 00:03 addozhang

That helps a bit, thanks. Do I understand correctly you'd want to migrate the generated classes, and then from that point onwards maintain them and stop relying on the code generator? I wonder if the code generator can be made to produce alternative outputs that already match your desired outcome, and if it makes sense to move your generated sources to src/main such that no plugin/framework changes are needed.

timtebeek avatar Mar 30 '25 11:03 timtebeek

It might be a good idea to have the OAS Generator plug-in generate classes to the src/main directory. The generated code output path is currently configured in the parent pom, and I need to see if it can be configured. The purpose of the current output path is to treat the generated code as unmaintainable, and developers only need to focus on oas yaml.

Tim te Beek @.***> 于 2025年3月30日周日 下午7:16写道:

That helps a bit, thanks. Do I understand correctly you'd want to migrate the generated classes, and then from that point onwards maintain them and stop relying on the code generator? I wonder if the code generator can be made to produce alternative outputs that already match your desired outcome, and if it makes sense to move your generated sources to src/main such that no plugin/framework changes are needed.

— Reply to this email directly, view it on GitHub https://github.com/openrewrite/rewrite-maven-plugin/issues/968#issuecomment-2764508774, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ7C3D5HQK3NR6J455WT432W7HB5AVCNFSM6AAAAABZZM6ELSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONRUGUYDQNZXGQ . You are receiving this because you were mentioned.Message ID: @.***> [image: timtebeek]timtebeek left a comment (openrewrite/rewrite-maven-plugin#968) https://github.com/openrewrite/rewrite-maven-plugin/issues/968#issuecomment-2764508774

That helps a bit, thanks. Do I understand correctly you'd want to migrate the generated classes, and then from that point onwards maintain them and stop relying on the code generator? I wonder if the code generator can be made to produce alternative outputs that already match your desired outcome, and if it makes sense to move your generated sources to src/main such that no plugin/framework changes are needed.

— Reply to this email directly, view it on GitHub https://github.com/openrewrite/rewrite-maven-plugin/issues/968#issuecomment-2764508774, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ7C3D5HQK3NR6J455WT432W7HB5AVCNFSM6AAAAABZZM6ELSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONRUGUYDQNZXGQ . You are receiving this because you were mentioned.Message ID: @.***>

addozhang avatar Mar 30 '25 13:03 addozhang