Skip to content

Commit

Permalink
Current report sections are conditional to Boot 2.7 or 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fabapp2 committed Dec 2, 2022
1 parent 57b3902 commit 12b033d
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +28,8 @@

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

public static final String VERSION_PATTERN = "(2\\.7\\..*)|(3\\.0\\..*)";

private List<Path> foundBanners;

@Override
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,6 +36,8 @@
*/
public class ChangesToDataPropertiesHelper implements SpringBootUpgradeReportSection.Helper<List<ChangesToDataPropertiesHelper.Match>> {

public static final String VERSION_PATTERN = "(2\\.7\\..*)|(3\\.0\\..*)";

private Map<String, List<Match>> data = new HashMap<>();

@Override
Expand All @@ -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<SpringBootApplicationProperties> search = context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +28,8 @@
import java.util.stream.Collectors;

public class CommonsMultipartResolverHelper implements SpringBootUpgradeReportSection.Helper<List<String>>{

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<String> types;

Expand All @@ -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<MatchingMethod> search = context
.search(
new SpringBeanMethodDeclarationFinder(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,6 +36,7 @@

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

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

@Override
Expand All @@ -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<TreeVisitor<?, ExecutionContext>> recipe =
new GenericOpenRewriteRecipe<>(() -> new UsesType("org.springframework.boot.context.properties.ConstructorBinding"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,6 +29,7 @@
*/
public class LoggingDateFormatHelper implements SpringBootUpgradeReportSection.Helper<List<? extends PropertiesSource>> {

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

@Override
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import java.util.stream.Collectors;

public class PagingAndSortingHelper implements SpringBootUpgradeReportSection.Helper<List<String>> {

public static final String VERSION_PATTERN = "(2\\.7\\..*)|(3\\.0\\..*)";
private List<String> pagingAndSortingRepo;
private List<String> reactivePagingAndSortingRepo;
private List<String> rxJavaSortingRepo;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,6 +34,7 @@
*/
public class SpringMVCAndWebFluxUrlMatchingChangesHelper implements SpringBootUpgradeReportSection.Helper<List<JavaSource>> {

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<JavaSource> matches = new ArrayList<>();

Expand All @@ -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<UsesType<ExecutionContext>> usesTypeRecipe = new GenericOpenRewriteRecipe<>(() -> new UsesType<>(SPRING_REST_CONTROLLER_FQN));

matches = context.getProjectJavaSources().find(usesTypeRecipe).stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,13 +28,22 @@
* @author Fabian Krüger
*/
public class UpgradeDependenciesHelper implements SpringBootUpgradeReportSection.Helper<List<String>> {

public static final String VERSION_PATTERN = "(2\\.7\\..*)|(3\\.0\\..*)";
@Override
public String getDescription() {
return "";
}

@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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
* @author Fabian Krüger
*/
public class UpgradeSpringBootVersionHelper implements SpringBootUpgradeReportSection.Helper<String> {

public static final String VERSION_PATTERN = "(2\\.7\\..*)|(3\\.0\\..*)";
@Override
public String getDescription() {
return "";
Expand All @@ -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<String, String> 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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -55,6 +56,7 @@ void isApplicableWithExistingPropertiesFile() {
void isApplicableWithoutExistingPropertiesFile() {
ProjectContext context = TestProjectContext
.buildProjectContext()
.withSpringBootParentOf("2.7.5")
.build();

LoggingDateFormatHelper sut = new LoggingDateFormatHelper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -65,6 +66,7 @@ void shouldRenderSectionWhenNoPropertiesExist() {
void shouldRenderSectionWhenPropertyNotDefined() {
ProjectContext context = TestProjectContext
.buildProjectContext()
.withSpringBootParentOf("2.7.5")
.build();

SpringBootUpgradeReportTestSupport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 12b033d

Please sign in to comment.