diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/conditions/IsAnyMatchingSpringBootVersion.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/conditions/IsAnyMatchingSpringBootVersion.java deleted file mode 100644 index cd274b132..000000000 --- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/conditions/IsAnyMatchingSpringBootVersion.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2021 - 2022 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.common.conditions; - -import org.jetbrains.annotations.NotNull; -import org.springframework.sbm.engine.context.ProjectContext; -import org.springframework.sbm.engine.recipe.Condition; - -import javax.validation.constraints.NotEmpty; -import java.util.Arrays; -import java.util.List; - -public class IsAnyMatchingSpringBootVersion implements Condition { - - /** - * VersionPattern will be used for {@code startsWith} check against the version number found. - */ - @NotNull - @NotEmpty - private List versionPatterns; - - @Override - public String getDescription() { - return "Check if scanned application is Spring Boot application of given version"; - } - - @Override - public boolean evaluate(ProjectContext context) { - return versionPatterns.stream() - .anyMatch(p -> new IsMatchingSpringBootVersion(p).evaluate(context)); - } - - public void setVersionPatterns(String versionPatterns) { - this.versionPatterns = Arrays.asList(versionPatterns.split(",")); - } -} diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/conditions/IsMatchingSpringBootVersion.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/conditions/IsMatchingSpringBootVersion.java deleted file mode 100644 index 600918e14..000000000 --- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade/common/conditions/IsMatchingSpringBootVersion.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2021 - 2022 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.common.conditions; - -import lombok.AllArgsConstructor; -import lombok.NoArgsConstructor; -import lombok.Setter; -import org.jetbrains.annotations.NotNull; -import org.springframework.sbm.build.migration.conditions.AnyDependencyExistMatchingRegex; -import org.springframework.sbm.engine.context.ProjectContext; -import org.springframework.sbm.engine.recipe.Condition; - -import java.util.List; - -@AllArgsConstructor -@NoArgsConstructor -public class IsMatchingSpringBootVersion implements Condition { - - /** - * VersionPattern will be used for {@code startsWith} check against the version number found. - */ - @NotNull - @Setter - private String versionPattern; - - @Override - public String getDescription() { - return "Check if scanned application is Spring Boot application of given version"; - } - - @Override - public boolean evaluate(ProjectContext context) { - HasSpringBootParentOfVersion hasSpringBootParentOfVersion = new HasSpringBootParentOfVersion(); - hasSpringBootParentOfVersion.setVersionStartingWith(versionPattern); - String versionRegex = versionPattern.replace(".", "\\.") + ".*"; - AnyDependencyExistMatchingRegex anyDependencyExistMatchingRegex = new AnyDependencyExistMatchingRegex(List.of("org\\.springframework\\.boot\\:.*\\:" + versionRegex)); - return hasSpringBootParentOfVersion.evaluate(context) || anyDependencyExistMatchingRegex.evaluate(context); - } -} diff --git a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_24_25/actions/Boot_24_25_UpgradeReportAction.java b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_24_25/actions/Boot_24_25_UpgradeReportAction.java index 6188e914a..840855a8e 100644 --- a/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_24_25/actions/Boot_24_25_UpgradeReportAction.java +++ b/components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_24_25/actions/Boot_24_25_UpgradeReportAction.java @@ -16,37 +16,19 @@ package org.springframework.sbm.boot.upgrade_24_25.actions; import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; +import org.springframework.sbm.boot.common.conditions.IsSpringBootProject; import org.springframework.sbm.boot.upgrade.common.UpgradeReportUtil; -import org.springframework.sbm.boot.upgrade.common.conditions.IsMatchingSpringBootVersion; import org.springframework.sbm.engine.recipe.AbstractAction; import org.springframework.sbm.boot.UpgradeSectionBuilder; import org.springframework.sbm.boot.asciidoctor.Section; -import org.springframework.sbm.boot.upgrade_24_25.report.*; import org.springframework.sbm.engine.context.ProjectContext; import org.springframework.sbm.java.api.JavaSource; import org.springframework.sbm.project.resource.StringProjectResource; import freemarker.template.Configuration; -import freemarker.template.Template; import lombok.Getter; -import org.asciidoctor.Asciidoctor; -import org.asciidoctor.Options; -import org.asciidoctor.SafeMode; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.sbm.boot.UpgradeSectionBuilder; -import org.springframework.sbm.boot.asciidoctor.Section; import org.springframework.sbm.boot.upgrade_24_25.report.Boot_24_25_Introduction; -import org.springframework.sbm.boot.upgrade_24_25.report.Boot_24_25_SchemaSqlAndDataSqlFiles; -import org.springframework.sbm.boot.upgrade_24_25.report.Boot_24_25_SeparateCredentials; -import org.springframework.sbm.boot.upgrade_24_25.report.Boot_24_25_SpringDataJpa; -import org.springframework.sbm.boot.upgrade_24_25.report.Boot_24_25_SqlScriptDataSourceInitialization; -import org.springframework.sbm.boot.upgrade_24_25.report.Boot_24_25_UpdateDependencies; -import org.springframework.sbm.engine.context.ProjectContext; -import org.springframework.sbm.engine.recipe.AbstractAction; -import org.springframework.sbm.java.api.JavaSource; -import org.springframework.sbm.project.resource.StringProjectResource; -import java.io.StringWriter; import java.nio.file.Path; import java.util.ArrayList; import java.util.HashMap; @@ -88,7 +70,10 @@ public void apply(ProjectContext projectContext) { @Override public boolean isApplicable(ProjectContext context) { // Verify it's a 2.4.x Spring Boot project - return new IsMatchingSpringBootVersion("2.4.").evaluate(context); + IsSpringBootProject isSpringBootProject = new IsSpringBootProject(); + isSpringBootProject.setVersionPattern("2\\.4\\..*"); + + return isSpringBootProject.evaluate(context); } @Getter diff --git a/components/sbm-recipes-boot-upgrade/src/main/resources/recipes/boot-2.4-2.5-upgrade-report.yaml b/components/sbm-recipes-boot-upgrade/src/main/resources/recipes/boot-2.4-2.5-upgrade-report.yaml index 5bd789aa5..a32b0637a 100644 --- a/components/sbm-recipes-boot-upgrade/src/main/resources/recipes/boot-2.4-2.5-upgrade-report.yaml +++ b/components/sbm-recipes-boot-upgrade/src/main/resources/recipes/boot-2.4-2.5-upgrade-report.yaml @@ -1,10 +1,10 @@ - name: boot-2.4-2.5-upgrade-report description: Create Upgrade Report for a Spring Boot 2.4 Application condition: - type: org.springframework.sbm.boot.upgrade.common.conditions.IsAnyMatchingSpringBootVersion - versionPatterns: 2.4.,2.5. + type: org.springframework.sbm.boot.common.conditions.IsSpringBootProject + versionPattern: "2\\.4\\..*|2\\.5\\..*" actions: - type: org.springframework.sbm.boot.upgrade_24_25.actions.Boot_24_25_UpgradeReportAction description: Create Upgrade Report for a Spring Boot 2.4 Application condition: - type: org.springframework.sbm.common.migration.conditions.TrueCondition \ No newline at end of file + type: org.springframework.sbm.common.migration.conditions.TrueCondition diff --git a/components/sbm-recipes-boot-upgrade/src/main/resources/recipes/boot-2.7-3.0-upgrade-report.yaml b/components/sbm-recipes-boot-upgrade/src/main/resources/recipes/boot-2.7-3.0-upgrade-report.yaml index d9f878ff0..af16cc6f7 100644 --- a/components/sbm-recipes-boot-upgrade/src/main/resources/recipes/boot-2.7-3.0-upgrade-report.yaml +++ b/components/sbm-recipes-boot-upgrade/src/main/resources/recipes/boot-2.7-3.0-upgrade-report.yaml @@ -1,8 +1,8 @@ - name: boot-2.7-3.0-upgrade-report description: Create a report for Spring Boot Upgrade from 2.7.x to 3.0.0-M3 condition: - type: org.springframework.sbm.boot.upgrade.common.conditions.IsAnyMatchingSpringBootVersion - versionPatterns: 2.7.,3.0. + type: org.springframework.sbm.boot.common.conditions.IsSpringBootProject + versionPattern: "2\\.7\\..*|3\\.0\\..*" actions: - type: org.springframework.sbm.boot.upgrade_27_30.SpringBoot30UpgradeReport @@ -17,4 +17,4 @@ - type: org.springframework.sbm.boot.upgrade_27_30.actions.Boot_27_30_AddLoggingDateFormat description: "Sets logging date format to yyyy-MM-dd HH:mm:ss.SSS" condition: - type: org.springframework.sbm.boot.upgrade_27_30.conditions.LoggingDateFormatCondition \ No newline at end of file + type: org.springframework.sbm.boot.upgrade_27_30.conditions.LoggingDateFormatCondition diff --git a/components/sbm-support-boot/src/test/java/org/springframework/sbm/boot/common/conditions/IsSpringBootProjectTest.java b/components/sbm-support-boot/src/test/java/org/springframework/sbm/boot/common/conditions/IsSpringBootProjectTest.java new file mode 100644 index 000000000..131758beb --- /dev/null +++ b/components/sbm-support-boot/src/test/java/org/springframework/sbm/boot/common/conditions/IsSpringBootProjectTest.java @@ -0,0 +1,62 @@ +/* + * Copyright 2021 - 2022 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.common.conditions; + +import org.intellij.lang.annotations.Language; +import org.junit.jupiter.api.Test; +import org.springframework.sbm.engine.context.ProjectContext; +import org.springframework.sbm.project.resource.TestProjectContext; + +import static org.assertj.core.api.Assertions.assertThat; + +class IsSpringBootProjectTest { + @Test + public void worksWithDependencyManagement() { + + IsSpringBootProject target = new IsSpringBootProject(); + target.setVersionPattern("2\\.7\\..*"); + + @Language("xml") + String pomXml = """ + + + 4.0.0 + com.example + demo + 0.0.1-SNAPSHOT + + + + org.springframework.boot + spring-boot-dependencies + 2.7.4 + pom + import + + + + + """; + ProjectContext context = TestProjectContext.buildProjectContext() + .withMavenRootBuildFileSource(pomXml) + .build(); + boolean result = target.evaluate(context); + + assertThat(result).isTrue(); + } +}