Skip to content

Commit 12b033d

Browse files
committed
Current report sections are conditional to Boot 2.7 or 3.0
1 parent 57b3902 commit 12b033d

18 files changed

+126
-96
lines changed

components/sbm-core/src/test/java/org/springframework/sbm/build/util/PomBuilder.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ public static PomBuilder buildParentPom(String parentCoordinate, String coordina
6161
return pomBuilder;
6262
}
6363

64+
/**
65+
* Create a root {@code pom.xml} with a parent, e.g. spring-boot-starter-parent
66+
*/
67+
public static PomBuilder buildRootWithParent(String parentCoordinate, String pomCoordinate) {
68+
PomBuilder pomBuilder = new PomBuilder();
69+
pomBuilder.parentPom = parentCoordinate;
70+
pomBuilder.coordinate = pomCoordinate;
71+
return pomBuilder;
72+
}
73+
6474
/**
6575
* Add modules to a pom.
6676
*

components/sbm-openrewrite/src/test/java/org/openrewrite/maven/spring/UpgradeUnmanagedSpringProjectTest.java

Lines changed: 32 additions & 92 deletions
Large diffs are not rendered by default.

components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/BannerSupportHelper.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.sbm.boot.upgrade_27_30.report.helper;
1818

19+
import org.springframework.sbm.boot.common.conditions.IsSpringBootProject;
1920
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection;
2021
import org.springframework.sbm.engine.context.ProjectContext;
2122
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
@@ -27,6 +28,8 @@
2728

2829
public class BannerSupportHelper implements SpringBootUpgradeReportSection.Helper<List<String>> {
2930

31+
public static final String VERSION_PATTERN = "(2\\.7\\..*)|(3\\.0\\..*)";
32+
3033
private List<Path> foundBanners;
3134

3235
@Override
@@ -36,6 +39,13 @@ public String getDescription() {
3639

3740
@Override
3841
public boolean evaluate(ProjectContext context) {
42+
IsSpringBootProject isSpringBootProjectCondition = new IsSpringBootProject();
43+
isSpringBootProjectCondition.setVersionPattern(VERSION_PATTERN);
44+
boolean isSpringBoot3Application = isSpringBootProjectCondition.evaluate(context);
45+
if(! isSpringBoot3Application) {
46+
return false;
47+
}
48+
3949
foundBanners = context
4050
.getProjectResources()
4151
.stream()

components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/ChangesToDataPropertiesHelper.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import lombok.Getter;
1919
import lombok.RequiredArgsConstructor;
20+
import org.springframework.sbm.boot.common.conditions.IsSpringBootProject;
2021
import org.springframework.sbm.boot.properties.api.SpringBootApplicationProperties;
2122
import org.springframework.sbm.boot.properties.search.SpringBootApplicationPropertiesResourceListFilter;
2223
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection;
@@ -35,6 +36,8 @@
3536
*/
3637
public class ChangesToDataPropertiesHelper implements SpringBootUpgradeReportSection.Helper<List<ChangesToDataPropertiesHelper.Match>> {
3738

39+
public static final String VERSION_PATTERN = "(2\\.7\\..*)|(3\\.0\\..*)";
40+
3841
private Map<String, List<Match>> data = new HashMap<>();
3942

4043
@Override
@@ -44,6 +47,14 @@ public String getDescription() {
4447

4548
@Override
4649
public boolean evaluate(ProjectContext context) {
50+
IsSpringBootProject isSpringBootProjectCondition = new IsSpringBootProject();
51+
isSpringBootProjectCondition.setVersionPattern(VERSION_PATTERN);
52+
boolean isSpringBoot3Application = isSpringBootProjectCondition.evaluate(context);
53+
if(! isSpringBoot3Application) {
54+
return false;
55+
}
56+
57+
4758
boolean noDepExists = new NoDependencyExistMatchingRegex(List.of("org\\.springframework\\.data\\:.*")).evaluate(
4859
context);
4960
List<SpringBootApplicationProperties> search = context

components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/CommonsMultipartResolverHelper.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.sbm.boot.upgrade_27_30.report.helper;
1818

19+
import org.springframework.sbm.boot.common.conditions.IsSpringBootProject;
1920
import org.springframework.sbm.boot.common.finder.MatchingMethod;
2021
import org.springframework.sbm.boot.common.finder.SpringBeanMethodDeclarationFinder;
2122
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection;
@@ -27,6 +28,8 @@
2728
import java.util.stream.Collectors;
2829

2930
public class CommonsMultipartResolverHelper implements SpringBootUpgradeReportSection.Helper<List<String>>{
31+
32+
public static final String VERSION_PATTERN = "(2\\.7\\..*)|(3\\.0\\..*)";
3033
private static final String COMMONS_MULTIPART_RESOLVER_CLASS = "org.springframework.web.multipart.commons.CommonsMultipartResolver";
3134
private List<String> types;
3235

@@ -37,6 +40,13 @@ public String getDescription() {
3740

3841
@Override
3942
public boolean evaluate(ProjectContext context) {
43+
IsSpringBootProject isSpringBootProjectCondition = new IsSpringBootProject();
44+
isSpringBootProjectCondition.setVersionPattern(VERSION_PATTERN);
45+
boolean isSpringBoot3Application = isSpringBootProjectCondition.evaluate(context);
46+
if(! isSpringBoot3Application) {
47+
return false;
48+
}
49+
4050
List<MatchingMethod> search = context
4151
.search(
4252
new SpringBeanMethodDeclarationFinder(

components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/ConstructorBindingHelper.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.openrewrite.java.search.UsesType;
2323
import org.openrewrite.java.spring.boot3.RemoveConstructorBindingAnnotation;
2424
import org.openrewrite.java.tree.J;
25+
import org.springframework.sbm.boot.common.conditions.IsSpringBootProject;
2526
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection;
2627
import org.springframework.sbm.engine.context.ProjectContext;
2728
import org.springframework.sbm.engine.recipe.OpenRewriteSourceFilesFinder;
@@ -35,6 +36,7 @@
3536

3637
public class ConstructorBindingHelper implements SpringBootUpgradeReportSection.Helper<List<String>> {
3738

39+
public static final String VERSION_PATTERN = "(2\\.7\\..*)|(3\\.0\\..*)";
3840
private List<String> constructorBindingFiles;
3941

4042
@Override
@@ -44,6 +46,12 @@ public String getDescription() {
4446

4547
@Override
4648
public boolean evaluate(ProjectContext context) {
49+
IsSpringBootProject isSpringBootProjectCondition = new IsSpringBootProject();
50+
isSpringBootProjectCondition.setVersionPattern(VERSION_PATTERN);
51+
boolean isSpringBoot3Application = isSpringBootProjectCondition.evaluate(context);
52+
if(! isSpringBoot3Application) {
53+
return false;
54+
}
4755

4856
GenericOpenRewriteRecipe<TreeVisitor<?, ExecutionContext>> recipe =
4957
new GenericOpenRewriteRecipe<>(() -> new UsesType("org.springframework.boot.context.properties.ConstructorBinding"));

components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/LoggingDateFormatHelper.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.sbm.boot.upgrade_27_30.report.helper;
1717

18+
import org.springframework.sbm.boot.common.conditions.IsSpringBootProject;
1819
import org.springframework.sbm.boot.upgrade_27_30.filter.LoggingDateFormatPropertyFinder;
1920
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection;
2021
import org.springframework.sbm.engine.context.ProjectContext;
@@ -28,6 +29,7 @@
2829
*/
2930
public class LoggingDateFormatHelper implements SpringBootUpgradeReportSection.Helper<List<? extends PropertiesSource>> {
3031

32+
public static final String VERSION_PATTERN = "(2\\.7\\..*)|(3\\.0\\..*)";
3133
private List<? extends PropertiesSource> propertiesSources;
3234

3335
@Override
@@ -37,6 +39,13 @@ public String getDescription() {
3739

3840
@Override
3941
public boolean evaluate(ProjectContext context) {
42+
IsSpringBootProject isSpringBootProjectCondition = new IsSpringBootProject();
43+
isSpringBootProjectCondition.setVersionPattern(VERSION_PATTERN);
44+
boolean isSpringBoot3Application = isSpringBootProjectCondition.evaluate(context);
45+
if(! isSpringBoot3Application) {
46+
return false;
47+
}
48+
4049
propertiesSources = context.search(new LoggingDateFormatPropertyFinder());
4150
return propertiesSources.isEmpty();
4251
}

components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/PagingAndSortingHelper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import java.util.stream.Collectors;
3333

3434
public class PagingAndSortingHelper implements SpringBootUpgradeReportSection.Helper<List<String>> {
35+
36+
public static final String VERSION_PATTERN = "(2\\.7\\..*)|(3\\.0\\..*)";
3537
private List<String> pagingAndSortingRepo;
3638
private List<String> reactivePagingAndSortingRepo;
3739
private List<String> rxJavaSortingRepo;
@@ -44,7 +46,7 @@ public String getDescription() {
4446
@Override
4547
public boolean evaluate(ProjectContext context) {
4648
IsSpringBootProject isSpringBootProject = new IsSpringBootProject();
47-
isSpringBootProject.setVersionPattern("2\\.7\\..*|3\\.0\\..*");
49+
isSpringBootProject.setVersionPattern(VERSION_PATTERN);
4850
boolean isSpringBootApplication = isSpringBootProject.evaluate(context);
4951
if(!isSpringBootApplication) {
5052
return false;

components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/SpringMVCAndWebFluxUrlMatchingChangesHelper.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.openrewrite.ExecutionContext;
1919
import org.openrewrite.java.search.UsesType;
2020
import org.openrewrite.java.tree.J;
21+
import org.springframework.sbm.boot.common.conditions.IsSpringBootProject;
2122
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection;
2223
import org.springframework.sbm.engine.context.ProjectContext;
2324
import org.springframework.sbm.java.api.JavaSource;
@@ -33,6 +34,7 @@
3334
*/
3435
public class SpringMVCAndWebFluxUrlMatchingChangesHelper implements SpringBootUpgradeReportSection.Helper<List<JavaSource>> {
3536

37+
public static final String VERSION_PATTERN = "(2\\.7\\..*)|(3\\.0\\..*)";
3638
private static final String SPRING_REST_CONTROLLER_FQN = "org.springframework.web.bind.annotation.RestController";
3739
private List<JavaSource> matches = new ArrayList<>();
3840

@@ -43,6 +45,13 @@ public String getDescription() {
4345

4446
@Override
4547
public boolean evaluate(ProjectContext context) {
48+
IsSpringBootProject isSpringBootProject = new IsSpringBootProject();
49+
isSpringBootProject.setVersionPattern(VERSION_PATTERN);
50+
boolean isSpringBootApplication = isSpringBootProject.evaluate(context);
51+
if(!isSpringBootApplication) {
52+
return false;
53+
}
54+
4655
GenericOpenRewriteRecipe<UsesType<ExecutionContext>> usesTypeRecipe = new GenericOpenRewriteRecipe<>(() -> new UsesType<>(SPRING_REST_CONTROLLER_FQN));
4756

4857
matches = context.getProjectJavaSources().find(usesTypeRecipe).stream()

components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/UpgradeDependenciesHelper.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.sbm.boot.upgrade_27_30.report.helper;
1717

18+
import org.springframework.sbm.boot.common.conditions.IsSpringBootProject;
1819
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportAction;
1920
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection;
2021
import org.springframework.sbm.engine.context.ProjectContext;
@@ -27,13 +28,22 @@
2728
* @author Fabian Krüger
2829
*/
2930
public class UpgradeDependenciesHelper implements SpringBootUpgradeReportSection.Helper<List<String>> {
31+
32+
public static final String VERSION_PATTERN = "(2\\.7\\..*)|(3\\.0\\..*)";
3033
@Override
3134
public String getDescription() {
3235
return "";
3336
}
3437

3538
@Override
3639
public boolean evaluate(ProjectContext context) {
40+
IsSpringBootProject isSpringBootProject = new IsSpringBootProject();
41+
isSpringBootProject.setVersionPattern(VERSION_PATTERN);
42+
boolean isSpringBootApplication = isSpringBootProject.evaluate(context);
43+
if(!isSpringBootApplication) {
44+
return false;
45+
}
46+
3747
// FIXME: dummy
3848
return true;
3949
}

components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/UpgradeSpringBootVersionHelper.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
* @author Fabian Krüger
2828
*/
2929
public class UpgradeSpringBootVersionHelper implements SpringBootUpgradeReportSection.Helper<String> {
30+
31+
public static final String VERSION_PATTERN = "(2\\.7\\..*)|(3\\.0\\..*)";
3032
@Override
3133
public String getDescription() {
3234
return "";
@@ -35,13 +37,13 @@ public String getDescription() {
3537
@Override
3638
public boolean evaluate(ProjectContext context) {
3739
IsSpringBootProject isSpringBootProject = new IsSpringBootProject();
38-
isSpringBootProject.setVersionPattern("2\\.7\\..*");
40+
isSpringBootProject.setVersionPattern(VERSION_PATTERN);
3941
return isSpringBootProject.evaluate(context);
4042
}
4143

4244
@Override
4345
public Map<String, String> getData() {
4446
// FIXME: Provide correct boot version, see https://github.com/spring-projects-experimental/spring-boot-migrator/issues/560
45-
return Map.of("bootVersion", "2.7.3");
47+
return Map.of("bootVersion", "2.7.x");
4648
}
4749
}

components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/RemoveImageBannerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void testGlobExpression() {
4343
@Test
4444
void applyRemoveImageBannerRecipeShouldRemoveAllImageBannerAtDefaultLocation() {
4545
String parentPom = PomBuilder
46-
.buildPom("com.example:parent:1.0")
46+
.buildRootWithParent("org.springframework.boot:spring-boot-starter-parent:2.7.5", "com.example:parent:1.0")
4747
.withModules("moduleA", "moduleB", "moduleC")
4848
.build();
4949
String moduleA = PomBuilder.buildPom("com.example:parent:1.0", "moduleA").build();

components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/BannerSupportReportSectionTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class BannerSupportReportSectionTest {
2727
@Test
2828
public void rendersBannerSupportInformation() {
2929
ProjectContext context = TestProjectContext.buildProjectContext()
30+
.withSpringBootParentOf("2.7.5")
3031
.addProjectResource("src/main/resources/banner.gif", "gif-banner")
3132
.addProjectResource("src/main/resources/banner.jpg", "jpg-banner")
3233
.addProjectResource("src/main/com/test/banner.java","class banner {}")

components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/ChangesToDataPropertiesReportSectionTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class ChangesToDataPropertiesReportSectionTest {
3333
@DisplayName("Changes to Data Properties should render")
3434
void changesToDataPropertiesSection_renders() {
3535
ProjectContext context = TestProjectContext.buildProjectContext()
36+
.withSpringBootParentOf("2.7.5")
3637
.addRegistrar(new SpringBootApplicationPropertiesRegistrar(new SpringApplicationPropertiesPathMatcher()))
3738
.addProjectResource("src/main/resources/application.properties", "spring.data.foo=bar")
3839
.addProjectResource("src/main/resources/application-another.properties", "spring.data.here=there")
@@ -68,6 +69,7 @@ void changesToDataPropertiesSection_renders() {
6869
@DisplayName("Changes to Data Properties shouldn't render")
6970
void changesToDataPropertiesSection_notRendered() {
7071
ProjectContext context = TestProjectContext.buildProjectContext()
72+
.withSpringBootParentOf("2.7.5")
7173
.addRegistrar(new SpringBootApplicationPropertiesRegistrar(new SpringApplicationPropertiesPathMatcher()))
7274
.addProjectResource("src/main/resources/application.properties", "data.foo=bar")
7375
.addProjectResource("src/main/resources/application-another.properties", "data.here=there")

components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/LoggingDateFormatHelperTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class LoggingDateFormatHelperTest {
3737
void isApplicableWithExistingPropertiesFile() {
3838
ProjectContext context = TestProjectContext
3939
.buildProjectContext()
40+
.withSpringBootParentOf("2.7.5")
4041
.addRegistrar(
4142
new SpringBootApplicationPropertiesRegistrar(new SpringApplicationPropertiesPathMatcher()))
4243
.addProjectResource("src/main/resources/application-myprofile.properties", "not.logging.pattern.dateformat=value")
@@ -55,6 +56,7 @@ void isApplicableWithExistingPropertiesFile() {
5556
void isApplicableWithoutExistingPropertiesFile() {
5657
ProjectContext context = TestProjectContext
5758
.buildProjectContext()
59+
.withSpringBootParentOf("2.7.5")
5860
.build();
5961

6062
LoggingDateFormatHelper sut = new LoggingDateFormatHelper();

components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/LoggingDateFormatReportSectionTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class LoggingDateFormatReportSectionTest {
3131
void shouldRenderSectionWhenNoPropertiesExist() {
3232
ProjectContext context = TestProjectContext
3333
.buildProjectContext()
34+
.withSpringBootParentOf("2.7.5")
3435
.addRegistrar(new SpringBootApplicationPropertiesRegistrar(new SpringApplicationPropertiesPathMatcher()))
3536
.addProjectResource("src/main/resources/application-myprofile.properties", "not.logging.pattern.dateformat=some-format")
3637
.build();
@@ -65,6 +66,7 @@ void shouldRenderSectionWhenNoPropertiesExist() {
6566
void shouldRenderSectionWhenPropertyNotDefined() {
6667
ProjectContext context = TestProjectContext
6768
.buildProjectContext()
69+
.withSpringBootParentOf("2.7.5")
6870
.build();
6971

7072
SpringBootUpgradeReportTestSupport

components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/SpringMVCAndWebFluxUrlMatchingChangesHelperTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class AnotherClass {};
5959

6060
ProjectContext context = TestProjectContext
6161
.buildProjectContext()
62+
.withSpringBootParentOf("2.7.5")
6263
.withBuildFileHavingDependencies("org.springframework:spring-web:5.3.23")
6364
.addJavaSource("src/main/java", restController1)
6465
.addJavaSource("src/main/java", restController2)

components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_27_30/report/helper/SpringMVCAndWebFluxUrlMatchingChangesReportSectionTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class AnotherClass {};
5656

5757
ProjectContext context = TestProjectContext
5858
.buildProjectContext()
59+
.withSpringBootParentOf("2.7.5")
5960
.withBuildFileHavingDependencies("org.springframework:spring-web:5.3.23")
6061
.addJavaSource("src/main/java", restController1)
6162
.addJavaSource("src/main/java", restController2)

0 commit comments

Comments
 (0)