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

Do not wrap single active recipe & remove activateAll() #4349

Merged
merged 6 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,28 +150,30 @@ public Recipe activateRecipes(Iterable<String> activeRecipes) {
}
}
if (!recipesNotFound.isEmpty()) {
@SuppressWarnings("deprecation")
List<String> 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);
timtebeek marked this conversation as resolved.
Show resolved Hide resolved
}

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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
""",
Expand All @@ -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
Expand All @@ -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
""",
Expand All @@ -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
""",
Expand All @@ -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()),
Expand All @@ -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()),
Expand All @@ -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()),
Expand All @@ -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"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,24 @@ class SourceFileResultsTest implements RewriteTest {
void hierarchical() {
rewriteRun(
spec -> spec
.recipe(
new ByteArrayInputStream(
.recipeFromYaml(
//language=yml
"""
type: specs.openrewrite.org/v1beta/recipe
name: test.ChangeTextToHello
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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(..)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Loading