From a50224e32d8d1d7eea1023c599eafc19ff37b1d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Kr=C3=BCger?= Date: Thu, 14 Dec 2023 01:42:11 +0100 Subject: [PATCH] Replace broken includes in README --- README.adoc | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/README.adoc b/README.adoc index 2083ace..87a18ce 100644 --- a/README.adoc +++ b/README.adoc @@ -15,14 +15,78 @@ ____ === Add Dependency **Maven** -include::{partials_dir}/maven-dependency-snippet.adoc[] +[source,xml,indent=0,subs="verbatim,quotes,attributes",role="primary"] +---- + + org.springframwork.rewrite + spring-rewrite-commons-launcher + {project-version} + +---- **Gradle** -include::{partials_dir}/gradle-dependency-snippet.adoc[] +[source,groovy,indent=0,subs="verbatim,quotes,attributes",role="secondary"s] +---- +compile 'org.springframework.rewrite:spring-rewrite-commons-launcher:{projectVersion}' +---- === Implement a Recipe Launcher -include::{partials_dir}/example-application-code.adoc[] +[source,java] +.... +package com.acme.example; + +import org.openrewrite.Recipe; +import org.openrewrite.SourceFile; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.rewrite.parsers.RewriteProjectParser; +import org.springframework.rewrite.parsers.RewriteProjectParsingResult; +import org.springframework.rewrite.project.resource.ProjectResourceSet; +import org.springframework.rewrite.project.resource.ProjectResourceSetFactory; +import org.springframework.rewrite.project.resource.ProjectResourceSetSerializer; +import org.springframework.rewrite.recipes.RewriteRecipeDiscovery; +import org.springframework.stereotype.Component; + +import java.nio.file.Path; +import java.util.List; + +@Component +public class MyMigrationApplication { + + @Autowired <1> + private RewriteProjectParser parser; + + @Autowired + private RewriteRecipeDiscovery discovery; <2> + + @Autowired + private ProjectResourceSetFactory resourceSetFactory; + + @Autowired + private ProjectResourceSetSerializer serializer; + + + public void migrateToBoot3_1() { + Path baseDir = Path.of("."); <2> + String recipeName = "org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_1"; + Recipe boot3Upgrade = discovery.getByName(recipeName); <3> + + RewriteProjectParsingResult 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. == Reference documentation