From 12b033de81fa83a730196cdf62640d01eae57488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Kr=C3=BCger?= Date: Thu, 1 Dec 2022 17:19:57 +0100 Subject: [PATCH] Current report sections are conditional to Boot 2.7 or 3.0 --- .../sbm/build/util/PomBuilder.java | 10 ++ .../UpgradeUnmanagedSpringProjectTest.java | 124 +++++------------- .../report/helper/BannerSupportHelper.java | 10 ++ .../helper/ChangesToDataPropertiesHelper.java | 11 ++ .../CommonsMultipartResolverHelper.java | 10 ++ .../helper/ConstructorBindingHelper.java | 8 ++ .../helper/LoggingDateFormatHelper.java | 9 ++ .../report/helper/PagingAndSortingHelper.java | 4 +- ...MVCAndWebFluxUrlMatchingChangesHelper.java | 9 ++ .../helper/UpgradeDependenciesHelper.java | 10 ++ .../UpgradeSpringBootVersionHelper.java | 6 +- .../upgrade_27_30/RemoveImageBannerTest.java | 2 +- .../BannerSupportReportSectionTest.java | 1 + ...ngesToDataPropertiesReportSectionTest.java | 2 + .../helper/LoggingDateFormatHelperTest.java | 2 + .../LoggingDateFormatReportSectionTest.java | 2 + ...ndWebFluxUrlMatchingChangesHelperTest.java | 1 + ...uxUrlMatchingChangesReportSectionTest.java | 1 + 18 files changed, 126 insertions(+), 96 deletions(-) diff --git a/components/sbm-core/src/test/java/org/springframework/sbm/build/util/PomBuilder.java b/components/sbm-core/src/test/java/org/springframework/sbm/build/util/PomBuilder.java index 00bd96714..342177926 100644 --- a/components/sbm-core/src/test/java/org/springframework/sbm/build/util/PomBuilder.java +++ b/components/sbm-core/src/test/java/org/springframework/sbm/build/util/PomBuilder.java @@ -61,6 +61,16 @@ public static PomBuilder buildParentPom(String parentCoordinate, String coordina return pomBuilder; } + /** + * Create a root {@code pom.xml} with a parent, e.g. spring-boot-starter-parent + */ + public static PomBuilder buildRootWithParent(String parentCoordinate, String pomCoordinate) { + PomBuilder pomBuilder = new PomBuilder(); + pomBuilder.parentPom = parentCoordinate; + pomBuilder.coordinate = pomCoordinate; + return pomBuilder; + } + /** * Add modules to a pom. * diff --git a/components/sbm-openrewrite/src/test/java/org/openrewrite/maven/spring/UpgradeUnmanagedSpringProjectTest.java b/components/sbm-openrewrite/src/test/java/org/openrewrite/maven/spring/UpgradeUnmanagedSpringProjectTest.java index 7a9862329..f1064ed8f 100644 --- a/components/sbm-openrewrite/src/test/java/org/openrewrite/maven/spring/UpgradeUnmanagedSpringProjectTest.java +++ b/components/sbm-openrewrite/src/test/java/org/openrewrite/maven/spring/UpgradeUnmanagedSpringProjectTest.java @@ -37,7 +37,7 @@ public class UpgradeUnmanagedSpringProjectTest { @Test void shouldUpdateDependencyVersionTo30() { - Recipe recipe = new UpgradeUnmanagedSpringProject("3.0.0-M3", "2\\.7\\..*"); + Recipe recipe = new UpgradeUnmanagedSpringProject("3.0.0", "2\\.7\\..*"); InMemoryExecutionContext ctx = new InMemoryExecutionContext((ex) -> { throw new RuntimeException("Error due UpgradeUnmanagedSpringProject recipe: " + ex.getMessage(), ex); @@ -135,17 +135,17 @@ void shouldUpdateDependencyVersionTo30() { org.springframework.boot spring-boot-starter-web - 3.0.0-M3 + 3.0.0 io.dropwizard.metrics metrics-annotation - 4.2.9 + 4.2.13 org.springframework.boot spring-boot-starter-test - 3.0.0-M3 + 3.0.0 test @@ -164,7 +164,7 @@ void shouldUpdateDependencyVersionTo30() { @Test void shouldNotUpdateSinceTheProjectIsNotSpring() { - Recipe recipe = new UpgradeUnmanagedSpringProject("3.0.0-M3", "2\\.7\\..*"); + Recipe recipe = new UpgradeUnmanagedSpringProject("3.0.0", "2\\.7\\..*"); InMemoryExecutionContext ctx = new InMemoryExecutionContext((ex) -> { throw new RuntimeException("Error due UpgradeUnmanagedSpringProject recipe: " + ex.getMessage(), ex); }); @@ -211,7 +211,7 @@ void shouldNotUpdateSinceTheProjectIsNotSpring() { @Test void shouldNotUpdateBomForOldVersion() { - Recipe recipe = new UpgradeUnmanagedSpringProject("3.0.0-M3", "2\\.7\\..*"); + Recipe recipe = new UpgradeUnmanagedSpringProject("3.0.0", "2\\.7\\..*"); InMemoryExecutionContext ctx = new InMemoryExecutionContext((ex) -> { throw new RuntimeException("Error due UpgradeUnmanagedSpringProject recipe: " + ex.getMessage(), ex); @@ -275,7 +275,7 @@ void shouldNotUpdateBomForOldVersion() { @Test void shouldNotUpdateIfSpringParent() { - Recipe recipe = new UpgradeUnmanagedSpringProject("3.0.0-M3", "2\\.7\\..*"); + Recipe recipe = new UpgradeUnmanagedSpringProject("3.0.0", "2\\.7\\..*"); InMemoryExecutionContext ctx = new InMemoryExecutionContext((ex) -> { throw new RuntimeException("Error due UpgradeUnmanagedSpringProject recipe: " + ex.getMessage(), ex); @@ -344,7 +344,7 @@ void shouldNotUpdateIfSpringParent() { @Test void shouldUpdateIfSpringParentAndExplicitDependency() { - Recipe recipe = new UpgradeUnmanagedSpringProject("3.0.0-M3", "2\\.7\\..*"); + Recipe recipe = new UpgradeUnmanagedSpringProject("3.0.0", "2\\.7\\..*"); InMemoryExecutionContext ctx = new InMemoryExecutionContext((ex) -> { throw new RuntimeException("Error due UpgradeUnmanagedSpringProject recipe: " + ex.getMessage(), ex); @@ -434,7 +434,7 @@ void shouldUpdateIfSpringParentAndExplicitDependency() { 17 17 17 - 3.0.0-M3 + 3.0.0 @@ -474,7 +474,7 @@ void shouldUpdateIfSpringParentAndExplicitDependency() { @Test public void shouldNotUpdateIfSpringDependencyManagement() { - Recipe recipe = new UpgradeUnmanagedSpringProject("3.0.0-M3", "2\\.7\\..*"); + Recipe recipe = new UpgradeUnmanagedSpringProject("3.0.0", "2\\.7\\..*"); InMemoryExecutionContext ctx = new InMemoryExecutionContext((ex) -> { throw new RuntimeException("Error due UpgradeUnmanagedSpringProject recipe: " + ex.getMessage(), ex); @@ -547,7 +547,7 @@ public void shouldNotUpdateIfSpringDependencyManagement() { @Test public void shouldUpdateIfSpringDependencyManagementAndExplicitVersion() { - Recipe recipe = new UpgradeUnmanagedSpringProject("3.0.0-M3", "2\\.7\\..*"); + Recipe recipe = new UpgradeUnmanagedSpringProject("3.0.0", "2\\.7\\..*"); InMemoryExecutionContext ctx = new InMemoryExecutionContext((ex) -> { throw new RuntimeException("Error due UpgradeUnmanagedSpringProject recipe: " + ex.getMessage(), ex); @@ -570,16 +570,6 @@ public void shouldUpdateIfSpringDependencyManagementAndExplicitVersion() { 17 - - - spring-milestone - https://repo.spring.io/milestone - - false - - - - @@ -635,16 +625,6 @@ public void shouldUpdateIfSpringDependencyManagementAndExplicitVersion() { 17 - - - spring-milestone - https://repo.spring.io/milestone - - false - - - - @@ -664,7 +644,7 @@ public void shouldUpdateIfSpringDependencyManagementAndExplicitVersion() { io.dropwizard.metrics metrics-annotation - 4.2.9 + 4.2.13 @@ -682,7 +662,7 @@ public void shouldUpdateIfSpringDependencyManagementAndExplicitVersion() { @Test void shouldUpdateBomVersionTo30ForDependencyManaged() { - Recipe recipe = new UpgradeUnmanagedSpringProject("3.0.0-M3", "2\\.7\\..*"); + Recipe recipe = new UpgradeUnmanagedSpringProject("3.0.0", "2\\.7\\..*"); InMemoryExecutionContext ctx = new InMemoryExecutionContext((ex) -> { throw new RuntimeException("Error due UpgradeUnmanagedSpringProject recipe: " + ex.getMessage(), ex); @@ -705,16 +685,6 @@ void shouldUpdateBomVersionTo30ForDependencyManaged() { 17 - - - spring-milestone - https://repo.spring.io/milestone - - false - - - - @@ -765,33 +735,23 @@ void shouldUpdateBomVersionTo30ForDependencyManaged() { 17 17 - - - - spring-milestone - https://repo.spring.io/milestone - - false - - - - + org.springframework.boot spring-boot-starter-web - 3.0.0-M3 + 3.0.0 io.dropwizard.metrics metrics-annotation - 4.2.9 + 4.2.13 org.springframework.boot spring-boot-starter-test - 3.0.0-M3 + 3.0.0 test @@ -811,7 +771,7 @@ void shouldUpdateBomVersionTo30ForDependencyManaged() { @Test void shouldUpdateVersionsWithPropertyVariable() { - Recipe recipe = new UpgradeUnmanagedSpringProject("3.0.0-M3", "2\\.7\\..*"); + Recipe recipe = new UpgradeUnmanagedSpringProject("3.0.0", "2\\.7\\..*"); InMemoryExecutionContext ctx = new InMemoryExecutionContext((ex) -> { throw new RuntimeException("Error due UpgradeUnmanagedSpringProject recipe: " + ex.getMessage(), ex); @@ -835,16 +795,6 @@ void shouldUpdateVersionsWithPropertyVariable() { 2.7.3 - - - spring-milestone - https://repo.spring.io/milestone - - false - - - - org.springframework.boot @@ -894,19 +844,9 @@ void shouldUpdateVersionsWithPropertyVariable() { 17 17 17 - 3.0.0-M3 + 3.0.0 - - - spring-milestone - https://repo.spring.io/milestone - - false - - - - org.springframework.boot @@ -916,7 +856,7 @@ void shouldUpdateVersionsWithPropertyVariable() { io.dropwizard.metrics metrics-annotation - 4.2.9 + 4.2.13 org.springframework.boot @@ -940,7 +880,7 @@ void shouldUpdateVersionsWithPropertyVariable() { @Test void shouldNotTouchNewerVersions() { - Recipe recipe = new UpgradeUnmanagedSpringProject("3.0.0-M3", "2\\.7\\..*|3\\.0\\..*"); + Recipe recipe = new UpgradeUnmanagedSpringProject("3.0.0", "2\\.7\\..*|3\\.0\\..*"); InMemoryExecutionContext ctx = new InMemoryExecutionContext((ex) -> { throw new RuntimeException("Error due UpgradeUnmanagedSpringProject recipe: " + ex.getMessage(), ex); @@ -989,7 +929,7 @@ void shouldNotTouchNewerVersions() { org.springframework.boot spring-boot-starter-test - 3.0.0-M3 + 3.0.0 test @@ -1024,8 +964,8 @@ void shouldNotTouchNewerVersions() { 17 17 17 - 3.0.0-M3 - 4.2.12 + 3.0.0 + 4.2.13 @@ -1052,7 +992,7 @@ void shouldNotTouchNewerVersions() { org.springframework.boot spring-boot-starter-test - 3.0.0-M3 + 3.0.0 test @@ -1072,7 +1012,7 @@ void shouldNotTouchNewerVersions() { @Test void shouldBuildCorrectPomModelAfterUpdateTo30() { Recipe recipe = new UpgradeUnmanagedSpringProject( - "3.0.0-M3", + "3.0.0", "2\\.7\\..*"); List errors = new ArrayList<>(); @@ -1141,18 +1081,18 @@ void shouldBuildCorrectPomModelAfterUpdateTo30() { assertThat(resolvedDependencies).isNotEmpty(); Condition cSpringStarterWeb = new Condition<>( - rd -> rd.getArtifactId().equals("spring-boot-starter-web") && rd.getVersion().equals("3.0.0-M3"), - "spring-boot-starter-web in version 3.0.0-M3"); + rd -> rd.getArtifactId().equals("spring-boot-starter-web") && rd.getVersion().equals("3.0.0"), + "spring-boot-starter-web in version 3.0.0"); assertThat(resolvedDependencies).haveExactly(1, cSpringStarterWeb); Condition cMetrics = new Condition<>( - rd -> rd.getArtifactId().equals("metrics-annotation") && rd.getVersion().equals("4.2.9"), - "metrics-annotation in version 4.2.9"); + rd -> rd.getArtifactId().equals("metrics-annotation") && rd.getVersion().equals("4.2.13"), + "metrics-annotation in version 4.2.13"); assertThat(resolvedDependencies).haveExactly(1, cMetrics); Condition cSpringStarterTest = new Condition<>( - rd -> rd.getArtifactId().equals("spring-boot-starter-test") && rd.getVersion().equals("3.0.0-M3"), - "spring-boot-starter-test in version 3.0.0-M3"); + rd -> rd.getArtifactId().equals("spring-boot-starter-test") && rd.getVersion().equals("3.0.0"), + "spring-boot-starter-test in version 3.0.0"); assertThat(resolvedTestDependencies).haveExactly(1, cSpringStarterTest); } } diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/BannerSupportHelper.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/BannerSupportHelper.java index 76c57753a..96cbdad3d 100644 --- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/BannerSupportHelper.java +++ b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/BannerSupportHelper.java @@ -16,6 +16,7 @@ package org.springframework.sbm.boot.upgrade_27_30.report.helper; +import org.springframework.sbm.boot.common.conditions.IsSpringBootProject; import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection; import org.springframework.sbm.engine.context.ProjectContext; import org.springframework.sbm.project.resource.RewriteSourceFileHolder; @@ -27,6 +28,8 @@ public class BannerSupportHelper implements SpringBootUpgradeReportSection.Helper> { + public static final String VERSION_PATTERN = "(2\\.7\\..*)|(3\\.0\\..*)"; + private List foundBanners; @Override @@ -36,6 +39,13 @@ public String getDescription() { @Override public boolean evaluate(ProjectContext context) { + IsSpringBootProject isSpringBootProjectCondition = new IsSpringBootProject(); + isSpringBootProjectCondition.setVersionPattern(VERSION_PATTERN); + boolean isSpringBoot3Application = isSpringBootProjectCondition.evaluate(context); + if(! isSpringBoot3Application) { + return false; + } + foundBanners = context .getProjectResources() .stream() diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/ChangesToDataPropertiesHelper.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/ChangesToDataPropertiesHelper.java index a1cda1d0d..eb1cef43d 100644 --- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/ChangesToDataPropertiesHelper.java +++ b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/ChangesToDataPropertiesHelper.java @@ -17,6 +17,7 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; +import org.springframework.sbm.boot.common.conditions.IsSpringBootProject; import org.springframework.sbm.boot.properties.api.SpringBootApplicationProperties; import org.springframework.sbm.boot.properties.search.SpringBootApplicationPropertiesResourceListFilter; import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection; @@ -35,6 +36,8 @@ */ public class ChangesToDataPropertiesHelper implements SpringBootUpgradeReportSection.Helper> { + public static final String VERSION_PATTERN = "(2\\.7\\..*)|(3\\.0\\..*)"; + private Map> data = new HashMap<>(); @Override @@ -44,6 +47,14 @@ public String getDescription() { @Override public boolean evaluate(ProjectContext context) { + IsSpringBootProject isSpringBootProjectCondition = new IsSpringBootProject(); + isSpringBootProjectCondition.setVersionPattern(VERSION_PATTERN); + boolean isSpringBoot3Application = isSpringBootProjectCondition.evaluate(context); + if(! isSpringBoot3Application) { + return false; + } + + boolean noDepExists = new NoDependencyExistMatchingRegex(List.of("org\\.springframework\\.data\\:.*")).evaluate( context); List search = context diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/CommonsMultipartResolverHelper.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/CommonsMultipartResolverHelper.java index 6a243019e..5fec2bfb8 100644 --- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/CommonsMultipartResolverHelper.java +++ b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/CommonsMultipartResolverHelper.java @@ -16,6 +16,7 @@ package org.springframework.sbm.boot.upgrade_27_30.report.helper; +import org.springframework.sbm.boot.common.conditions.IsSpringBootProject; import org.springframework.sbm.boot.common.finder.MatchingMethod; import org.springframework.sbm.boot.common.finder.SpringBeanMethodDeclarationFinder; import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection; @@ -27,6 +28,8 @@ import java.util.stream.Collectors; public class CommonsMultipartResolverHelper implements SpringBootUpgradeReportSection.Helper>{ + + public static final String VERSION_PATTERN = "(2\\.7\\..*)|(3\\.0\\..*)"; private static final String COMMONS_MULTIPART_RESOLVER_CLASS = "org.springframework.web.multipart.commons.CommonsMultipartResolver"; private List types; @@ -37,6 +40,13 @@ public String getDescription() { @Override public boolean evaluate(ProjectContext context) { + IsSpringBootProject isSpringBootProjectCondition = new IsSpringBootProject(); + isSpringBootProjectCondition.setVersionPattern(VERSION_PATTERN); + boolean isSpringBoot3Application = isSpringBootProjectCondition.evaluate(context); + if(! isSpringBoot3Application) { + return false; + } + List search = context .search( new SpringBeanMethodDeclarationFinder( diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/ConstructorBindingHelper.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/ConstructorBindingHelper.java index c3426e793..7fce8ff2a 100644 --- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/ConstructorBindingHelper.java +++ b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/ConstructorBindingHelper.java @@ -22,6 +22,7 @@ import org.openrewrite.java.search.UsesType; import org.openrewrite.java.spring.boot3.RemoveConstructorBindingAnnotation; import org.openrewrite.java.tree.J; +import org.springframework.sbm.boot.common.conditions.IsSpringBootProject; import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection; import org.springframework.sbm.engine.context.ProjectContext; import org.springframework.sbm.engine.recipe.OpenRewriteSourceFilesFinder; @@ -35,6 +36,7 @@ public class ConstructorBindingHelper implements SpringBootUpgradeReportSection.Helper> { + public static final String VERSION_PATTERN = "(2\\.7\\..*)|(3\\.0\\..*)"; private List constructorBindingFiles; @Override @@ -44,6 +46,12 @@ public String getDescription() { @Override public boolean evaluate(ProjectContext context) { + IsSpringBootProject isSpringBootProjectCondition = new IsSpringBootProject(); + isSpringBootProjectCondition.setVersionPattern(VERSION_PATTERN); + boolean isSpringBoot3Application = isSpringBootProjectCondition.evaluate(context); + if(! isSpringBoot3Application) { + return false; + } GenericOpenRewriteRecipe> recipe = new GenericOpenRewriteRecipe<>(() -> new UsesType("org.springframework.boot.context.properties.ConstructorBinding")); diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/LoggingDateFormatHelper.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/LoggingDateFormatHelper.java index 003452fc5..9aae32ddb 100644 --- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/LoggingDateFormatHelper.java +++ b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/LoggingDateFormatHelper.java @@ -15,6 +15,7 @@ */ package org.springframework.sbm.boot.upgrade_27_30.report.helper; +import org.springframework.sbm.boot.common.conditions.IsSpringBootProject; import org.springframework.sbm.boot.upgrade_27_30.filter.LoggingDateFormatPropertyFinder; import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection; import org.springframework.sbm.engine.context.ProjectContext; @@ -28,6 +29,7 @@ */ public class LoggingDateFormatHelper implements SpringBootUpgradeReportSection.Helper> { + public static final String VERSION_PATTERN = "(2\\.7\\..*)|(3\\.0\\..*)"; private List propertiesSources; @Override @@ -37,6 +39,13 @@ public String getDescription() { @Override public boolean evaluate(ProjectContext context) { + IsSpringBootProject isSpringBootProjectCondition = new IsSpringBootProject(); + isSpringBootProjectCondition.setVersionPattern(VERSION_PATTERN); + boolean isSpringBoot3Application = isSpringBootProjectCondition.evaluate(context); + if(! isSpringBoot3Application) { + return false; + } + propertiesSources = context.search(new LoggingDateFormatPropertyFinder()); return propertiesSources.isEmpty(); } diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/PagingAndSortingHelper.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/PagingAndSortingHelper.java index 53ea8e1bc..d0e2afb74 100644 --- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/PagingAndSortingHelper.java +++ b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/PagingAndSortingHelper.java @@ -32,6 +32,8 @@ import java.util.stream.Collectors; public class PagingAndSortingHelper implements SpringBootUpgradeReportSection.Helper> { + + public static final String VERSION_PATTERN = "(2\\.7\\..*)|(3\\.0\\..*)"; private List pagingAndSortingRepo; private List reactivePagingAndSortingRepo; private List rxJavaSortingRepo; @@ -44,7 +46,7 @@ public String getDescription() { @Override public boolean evaluate(ProjectContext context) { IsSpringBootProject isSpringBootProject = new IsSpringBootProject(); - isSpringBootProject.setVersionPattern("2\\.7\\..*|3\\.0\\..*"); + isSpringBootProject.setVersionPattern(VERSION_PATTERN); boolean isSpringBootApplication = isSpringBootProject.evaluate(context); if(!isSpringBootApplication) { return false; 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 85da582e2..7c0e0b5a3 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 @@ -18,6 +18,7 @@ import org.openrewrite.ExecutionContext; import org.openrewrite.java.search.UsesType; import org.openrewrite.java.tree.J; +import org.springframework.sbm.boot.common.conditions.IsSpringBootProject; import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection; import org.springframework.sbm.engine.context.ProjectContext; import org.springframework.sbm.java.api.JavaSource; @@ -33,6 +34,7 @@ */ public class SpringMVCAndWebFluxUrlMatchingChangesHelper implements SpringBootUpgradeReportSection.Helper> { + public static final String VERSION_PATTERN = "(2\\.7\\..*)|(3\\.0\\..*)"; private static final String SPRING_REST_CONTROLLER_FQN = "org.springframework.web.bind.annotation.RestController"; private List matches = new ArrayList<>(); @@ -43,6 +45,13 @@ public String getDescription() { @Override public boolean evaluate(ProjectContext context) { + IsSpringBootProject isSpringBootProject = new IsSpringBootProject(); + isSpringBootProject.setVersionPattern(VERSION_PATTERN); + boolean isSpringBootApplication = isSpringBootProject.evaluate(context); + if(!isSpringBootApplication) { + return false; + } + GenericOpenRewriteRecipe> usesTypeRecipe = new GenericOpenRewriteRecipe<>(() -> new UsesType<>(SPRING_REST_CONTROLLER_FQN)); matches = context.getProjectJavaSources().find(usesTypeRecipe).stream() diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/UpgradeDependenciesHelper.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/UpgradeDependenciesHelper.java index 8c367210b..64ce3c693 100644 --- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/UpgradeDependenciesHelper.java +++ b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/UpgradeDependenciesHelper.java @@ -15,6 +15,7 @@ */ package org.springframework.sbm.boot.upgrade_27_30.report.helper; +import org.springframework.sbm.boot.common.conditions.IsSpringBootProject; import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportAction; import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection; import org.springframework.sbm.engine.context.ProjectContext; @@ -27,6 +28,8 @@ * @author Fabian Krüger */ public class UpgradeDependenciesHelper implements SpringBootUpgradeReportSection.Helper> { + + public static final String VERSION_PATTERN = "(2\\.7\\..*)|(3\\.0\\..*)"; @Override public String getDescription() { return ""; @@ -34,6 +37,13 @@ public String getDescription() { @Override public boolean evaluate(ProjectContext context) { + IsSpringBootProject isSpringBootProject = new IsSpringBootProject(); + isSpringBootProject.setVersionPattern(VERSION_PATTERN); + boolean isSpringBootApplication = isSpringBootProject.evaluate(context); + if(!isSpringBootApplication) { + return false; + } + // FIXME: dummy return true; } diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/UpgradeSpringBootVersionHelper.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/UpgradeSpringBootVersionHelper.java index 8cb1a717c..6208a4c07 100644 --- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/UpgradeSpringBootVersionHelper.java +++ b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/UpgradeSpringBootVersionHelper.java @@ -27,6 +27,8 @@ * @author Fabian Krüger */ public class UpgradeSpringBootVersionHelper implements SpringBootUpgradeReportSection.Helper { + + public static final String VERSION_PATTERN = "(2\\.7\\..*)|(3\\.0\\..*)"; @Override public String getDescription() { return ""; @@ -35,13 +37,13 @@ public String getDescription() { @Override public boolean evaluate(ProjectContext context) { IsSpringBootProject isSpringBootProject = new IsSpringBootProject(); - isSpringBootProject.setVersionPattern("2\\.7\\..*"); + isSpringBootProject.setVersionPattern(VERSION_PATTERN); return isSpringBootProject.evaluate(context); } @Override public Map getData() { // FIXME: Provide correct boot version, see https://github.com/spring-projects-experimental/spring-boot-migrator/issues/560 - return Map.of("bootVersion", "2.7.3"); + return Map.of("bootVersion", "2.7.x"); } } diff --git a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/RemoveImageBannerTest.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/RemoveImageBannerTest.java index 08e281f56..eb7bd199f 100644 --- a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/RemoveImageBannerTest.java +++ b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/RemoveImageBannerTest.java @@ -43,7 +43,7 @@ void testGlobExpression() { @Test void applyRemoveImageBannerRecipeShouldRemoveAllImageBannerAtDefaultLocation() { String parentPom = PomBuilder - .buildPom("com.example:parent:1.0") + .buildRootWithParent("org.springframework.boot:spring-boot-starter-parent:2.7.5", "com.example:parent:1.0") .withModules("moduleA", "moduleB", "moduleC") .build(); String moduleA = PomBuilder.buildPom("com.example:parent:1.0", "moduleA").build(); diff --git a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/BannerSupportReportSectionTest.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/BannerSupportReportSectionTest.java index 0219b1c24..13e2a3494 100644 --- a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/BannerSupportReportSectionTest.java +++ b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/BannerSupportReportSectionTest.java @@ -27,6 +27,7 @@ public class BannerSupportReportSectionTest { @Test public void rendersBannerSupportInformation() { ProjectContext context = TestProjectContext.buildProjectContext() + .withSpringBootParentOf("2.7.5") .addProjectResource("src/main/resources/banner.gif", "gif-banner") .addProjectResource("src/main/resources/banner.jpg", "jpg-banner") .addProjectResource("src/main/com/test/banner.java","class banner {}") diff --git a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/ChangesToDataPropertiesReportSectionTest.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/ChangesToDataPropertiesReportSectionTest.java index 070bf40cf..496abeb70 100644 --- a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/ChangesToDataPropertiesReportSectionTest.java +++ b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/ChangesToDataPropertiesReportSectionTest.java @@ -33,6 +33,7 @@ public class ChangesToDataPropertiesReportSectionTest { @DisplayName("Changes to Data Properties should render") void changesToDataPropertiesSection_renders() { ProjectContext context = TestProjectContext.buildProjectContext() + .withSpringBootParentOf("2.7.5") .addRegistrar(new SpringBootApplicationPropertiesRegistrar(new SpringApplicationPropertiesPathMatcher())) .addProjectResource("src/main/resources/application.properties", "spring.data.foo=bar") .addProjectResource("src/main/resources/application-another.properties", "spring.data.here=there") @@ -68,6 +69,7 @@ void changesToDataPropertiesSection_renders() { @DisplayName("Changes to Data Properties shouldn't render") void changesToDataPropertiesSection_notRendered() { ProjectContext context = TestProjectContext.buildProjectContext() + .withSpringBootParentOf("2.7.5") .addRegistrar(new SpringBootApplicationPropertiesRegistrar(new SpringApplicationPropertiesPathMatcher())) .addProjectResource("src/main/resources/application.properties", "data.foo=bar") .addProjectResource("src/main/resources/application-another.properties", "data.here=there") diff --git a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/LoggingDateFormatHelperTest.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/LoggingDateFormatHelperTest.java index fb468e2bb..956ec1d00 100644 --- a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/LoggingDateFormatHelperTest.java +++ b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/LoggingDateFormatHelperTest.java @@ -37,6 +37,7 @@ public class LoggingDateFormatHelperTest { void isApplicableWithExistingPropertiesFile() { ProjectContext context = TestProjectContext .buildProjectContext() + .withSpringBootParentOf("2.7.5") .addRegistrar( new SpringBootApplicationPropertiesRegistrar(new SpringApplicationPropertiesPathMatcher())) .addProjectResource("src/main/resources/application-myprofile.properties", "not.logging.pattern.dateformat=value") @@ -55,6 +56,7 @@ void isApplicableWithExistingPropertiesFile() { void isApplicableWithoutExistingPropertiesFile() { ProjectContext context = TestProjectContext .buildProjectContext() + .withSpringBootParentOf("2.7.5") .build(); LoggingDateFormatHelper sut = new LoggingDateFormatHelper(); diff --git a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/LoggingDateFormatReportSectionTest.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/LoggingDateFormatReportSectionTest.java index 96aa5a4aa..cb53126a0 100644 --- a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/LoggingDateFormatReportSectionTest.java +++ b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/LoggingDateFormatReportSectionTest.java @@ -31,6 +31,7 @@ public class LoggingDateFormatReportSectionTest { void shouldRenderSectionWhenNoPropertiesExist() { ProjectContext context = TestProjectContext .buildProjectContext() + .withSpringBootParentOf("2.7.5") .addRegistrar(new SpringBootApplicationPropertiesRegistrar(new SpringApplicationPropertiesPathMatcher())) .addProjectResource("src/main/resources/application-myprofile.properties", "not.logging.pattern.dateformat=some-format") .build(); @@ -65,6 +66,7 @@ void shouldRenderSectionWhenNoPropertiesExist() { void shouldRenderSectionWhenPropertyNotDefined() { ProjectContext context = TestProjectContext .buildProjectContext() + .withSpringBootParentOf("2.7.5") .build(); SpringBootUpgradeReportTestSupport diff --git a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/SpringMVCAndWebFluxUrlMatchingChangesHelperTest.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/SpringMVCAndWebFluxUrlMatchingChangesHelperTest.java index 28e68ccee..c7b8dd4db 100644 --- a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/SpringMVCAndWebFluxUrlMatchingChangesHelperTest.java +++ b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/SpringMVCAndWebFluxUrlMatchingChangesHelperTest.java @@ -59,6 +59,7 @@ public class AnotherClass {}; ProjectContext context = TestProjectContext .buildProjectContext() + .withSpringBootParentOf("2.7.5") .withBuildFileHavingDependencies("org.springframework:spring-web:5.3.23") .addJavaSource("src/main/java", restController1) .addJavaSource("src/main/java", restController2) diff --git a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/SpringMVCAndWebFluxUrlMatchingChangesReportSectionTest.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/SpringMVCAndWebFluxUrlMatchingChangesReportSectionTest.java index c16f8a872..623b7fa88 100644 --- a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/SpringMVCAndWebFluxUrlMatchingChangesReportSectionTest.java +++ b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/SpringMVCAndWebFluxUrlMatchingChangesReportSectionTest.java @@ -56,6 +56,7 @@ public class AnotherClass {}; ProjectContext context = TestProjectContext .buildProjectContext() + .withSpringBootParentOf("2.7.5") .withBuildFileHavingDependencies("org.springframework:spring-web:5.3.23") .addJavaSource("src/main/java", restController1) .addJavaSource("src/main/java", restController2)