diff --git a/components/sbm-recipes-boot-upgrade/pom.xml b/components/sbm-recipes-boot-upgrade/pom.xml
index 855e94a01..0aab2b812 100644
--- a/components/sbm-recipes-boot-upgrade/pom.xml
+++ b/components/sbm-recipes-boot-upgrade/pom.xml
@@ -29,8 +29,8 @@
UTF-8
UTF-8
- 11
- 11
+ 17
+ 17
@@ -73,6 +73,7 @@
org.springframework.sbm
recipe-test-support
+ ${project.version}
test
diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/CassandraApplicationPropertiesMove.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/CassandraApplicationPropertiesMove.java
index 6cb8ecc8a..1ef3633ed 100644
--- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/CassandraApplicationPropertiesMove.java
+++ b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/CassandraApplicationPropertiesMove.java
@@ -36,7 +36,7 @@ public String getDescription() {
}
@Override
- protected TreeVisitor, ExecutionContext> getVisitor() {
+ public TreeVisitor, ExecutionContext> getVisitor() {
return new PropertiesVisitor() {
diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/checks/DatabaseDriverGaeSectionBuilder.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/checks/DatabaseDriverGaeSectionBuilder.java
index 564ada81b..335032452 100644
--- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/checks/DatabaseDriverGaeSectionBuilder.java
+++ b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/checks/DatabaseDriverGaeSectionBuilder.java
@@ -44,7 +44,7 @@ public Sbu30_PreconditionCheckResult run(ProjectContext context) {
if(collect.isEmpty()) {
return new Sbu30_PreconditionCheckResult(PreconditionCheck.ResultState.PASSED, "No dependency to Google AppEngine's AppEngineDriver found.");
} else {
- String message = "Dependencies containing 'com.google.appengine.api.rdbms.AppEngineDriver' were found in these modules: '" + collect.stream().map(m -> m.getBuildFile().getCoordinates()).collect(Collectors.joining("', '")) + "'";
+ String message = "Dependencies containing 'com.google.appengine.api.rdbms.AppEngineDriver' were found in these modules: '" + collect.stream().map(m -> m.getBuildFile().getGav()).collect(Collectors.joining("', '")) + "'";
return new Sbu30_PreconditionCheckResult(PreconditionCheck.ResultState.FAILED, message);
}
}
diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/checks/RedeclaredDependenciesBuilder.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/checks/RedeclaredDependenciesBuilder.java
index 82b7b75ed..9a14f7f12 100644
--- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/checks/RedeclaredDependenciesBuilder.java
+++ b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/checks/RedeclaredDependenciesBuilder.java
@@ -46,7 +46,7 @@ public Section build(ProjectContext projectContext) {
Set matches = finder.findMatches(projectContext);
List todos = matches.stream()
.map(m -> TodoList.Todo.builder()
- .text(String.format("Remove explicit declaration of version for artifact: %s, its already declared with version %s", m.getRedeclaredDependency().getCoordinates(), m.originalVersion()))
+ .text(String.format("Remove explicit declaration of version for artifact: %s, its already declared with version %s", m.getRedeclaredDependency().getGav(), m.originalVersion()))
.build()).toList();
return ChangeSection.RelevantChangeSection.builder()
diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/openrewrite/SecurityManagerUsagesFinder.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/openrewrite/SecurityManagerUsagesFinder.java
index b4d430006..6e36ac3d6 100644
--- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/openrewrite/SecurityManagerUsagesFinder.java
+++ b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/openrewrite/SecurityManagerUsagesFinder.java
@@ -36,7 +36,12 @@ public String getDisplayName() {
}
@Override
- protected TreeVisitor, ExecutionContext> getVisitor() {
+ public String getDescription() {
+ return getDisplayName();
+ }
+
+ @Override
+ public TreeVisitor, ExecutionContext> getVisitor() {
return new JavaIsoVisitor<>() {
@Override
public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, ExecutionContext executionContext) {
diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/SpringBootUpgradeReportDataProvider.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/SpringBootUpgradeReportDataProvider.java
index a5965ac97..8bae8b9d3 100644
--- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/SpringBootUpgradeReportDataProvider.java
+++ b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/SpringBootUpgradeReportDataProvider.java
@@ -42,7 +42,7 @@ public Map getData(ProjectContext context, @Valid List> recipe =
- new GenericOpenRewriteRecipe<>(() -> new UsesType("org.springframework.boot.context.properties.ConstructorBinding"));
+ new GenericOpenRewriteRecipe<>(() -> new UsesType("org.springframework.boot.context.properties.ConstructorBinding", false));
List> rewriteSourceFileHolders =
context.getProjectJavaSources().find(recipe);
diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/JohnzonDependencyHelper.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/JohnzonDependencyHelper.java
index 54c22247c..8f8c2f578 100644
--- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/JohnzonDependencyHelper.java
+++ b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/JohnzonDependencyHelper.java
@@ -35,10 +35,10 @@ public String getDescription() {
@Override
public boolean evaluate(ProjectContext context) {
-
- Optional d = context.getBuildFile().getDeclaredDependencies().stream()
- .filter(x -> x.getCoordinates().contains("org.apache.johnzon:johnzon-core")).findFirst();
- return d.isPresent();
+ return context.getApplicationModules().getRootModule().getBuildFile()
+ .getDeclaredDependencies()
+ .stream()
+ .anyMatch(x -> x.getGav().contains("org.apache.johnzon:johnzon-core"));
}
@Override
diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/SpringMVCAndWebFluxUrlMatchingChangesHelper.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/SpringMVCAndWebFluxUrlMatchingChangesHelper.java
index 707ba7efe..1f1c2988a 100644
--- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/SpringMVCAndWebFluxUrlMatchingChangesHelper.java
+++ b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/SpringMVCAndWebFluxUrlMatchingChangesHelper.java
@@ -51,7 +51,7 @@ public boolean evaluate(ProjectContext context) {
return false;
}
- GenericOpenRewriteRecipe> usesTypeRecipe = new GenericOpenRewriteRecipe<>(() -> new UsesType<>(SPRING_REST_CONTROLLER_FQN));
+ GenericOpenRewriteRecipe> usesTypeRecipe = new GenericOpenRewriteRecipe<>(() -> new UsesType<>(SPRING_REST_CONTROLLER_FQN, false));
matches = context.getProjectJavaSources().find(usesTypeRecipe).stream()
.filter(m -> OpenRewriteJavaSource.class.isInstance(m))
diff --git a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/architecture/ControlledInstantiationOfExecutionContextTest.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/architecture/ControlledInstantiationOfExecutionContextTest.java
index 4ca962036..70e08f74f 100644
--- a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/architecture/ControlledInstantiationOfExecutionContextTest.java
+++ b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/architecture/ControlledInstantiationOfExecutionContextTest.java
@@ -24,7 +24,7 @@
import com.tngtech.archunit.lang.ArchRule;
import org.openrewrite.ExecutionContext;
import org.springframework.sbm.boot.autoconfigure.ScopeConfiguration;
-import org.springframework.sbm.openrewrite.RewriteExecutionContext;
+import org.springframework.sbm.parsers.RewriteExecutionContext;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
diff --git a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/ConfigRecipeTestHelper.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/ConfigRecipeTestHelper.java
index 66f4ecabb..fd674e3d7 100644
--- a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/ConfigRecipeTestHelper.java
+++ b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/ConfigRecipeTestHelper.java
@@ -21,6 +21,8 @@
import org.junit.jupiter.params.provider.Arguments;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.Result;
+import org.openrewrite.SourceFile;
+import org.openrewrite.internal.InMemoryLargeSourceSet;
import org.openrewrite.properties.PropertiesParser;
import org.openrewrite.properties.tree.Properties;
import org.openrewrite.test.RewriteTest;
@@ -42,10 +44,10 @@ public class ConfigRecipeTestHelper {
public static List runRecipeOnYaml(@Language("yml") String source, String recipeName) {
InMemoryExecutionContext ctx = new InMemoryExecutionContext(Throwable::printStackTrace);
- List document = new YamlParser().parse(source);
+ List document = new YamlParser().parse(source).toList();
return RewriteTest
.fromRuntimeClasspath(recipeName)
- .run(document, ctx).getResults();
+ .run(new InMemoryLargeSourceSet(document), ctx).getChangeset().getAllResults();
}
// public static List runRecipeOnProperties(@Language("properties") String source, String recipeName) {
diff --git a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/CrudRepositoryExtensionTest.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/CrudRepositoryExtensionTest.java
deleted file mode 100644
index 925015c18..000000000
--- a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/CrudRepositoryExtensionTest.java
+++ /dev/null
@@ -1,410 +0,0 @@
-/*
- * Copyright 2021 - 2023 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.sbm.boot.upgrade_27_30;
-
-import org.jetbrains.annotations.NotNull;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.Arguments;
-import org.junit.jupiter.params.provider.MethodSource;
-import org.openrewrite.Recipe;
-import org.openrewrite.Result;
-import org.openrewrite.test.RewriteTest;
-
-import java.util.List;
-import java.util.stream.Stream;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-
-public class CrudRepositoryExtensionTest implements RewriteTest {
-
- private final JavaTestHelper javaTestHelper = new JavaTestHelper();
- private static final Recipe crudRepoExtensionRecipe = new CrudRepositoryExtensionWithReferences(
- "org.springframework.data.repository.PagingAndSortingRepository",
- "org.springframework.data.repository.CrudRepository"
- );
-
- private static final Recipe reactiveCrudExtensionRecipe = new CrudRepositoryExtensionWithReferences(
- "org.springframework.data.repository.reactive.ReactiveSortingRepository",
- "org.springframework.data.repository.reactive.ReactiveCrudRepository"
- );
-
- private static final Recipe rxJavaCrudExtensionRecipe = new CrudRepositoryExtensionWithReferences(
- "org.springframework.data.repository.reactive.RxJava3SortingRepository",
- "org.springframework.data.repository.reactive.RxJava3CrudRepository"
- );
-
-
- @ParameterizedTest
- @MethodSource("repositoryTestArguments")
- public void shouldAddCrudRepository(Recipe recipe, String pagingAndSortingRepository, String crudRepository, String repositoryPackage) {
-
- @NotNull List result = javaTestHelper.runRecipe(
- recipe,
- List.of(replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -pagingRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -crudRepository- {
- void save(T entity);
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- ),
- replacePagingRepoAndCrudRepo("""
- package test;
- import -repositoryPackage-.-pagingRepository-;
- public interface A extends -pagingRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package test;
- public class Hello {
- public void test(A a) {
- a.save("Hello");
- }
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- );
-
- javaTestHelper.assertResult(result, replacePagingRepoAndCrudRepo("""
- package test;
- import -repositoryPackage-.-crudRepository-;
- import -repositoryPackage-.-pagingRepository-;
-
- public interface A extends -pagingRepository-, -crudRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage
- ));
- }
-
- @ParameterizedTest
- @MethodSource("repositoryTestArguments")
- public void canDoQuestionMark(Recipe recipe, String pagingAndSortingRepository, String crudRepository, String repositoryPackage) {
-
- @NotNull List result = javaTestHelper.runRecipe(recipe,
- List.of(replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -pagingRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -crudRepository- {
- void save(T);
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package test;
- public interface Payment {
- T hello();
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)),
- replacePagingRepoAndCrudRepo("""
- package test;
- import -repositoryPackage-.-pagingRepository-;
- public interface A extends -pagingRepository-, Long> {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package test;
- public class Hello {
- public void test(A a) {
- a.save("Hello");
- }
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- );
-
- javaTestHelper.assertResult(result, replacePagingRepoAndCrudRepo("""
- package test;
- import -repositoryPackage-.-crudRepository-;
- import -repositoryPackage-.-pagingRepository-;
-
- public interface A extends -pagingRepository-, Long>, -crudRepository-, Long> {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage));
- }
-
- @MethodSource("repositoryTestArguments")
- @ParameterizedTest
- public void whenThereAreNoParametersWhilstExtending(Recipe recipe, String pagingAndSortingRepository, String crudRepository, String repositoryPackage) {
-
- @NotNull List results = javaTestHelper.runRecipe(
- recipe,
- List.of(replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -pagingRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -crudRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)),
- replacePagingRepoAndCrudRepo("""
- package test;
- import -repositoryPackage-.-pagingRepository-;
- public interface A extends -pagingRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package test;
- public class Hello {
- public void test(A a) {
- a.save("Hello");
- }
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- );
-
- javaTestHelper.assertResult(results, replacePagingRepoAndCrudRepo("""
- package test;
- import -repositoryPackage-.-crudRepository-;
- import -repositoryPackage-.-pagingRepository-;
-
- public interface A extends -pagingRepository-, -crudRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage));
- }
-
- @MethodSource("repositoryTestArguments")
- @ParameterizedTest
- public void multipleExtends(Recipe recipe, String pagingAndSortingRepository, String crudRepository, String repositoryPackage) {
- @NotNull List results = javaTestHelper.runRecipe(
- recipe,
- List.of(replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -pagingRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package temp;
- public interface Hello {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -crudRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)),
- replacePagingRepoAndCrudRepo("""
- package test;
- import -repositoryPackage-.-pagingRepository-;
- import temp.Hello;
- public interface A extends Hello, -pagingRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package test;
- public class Hello {
- public void test(A a) {
- a.save("Hello");
- }
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- );
-
- javaTestHelper.assertResult(results, replacePagingRepoAndCrudRepo("""
- package test;
- import -repositoryPackage-.-crudRepository-;
- import -repositoryPackage-.-pagingRepository-;
- import temp.Hello;
-
- public interface A extends Hello, -pagingRepository-, -crudRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage));
- }
-
- @MethodSource("repositoryTestArguments")
- @ParameterizedTest
- public void classImplementsPagingRepository(Recipe recipe, String pagingAndSortingRepository, String crudRepository, String repositoryPackage) {
- @NotNull List result = javaTestHelper.runRecipe(
- recipe,
- List.of(replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -pagingRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- """
- package temp;
- public interface Hello {
- }
- """,
- replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -crudRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)),
- replacePagingRepoAndCrudRepo("""
- package test;
- import -repositoryPackage-.-pagingRepository-;
- import temp.Hello;
- public class A implements Hello, -pagingRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package test;
- public class Hello {
- public void test(A a) {
- a.save("Hello");
- }
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- );
-
- javaTestHelper.assertResult(result, replacePagingRepoAndCrudRepo("""
- package test;
- import -repositoryPackage-.-crudRepository-;
- import -repositoryPackage-.-pagingRepository-;
- import temp.Hello;
-
- public class A implements Hello, -pagingRepository-, -crudRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage));
- }
-
- @ParameterizedTest
- @MethodSource("repositoryTestArguments")
- void shouldExtendCrudRepositoryInInnerInterface(Recipe recipe, String pagingAndSortingRepository,
- String crudRepository,
- String repositoryPackage) {
- @NotNull List result = javaTestHelper.runRecipe(
- recipe,
- List.of(replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -crudRepository- {
- void save(String entity);
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -pagingRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- ),
- replacePagingRepoAndCrudRepo("""
- package test;
- import -repositoryPackage-.-pagingRepository-;
- class Hello {
- public interface A extends -pagingRepository- {
- }
-
- public void myCall(A a) {
- a.save("");
- }
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- );
-
- assertThat(result).hasSize(1);
- assertThat(result.get(0).getAfter().printAll())
- .isEqualTo(
- replacePagingRepoAndCrudRepo("""
- package test;
- import -repositoryPackage-.-crudRepository-;
- import -repositoryPackage-.-pagingRepository-;
-
- class Hello {
- public interface A extends -pagingRepository-, -crudRepository- {
- }
-
- public void myCall(A a) {
- a.save("");
- }
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- );
- }
-
- @ParameterizedTest
- @MethodSource("repositoryTestArguments")
- void shouldExtendCrudRepositoryForCrudMethodReference(Recipe recipe, String pagingAndSortingRepository,
- String crudRepository,
- String repositoryPackage) {
- @NotNull List result = javaTestHelper.runRecipe(
- recipe,
- List.of(replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -crudRepository- {
- void save(String entity);
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -pagingRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- ),
- replacePagingRepoAndCrudRepo("""
- package test;
- import java.util.List;
-
- import -repositoryPackage-.-pagingRepository-;
-
- class Hello {
- public interface A extends -pagingRepository- {
- }
-
- public void myCall(A a) {
- List.of("1", "2", "3").stream()
- .forEach(a::save);
- }
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- );
-
- assertThat(result).hasSize(1);
- assertThat(result.get(0).getAfter().printAll())
- .isEqualTo(
- replacePagingRepoAndCrudRepo("""
- package test;
- import java.util.List;
-
- import -repositoryPackage-.-crudRepository-;
- import -repositoryPackage-.-pagingRepository-;
-
- class Hello {
- public interface A extends -pagingRepository-, -crudRepository- {
- }
-
- public void myCall(A a) {
- List.of("1", "2", "3").stream()
- .forEach(a::save);
- }
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- );
- }
-
- private String replacePagingRepoAndCrudRepo(String template, String pagingRepo, String crudRepo, String repositoryPackage) {
-
- return template
- .replaceAll("-pagingRepository-", pagingRepo)
- .replaceAll("-crudRepository-", crudRepo)
- .replaceAll("-repositoryPackage-", repositoryPackage);
- }
-
- private static Stream repositoryTestArguments() {
- return Stream.of(
- Arguments.of(crudRepoExtensionRecipe, "PagingAndSortingRepository", "CrudRepository", "org.springframework.data.repository"),
- Arguments.of(reactiveCrudExtensionRecipe, "ReactiveSortingRepository", "ReactiveCrudRepository", "org.springframework.data.repository.reactive"),
- Arguments.of(rxJavaCrudExtensionRecipe, "RxJava3SortingRepository", "RxJava3CrudRepository", "org.springframework.data.repository.reactive")
- );
- }
-}
diff --git a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/CrudRepositoryExtensionWithReferencesTest.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/CrudRepositoryExtensionWithReferencesTest.java
deleted file mode 100644
index 54dae5fb6..000000000
--- a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/CrudRepositoryExtensionWithReferencesTest.java
+++ /dev/null
@@ -1,587 +0,0 @@
-/*
- * Copyright 2021 - 2023 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.sbm.boot.upgrade_27_30;
-
-import org.jetbrains.annotations.NotNull;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.Arguments;
-import org.junit.jupiter.params.provider.MethodSource;
-import org.openrewrite.Recipe;
-import org.openrewrite.Result;
-import org.openrewrite.test.RewriteTest;
-
-import java.util.List;
-import java.util.stream.Stream;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-
-public class CrudRepositoryExtensionWithReferencesTest implements RewriteTest {
-
- private final JavaTestHelper javaTestHelper = new JavaTestHelper();
- private static final Recipe crudRepoExtensionRecipe = new CrudRepositoryExtensionWithReferences(
- "org.springframework.data.repository.PagingAndSortingRepository",
- "org.springframework.data.repository.CrudRepository"
- );
-
- private static final Recipe reactiveCrudExtensionRecipe = new CrudRepositoryExtensionWithReferences(
- "org.springframework.data.repository.reactive.ReactiveSortingRepository",
- "org.springframework.data.repository.reactive.ReactiveCrudRepository"
- );
-
- private static final Recipe rxJavaCrudExtensionRecipe = new CrudRepositoryExtensionWithReferences(
- "org.springframework.data.repository.reactive.RxJava3SortingRepository",
- "org.springframework.data.repository.reactive.RxJava3CrudRepository"
- );
-
-
- @ParameterizedTest
- @MethodSource("repositoryTestArguments")
- public void shouldAddCrudRepository(Recipe recipe, String pagingAndSortingRepository, String crudRepository, String repositoryPackage) {
-
- @NotNull List result = javaTestHelper.runRecipe(
- recipe,
- List.of(replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -pagingRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -crudRepository- {
- void save(T entity);
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- ),
- replacePagingRepoAndCrudRepo("""
- package test;
- import -repositoryPackage-.-pagingRepository-;
- public interface A extends -pagingRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package test;
- public class Hello {
- public void test(A a) {
- a.save("Hello");
- }
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- );
-
- javaTestHelper.assertResult(result, replacePagingRepoAndCrudRepo("""
- package test;
- import -repositoryPackage-.-crudRepository-;
- import -repositoryPackage-.-pagingRepository-;
-
- public interface A extends -pagingRepository-, -crudRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage
- ));
- }
-
- @ParameterizedTest
- @MethodSource("repositoryTestArguments")
- public void canDoQuestionMark(Recipe recipe, String pagingAndSortingRepository, String crudRepository, String repositoryPackage) {
-
- @NotNull List result = javaTestHelper.runRecipe(recipe,
- List.of(replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -pagingRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -crudRepository- {
- void save(T);
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package test;
- public interface Payment {
- T hello();
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)),
- replacePagingRepoAndCrudRepo("""
- package test;
- import -repositoryPackage-.-pagingRepository-;
- public interface A extends -pagingRepository-, Long> {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package test;
- public class Hello {
- public void test(A a) {
- a.save("Hello");
- }
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- );
-
- javaTestHelper.assertResult(result, replacePagingRepoAndCrudRepo("""
- package test;
- import -repositoryPackage-.-crudRepository-;
- import -repositoryPackage-.-pagingRepository-;
-
- public interface A extends -pagingRepository-, Long>, -crudRepository-, Long> {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage));
- }
-
- @MethodSource("repositoryTestArguments")
- @ParameterizedTest
- public void onlyExtendCrudRepoIfInterfaceHasPagingAndSortingRepository(Recipe recipe, String pagingAndSortingRepository, String crudRepository, String repositoryPackage) {
- @NotNull List result = javaTestHelper.runRecipe(recipe,
- List.of("""
- package -repositoryPackage-;
- public interface HelloWorld {
- }
- """,
- replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -crudRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- """
- package test;
- public interface Payment {
- T hello();
- }
- """,
- """
- package test;
- import org.springframework.data.repository.HelloWorld;
- public interface A extends HelloWorld, Long> {
- }
- """
- )
- );
-
- assertThat(result).hasSize(0);
- }
-
-
- @MethodSource("repositoryTestArguments")
- @ParameterizedTest
- public void whenThereAreNoParametersWhilstExtending(Recipe recipe, String pagingAndSortingRepository, String crudRepository, String repositoryPackage) {
-
- @NotNull List results = javaTestHelper.runRecipe(
- recipe,
- List.of(replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -pagingRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -crudRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)),
- replacePagingRepoAndCrudRepo("""
- package test;
- import -repositoryPackage-.-pagingRepository-;
- public interface A extends -pagingRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package test;
- public class Hello {
- public void test(A a) {
- a.save("Hello");
- }
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- );
-
- javaTestHelper.assertResult(results, replacePagingRepoAndCrudRepo("""
- package test;
- import -repositoryPackage-.-crudRepository-;
- import -repositoryPackage-.-pagingRepository-;
-
- public interface A extends -pagingRepository-, -crudRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage));
- }
-
- @MethodSource("repositoryTestArguments")
- @ParameterizedTest
- public void multipleExtends(Recipe recipe, String pagingAndSortingRepository, String crudRepository, String repositoryPackage) {
- @NotNull List results = javaTestHelper.runRecipe(
- recipe,
- List.of(replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -pagingRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package temp;
- public interface Hello {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -crudRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)),
- replacePagingRepoAndCrudRepo("""
- package test;
- import -repositoryPackage-.-pagingRepository-;
- import temp.Hello;
- public interface A extends Hello, -pagingRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package test;
- public class Hello {
- public void test(A a) {
- a.save("Hello");
- }
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- );
-
- javaTestHelper.assertResult(results, replacePagingRepoAndCrudRepo("""
- package test;
- import -repositoryPackage-.-crudRepository-;
- import -repositoryPackage-.-pagingRepository-;
- import temp.Hello;
-
- public interface A extends Hello, -pagingRepository-, -crudRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage));
- }
-
- @MethodSource("repositoryTestArguments")
- @ParameterizedTest
- public void classImplementsPagingRepository(Recipe recipe, String pagingAndSortingRepository, String crudRepository, String repositoryPackage) {
- @NotNull List result = javaTestHelper.runRecipe(
- recipe,
- List.of(replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -pagingRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- """
- package temp;
- public interface Hello {
- }
- """,
- replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -crudRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)),
- replacePagingRepoAndCrudRepo("""
- package test;
- import -repositoryPackage-.-pagingRepository-;
- import temp.Hello;
- public class A implements Hello, -pagingRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package test;
- public class Hello {
- public void test(A a) {
- a.save("Hello");
- }
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- );
-
- javaTestHelper.assertResult(result, replacePagingRepoAndCrudRepo("""
- package test;
- import -repositoryPackage-.-crudRepository-;
- import -repositoryPackage-.-pagingRepository-;
- import temp.Hello;
-
- public class A implements Hello, -pagingRepository-, -crudRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage));
- }
-
- @ParameterizedTest
- @MethodSource("repositoryTestArguments")
- void shouldExtendCrudRepositoryInInnerInterface(Recipe recipe, String pagingAndSortingRepository,
- String crudRepository,
- String repositoryPackage) {
- @NotNull List result = javaTestHelper.runRecipe(
- recipe,
- List.of(replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -crudRepository- {
- void save(String entity);
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -pagingRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- ),
- replacePagingRepoAndCrudRepo("""
- package test;
- import -repositoryPackage-.-pagingRepository-;
- class Hello {
- public interface A extends -pagingRepository- {
- }
-
- public void myCall(A a) {
- a.save("");
- }
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- );
-
- assertThat(result).hasSize(1);
- assertThat(result.get(0).getAfter().printAll())
- .isEqualTo(
- replacePagingRepoAndCrudRepo("""
- package test;
- import -repositoryPackage-.-crudRepository-;
- import -repositoryPackage-.-pagingRepository-;
-
- class Hello {
- public interface A extends -pagingRepository-, -crudRepository- {
- }
-
- public void myCall(A a) {
- a.save("");
- }
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- );
- }
-
- @ParameterizedTest
- @MethodSource("repositoryTestArguments")
- void shouldNotExtendCrudRepositoryIfMethodIsNotCrud(Recipe recipe, String pagingAndSortingRepository,
- String crudRepository,
- String repositoryPackage) {
- @NotNull List result = javaTestHelper.runRecipe(
- recipe,
- List.of(replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -crudRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -pagingRepository- {
- void findAll(String entity);
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- ),
- replacePagingRepoAndCrudRepo("""
- package test;
- import -repositoryPackage-.-pagingRepository-;
-
- public interface A extends -pagingRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package test;
- import -repositoryPackage-.-pagingRepository-;
-
- public interface B extends -pagingRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package test;
- class Hello {
-
- public void myCall(A a, B b) {
- a.findAll("");
- }
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- );
-
- assertThat(result).hasSize(0);
- }
-
- @ParameterizedTest
- @MethodSource("repositoryTestArguments")
- void shouldExtendCrudRepositoryForCrudMethodReference(Recipe recipe, String pagingAndSortingRepository,
- String crudRepository,
- String repositoryPackage) {
- @NotNull List result = javaTestHelper.runRecipe(
- recipe,
- List.of(replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -crudRepository- {
- void save(String entity);
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -pagingRepository- {
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- ),
- replacePagingRepoAndCrudRepo("""
- package test;
- import java.util.List;
-
- import -repositoryPackage-.-pagingRepository-;
-
- class Hello {
- public interface A extends -pagingRepository- {
- }
-
- public void myCall(A a) {
- List.of("1", "2", "3").stream()
- .forEach(a::save);
- }
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- );
-
- assertThat(result).hasSize(1);
- assertThat(result.get(0).getAfter().printAll())
- .isEqualTo(
- replacePagingRepoAndCrudRepo("""
- package test;
- import java.util.List;
-
- import -repositoryPackage-.-crudRepository-;
- import -repositoryPackage-.-pagingRepository-;
-
- class Hello {
- public interface A extends -pagingRepository-, -crudRepository- {
- }
-
- public void myCall(A a) {
- List.of("1", "2", "3").stream()
- .forEach(a::save);
- }
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- );
- }
-
- @ParameterizedTest
- @MethodSource("repositoryTestArguments")
- void shouldNotExtendCrudRepositoryForNonPagingMethodReference(Recipe recipe, String pagingAndSortingRepository,
- String crudRepository,
- String repositoryPackage) {
- @NotNull List result = javaTestHelper.runRecipe(
- recipe,
- List.of(replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -crudRepository- {
-
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -pagingRepository- {
- void save(String entity);
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- ),
- replacePagingRepoAndCrudRepo("""
- package test;
- import java.util.List;
-
- import -repositoryPackage-.-pagingRepository-;
-
- class Hello {
- public interface A extends -pagingRepository- {
- }
-
- public void myCall(A a) {
- List.of("1", "2", "3").stream()
- .forEach(a::save);
- }
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- );
-
- assertThat(result).hasSize(0);
- }
-
- @ParameterizedTest
- @MethodSource("repositoryTestArguments")
- public void worksWithStaticImports(Recipe recipe, String pagingAndSortingRepository,
- String crudRepository,
- String repositoryPackage) {
- @NotNull List result = javaTestHelper.runRecipe(
- recipe,
- List.of(replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -crudRepository- {
-
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- replacePagingRepoAndCrudRepo("""
- package -repositoryPackage-;
- public interface -pagingRepository- {
- void save(String entity);
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage),
- """
- package test;
-
- public class StaticClass {
- public static int ret() {
- return 0;
- }
- }
- """
- ),
-
- replacePagingRepoAndCrudRepo("""
- package test;
- import java.util.List;
- import static StaticClass.*;
- import -repositoryPackage-.-pagingRepository-;
-
- class Hello {
- public static int temp() {
- return 10;
- }
- public interface A extends -pagingRepository- {
- }
-
- public void myCall(A a) {
- int x = ret();
- List.of("1", "2", "3").stream()
- .forEach(a::save);
- }
- }
- """, pagingAndSortingRepository, crudRepository, repositoryPackage)
- );
-
- assertThat(result).hasSize(0);
- }
-
-
- private String replacePagingRepoAndCrudRepo(String template, String pagingRepo, String crudRepo, String repositoryPackage) {
-
- return template
- .replaceAll("-pagingRepository-", pagingRepo)
- .replaceAll("-crudRepository-", crudRepo)
- .replaceAll("-repositoryPackage-", repositoryPackage);
- }
-
- private static Stream repositoryTestArguments() {
- return Stream.of(
- Arguments.of(crudRepoExtensionRecipe, "PagingAndSortingRepository", "CrudRepository", "org.springframework.data.repository"),
- Arguments.of(reactiveCrudExtensionRecipe, "ReactiveSortingRepository", "ReactiveCrudRepository", "org.springframework.data.repository.reactive"),
- Arguments.of(rxJavaCrudExtensionRecipe, "RxJava3SortingRepository", "RxJava3CrudRepository", "org.springframework.data.repository.reactive")
- );
- }
-}
diff --git a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/JavaTestHelper.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/JavaTestHelper.java
deleted file mode 100644
index 3002afa28..000000000
--- a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/JavaTestHelper.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright 2021 - 2023 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.sbm.boot.upgrade_27_30;
-
-import org.intellij.lang.annotations.Language;
-import org.jetbrains.annotations.NotNull;
-import org.openrewrite.InMemoryExecutionContext;
-import org.openrewrite.Recipe;
-import org.openrewrite.Result;
-import org.openrewrite.java.JavaParser;
-import org.openrewrite.java.tree.J;
-import org.openrewrite.test.RewriteTest;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class JavaTestHelper {
-
- public void runAndVerifyNoChanges(
- Recipe recipe,
- List dependsOn,
- @Language("java") String before
- ) {
- List result = runRecipe(recipe, dependsOn, before);
- assertThat(result).hasSize(0);
- }
-
-
- @NotNull
- public List runRecipe(Recipe recipe, List dependsOn, @Language("java") String... before) {
-
- List errors = new ArrayList<>();
- InMemoryExecutionContext ctx = new InMemoryExecutionContext((ex) -> {
- ex.printStackTrace();
- errors.add(ex);
- });
-
- JavaParser parser = JavaParser
- .fromJavaVersion()
- .dependsOn(dependsOn.toArray(new String[0]))
- .build();
-
- List cu = parser.parse(before);
-
- List result = recipe.run(cu, ctx).getResults();
-
- assertThat(errors).hasSize(0);
- return result;
- }
-
- public void assertResult(List result, String after) {
-
- assertThat(result).hasSize(1);
- assertThat(result.get(0).getAfter().printAll()).isEqualTo(after);
- }
-}
diff --git a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/UpgradeBomTo30Test.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/UpgradeBomTo30Test.java
index b77c5ca48..e262811fb 100644
--- a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/UpgradeBomTo30Test.java
+++ b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/UpgradeBomTo30Test.java
@@ -15,10 +15,13 @@
*/
package org.springframework.sbm.boot.upgrade_27_30;
+import jnr.ffi.annotations.In;
import org.junit.jupiter.api.Test;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.Recipe;
import org.openrewrite.Result;
+import org.openrewrite.SourceFile;
+import org.openrewrite.internal.InMemoryLargeSourceSet;
import org.openrewrite.maven.MavenParser;
import org.openrewrite.maven.UpgradeDependencyVersion;
import org.openrewrite.xml.tree.Xml;
@@ -37,6 +40,7 @@ void shouldUpdateBomVersionTo30() {
"spring-boot-dependencies",
"3.0.0-M3",
null,
+ null,
null
);
@@ -47,7 +51,7 @@ void shouldUpdateBomVersionTo30() {
});
MavenParser parser = MavenParser.builder().build();
- List documentList = parser.parse("""
+ List documentList = parser.parse("""
@@ -93,9 +97,10 @@ void shouldUpdateBomVersionTo30() {
- """);
+ """)
+ .toList();
- List result = recipe.run(documentList, ctx).getResults();
+ List result = recipe.run(new InMemoryLargeSourceSet(documentList), ctx).getChangeset().getAllResults();
assertThat(result).hasSize(1);
@@ -156,6 +161,7 @@ public void whenThereIsNoBomNoChanges() {
"spring-boot-dependencies",
"3.0.0-M3",
null,
+ null,
null
);
@@ -166,7 +172,7 @@ public void whenThereIsNoBomNoChanges() {
});
MavenParser parser = MavenParser.builder().build();
- List documentList = parser.parse("""
+ List documentList = parser.parse("""
@@ -206,9 +212,10 @@ public void whenThereIsNoBomNoChanges() {
- """);
+ """)
+ .toList();
- List result = recipe.run(documentList, ctx).getResults();
+ List result = recipe.run(new InMemoryLargeSourceSet(documentList), ctx).getChangeset().getAllResults();
assertThat(result).hasSize(0);
}
diff --git a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/checks/JerseyTemporarilyRemovedFinderTest.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/checks/JerseyTemporarilyRemovedFinderTest.java
index 9f640d6ec..47482f8dd 100644
--- a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/checks/JerseyTemporarilyRemovedFinderTest.java
+++ b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/checks/JerseyTemporarilyRemovedFinderTest.java
@@ -39,7 +39,7 @@ void finderShouldFindAnyJerseyDependency() {
Set matches = sut.findMatches(context);
assertThat(matches).isNotEmpty();
assertThat(matches).hasSize(1);
- assertThat(matches.iterator().next().getBuildFile().getDeclaredDependencies(Scope.Compile).get(0).getCoordinates()).isEqualTo(dependencyCoordinates);
+ assertThat(matches.iterator().next().getBuildFile().getDeclaredDependencies(Scope.Compile).get(0).getGav()).isEqualTo(dependencyCoordinates);
}
@Test
@@ -122,7 +122,7 @@ void finderShouldFindOnlyJerseyDependency() {
assertThat(context.getApplicationModules().list()).hasSize(3);
assertThat(matches).isNotEmpty();
assertThat(matches).hasSize(1);
- assertThat(matches.iterator().next().getBuildFile().getDeclaredDependencies(Scope.Compile).get(0).getCoordinates()).isEqualTo(jerseyDependencyCoordinates);
+ assertThat(matches.iterator().next().getBuildFile().getDeclaredDependencies(Scope.Compile).get(0).getGav()).isEqualTo(jerseyDependencyCoordinates);
}
}
diff --git a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/checks/RedeclaredDependenciesFinderTest.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/checks/RedeclaredDependenciesFinderTest.java
index 5dfcc111d..743ecb73d 100644
--- a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/checks/RedeclaredDependenciesFinderTest.java
+++ b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/checks/RedeclaredDependenciesFinderTest.java
@@ -90,7 +90,7 @@ void shouldFindDependencyRedefinedParentVersion() {
assertThat(matches).hasSize(1);
RedeclaredDependency explicitDependency = matches.iterator().next();
String explicitVersionDependencyCoordinates = "javax.validation:validation-api:1.1.0.Final";
- assertThat(explicitDependency.getRedeclaredDependency().getCoordinates()).isEqualTo(explicitVersionDependencyCoordinates);
+ assertThat(explicitDependency.getRedeclaredDependency().getGav()).isEqualTo(explicitVersionDependencyCoordinates);
assertThat(explicitDependency.getOriginalVersion()).isEqualTo("2.0.0.Final");
}
@@ -152,7 +152,7 @@ void shouldReportSameVersion() {
assertThat(matches).hasSize(1);
RedeclaredDependency explicitDependency = matches.iterator().next();
String explicitVersionDependencyCoordinates = "javax.validation:validation-api:2.0.0.Final";
- assertThat(explicitDependency.getRedeclaredDependency().getCoordinates()).isEqualTo(explicitVersionDependencyCoordinates);
+ assertThat(explicitDependency.getRedeclaredDependency().getGav()).isEqualTo(explicitVersionDependencyCoordinates);
assertThat(explicitDependency.getOriginalVersion()).isEqualTo("2.0.0.Final");
}
@@ -231,7 +231,7 @@ void shouldFindDependencyRedefinedBomVersion() {
assertThat(context.getApplicationModules().list()).hasSize(2);
assertThat(matches).isNotEmpty();
assertThat(matches).hasSize(1);
- assertThat(matches.iterator().next().getRedeclaredDependency().getCoordinates()).isEqualTo(explicitVersionDependencyCoordinates);
+ assertThat(matches.iterator().next().getRedeclaredDependency().getGav()).isEqualTo(explicitVersionDependencyCoordinates);
}
@Test
@@ -350,8 +350,8 @@ void shouldFindAllRedefinedDependencies() {
ProjectContext context = TestProjectContext.buildProjectContext()
.withMavenRootBuildFileSource(parentPomXml)
.withMavenBuildFileSource("module1", module1PomXml)
- .serializeProjectContext(Path.of("./target/test"));
-// .build();
+// .serializeProjectContext(Path.of("./target/test"));
+ .build();
RedeclaredDependenciesFinder finder = new RedeclaredDependenciesFinder(Set.of());
Set matches = finder.findMatches(context);
@@ -445,7 +445,7 @@ void shouldFindRedeclaredDependenciesOnlyFromList() {
assertThat(matches).hasSize(1);
RedeclaredDependency explicitDependency = matches.iterator().next();
String explicitVersionDependencyCoordinates = "javax.validation:validation-api:1.1.0.Final";
- assertThat(explicitDependency.getRedeclaredDependency().getCoordinates()).isEqualTo(explicitVersionDependencyCoordinates);
+ assertThat(explicitDependency.getRedeclaredDependency().getGav()).isEqualTo(explicitVersionDependencyCoordinates);
assertThat(explicitDependency.getOriginalVersion()).isEqualTo("2.0.1.Final");
}
diff --git a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/config/ConfigRecipeTestHelper.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/config/ConfigRecipeTestHelper.java
index 663451043..e1110fcec 100644
--- a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/config/ConfigRecipeTestHelper.java
+++ b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/config/ConfigRecipeTestHelper.java
@@ -21,6 +21,8 @@
import org.junit.jupiter.params.provider.Arguments;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.Result;
+import org.openrewrite.SourceFile;
+import org.openrewrite.internal.InMemoryLargeSourceSet;
import org.openrewrite.properties.PropertiesParser;
import org.openrewrite.properties.tree.Properties;
import org.openrewrite.test.RewriteTest;
@@ -42,18 +44,18 @@ public class ConfigRecipeTestHelper {
public static List runRecipeOnYaml(@Language("yml") String source, String recipeName) {
InMemoryExecutionContext ctx = new InMemoryExecutionContext(Throwable::printStackTrace);
- List document = new YamlParser().parse(source);
+ Stream document = new YamlParser().parse(source);
return RewriteTest
.fromRuntimeClasspath(recipeName)
- .run(document, ctx).getResults();
+ .run(new InMemoryLargeSourceSet(document.toList()), ctx).getChangeset().getAllResults();
}
public static List runRecipeOnProperties(@Language("properties") String source, String recipeName) {
InMemoryExecutionContext ctx = new InMemoryExecutionContext(Throwable::printStackTrace);
- List document = new PropertiesParser().parse(source);
+ List document = new PropertiesParser().parse(source).toList();
return RewriteTest
.fromRuntimeClasspath(recipeName)
- .run(document, ctx).getResults();
+ .run(new InMemoryLargeSourceSet(document), ctx).getChangeset().getAllResults();
}
public static Pair provideIO(String inputFilePath) throws IOException {
diff --git a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/SpringBootUpgradeReportActionTest.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/SpringBootUpgradeReportActionTest.java
index a2f1411ab..f4b50e72d 100644
--- a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/SpringBootUpgradeReportActionTest.java
+++ b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/SpringBootUpgradeReportActionTest.java
@@ -201,7 +201,7 @@ void verifyRenderedHtml(@TempDir Path tempDir) throws IOException {
.withMavenRootBuildFileSource(pomSource)
.withProjectResource("src/main/resources/application.properties", "spring.data.foo=bar")
.withProjectResource("src/main/resources/application-another.properties", "spring.data.here=there")
- .serializeProjectContext(tempDir);
+ .buildAndSerializeProjectContext(tempDir);
RecipeIntegrationTestSupport.initializeProject(tempDir, "spring-upgrade-report")
.andApplyRecipe("sbu30-report");
diff --git a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/UpgradeDepenenciesMigrationTest.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/UpgradeDepenenciesMigrationTest.java
index e37062b4e..e90d62077 100644
--- a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/UpgradeDepenenciesMigrationTest.java
+++ b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/UpgradeDepenenciesMigrationTest.java
@@ -17,6 +17,7 @@
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
+import org.openrewrite.SourceFile;
import org.openrewrite.maven.MavenParser;
import org.openrewrite.xml.tree.Xml;
import org.springframework.sbm.engine.context.ProjectContext;
@@ -41,7 +42,7 @@ void migrateEhCacheToSpringBoot3() {
.withBuildFileHavingDependencies("org.ehcache:ehcache")
.build();
- System.out.println(context.getBuildFile().print());
+ System.out.println(context.getApplicationModules().getRootModule().getBuildFile().print());
RecipeTestSupport.testRecipe(Path.of("recipes/27_30/migration/sbu30-upgrade-dependencies.yaml"), recipes -> {
Recipe recipe = recipes.getRecipeByName("sbu30-upgrade-dependencies").get();
@@ -75,7 +76,7 @@ void migrateEhCacheToSpringBoot3() {
"""
);
- Xml.Document document = MavenParser.builder().build().parse(modifiedPom).get(0);
+ SourceFile document = MavenParser.builder().build().parse(modifiedPom).toList().get(0);
assertThat(document).isNotNull();
});
}
diff --git a/pom.xml b/pom.xml
index 036c26abd..48c31c601 100644
--- a/pom.xml
+++ b/pom.xml
@@ -59,6 +59,7 @@
components/sbm-support-weblogic
components/sbm-recipes-jee-to-boot
components/sbm-recipes-spring-cloud
+ components/sbm-recipes-boot-upgrade