Skip to content

Commit 2118d4d

Browse files
committed
Moved Helper to separate class
1 parent 3651f96 commit 2118d4d

13 files changed

+80
-59
lines changed

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

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -47,37 +47,16 @@
4747
@Setter
4848
public class SpringBootUpgradeReportSection {
4949

50-
private static final String ls = System.lineSeparator();
51-
private List<String> projects;
52-
53-
/**
54-
* Helper acting as {@link Condition} and data provide for a {@link SpringBootUpgradeReportSection}.
55-
* @deprecated Use {@link AbstractHelper} instead
56-
*/
57-
@Deprecated(forRemoval = true)
58-
public interface Helper<T> extends Condition {
59-
/**
60-
* @return {@code Map<String, T>} the model data for the template.
61-
*/
62-
Map<String, T> getData();
63-
}
64-
65-
public static abstract class AbstractHelper<T> implements Helper<T> {
66-
67-
@Override
68-
public String getDescription() {
69-
return "";
70-
}
71-
}
72-
7350
public static final String CHANGE_HEADER = "What Changed";
7451
public static final String AFFECTED = "Why is the application affected";
7552
public static final String REMEDIATION = "Remediation";
76-
77-
public boolean shouldRender(ProjectContext context) {
78-
return helper.evaluate(context);
79-
}
80-
53+
private static final String ls = System.lineSeparator();
54+
/**
55+
* The spring project(s)/modules this change comes from.
56+
*
57+
* e.g. {@code spring-boot} and {@code actuator}
58+
*/
59+
private List<String> projects;
8160
/**
8261
* Section title
8362
*/
@@ -109,15 +88,22 @@ public boolean shouldRender(ProjectContext context) {
10988
@NotNull
11089
private Set<String> contributors;
11190

112-
@JsonIgnore
113-
private Helper<Object> helper;
91+
@NotNull
92+
private SpringBootUpgradeReportSectionHelper<?> helper;
93+
11494
@JsonIgnore
11595
@Autowired
11696
private SpringBootUpgradeReportFreemarkerSupport freemarkerSupport;
11797

98+
public boolean shouldRender(ProjectContext context) {
99+
return helper.evaluate(context);
100+
}
101+
102+
103+
118104
public String render(ProjectContext context) {
119105
if (getHelper().evaluate(context)) {
120-
Map<String, Object> params = getHelper().getData();
106+
Map<String, ?> params = getHelper().getData();
121107

122108
try (StringWriter writer = new StringWriter()) {
123109
String templateContent = buildTemplate();
@@ -138,7 +124,7 @@ public String render(ProjectContext context) {
138124
throw new IllegalArgumentException("Could not render Section '"+ getTitle()+"', evaluating the context returned false");
139125
}
140126

141-
private void renderTemplate(Map<String, Object> params, StringWriter writer, String templateContent) throws IOException, TemplateException {
127+
private void renderTemplate(Map<String, ?> params, StringWriter writer, String templateContent) throws IOException, TemplateException {
142128
String templateName = getTitle().replace(" ", "") + UUID.randomUUID();
143129
freemarkerSupport.getStringLoader().putTemplate(templateName, templateContent);
144130
Template t = freemarkerSupport.getConfiguration().getTemplate(templateName);
@@ -208,28 +194,20 @@ private void renderLineBreak(StringBuilder sb) {
208194
sb.append(ls);
209195
}
210196

211-
private void renderGitHubInfo(StringBuilder sb) {
212-
sb.append("****").append(ls);
213-
sb.append("[%hardbreaks]").append(ls);
197+
void renderGitHubInfo(StringBuilder sb) {
214198
if(gitHubIssue != null) {
215-
sb.append("**Issue:** https://github.com/spring-projects-experimental/spring-boot-migrator/issues/").append(gitHubIssue).append("[#").append(gitHubIssue).append("^, role=\"ext-link\"] ").append(ls);
199+
sb.append("**Issue:** https://github.com/spring-projects-experimental/spring-boot-migrator/issues/").append(gitHubIssue).append("[#").append(gitHubIssue).append("^, role=\"ext-link\"] ").append(" + ").append(ls);
216200
}
217-
// if(contributors != null && gitHubIssue != null) {
218-
// sb.append(", ");
219-
// } else {
220-
// sb.append(ls);
221-
// }
222201
if(contributors != null) {
223202
List<Author> authors = getAuthors();
224203
sb.append("**Contributors:** ");
225204
String authorsString = authors.stream().map(a -> "https://github.com/" + a.getHandle() + "[@" + a.getHandle() + "^, role=\"ext-link\"]").collect(Collectors.joining(", "));
226-
sb.append(authorsString).append(ls);
205+
sb.append(authorsString).append(" + ").append(ls);
227206
}
228207
if(projects != null){
229208
String projectsList = projects.stream().collect(Collectors.joining(", "));
230209
sb.append("**Projects:** ").append(projectsList).append(ls);
231210
}
232-
sb.append("****").append(ls);
233211
}
234212

235213
private void renderSectionTitle(StringBuilder sb) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
package org.springframework.sbm.boot.upgrade_27_30.report;
17+
18+
import org.springframework.sbm.engine.recipe.Condition;
19+
20+
import java.util.Map;
21+
22+
/**
23+
* Helper base class which is {@link Condition} and data provider for a {@link SpringBootUpgradeReportSection}.
24+
*
25+
* @author Fabian Krüger
26+
*/
27+
public abstract class SpringBootUpgradeReportSectionHelper<T> implements Condition {
28+
/**
29+
* @return {@code Map<String, T>} the model data for the template.
30+
*/
31+
public abstract Map<String, T> getData();
32+
33+
@Override
34+
public String getDescription() {
35+
return "";
36+
}
37+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.springframework.sbm.boot.upgrade_27_30.report.helper;
1717
import org.springframework.sbm.boot.common.conditions.IsSpringBootProject;
1818
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection;
19+
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSectionHelper;
1920
import org.springframework.sbm.build.api.BuildFile;
2021
import org.springframework.sbm.build.api.Module;
2122
import org.springframework.sbm.engine.context.ProjectContext;
@@ -29,7 +30,7 @@
2930
/**
3031
* @author Fabian Krüger
3132
*/
32-
public class ActuatorEndpointsSanitizationHelper extends SpringBootUpgradeReportSection.AbstractHelper<List<BuildFile>> {
33+
public class ActuatorEndpointsSanitizationHelper extends SpringBootUpgradeReportSectionHelper<List<BuildFile>> {
3334

3435
private static final String ACTUATOR_GROUP_ID = "org.springframework.boot";
3536
private static final String ACTUATOR_ARTIFACT_ID = "spring-boot-actuator";

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,14 @@
1717
package org.springframework.sbm.boot.upgrade_27_30.report.helper;
1818

1919
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection;
20+
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSectionHelper;
2021
import org.springframework.sbm.build.migration.conditions.NoPluginRepositoryExistsCondition;
2122
import org.springframework.sbm.build.migration.conditions.NoRepositoryExistsCondition;
2223
import org.springframework.sbm.engine.context.ProjectContext;
2324

2425
import java.util.Map;
2526

26-
public class AddSpringBootRepositoriesHelper implements SpringBootUpgradeReportSection.Helper<String>{
27-
@Override
28-
public String getDescription() {
29-
return null;
30-
}
31-
27+
public class AddSpringBootRepositoriesHelper extends SpringBootUpgradeReportSectionHelper<String> {
3228
@Override
3329
public boolean evaluate(ProjectContext context) {
3430
return new NoRepositoryExistsCondition().evaluate(context) && new NoPluginRepositoryExistsCondition().evaluate(context);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.springframework.sbm.boot.common.conditions.IsSpringBootProject;
2020
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection;
21+
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSectionHelper;
2122
import org.springframework.sbm.engine.context.ProjectContext;
2223
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
2324

@@ -26,7 +27,7 @@
2627
import java.util.Map;
2728
import java.util.stream.Collectors;
2829

29-
public class BannerSupportHelper implements SpringBootUpgradeReportSection.Helper<List<String>> {
30+
public class BannerSupportHelper extends SpringBootUpgradeReportSectionHelper<List<String>> {
3031

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

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.springframework.sbm.boot.properties.api.SpringBootApplicationProperties;
2222
import org.springframework.sbm.boot.properties.search.SpringBootApplicationPropertiesResourceListFilter;
2323
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection;
24+
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSectionHelper;
2425
import org.springframework.sbm.build.migration.conditions.NoDependencyExistMatchingRegex;
2526
import org.springframework.sbm.engine.context.ProjectContext;
2627

@@ -34,7 +35,7 @@
3435
/**
3536
* @author Fabian Krüger
3637
*/
37-
public class ChangesToDataPropertiesHelper implements SpringBootUpgradeReportSection.Helper<List<ChangesToDataPropertiesHelper.Match>> {
38+
public class ChangesToDataPropertiesHelper extends SpringBootUpgradeReportSectionHelper<List<ChangesToDataPropertiesHelper.Match>> {
3839

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

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020
import org.springframework.sbm.boot.common.finder.MatchingMethod;
2121
import org.springframework.sbm.boot.common.finder.SpringBeanMethodDeclarationFinder;
2222
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection;
23+
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSectionHelper;
2324
import org.springframework.sbm.engine.context.ProjectContext;
2425

2526
import java.util.HashMap;
2627
import java.util.List;
2728
import java.util.Map;
2829
import java.util.stream.Collectors;
2930

30-
public class CommonsMultipartResolverHelper implements SpringBootUpgradeReportSection.Helper<List<String>>{
31+
public class CommonsMultipartResolverHelper extends SpringBootUpgradeReportSectionHelper<List<String>> {
3132

3233
public static final String VERSION_PATTERN = "(2\\.7\\..*)|(3\\.0\\..*)";
3334
private static final String COMMONS_MULTIPART_RESOLVER_CLASS = "org.springframework.web.multipart.commons.CommonsMultipartResolver";

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.openrewrite.java.tree.J;
2525
import org.springframework.sbm.boot.common.conditions.IsSpringBootProject;
2626
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection;
27+
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSectionHelper;
2728
import org.springframework.sbm.engine.context.ProjectContext;
2829
import org.springframework.sbm.engine.recipe.OpenRewriteSourceFilesFinder;
2930
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
@@ -34,7 +35,7 @@
3435
import java.util.stream.Collectors;
3536

3637

37-
public class ConstructorBindingHelper implements SpringBootUpgradeReportSection.Helper<List<String>> {
38+
public class ConstructorBindingHelper extends SpringBootUpgradeReportSectionHelper<List<String>> {
3839

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

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.springframework.sbm.boot.common.conditions.IsSpringBootProject;
1919
import org.springframework.sbm.boot.upgrade_27_30.filter.LoggingDateFormatPropertyFinder;
2020
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection;
21+
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSectionHelper;
2122
import org.springframework.sbm.engine.context.ProjectContext;
2223
import org.springframework.sbm.properties.api.PropertiesSource;
2324

@@ -27,7 +28,7 @@
2728
/**
2829
* @author Fabian Krüger
2930
*/
30-
public class LoggingDateFormatHelper implements SpringBootUpgradeReportSection.Helper<List<? extends PropertiesSource>> {
31+
public class LoggingDateFormatHelper extends SpringBootUpgradeReportSectionHelper<List<? extends PropertiesSource>> {
3132

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

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.openrewrite.java.tree.J;
2323
import org.springframework.sbm.boot.common.conditions.IsSpringBootProject;
2424
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection;
25+
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSectionHelper;
2526
import org.springframework.sbm.engine.context.ProjectContext;
2627
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
2728
import org.springframework.sbm.support.openrewrite.GenericOpenRewriteRecipe;
@@ -31,7 +32,7 @@
3132
import java.util.Map;
3233
import java.util.stream.Collectors;
3334

34-
public class PagingAndSortingHelper implements SpringBootUpgradeReportSection.Helper<List<String>> {
35+
public class PagingAndSortingHelper extends SpringBootUpgradeReportSectionHelper<List<String>> {
3536

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

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.openrewrite.java.tree.J;
2121
import org.springframework.sbm.boot.common.conditions.IsSpringBootProject;
2222
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection;
23+
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSectionHelper;
2324
import org.springframework.sbm.engine.context.ProjectContext;
2425
import org.springframework.sbm.java.api.JavaSource;
2526
import org.springframework.sbm.java.impl.OpenRewriteJavaSource;
@@ -32,7 +33,7 @@
3233
/**
3334
* @author Fabian Krüger
3435
*/
35-
public class SpringMVCAndWebFluxUrlMatchingChangesHelper implements SpringBootUpgradeReportSection.Helper<List<JavaSource>> {
36+
public class SpringMVCAndWebFluxUrlMatchingChangesHelper extends SpringBootUpgradeReportSectionHelper<List<JavaSource>> {
3637

3738
public static final String VERSION_PATTERN = "(2\\.7\\..*)|(3\\.0\\..*)";
3839
private static final String SPRING_REST_CONTROLLER_FQN = "org.springframework.web.bind.annotation.RestController";

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.springframework.sbm.boot.common.conditions.IsSpringBootProject;
1919
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportAction;
2020
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection;
21+
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSectionHelper;
2122
import org.springframework.sbm.engine.context.ProjectContext;
2223
import org.springframework.sbm.java.api.JavaSource;
2324

@@ -27,7 +28,7 @@
2728
/**
2829
* @author Fabian Krüger
2930
*/
30-
public class UpgradeDependenciesHelper implements SpringBootUpgradeReportSection.Helper<List<String>> {
31+
public class UpgradeDependenciesHelper extends SpringBootUpgradeReportSectionHelper<List<String>> {
3132

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

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.springframework.sbm.boot.common.conditions.IsSpringBootProject;
1919
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection;
20+
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSectionHelper;
2021
import org.springframework.sbm.engine.context.ProjectContext;
2122
import org.springframework.sbm.java.api.JavaSource;
2223

@@ -26,7 +27,7 @@
2627
/**
2728
* @author Fabian Krüger
2829
*/
29-
public class UpgradeSpringBootVersionHelper implements SpringBootUpgradeReportSection.Helper<String> {
30+
public class UpgradeSpringBootVersionHelper extends SpringBootUpgradeReportSectionHelper<String> {
3031

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

0 commit comments

Comments
 (0)