Skip to content

Commit

Permalink
Add README using snippets from docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fabapp2 committed Dec 13, 2023
1 parent e569d88 commit a0a1d76
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 55 deletions.
35 changes: 35 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -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].
Original file line number Diff line number Diff line change
Expand Up @@ -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<SourceFile> 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].
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,9 @@
======
Maven::
+
[source,xml,indent=0,subs="verbatim,quotes,attributes",role="primary"]
----
<dependency>
<groupId>org.springframwork.rewrite</groupId>
<artifactId>spring-rewrite-commons</artifactId>
<version>{projectVersion}</version>
</dependency>
----
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[]
======
Original file line number Diff line number Diff line change
@@ -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<SourceFile> 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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[source,groovy,indent=0,subs="verbatim,quotes,attributes",role="secondary"s]
----
compile 'org.springframework.rewrite:spring-rewrite-commons:{projectVersion}'
----
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[source,xml,indent=0,subs="verbatim,quotes,attributes",role="primary"]
----
<dependency>
<groupId>org.springframwork.rewrite</groupId>
<artifactId>spring-rewrite-commons</artifactId>
<version>{project-version}</version>
</dependency>
----
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<groupId>org.example</groupId>
<artifactId>list-applicable-recipes-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>list-applicable-recipes-example</name>
<description>list-applicable-recipes-example</description>
<name>Spring Rewrite Commons Examples - List Applicable Recipes</name>
<description>Example project listing applicable recipes for a given application</description>
<properties>
<java.version>17</java.version>
</properties>
Expand Down

0 comments on commit a0a1d76

Please sign in to comment.