From a0a1d7699c4bf4c2e5d77bd0b67b603017e6fe0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Kr=C3=BCger?= Date: Wed, 13 Dec 2023 09:34:14 +0100 Subject: [PATCH] Add README using snippets from docs --- README.adoc | 35 ++++++++++++++++ .../modules/ROOT/pages/getting-started.adoc | 42 +------------------ .../ROOT/pages/partials/dependency-code.adoc | 14 +------ .../partials/example-application-code.adoc | 41 ++++++++++++++++++ .../partials/gradle-dependency-snippet.adoc | 4 ++ .../partials/maven-dependency-snippet.adoc | 8 ++++ .../list-applicable-recipes-example/pom.xml | 4 +- 7 files changed, 93 insertions(+), 55 deletions(-) create mode 100644 README.adoc create mode 100644 spring-rewrite-commons-docs/src/main/antora/modules/ROOT/pages/partials/example-application-code.adoc create mode 100644 spring-rewrite-commons-docs/src/main/antora/modules/ROOT/pages/partials/gradle-dependency-snippet.adoc create mode 100644 spring-rewrite-commons-docs/src/main/antora/modules/ROOT/pages/partials/maven-dependency-snippet.adoc diff --git a/README.adoc b/README.adoc new file mode 100644 index 000000000..2ba165e35 --- /dev/null +++ b/README.adoc @@ -0,0 +1,35 @@ += Spring Rewrite Commons +:partials_dir: spring-rewrite-commons-docs/src/main/antora/modules/ROOT/pages/partials +:project-version: 0.1.0-SNAPSHOTS + +[quote] +____ +Spring Rewrite Commons provides a set of components to parse a Java project to OpenRewrite LST and apply recipes outside a build tool plugin. +____ + +== Get started + +=== Add Dependency + +**Maven** +include::{partials_dir}/maven-dependency-snippet.adoc[] + +**Gradle** +include::{partials_dir}/gradle-dependency-snippet.adoc[] + +=== Implement a Recipe Launcher + +include::{partials_dir}/example-application-code.adoc[] + + +== Reference documentation + +Find the reference documentation link:{docs}[here]. + +== Contributing + +https://help.github.com/articles/creating-a-pull-request[Pull requests] are welcome. Note, that we expect everyone to follow the https://github.com/spring-projects/.github/blob/main/CODE_OF_CONDUCT.md[code of conduct]. + +== License +Spring Rewrite Commons is Open Source software released under the +https://www.apache.org/licenses/LICENSE-2.0.html[Apache 2.0 license]. \ No newline at end of file diff --git a/spring-rewrite-commons-docs/src/main/antora/modules/ROOT/pages/getting-started.adoc b/spring-rewrite-commons-docs/src/main/antora/modules/ROOT/pages/getting-started.adoc index 12b7c49c6..929f231ff 100644 --- a/spring-rewrite-commons-docs/src/main/antora/modules/ROOT/pages/getting-started.adoc +++ b/spring-rewrite-commons-docs/src/main/antora/modules/ROOT/pages/getting-started.adoc @@ -23,46 +23,6 @@ include::partials/dependency-code.adoc[] This dummy code of a Spring application shows how to use the components provided by Spring Rewrite Commons to parse an application and write back the changes to the filesystem. -[source,java] -.... -import org.springframework.beans.factory.annotation.Autowired; - -@Component -public class MyMigrationApplication { - - @Autowired <1> - private RewriteProjectParser parser; - - @Autowired - private RewriteRecipeDiscovery discovery; <3> - - @Autowired - private ProjectResourceSetFactory resourceSetFactory; <4> - - @Autowired - private ProjectResourceSetSerializer serializer; <5> - - - public void migrateToBoot3_1() { - Path baseDir = ... <2> - String recipeName = "org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_1"; - Recipe boot3Upgrade = discover.getByName(recipeName); <3> - - RewriteParsingResult result = parser.parse(baseDir); <4> - List lst = result.sourceFiles(); <5> - ProjectResourceSet resourceSet = resourceSetFactory.create(baseDir, lst); <6> - resourceSet.apply(boot3Upgrade); <7> - serializer.writeChanges(resourceSet); <8> - } -} -.... -<1> All components are Spring beans and can be injected as such. -<2> The path of the project that should be migrated. -<3> `RewriteRecipeDiscovery` is used to discover an OpenRewrite recipe by name. -<4> `RewriteProjectParser` parses a given project to OpenRewrite LST. -<5> The result contains the list of ``SourceFile``s (the LST). -<6> `ProjectResourceSetFactory` can be used to create a `ProjectResourceSet`. -<7> The recipe is applied to the `ProjectResourceSet` which wraps the LST. -<8> `ProjectResourceSetSerializer` is used to serialize the changes to disk. +include::partials/example-application-code.adoc[] Read more about the xref:components.adoc[available components]. diff --git a/spring-rewrite-commons-docs/src/main/antora/modules/ROOT/pages/partials/dependency-code.adoc b/spring-rewrite-commons-docs/src/main/antora/modules/ROOT/pages/partials/dependency-code.adoc index baa9ae344..415be5030 100644 --- a/spring-rewrite-commons-docs/src/main/antora/modules/ROOT/pages/partials/dependency-code.adoc +++ b/spring-rewrite-commons-docs/src/main/antora/modules/ROOT/pages/partials/dependency-code.adoc @@ -2,19 +2,9 @@ ====== Maven:: + -[source,xml,indent=0,subs="verbatim,quotes,attributes",role="primary"] ----- - - org.springframwork.rewrite - spring-rewrite-commons - {projectVersion} - ----- +include::maven-dependency-snippet.adoc[] Gradle:: + -[source,groovy,indent=0,subs="verbatim,quotes,attributes",role="secondary"s] ----- -compile 'org.springframework.rewrite:spring-rewrite-commons:{projectVersion}' ----- +include::gradle-dependency-snippet.adoc[] ====== \ No newline at end of file diff --git a/spring-rewrite-commons-docs/src/main/antora/modules/ROOT/pages/partials/example-application-code.adoc b/spring-rewrite-commons-docs/src/main/antora/modules/ROOT/pages/partials/example-application-code.adoc new file mode 100644 index 000000000..b6f60c9a2 --- /dev/null +++ b/spring-rewrite-commons-docs/src/main/antora/modules/ROOT/pages/partials/example-application-code.adoc @@ -0,0 +1,41 @@ +[source,java] +.... +import org.springframework.beans.factory.annotation.Autowired; + +@Component +public class MyMigrationApplication { + + @Autowired <1> + private RewriteProjectParser parser; + + @Autowired + private RewriteRecipeDiscovery discovery; <3> + + @Autowired + private ProjectResourceSetFactory resourceSetFactory; <4> + + @Autowired + private ProjectResourceSetSerializer serializer; <5> + + + public void migrateToBoot3_1() { + Path baseDir = ... <2> + String recipeName = "org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_1"; + Recipe boot3Upgrade = discover.getByName(recipeName); <3> + + RewriteParsingResult result = parser.parse(baseDir); <4> + List lst = result.sourceFiles(); <5> + ProjectResourceSet resourceSet = resourceSetFactory.create(baseDir, lst); <6> + resourceSet.apply(boot3Upgrade); <7> + serializer.writeChanges(resourceSet); <8> + } +} +.... +<1> All components are Spring beans and can be injected as such. +<2> The path of the project that should be migrated. +<3> `RewriteRecipeDiscovery` is used to discover an OpenRewrite recipe by name. +<4> `RewriteProjectParser` parses a given project to OpenRewrite LST. +<5> The result contains the list of ``SourceFile``s (the LST). +<6> `ProjectResourceSetFactory` can be used to create a `ProjectResourceSet`. +<7> The recipe is applied to the `ProjectResourceSet` which wraps the LST. +<8> `ProjectResourceSetSerializer` is used to serialize the changes to disk. \ No newline at end of file diff --git a/spring-rewrite-commons-docs/src/main/antora/modules/ROOT/pages/partials/gradle-dependency-snippet.adoc b/spring-rewrite-commons-docs/src/main/antora/modules/ROOT/pages/partials/gradle-dependency-snippet.adoc new file mode 100644 index 000000000..7fb73bfc1 --- /dev/null +++ b/spring-rewrite-commons-docs/src/main/antora/modules/ROOT/pages/partials/gradle-dependency-snippet.adoc @@ -0,0 +1,4 @@ +[source,groovy,indent=0,subs="verbatim,quotes,attributes",role="secondary"s] +---- +compile 'org.springframework.rewrite:spring-rewrite-commons:{projectVersion}' +---- \ No newline at end of file diff --git a/spring-rewrite-commons-docs/src/main/antora/modules/ROOT/pages/partials/maven-dependency-snippet.adoc b/spring-rewrite-commons-docs/src/main/antora/modules/ROOT/pages/partials/maven-dependency-snippet.adoc new file mode 100644 index 000000000..220543996 --- /dev/null +++ b/spring-rewrite-commons-docs/src/main/antora/modules/ROOT/pages/partials/maven-dependency-snippet.adoc @@ -0,0 +1,8 @@ +[source,xml,indent=0,subs="verbatim,quotes,attributes",role="primary"] +---- + + org.springframwork.rewrite + spring-rewrite-commons + {project-version} + +---- \ No newline at end of file diff --git a/spring-rewrite-commons-examples/list-applicable-recipes-example/pom.xml b/spring-rewrite-commons-examples/list-applicable-recipes-example/pom.xml index 9bceea3c1..7fde061a8 100644 --- a/spring-rewrite-commons-examples/list-applicable-recipes-example/pom.xml +++ b/spring-rewrite-commons-examples/list-applicable-recipes-example/pom.xml @@ -11,8 +11,8 @@ org.example list-applicable-recipes-example 0.0.1-SNAPSHOT - list-applicable-recipes-example - list-applicable-recipes-example + Spring Rewrite Commons Examples - List Applicable Recipes + Example project listing applicable recipes for a given application 17