Skip to content

Commit 8bdbee3

Browse files
committed
Add recipe to create report with precondition for Boot 3.0 upgrade
1 parent 6ce6c76 commit 8bdbee3

File tree

10 files changed

+244
-207
lines changed

10 files changed

+244
-207
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2021 - 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.sbm.boot.upgrade.common;
18+
19+
import freemarker.template.Configuration;
20+
import freemarker.template.Template;
21+
import org.asciidoctor.Asciidoctor;
22+
import org.asciidoctor.Options;
23+
import org.asciidoctor.SafeMode;
24+
25+
import java.io.StringWriter;
26+
import java.util.Map;
27+
28+
public class UpgradeReportUtil {
29+
30+
public static String renderMarkdown(Map<String, Object> params, Configuration configuration) {
31+
try (StringWriter writer = new StringWriter()) {
32+
Template template = configuration.getTemplate("upgrade-asciidoc.ftl");
33+
template.process(params, writer);
34+
return writer.toString();
35+
} catch (Exception e) {
36+
throw new RuntimeException(e);
37+
}
38+
}
39+
40+
41+
public static String renderHtml(String markdown) {
42+
Asciidoctor asciidoctor = Asciidoctor.Factory.create();
43+
String html = asciidoctor.convert(markdown,
44+
Options.builder()
45+
.toFile(true)
46+
.backend("html5")
47+
.headerFooter(true)
48+
.safe(SafeMode.UNSAFE)
49+
.build());
50+
return html;
51+
}
52+
}

components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_24_25/actions/Boot_24_25_UpgradeReportAction.java

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import com.fasterxml.jackson.annotation.JsonIgnore;
1919
import com.fasterxml.jackson.annotation.JsonInclude;
20+
import org.springframework.sbm.boot.upgrade.common.UpgradeReportUtil;
21+
import org.springframework.sbm.boot.upgrade.common.conditions.IsMatchingSpringBootVersion;
2022
import org.springframework.sbm.engine.recipe.AbstractAction;
2123
import org.springframework.sbm.boot.UpgradeSectionBuilder;
2224
import org.springframework.sbm.boot.asciidoctor.Section;
@@ -74,39 +76,19 @@ public void apply(ProjectContext projectContext) {
7476
Section introductionSection = new Boot_24_25_Introduction().build(projectContext);
7577
params.put("introductionSection", introductionSection);
7678
params.put("changeSections", sections);
77-
String markdown = renderMarkdown(params);
78-
String html = renderHtml(markdown);
79+
String markdown = UpgradeReportUtil.renderMarkdown(params, configuration);
80+
String html = UpgradeReportUtil.renderHtml(markdown);
7981
Path htmlPath = projectContext.getProjectRootDirectory().resolve(Path.of("Upgrade-Spring-Boot-2.4-to-2.5.html"));
8082
projectContext.getProjectResources().add(new StringProjectResource(projectContext.getProjectRootDirectory(), htmlPath, html));
8183
}
8284

83-
private String renderMarkdown(Map<String, Object> params) {
84-
try(StringWriter writer = new StringWriter()) {
85-
Template template = configuration.getTemplate("upgrade-asciidoc.ftl");
86-
template.process(params, writer);
87-
return writer.toString();
88-
} catch (Exception e) {
89-
throw new RuntimeException(e);
90-
}
91-
}
9285

93-
private String renderHtml(String markdown) {
94-
Asciidoctor asciidoctor = Asciidoctor.Factory.create();
95-
String html = asciidoctor.convert(markdown,
96-
Options.builder()
97-
.toFile(true)
98-
.backend("html5")
99-
.headerFooter(true)
100-
.safe(SafeMode.UNSAFE)
101-
.build());
102-
return html;
103-
}
10486

10587

10688
@Override
10789
public boolean isApplicable(ProjectContext context) {
10890
// Verify it's a 2.4.x Spring Boot project
109-
return true;
91+
return new IsMatchingSpringBootVersion("2.4.").evaluate(context);
11092
}
11193

11294
@Getter

components/sbm-recipes-boot-upgrade/src/main/java/org/springframework/sbm/boot/upgrade_27_30/CrudRepositoryExtension.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717

1818

1919
import org.jetbrains.annotations.NotNull;
20-
import org.openrewrite.*;
21-
import org.openrewrite.internal.lang.NonNullApi;
20+
import org.openrewrite.ExecutionContext;
21+
import org.openrewrite.Recipe;
22+
import org.openrewrite.TreeVisitor;
2223
import org.openrewrite.internal.lang.Nullable;
2324
import org.openrewrite.java.JavaIsoVisitor;
2425
import org.openrewrite.java.tree.J;
2526
import org.openrewrite.java.tree.JavaType;
26-
import org.springframework.sbm.boot.upgrade_27_30.helperrecipe.ImplementTypedInterface;
2727

2828
import java.util.List;
2929
import java.util.Optional;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright 2021 - 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.sbm.boot.upgrade_27_30;
18+
19+
import org.springframework.sbm.boot.UpgradeSectionBuilder;
20+
21+
public interface Sbu30_UpgradeSectionBuilder extends UpgradeSectionBuilder {
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2021 - 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.sbm.boot.upgrade_27_30;
18+
19+
import com.fasterxml.jackson.annotation.JsonIgnore;
20+
import freemarker.template.Configuration;
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.sbm.boot.UpgradeSectionBuilder;
23+
import org.springframework.sbm.boot.asciidoctor.Section;
24+
import org.springframework.sbm.boot.upgrade.common.UpgradeReportUtil;
25+
import org.springframework.sbm.boot.upgrade_24_25.report.Boot_24_25_Introduction;
26+
import org.springframework.sbm.engine.context.ProjectContext;
27+
import org.springframework.sbm.engine.recipe.AbstractAction;
28+
import org.springframework.sbm.project.resource.StringProjectResource;
29+
30+
import java.nio.file.Path;
31+
import java.util.ArrayList;
32+
import java.util.HashMap;
33+
import java.util.List;
34+
import java.util.Map;
35+
import java.util.stream.Collectors;
36+
37+
public class SpringBoot30UpgradeReport extends AbstractAction {
38+
39+
@Autowired
40+
@JsonIgnore
41+
private Configuration configuration;
42+
43+
@Autowired
44+
@JsonIgnore
45+
private List<Sbu30_UpgradeSectionBuilder> upgradeSectionBuilders = new ArrayList<>();
46+
47+
@Override
48+
public void apply(ProjectContext projectContext) {
49+
final List<Section> sections = upgradeSectionBuilders.stream()
50+
.filter(b -> b.isApplicable(projectContext))
51+
.map(b -> b.build(projectContext))
52+
.collect(Collectors.toList());
53+
54+
Map<String, Object> params = new HashMap<>();
55+
Section introductionSection = new Boot_24_25_Introduction().build(projectContext);
56+
params.put("introductionSection", introductionSection);
57+
params.put("changeSections", sections);
58+
String markdown = UpgradeReportUtil.renderMarkdown(params, configuration);
59+
String html = UpgradeReportUtil.renderHtml(markdown);
60+
Path htmlPath = projectContext.getProjectRootDirectory().resolve(Path.of("SPRING_BOOT_3_UPGRADE_REPORT.html"));
61+
projectContext.getProjectResources().add(new StringProjectResource(projectContext.getProjectRootDirectory(), htmlPath, html));
62+
}
63+
}
Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,38 +16,27 @@
1616

1717
package org.springframework.sbm.boot.upgrade_27_30.checks;
1818

19+
import org.jetbrains.annotations.NotNull;
1920
import org.openrewrite.java.tree.JavaType;
20-
import org.springframework.sbm.boot.upgrade_27_30.Sbu30_PreconditionCheck;
21-
import org.springframework.sbm.boot.upgrade_27_30.Sbu30_PreconditionCheckResult;
2221
import org.springframework.sbm.build.api.ApplicationModule;
2322
import org.springframework.sbm.engine.context.ProjectContext;
24-
import org.springframework.sbm.engine.precondition.PreconditionCheck;
2523
import org.springframework.sbm.java.api.JavaSource;
2624
import org.springframework.sbm.java.impl.OpenRewriteJavaSource;
2725
import org.springframework.stereotype.Component;
2826

29-
import java.util.List;
3027
import java.util.Set;
3128
import java.util.stream.Collectors;
3229
import java.util.stream.Stream;
3330

3431
@Component
35-
public class DatabaseDriverGaeCheck implements Sbu30_PreconditionCheck {
32+
public class DatabaseDriverGaeFinder {
3633

37-
@Override
38-
public Sbu30_PreconditionCheckResult run(ProjectContext context) {
39-
40-
Set<ApplicationModule> collect = context.getApplicationModules()
34+
@NotNull
35+
public Set<ApplicationModule> findMatches(ProjectContext context) {
36+
return context.getApplicationModules()
4137
.stream()
4238
.filter(this::hasClassAppEngineDriverOnClasspath)
4339
.collect(Collectors.toSet());
44-
45-
if(collect.isEmpty()) {
46-
return new Sbu30_PreconditionCheckResult(PreconditionCheck.ResultState.PASSED, "No dependency to Google AppEngine's AppEngineDriver found.");
47-
} else {
48-
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("', '")) + "'";
49-
return new Sbu30_PreconditionCheckResult(PreconditionCheck.ResultState.FAILED, message);
50-
}
5140
}
5241

5342
private boolean hasClassAppEngineDriverOnClasspath(ApplicationModule m) {
@@ -61,6 +50,7 @@ private boolean hasClassAppEngineDriverOnClasspath(ApplicationModule m) {
6150
});
6251
}
6352

53+
6454
private boolean dependsOn(JavaSource js, String s) {
6555
if (OpenRewriteJavaSource.class.isInstance(js)) {
6656
OpenRewriteJavaSource javaSource = OpenRewriteJavaSource.class.cast(js);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright 2021 - 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.sbm.boot.upgrade_27_30.checks;
18+
19+
import lombok.RequiredArgsConstructor;
20+
import org.springframework.sbm.boot.SectionBuilder;
21+
import org.springframework.sbm.boot.asciidoctor.RelevantChangeSection;
22+
import org.springframework.sbm.boot.asciidoctor.Section;
23+
import org.springframework.sbm.boot.asciidoctor.TodoList;
24+
import org.springframework.sbm.boot.upgrade_27_30.Sbu30_PreconditionCheck;
25+
import org.springframework.sbm.boot.upgrade_27_30.Sbu30_PreconditionCheckResult;
26+
import org.springframework.sbm.boot.upgrade_27_30.Sbu30_UpgradeSectionBuilder;
27+
import org.springframework.sbm.build.api.ApplicationModule;
28+
import org.springframework.sbm.engine.context.ProjectContext;
29+
import org.springframework.sbm.engine.precondition.PreconditionCheck;
30+
import org.springframework.stereotype.Component;
31+
32+
import java.util.Set;
33+
import java.util.stream.Collectors;
34+
35+
@Component
36+
@RequiredArgsConstructor
37+
public class DatabaseDriverGaeSectionBuilder implements Sbu30_PreconditionCheck, Sbu30_UpgradeSectionBuilder {
38+
39+
private final DatabaseDriverGaeFinder finder;
40+
41+
@Override
42+
public Sbu30_PreconditionCheckResult run(ProjectContext context) {
43+
44+
Set<ApplicationModule> collect = finder.findMatches(context);
45+
46+
if(collect.isEmpty()) {
47+
return new Sbu30_PreconditionCheckResult(PreconditionCheck.ResultState.PASSED, "No dependency to Google AppEngine's AppEngineDriver found.");
48+
} else {
49+
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("', '")) + "'";
50+
return new Sbu30_PreconditionCheckResult(PreconditionCheck.ResultState.FAILED, message);
51+
}
52+
}
53+
54+
55+
@Override
56+
public boolean isApplicable(ProjectContext projectContext) {
57+
return ! finder.findMatches(projectContext).isEmpty();
58+
}
59+
60+
@Override
61+
public Section build(ProjectContext projectContext) {
62+
return RelevantChangeSection.builder()
63+
.title("DatabaseDriver.GAE was deprecated in Spring Boot 2.7")
64+
.paragraph("Support for GAE database driver has been removed in 3.0.0 without replacement following the removal of AppEngineDriver from version 2.0 of the AppEngine API SDK.")
65+
.relevanceSection()
66+
.paragraph("The scan found `com.google.appengine.api.rdbms.AppEngineDriver` on the classpath.")
67+
.todoSection()
68+
.todoList(
69+
TodoList.builder()
70+
.todo(
71+
TodoList.Todo.builder()
72+
.text("You'll need to find a replacement for Google App Engine.")
73+
.build()
74+
)
75+
.build()
76+
)
77+
.build();
78+
}
79+
}

0 commit comments

Comments
 (0)