Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into feature/ChangeVersionValue
Browse files Browse the repository at this point in the history
  • Loading branch information
marcel-gepardec committed Jul 25, 2024
2 parents ca036df + 14aef40 commit 913be28
Show file tree
Hide file tree
Showing 27 changed files with 709 additions and 148 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/receive-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- org.openrewrite.recipes.RecipeTestingBestPracticesSubset
- org.openrewrite.recipes.RecipeNullabilityBestPracticesSubset
#- org.openrewrite.java.OrderImports
#- org.openrewrite.java.format.EmptyNewlineAtEndOfFile
- org.openrewrite.java.format.EmptyNewlineAtEndOfFile
- org.openrewrite.staticanalysis.InlineVariable
- org.openrewrite.staticanalysis.MissingOverrideAnnotation
- org.openrewrite.staticanalysis.UseDiamondOperator
Expand Down
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);
}

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 @@ -61,7 +61,7 @@ void migrate() {
""",
"""
plugins {
id 'com.gradle.develocity' version '3.17.5'
id 'com.gradle.develocity' version '3.17.6'
}
develocity {
server = 'https://ge.sam.com/'
Expand Down Expand Up @@ -101,7 +101,7 @@ void publishAlwaysIf() {
""",
"""
plugins {
id 'com.gradle.develocity' version '3.17.5'
id 'com.gradle.develocity' version '3.17.6'
}
develocity {
server = 'https://ge.sam.com/'
Expand Down Expand Up @@ -131,7 +131,7 @@ void publishOnFailure() {
""",
"""
plugins {
id 'com.gradle.develocity' version '3.17.5'
id 'com.gradle.develocity' version '3.17.6'
}
develocity {
server = 'https://ge.sam.com/'
Expand Down Expand Up @@ -161,7 +161,7 @@ void publishOnFailureIf() {
""",
"""
plugins {
id 'com.gradle.develocity' version '3.17.5'
id 'com.gradle.develocity' version '3.17.6'
}
develocity {
server = 'https://ge.sam.com/'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

package org.openrewrite.groovy.tree;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.openrewrite.Issue;
import org.openrewrite.java.tree.J;
import org.openrewrite.java.tree.JavaType;
import org.openrewrite.java.tree.TypeUtils;
import org.openrewrite.test.RewriteTest;
import org.openrewrite.test.TypeValidation;

import static java.util.Objects.requireNonNull;
import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -37,7 +39,7 @@ void multipleClassDeclarationsInOneCompilationUnit() {
"""
public class A {
int n
def sum(int m) {
n+m
}
Expand Down Expand Up @@ -128,9 +130,9 @@ void hasPackage() {
groovy(
"""
package org.openrewrite
public class A{}
"""
"""
)
);
}
Expand Down Expand Up @@ -168,7 +170,7 @@ void packagePrivate() {
groovy(
"""
import groovy.transform.PackageScope
@PackageScope
class A {}
""",
Expand Down Expand Up @@ -288,4 +290,21 @@ public final class A {}
)
);
}

@Issue("https://github.com/openrewrite/rewrite/pull/4346")
@Test
@Disabled("Known issue; still need to explore a fix")
void classExtendsGroovyLangScript() {
rewriteRun(
spec -> spec.typeValidationOptions(TypeValidation.none()),
// Reduced from https://github.com/openrewrite/rewrite/blob/3de7723ba43d8c44d7b524273ad7548d4fcd04eb/rewrite-gradle/src/main/groovy/RewriteSettings.groovy#L32
// "Source file was parsed into an LST that contains non-whitespace characters in its whitespace. This is indicative of a bug in the parser."
groovy(
"""
class RewriteSettings extends groovy.lang.Script {
}
"""
)
);
}
}
Loading

0 comments on commit 913be28

Please sign in to comment.