diff --git a/rewrite-core/src/main/java/org/openrewrite/config/Environment.java b/rewrite-core/src/main/java/org/openrewrite/config/Environment.java index 0f9554efc91..3cabc8c209a 100644 --- a/rewrite-core/src/main/java/org/openrewrite/config/Environment.java +++ b/rewrite-core/src/main/java/org/openrewrite/config/Environment.java @@ -150,16 +150,23 @@ public Recipe activateRecipes(Iterable activeRecipes) { } } if (!recipesNotFound.isEmpty()) { + @SuppressWarnings("deprecation") List suggestions = recipesNotFound.stream() .map(r -> recipesByName.keySet().stream() .min(comparingInt(a -> StringUtils.getLevenshteinDistance(a, r))) .orElse(r)) .collect(toList()); - String message = String.format("Recipes not found: %s\nDid you mean: %s", + String message = String.format("Recipe(s) not found: %s\nDid you mean: %s", String.join(", ", recipesNotFound), String.join(", ", suggestions)); throw new RecipeException(message); } + if (activatedRecipes.isEmpty()) { + return Recipe.noop(); + } + if (activatedRecipes.size() == 1) { + return activatedRecipes.get(0); + } return new CompositeRecipe(activatedRecipes); } @@ -167,11 +174,6 @@ public Recipe activateRecipes(String... activeRecipes) { return activateRecipes(Arrays.asList(activeRecipes)); } - //TODO: Nothing uses this and in most cases it would be a bad idea anyway, should consider removing - public Recipe activateAll() { - return new CompositeRecipe(listRecipes()); - } - /** * @return A list of validations of style names that could be activated. */ diff --git a/rewrite-core/src/test/java/org/openrewrite/RecipeLifecycleTest.java b/rewrite-core/src/test/java/org/openrewrite/RecipeLifecycleTest.java index ef289d80c2a..0752bbb78e2 100644 --- a/rewrite-core/src/test/java/org/openrewrite/RecipeLifecycleTest.java +++ b/rewrite-core/src/test/java/org/openrewrite/RecipeLifecycleTest.java @@ -280,6 +280,7 @@ void canCallImperativeRecipeWithoutArgsFromDeclarative() { type: specs.openrewrite.org/v1beta/recipe name: test.recipe displayName: Test Recipe + description: Test Recipe. recipeList: - org.openrewrite.NoArgRecipe """, @@ -295,6 +296,7 @@ void canCallImperativeRecipeWithUnnecessaryArgsFromDeclarative() { type: specs.openrewrite.org/v1beta/recipe name: test.recipe displayName: Test Recipe + description: Test Recipe. recipeList: - org.openrewrite.NoArgRecipe: foo: bar @@ -311,6 +313,7 @@ void canCallRecipeWithNoExplicitConstructor() { type: specs.openrewrite.org/v1beta/recipe name: test.recipe displayName: Test Recipe + description: Test Recipe. recipeList: - org.openrewrite.DefaultConstructorRecipe """, @@ -326,18 +329,21 @@ void declarativeRecipeChain() { type: specs.openrewrite.org/v1beta/recipe name: test.recipe.a displayName: Test Recipe + description: Test Recipe. recipeList: - test.recipe.b --- type: specs.openrewrite.org/v1beta/recipe name: test.recipe.b displayName: Test Recipe + description: Test Recipe. recipeList: - test.recipe.c --- type: specs.openrewrite.org/v1beta/recipe name: test.recipe.c displayName: Test Recipe + description: Test Recipe. recipeList: - org.openrewrite.NoArgRecipe """, @@ -354,6 +360,7 @@ void declarativeRecipeChainAcrossFiles() { type: specs.openrewrite.org/v1beta/recipe name: test.recipe.c displayName: Test Recipe + description: Test Recipe. recipeList: - org.openrewrite.NoArgRecipe """.getBytes()), @@ -363,6 +370,7 @@ void declarativeRecipeChainAcrossFiles() { type: specs.openrewrite.org/v1beta/recipe name: test.recipe.b displayName: Test Recipe + description: Test Recipe. recipeList: - test.recipe.c """.getBytes()), @@ -372,6 +380,7 @@ void declarativeRecipeChainAcrossFiles() { type: specs.openrewrite.org/v1beta/recipe name: test.recipe.a displayName: Test Recipe + description: Test Recipe. recipeList: - test.recipe.b """.getBytes()), @@ -391,7 +400,7 @@ void declarativeRecipeChainFromResources() { void declarativeRecipeChainFromResourcesIncludesImperativeRecipesInDescriptors() { rewriteRun(spec -> spec.recipeFromResources("test.declarative.sample.a") .afterRecipe(recipeRun -> assertThat(recipeRun.getChangeset().getAllResults().get(0) - .getRecipeDescriptorsThatMadeChanges().get(0).getRecipeList().get(0).getRecipeList().get(0) + .getRecipeDescriptorsThatMadeChanges().get(0).getRecipeList().get(0) .getDisplayName()).isEqualTo("Change text")), text("Hi", "after")); } diff --git a/rewrite-core/src/test/java/org/openrewrite/config/DeclarativeRecipeTest.java b/rewrite-core/src/test/java/org/openrewrite/config/DeclarativeRecipeTest.java index 016ac24bb02..ef7b9b90314 100644 --- a/rewrite-core/src/test/java/org/openrewrite/config/DeclarativeRecipeTest.java +++ b/rewrite-core/src/test/java/org/openrewrite/config/DeclarativeRecipeTest.java @@ -159,6 +159,7 @@ void yamlPrecondition() { --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.PreconditionTest + description: Test. preconditions: - org.openrewrite.text.Find: find: 1 @@ -180,6 +181,7 @@ void yamlPreconditionWithScanningRecipe() { --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.PreconditionTest + description: Test. preconditions: - org.openrewrite.text.Find: find: 1 diff --git a/rewrite-core/src/test/java/org/openrewrite/table/SourceFileResultsTest.java b/rewrite-core/src/test/java/org/openrewrite/table/SourceFileResultsTest.java index 44a418f41a9..b46e0cd8fbe 100644 --- a/rewrite-core/src/test/java/org/openrewrite/table/SourceFileResultsTest.java +++ b/rewrite-core/src/test/java/org/openrewrite/table/SourceFileResultsTest.java @@ -31,8 +31,7 @@ class SourceFileResultsTest implements RewriteTest { void hierarchical() { rewriteRun( spec -> spec - .recipe( - new ByteArrayInputStream( + .recipeFromYaml( //language=yml """ type: specs.openrewrite.org/v1beta/recipe @@ -40,17 +39,16 @@ void hierarchical() { displayName: Change text to hello description: Hello world. recipeList: - - org.openrewrite.text.ChangeText: - toText: Hello! - """.getBytes() - ), + - org.openrewrite.text.ChangeText: + toText: Hello! + """, "test.ChangeTextToHello" ).dataTable(SourcesFileResults.Row.class, rows -> { - assertThat(rows).hasSize(2); + assertThat(rows).hasSize(1); assertThat(rows.stream().map(SourcesFileResults.Row::getParentRecipe)) - .containsExactly("test.ChangeTextToHello", ""); + .containsExactly("test.ChangeTextToHello"); assertThat(rows.stream().map(SourcesFileResults.Row::getRecipe)) - .containsExactly("org.openrewrite.text.ChangeText", "test.ChangeTextToHello"); + .containsExactly("org.openrewrite.text.ChangeText"); }), text( "Hi", diff --git a/rewrite-core/src/test/resources/META-INF/rewrite/test-sample-a.yml b/rewrite-core/src/test/resources/META-INF/rewrite/test-sample-a.yml index 2a66687a08a..bca4fbc5f79 100644 --- a/rewrite-core/src/test/resources/META-INF/rewrite/test-sample-a.yml +++ b/rewrite-core/src/test/resources/META-INF/rewrite/test-sample-a.yml @@ -18,5 +18,6 @@ type: specs.openrewrite.org/v1beta/recipe name: test.declarative.sample.a displayName: Test Recipe +description: Test Recipe. recipeList: - test.declarative.sample.b \ No newline at end of file diff --git a/rewrite-core/src/test/resources/META-INF/rewrite/test-sample-b.yml b/rewrite-core/src/test/resources/META-INF/rewrite/test-sample-b.yml index 1ee001ecd96..21c9ec27e47 100644 --- a/rewrite-core/src/test/resources/META-INF/rewrite/test-sample-b.yml +++ b/rewrite-core/src/test/resources/META-INF/rewrite/test-sample-b.yml @@ -18,6 +18,7 @@ type: specs.openrewrite.org/v1beta/recipe name: test.declarative.sample.b displayName: Test Recipe +description: Test Recipe. recipeList: - org.openrewrite.text.ChangeText: toText: after \ No newline at end of file diff --git a/rewrite-java-test/src/test/java/org/openrewrite/java/ReplaceStringLiteralWithConstantTest.java b/rewrite-java-test/src/test/java/org/openrewrite/java/ReplaceStringLiteralWithConstantTest.java index 015470f478b..70930ae4811 100644 --- a/rewrite-java-test/src/test/java/org/openrewrite/java/ReplaceStringLiteralWithConstantTest.java +++ b/rewrite-java-test/src/test/java/org/openrewrite/java/ReplaceStringLiteralWithConstantTest.java @@ -193,6 +193,7 @@ void replaceStringLiteralWithConstantValueWhenLiteralValueIsNotConfiguredYaml() spec -> spec.recipeFromYaml(""" type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.ReplaceStringLiteralWithConstantList + description: Replace string literals with constants. recipeList: - org.openrewrite.java.ReplaceStringLiteralWithConstant: fullyQualifiedConstantName: %s @@ -221,6 +222,7 @@ void replaceStringLiteralWithConstantValueWhenLiteralValueIsConfiguredYaml() { spec -> spec.recipeFromYaml(""" type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.ReplaceStringLiteralWithConstantList + description: Replace string literals with constants. recipeList: - org.openrewrite.java.ReplaceStringLiteralWithConstant: literalValue: %s diff --git a/rewrite-java-test/src/test/java/org/openrewrite/java/search/HasJavaVersionTest.java b/rewrite-java-test/src/test/java/org/openrewrite/java/search/HasJavaVersionTest.java index 0d89f83d8c5..4acf0fcef83 100644 --- a/rewrite-java-test/src/test/java/org/openrewrite/java/search/HasJavaVersionTest.java +++ b/rewrite-java-test/src/test/java/org/openrewrite/java/search/HasJavaVersionTest.java @@ -68,6 +68,7 @@ void declarativePrecondition() { --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.PreconditionTest + description: Test. preconditions: - org.openrewrite.java.search.HasJavaVersion: version: 11 @@ -87,6 +88,7 @@ void declarativePreconditionMatch() { --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.PreconditionTest + description: Test. preconditions: - org.openrewrite.java.search.HasJavaVersion: version: 11 @@ -105,6 +107,7 @@ void combinedWithFindMethod() { --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.CombinedWithFindMethod + description: Test. recipeList: - org.openrewrite.java.search.HasJavaVersion: version: 11 @@ -142,6 +145,7 @@ void combinedWithFindMethodFirst() { --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.CombinedWithFindMethod + description: Test. recipeList: - org.openrewrite.java.search.FindMethods: methodPattern: java.util.List add(..) diff --git a/rewrite-java-test/src/test/java/org/openrewrite/text/FindAndReplaceJavaTest.java b/rewrite-java-test/src/test/java/org/openrewrite/text/FindAndReplaceJavaTest.java index 873ef0c9dea..0f68804b7a9 100644 --- a/rewrite-java-test/src/test/java/org/openrewrite/text/FindAndReplaceJavaTest.java +++ b/rewrite-java-test/src/test/java/org/openrewrite/text/FindAndReplaceJavaTest.java @@ -53,6 +53,7 @@ void filePatternShouldLimitApplication() { type: specs.openrewrite.org/v1beta/recipe name: com.yourorg.FindAndReplaceExample displayName: Find and replace example + description: Test. recipeList: - org.openrewrite.text.FindAndReplace: find: blacklist diff --git a/rewrite-maven/src/test/java/org/openrewrite/maven/RenamePropertyKeyTest.java b/rewrite-maven/src/test/java/org/openrewrite/maven/RenamePropertyKeyTest.java index f61ad5e5e5c..cb3ceeadca3 100644 --- a/rewrite-maven/src/test/java/org/openrewrite/maven/RenamePropertyKeyTest.java +++ b/rewrite-maven/src/test/java/org/openrewrite/maven/RenamePropertyKeyTest.java @@ -15,16 +15,11 @@ */ package org.openrewrite.maven; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.openrewrite.DocumentExample; -import org.openrewrite.maven.tree.MavenResolutionResult; import org.openrewrite.test.RecipeSpec; import org.openrewrite.test.RewriteTest; -import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; import static org.openrewrite.maven.Assertions.pomXml; class RenamePropertyKeyTest implements RewriteTest { @@ -42,15 +37,15 @@ void propertyInDependency() { """ 4.0.0 - + 29.0-jre - + com.mycompany.app my-app 1 - + com.google.guava @@ -63,15 +58,15 @@ void propertyInDependency() { """ 4.0.0 - + 29.0-jre - + com.mycompany.app my-app 1 - + com.google.guava @@ -92,15 +87,15 @@ void propertyInDependencyManagement() { """ 4.0.0 - + 29.0-jre - + com.mycompany.app my-app 1 - + @@ -115,15 +110,15 @@ void propertyInDependencyManagement() { """ 4.0.0 - + 29.0-jre - + com.mycompany.app my-app 1 - + @@ -146,14 +141,14 @@ void propertyInProperty() { """ 4.0.0 - + 29.0-jre ${guava.version} prefix ${guava.version} ${guava.version} suffix ${abc} - + com.mycompany.app my-app 1 @@ -162,14 +157,14 @@ void propertyInProperty() { """ 4.0.0 - + 29.0-jre ${version.com.google.guava} prefix ${version.com.google.guava} ${version.com.google.guava} suffix ${abc} - + com.mycompany.app my-app 1 @@ -186,7 +181,7 @@ void renamePropertyAndValue() { type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.RenamePropertyAndValue displayName: RenamePropertyAndValue - description: RenamePropertyAndValue description + description: RenamePropertyAndValue description. recipeList: - org.openrewrite.maven.RenamePropertyKey: oldKey: "abc" @@ -201,11 +196,11 @@ void renamePropertyAndValue() { """ 4.0.0 - + 1.0 - + com.mycompany.app my-app 1 @@ -214,11 +209,11 @@ void renamePropertyAndValue() { """ 4.0.0 - + 2.0 - + com.mycompany.app my-app 1 @@ -235,11 +230,11 @@ void nothingToRename() { """ 4.0.0 - + com.mycompany.app my-app 1 - + a b diff --git a/rewrite-maven/src/test/java/org/openrewrite/maven/search/FindPluginTest.java b/rewrite-maven/src/test/java/org/openrewrite/maven/search/FindPluginTest.java index 4fb57d6379a..8abd165a293 100644 --- a/rewrite-maven/src/test/java/org/openrewrite/maven/search/FindPluginTest.java +++ b/rewrite-maven/src/test/java/org/openrewrite/maven/search/FindPluginTest.java @@ -17,14 +17,9 @@ import org.junit.jupiter.api.Test; import org.openrewrite.DocumentExample; -import org.openrewrite.config.DeclarativeRecipe; import org.openrewrite.test.RewriteTest; -import java.net.URI; import java.net.URISyntaxException; -import java.util.Collections; -import java.util.List; -import java.util.Map; import static org.openrewrite.maven.Assertions.pomXml; @@ -97,6 +92,7 @@ void multiModulePrecondition() throws URISyntaxException { --- type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.MultiModuleTest + description: Test. preconditions: - org.openrewrite.maven.search.FindPlugin: groupId: org.apache.maven.plugins @@ -115,7 +111,7 @@ void multiModulePrecondition() throws URISyntaxException { pom submodule - + @@ -124,16 +120,16 @@ void multiModulePrecondition() throws URISyntaxException { 5.28.0 - + - """,sourceSpecs -> sourceSpecs.path("pom.xml")), + """, sourceSpecs -> sourceSpecs.path("pom.xml")), pomXml( """ org.example mvn_multi_module_test - 1.0-SNAPSHOT + 1.0-SNAPSHOT submodule @@ -146,7 +142,7 @@ void multiModulePrecondition() throws URISyntaxException { - """,sourceSpecs -> sourceSpecs.path("submodule.pom.xml") + """, sourceSpecs -> sourceSpecs.path("submodule.pom.xml") ) ); } diff --git a/rewrite-test/src/test/java/org/openrewrite/config/EnvironmentTest.java b/rewrite-test/src/test/java/org/openrewrite/config/EnvironmentTest.java index cfebb015b1c..199ded1e891 100644 --- a/rewrite-test/src/test/java/org/openrewrite/config/EnvironmentTest.java +++ b/rewrite-test/src/test/java/org/openrewrite/config/EnvironmentTest.java @@ -45,6 +45,7 @@ void declarativeRecipesDontAddToEstimatedTimeFixed() { type: specs.openrewrite.org/v1beta/recipe name: test.ChangeTextToHello displayName: Change text to hello + description: Test. recipeList: - org.openrewrite.text.ChangeText: toText: Hello @@ -74,6 +75,7 @@ void listRecipes() { type: specs.openrewrite.org/v1beta/recipe name: test.ChangeTextToHello displayName: Change text to hello + description: Test. recipeList: - org.openrewrite.text.ChangeText: toText: Hello @@ -112,6 +114,7 @@ void activeRecipeNotFoundSuggestions() { type: specs.openrewrite.org/v1beta/recipe name: test.ChangeTextToHello displayName: Change text to hello + description: Test. recipeList: - org.openrewrite.text.ChangeText: toText: Hello @@ -119,6 +122,7 @@ void activeRecipeNotFoundSuggestions() { type: specs.openrewrite.org/v1beta/recipe name: test.ChangeTextToHelloWorld displayName: Change text to hello world + description: Test. recipeList: - org.openrewrite.text.ChangeText: toText: Hello @@ -147,6 +151,7 @@ void recipeWithoutRequiredConfiguration() { type: specs.openrewrite.org/v1beta/recipe name: test.ChangeTextToHello displayName: Change text to hello + description: Test. recipeList: - org.openrewrite.text.ChangeText """.getBytes() @@ -172,12 +177,14 @@ void recipeDependsOnOtherDeclarativeRecipe() { type: specs.openrewrite.org/v1beta/recipe name: test.TextMigration displayName: Text migration + description: Test. recipeList: - test.ChangeTextToHello --- type: specs.openrewrite.org/v1beta/recipe name: test.ChangeTextToHello displayName: Change text to hello + description: Test. recipeList: - org.openrewrite.text.ChangeText: toText: Hello @@ -213,6 +220,7 @@ void recipeDependsOnOtherDeclarativeRecipeSpecifiedInAnotherFile() { type: specs.openrewrite.org/v1beta/recipe name: test.TextMigration displayName: Text migration + description: Test. recipeList: - test.ChangeTextToHello """.getBytes() @@ -262,6 +270,7 @@ void recipeDependsOnNonExistentRecipe() { type: specs.openrewrite.org/v1beta/recipe name: test.TextMigration displayName: Text migration + description: Test. recipeList: - test.DoesNotExist """.getBytes() @@ -286,7 +295,8 @@ void declarativeRecipeListClassCastException() { """ type: specs.openrewrite.org/v1beta/recipe name: test.LicenseHeader - displayName: License header. + displayName: License header + description: Test. recipeList: - org.openrewrite.java.AddLicenseHeader: |- LicenseHeader @@ -312,6 +322,7 @@ void declarativeRecipeWrongPackage() { type: specs.openrewrite.org/v1beta/recipe name: test.ResultOfFileMkdirsIgnored displayName: Test + description: Test. recipeList: - org.openrewrite.java.ResultOfMethodCallIgnored: methodPattern: 'java.io.File mkdir*()' @@ -427,6 +438,7 @@ void preserveRecipeListOrder() { type: specs.openrewrite.org/v1beta/recipe name: test.FooOne displayName: Test + description: Test. recipeList: - org.openrewrite.config.RecipeAcceptingParameters: foo: "foo" @@ -459,6 +471,7 @@ void preserveRecipeListOrder() { type: specs.openrewrite.org/v1beta/recipe name: test.OrderPreserved displayName: Test + description: Test. recipeList: - org.openrewrite.config.RecipeNoParameters - test.FooOne @@ -474,7 +487,7 @@ void preserveRecipeListOrder() { new Properties() )) .build(); - var recipeList = env.activateRecipes("test.OrderPreserved").getRecipeList().get(0).getRecipeList(); + var recipeList = env.activateRecipes("test.OrderPreserved").getRecipeList(); assertThat(recipeList.get(0).getName()).isEqualTo("org.openrewrite.config.RecipeNoParameters"); assertThat(recipeList.get(1).getName()).isEqualTo("test.FooOne"); assertThat(recipeList.get(2).getName()).isEqualTo("org.openrewrite.config.RecipeAcceptingParameters"); @@ -493,17 +506,18 @@ void canCauseAnotherCycle() { type: specs.openrewrite.org/v1beta/recipe name: test.Foo displayName: Test + description: Test. causesAnotherCycle: true recipeList: - org.openrewrite.config.RecipeNoParameters - + """.getBytes() ), URI.create("rewrite.yml"), new Properties() )).build(); var recipe = env.activateRecipes("test.Foo"); - assertThat(recipe.getRecipeList().get(0).causesAnotherCycle()).isTrue(); + assertThat(recipe.causesAnotherCycle()).isTrue(); } @Test @@ -516,6 +530,7 @@ void willBeValidIfIncludesRecipesFromDependencies() { type: specs.openrewrite.org/v1beta/recipe name: test.Foo displayName: Test + description: Test. recipeList: - org.openrewrite.config.RecipeNoParameters """.getBytes() @@ -530,6 +545,7 @@ void willBeValidIfIncludesRecipesFromDependencies() { type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.config.RecipeNoParameters displayName: Test + description: Test. recipeList: - org.openrewrite.config.RecipeSomeParameters """.getBytes() diff --git a/rewrite-test/src/test/resources/META-INF/rewrite/rewrite.yml b/rewrite-test/src/test/resources/META-INF/rewrite/rewrite.yml index 0568f885fc1..b4ba1c9c208 100644 --- a/rewrite-test/src/test/resources/META-INF/rewrite/rewrite.yml +++ b/rewrite-test/src/test/resources/META-INF/rewrite/rewrite.yml @@ -17,7 +17,7 @@ type: specs.openrewrite.org/v1beta/recipe name: org.openrewrite.text.ChangeTextToJon displayName: Change Text To Jon -description: Changes Text to "Hello Jon!" +description: Changes Text to "Hello Jon!". tags: - testing - plain text