Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework OpenRewrite recipe integration #181

Closed
fabapp2 opened this issue Jun 23, 2022 · 1 comment · Fixed by #180
Closed

Rework OpenRewrite recipe integration #181

fabapp2 opened this issue Jun 23, 2022 · 1 comment · Fixed by #180
Labels
type: enhancement New feature or request
Milestone

Comments

@fabapp2
Copy link
Collaborator

fabapp2 commented Jun 23, 2022

What needs to be done

OpenRewrite recipes should be runnable from within SBM.
It should also be possible to use OpenRewrite recipes inside SBM recipes

Why it needs to be done

OpenRewrite has a large set of recipes available which should be available in SBM.
This allows us to contribute recipes to OpenRewrite and still use them in SBM.

Acceptance Criteria

Reference OpenRewrite recipe by name

Given

Java class

@java.lang.Deprecated
public class Foo {}

SBM YAML recipe (src/main/resources/recipes/test-recipe.yaml)

- name: test-recipe
  description: Replace deprecated spring.datasource.* properties
  condition:
    type: org.springframework.sbm.common.migration.conditions.TrueCondition
  actions:
    - type: org.springframework.sbm.engine.recipe.OpenRewriteDeclarativeRecipeAdapter
      description: Call a OpenRewrite recipe
      openRewriteRecipe: |-
        type: specs.openrewrite.org/v1beta/recipe
        name: org.openrewrite.java.RemoveAnnotation
        displayName: Order imports
        description: Order imports
        recipeList:
          - org.openrewrite.java.RemoveAnnotation:
              annotationPattern: "@java.lang.Deprecated"

When

Recipe is applied apply test-recipe

Then

The OpenRewrite recipe org.openrewrite.java.RemoveAnnotation as declared in src/main/resources/recipes/test-recipe.yaml is applied and the annotation was removed

Java class

public class Foo {}

Reference OpenRewrite recipe by name

Given

Java class

@java.lang.Deprecated
public class Foo {}

SBM YAML recipe (src/main/resources/recipes/test-recipe.yaml)

- name: test-recipe
  description: "Remove @Deprecated annotations"
  condition:
    type: org.springframework.sbm.common.migration.conditions.TrueCondition
  actions:
    - type: org.springframework.sbm.engine.recipe.OpenRewriteNamedRecipeAdapter
      description: "Call a OpenRewrite recipe to remove @Deprecated annotations"
      openRewriteRecipeName: org.springframework.sbm.dummy.RemoveDeprecatedAnnotation

OpenRewrite recipe (src/main/resources/META-INF/rewrite/test-recipe.yml)

type: specs.openrewrite.org/v1beta/recipe
name: org.springframework.sbm.dummy.RemoveDeprecatedAnnotation
displayName: Order imports
description: Order imports
recipeList:
  - org.openrewrite.java.RemoveAnnotation:
      annotationPattern: "@java.lang.Deprecated"

When

Recipe is applied apply test-recipe

Then

The OpenRewrite recipe src/main/resources/META-INF/rewrite/test-recipe.yml was applied and the @Deprecated annotation was removed

Java class

public class Foo {}

Additional Information

@fabapp2 fabapp2 linked a pull request Jun 23, 2022 that will close this issue
@fabapp2
Copy link
Collaborator Author

fabapp2 commented Jul 7, 2022

  • Adds a class RewriteRecipeLoader which is currently disabled to not list all OpenRewrite recipes found as applicable recipes, see Provide a way to categorize and/or tag recipes #185. Enabling (add Component annotation) this class again will list all OpenRewrite recipes in the Shell
  • Allows to integrate OpenRewrite recipes in SBM by name
  • Allows to integrate OpenRewrite recipe snippets in SBM YAML syntax

@fabapp2 fabapp2 added this to the v0.12.0 milestone Sep 20, 2022
@fabapp2 fabapp2 added the type: enhancement New feature or request label Sep 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant