From a8a5a0aac1388e66025f7f95ec66681ef6e31b2b Mon Sep 17 00:00:00 2001 From: Mike Sol Date: Thu, 12 Oct 2023 09:18:06 -0700 Subject: [PATCH] Add Moderne CLI to recipes So that people can be aware of the fact that the Moderne CLi exists and can be used to run recipes. --- .../openrewrite/RecipeMarkdownGenerator.kt | 69 ++++++++++++++++--- src/main/resources/recipeDescriptors.yml | 20 +++--- 2 files changed, 71 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt b/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt index 49369a2..b15949e 100644 --- a/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt +++ b/src/main/kotlin/org/openrewrite/RecipeMarkdownGenerator.kt @@ -1043,7 +1043,8 @@ class RecipeMarkdownGenerator : Runnable { gradlePluginVersion, mavenPluginVersion, suppressMaven, - suppressGradle + suppressGradle, + getCliSnippet(recipeDescriptor), ) } else { writeSnippetsWithConfigurationWithoutDependency( @@ -1051,17 +1052,29 @@ class RecipeMarkdownGenerator : Runnable { gradlePluginVersion, mavenPluginVersion, suppressMaven, - suppressGradle + suppressGradle, + getCliSnippet(recipeDescriptor), ) } } else { if (origin.isFromCoreLibrary()) { writeSnippetsFromCoreLibrary( - recipeDescriptor, gradlePluginVersion, mavenPluginVersion, suppressMaven, suppressGradle + recipeDescriptor, + gradlePluginVersion, + mavenPluginVersion, + suppressMaven, + suppressGradle, + getCliSnippet(recipeDescriptor), ) } else { writeSnippetForOtherLibrary( - origin, recipeDescriptor, gradlePluginVersion, mavenPluginVersion, suppressMaven, suppressGradle + origin, + recipeDescriptor, + gradlePluginVersion, + mavenPluginVersion, + suppressMaven, + suppressGradle, + getCliSnippet(recipeDescriptor), ) } } @@ -1184,12 +1197,36 @@ class RecipeMarkdownGenerator : Runnable { return diffContent.toString() } + private fun getCliSnippet( + recipeDescriptor: RecipeDescriptor, + ): String { + val lastPeriod = recipeDescriptor.name.lastIndexOf('.') + var trimmedRecipeName = recipeDescriptor.name + + if (lastPeriod >= 0) { + trimmedRecipeName = recipeDescriptor.name.substring(lastPeriod + 1) + } + + return """ + {% tab title="Moderne CLI" %} + You will need to have configured the [Moderne CLI](https://docs.moderne.io/moderne-cli/cli-intro) on your machine before you can run the following command. + + {% code title="shell" %} + ```shell + mod run --recipe $trimmedRecipeName + ``` + {% endcode %} + {% endtab %} + """.trimIndent() + } + private fun BufferedWriter.writeSnippetsWithConfigurationWithoutDependency( exampleRecipeName: String, gradlePluginVersion: String, mavenPluginVersion: String, suppressMaven: Boolean, - suppressGradle: Boolean + suppressGradle: Boolean, + cliSnippet: String, ) { val gradleSnippet = if (suppressGradle) "" else """ {% tab title="Gradle" %} @@ -1212,6 +1249,7 @@ class RecipeMarkdownGenerator : Runnable { 2. Run `gradle rewriteRun` to run the recipe. {% endtab %} """.trimIndent() + val mavenSnippet = if (suppressMaven) "" else """ {% tab title="Maven" %} 1. Add the following to your `pom.xml` file: @@ -1238,12 +1276,14 @@ class RecipeMarkdownGenerator : Runnable { 2. Run `mvn rewrite:run` to run the recipe. {% endtab %} """.trimIndent() + writeln( """ Now that `$exampleRecipeName` has been defined activate it in your build file: {% tabs %} $gradleSnippet $mavenSnippet +$cliSnippet {% endtabs %} """.trimIndent() ) @@ -1255,7 +1295,8 @@ $mavenSnippet gradlePluginVersion: String, mavenPluginVersion: String, suppressMaven: Boolean, - suppressGradle: Boolean + suppressGradle: Boolean, + cliSnippet: String, ) { val gradleSnippet = if (suppressGradle) "" else """ {% tab title="Gradle" %} @@ -1282,6 +1323,7 @@ $mavenSnippet 2. Run `gradle rewriteRun` to run the recipe. {% endtab %} """.trimIndent() + val mavenSnippet = if (suppressMaven) "" else """ {% tab title="Maven" %} 1. Add the following to your `pom.xml` file: @@ -1315,12 +1357,14 @@ $mavenSnippet 2. Run `mvn rewrite:run` to run the recipe. {% endtab %} """.trimIndent() + writeln( """ Now that `$exampleRecipeName` has been defined activate it and take a dependency on ${origin.groupId}:${origin.artifactId}:${origin.version} in your build file: {% tabs %} $gradleSnippet $mavenSnippet +$cliSnippet {% endtabs %} """.trimIndent() ) @@ -1331,12 +1375,14 @@ $mavenSnippet gradlePluginVersion: String, mavenPluginVersion: String, suppressMaven: Boolean, - suppressGradle: Boolean + suppressGradle: Boolean, + cliSnippet: String, ) { writeln( "This recipe has no required configuration parameters and comes from a rewrite core library. " + "It can be activated directly without adding any dependencies." ) + val gradleSnippet = if (suppressGradle) "" else """ {% tab title="Gradle" %} 1. Add the following to your `build.gradle` file: @@ -1390,6 +1436,7 @@ $mavenSnippet 2. Run `gradle --init-script init.gradle rewriteRun` to run the recipe. {% endtab %} """.trimIndent() + val mavenSnippet = if (suppressMaven) "" else """ {% tab title="Maven POM" %} 1. Add the following to your `pom.xml` file: @@ -1431,6 +1478,7 @@ $mavenSnippet {% tabs %} $gradleSnippet $mavenSnippet +$cliSnippet {% endtabs %} """.trimIndent() ) @@ -1442,13 +1490,15 @@ $mavenSnippet gradlePluginVersion: String, mavenPluginVersion: String, suppressMaven: Boolean, - suppressGradle: Boolean + suppressGradle: Boolean, + cliSnippet: String, ) { writeln( "This recipe has no required configuration options. It can be activated by adding a dependency on " + "`${origin.groupId}:${origin.artifactId}:${origin.version}` in your build file or by running a shell " + "command (in which case no build changes are needed): " ) + val gradleSnippet = if (suppressGradle) "" else """ {% tab title="Gradle" %} 1. Add the following to your `build.gradle` file: @@ -1505,6 +1555,7 @@ $mavenSnippet 2. Run `gradle --init-script init.gradle rewriteRun` to run the recipe. {% endtab %} """.trimIndent() + val mavenSnippet = if (suppressMaven) "" else """ {% tab title="Maven POM" %} 1. Add the following to your `pom.xml` file: @@ -1550,11 +1601,13 @@ $mavenSnippet {% endcode %} {% endtab %} """.trimIndent() + writeln( """ {% tabs %} $gradleSnippet $mavenSnippet +$cliSnippet {% endtabs %} """.trimIndent() ) diff --git a/src/main/resources/recipeDescriptors.yml b/src/main/resources/recipeDescriptors.yml index 329daaf..5db4907 100644 --- a/src/main/resources/recipeDescriptors.yml +++ b/src/main/resources/recipeDescriptors.yml @@ -349,7 +349,7 @@ rewrite-concourse: artifactId: "rewrite-concourse" rewrite-core: artifactId: "rewrite-core" - version: "8.7.3" + version: "8.7.4" markdownRecipeDescriptors: org.openrewrite.DeleteSourceFiles: name: "org.openrewrite.DeleteSourceFiles" @@ -849,7 +849,7 @@ rewrite-github-actions: artifactId: "rewrite-github-actions" rewrite-gradle: artifactId: "rewrite-gradle" - version: "8.7.3" + version: "8.7.4" markdownRecipeDescriptors: org.openrewrite.gradle.AddDependency: name: "org.openrewrite.gradle.AddDependency" @@ -1414,7 +1414,7 @@ rewrite-gradle: artifactId: "rewrite-gradle" rewrite-groovy: artifactId: "rewrite-groovy" - version: "8.7.3" + version: "8.7.4" markdownRecipeDescriptors: org.openrewrite.groovy.format.OmitParenthesesForLastArgumentLambda: name: "org.openrewrite.groovy.format.OmitParenthesesForLastArgumentLambda" @@ -1433,7 +1433,7 @@ rewrite-groovy: artifactId: "rewrite-groovy" rewrite-hcl: artifactId: "rewrite-hcl" - version: "8.7.3" + version: "8.7.4" markdownRecipeDescriptors: org.openrewrite.hcl.DeleteContent: name: "org.openrewrite.hcl.DeleteContent" @@ -1584,7 +1584,7 @@ rewrite-hibernate: artifactId: "rewrite-hibernate" rewrite-java: artifactId: "rewrite-java" - version: "8.7.3" + version: "8.7.4" markdownRecipeDescriptors: org.openrewrite.java.AddApache2LicenseHeader: name: "org.openrewrite.java.AddApache2LicenseHeader" @@ -3353,7 +3353,7 @@ rewrite-jhipster: artifactId: "rewrite-jhipster" rewrite-json: artifactId: "rewrite-json" - version: "8.7.3" + version: "8.7.4" markdownRecipeDescriptors: org.openrewrite.json.ChangeKey: name: "org.openrewrite.json.ChangeKey" @@ -4271,7 +4271,7 @@ rewrite-logging-frameworks: artifactId: "rewrite-logging-frameworks" rewrite-maven: artifactId: "rewrite-maven" - version: "8.7.3" + version: "8.7.4" markdownRecipeDescriptors: org.openrewrite.maven.AddCommentToMavenDependency: name: "org.openrewrite.maven.AddCommentToMavenDependency" @@ -7899,7 +7899,7 @@ rewrite-okhttp: artifactId: "rewrite-okhttp" rewrite-properties: artifactId: "rewrite-properties" - version: "8.7.3" + version: "8.7.4" markdownRecipeDescriptors: org.openrewrite.properties.AddProperty: name: "org.openrewrite.properties.AddProperty" @@ -12579,7 +12579,7 @@ rewrite-testing-frameworks: artifactId: "rewrite-testing-frameworks" rewrite-xml: artifactId: "rewrite-xml" - version: "8.7.3" + version: "8.7.4" markdownRecipeDescriptors: org.openrewrite.xml.AddCommentToXmlTag: name: "org.openrewrite.xml.AddCommentToXmlTag" @@ -12785,7 +12785,7 @@ rewrite-xml: artifactId: "rewrite-xml" rewrite-yaml: artifactId: "rewrite-yaml" - version: "8.7.3" + version: "8.7.4" markdownRecipeDescriptors: org.openrewrite.yaml.AppendToSequence: name: "org.openrewrite.yaml.AppendToSequence"