Skip to content

Commit 788391d

Browse files
authored
Merge branch 'main' into spring-projects-experimentalgh-428
2 parents 6322f4d + 17e75ac commit 788391d

File tree

29 files changed

+259
-495
lines changed

29 files changed

+259
-495
lines changed

components/sbm-core/src/main/java/org/springframework/sbm/build/impl/OpenRewriteMavenBuildFile.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ public List<Dependency> getRequestedDependencies() {
286286
artifactId,
287287
d.getScope() != null ? Scope.fromName(d.getScope()) : null
288288
);
289+
if (dependencies.isEmpty()) {
290+
// requested dependency from another module in this multi-module project won't be resolvable
291+
return d;
292+
}
289293
ResolvedDependency resolvedDependency = dependencies.get(0);
290294
d.setVersion(resolvedDependency.getVersion());
291295
d.setClassifier(resolvedDependency.getClassifier());

components/sbm-core/src/main/java/org/springframework/sbm/java/impl/OpenRewriteMember.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public Annotation getAnnotation(String annotation) {
8282
} else if (type1.getClass().isAssignableFrom(JavaType.Class.class)) {
8383
JavaType.Class type = (JavaType.Class) a.getType();
8484
if (type == null) {
85-
String simpleName = ((J.Identifier) a.getAnnotationType()).getSimpleName();
85+
String simpleName = a.getSimpleName();
8686
log.error("Could not get Type for annotation: '" + simpleName + "' while comparing with '" + annotation + "'.");
8787
return false;
8888
}

components/sbm-core/src/main/java/org/springframework/sbm/java/impl/OpenRewriteType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ private List<J.Annotation> findORAnnotations(String annotation) {
178178
.stream()
179179
.filter(a -> {
180180
Object typeObject = a.getAnnotationType().getType();
181-
String simpleName = ((J.Identifier) a.getAnnotationType()).getSimpleName();
181+
String simpleName = a.getSimpleName();
182182
if (JavaType.Unknown.class.isInstance(typeObject)) {
183183
log.warn("Could not resolve Type for annotation: '" + simpleName + "' while comparing with '" + annotation + "'.");
184184
return false;

components/sbm-recipes-boot-upgrade/pom.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363
<artifactId>spring-asciidoctor-backends</artifactId>
6464
<version>${spring-asciidoctor-backends.version}</version>
6565
</dependency>
66+
<dependency>
67+
<groupId>org.openrewrite.recipe</groupId>
68+
<artifactId>rewrite-spring</artifactId>
69+
</dependency>
6670
<dependency>
6771
<groupId>org.springframework.boot</groupId>
6872
<artifactId>spring-boot-starter-test</artifactId>
@@ -91,7 +95,6 @@
9195
<scope>test</scope>
9296
</dependency>
9397
</dependencies>
94-
9598
<repositories>
9699
<repository>
97100
<id>spring-release</id>
@@ -102,4 +105,4 @@
102105
</snapshots>
103106
</repository>
104107
</repositories>
105-
</project>
108+
</project>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
4444
// find System.getSecurityManager()
4545

4646
J.MethodInvocation m = super.visitMethodInvocation(method, executionContext);
47-
if("java.lang.System".equals(m.getMethodType().getDeclaringType().getFullyQualifiedName()) && "getSecurityManager".equals(m.getName().getSimpleName())) {
47+
if(m.getMethodType() != null && "java.lang.System".equals(m.getMethodType().getDeclaringType().getFullyQualifiedName()) && "getSecurityManager".equals(m.getName().getSimpleName())) {
4848
return m.withMarkers(m.getMarkers().addIfAbsent(new SearchResult(UUID.randomUUID(), "Indicator for usage for SecurityManager: calls to System.getSecurityManager()")));
4949
}
5050
return m;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
2222

2323
import java.nio.file.Path;
24-
import java.util.ArrayList;
2524
import java.util.List;
2625
import java.util.Map;
2726
import java.util.stream.Collectors;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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.report.helper;
18+
19+
import org.openrewrite.ExecutionContext;
20+
import org.openrewrite.TreeVisitor;
21+
import org.openrewrite.internal.lang.Nullable;
22+
import org.openrewrite.java.search.UsesType;
23+
import org.openrewrite.java.spring.boot3.RemoveConstructorBindingAnnotation;
24+
import org.openrewrite.java.tree.J;
25+
import org.springframework.sbm.boot.upgrade_27_30.report.SpringBootUpgradeReportSection;
26+
import org.springframework.sbm.engine.context.ProjectContext;
27+
import org.springframework.sbm.engine.recipe.OpenRewriteSourceFilesFinder;
28+
import org.springframework.sbm.project.resource.RewriteSourceFileHolder;
29+
import org.springframework.sbm.support.openrewrite.GenericOpenRewriteRecipe;
30+
31+
import java.util.List;
32+
import java.util.Map;
33+
import java.util.stream.Collectors;
34+
35+
36+
public class ConstructorBindingHelper implements SpringBootUpgradeReportSection.Helper<List<String>> {
37+
38+
private List<String> constructorBindingFiles;
39+
40+
@Override
41+
public String getDescription() {
42+
return "";
43+
}
44+
45+
@Override
46+
public boolean evaluate(ProjectContext context) {
47+
48+
GenericOpenRewriteRecipe<TreeVisitor<?, ExecutionContext>> recipe =
49+
new GenericOpenRewriteRecipe<>(() -> new UsesType("org.springframework.boot.context.properties.ConstructorBinding"));
50+
51+
List<RewriteSourceFileHolder<J.CompilationUnit>> rewriteSourceFileHolders =
52+
context.getProjectJavaSources().find(recipe);
53+
54+
constructorBindingFiles = rewriteSourceFileHolders
55+
.stream()
56+
.map(k -> k.getAbsolutePath().toString())
57+
.collect(Collectors.toList());
58+
59+
return !rewriteSourceFileHolders.isEmpty();
60+
}
61+
62+
@Override
63+
public Map<String, List<String>> getData(ProjectContext context) {
64+
65+
return Map.of("files", constructorBindingFiles);
66+
}
67+
}

components/sbm-recipes-boot-upgrade/src/main/resources/recipes/boot-new-report.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,33 @@
130130
recipe: boot-2.7-3.0-upgrade-report
131131
contributors:
132132
- "Sandeep Nagaraj[@sanagaraj-pivotal]"
133+
134+
- title: Constructor Binding
135+
helper: org.springframework.sbm.boot.upgrade_27_30.report.helper.ConstructorBindingHelper
136+
change: |-
137+
When using constructor bound @ConfigurationProperties the @ConstructorBinding annotation
138+
is no longer required if the class has a single parameterized constructor.
139+
If you have more than one constructor, you’ll still need to use `@ConstructorBinding`
140+
to tell Spring Boot which one to use.
141+
142+
For most users, this updated logic will allow for simpler `@ConfigurationProperties`
143+
classes. If, however, you have a `@ConfigurationProperties` and you want to inject
144+
beans into the constructor rather than binding it, you’ll now need to add an
145+
`@Autowired` annotation.
146+
affected: |-
147+
We found usage of `@ConstructorBinding` in following files:
148+
149+
<#list files as file>
150+
* ${file}
151+
</#list>
152+
remediation: |-
153+
Remove `@ConstructorBinding` if it matches the criteria, please refer issue: https://github.com/spring-projects-experimental/spring-boot-migrator/issues/166[#166]
154+
for more information
155+
gitHubIssue: 166
156+
recipe: boot-2.7-3.0-upgrade-report
157+
contributors:
158+
- "Sandeep Nagaraj[@sanagaraj-pivotal]"
159+
133160
footer: |-
134161
We want to say thank you to all Contributors:
135162

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import org.openrewrite.InMemoryExecutionContext;
2121
import org.openrewrite.Recipe;
2222
import org.openrewrite.Result;
23-
import org.openrewrite.java.JavaParser;
24-
import org.openrewrite.java.tree.J;
2523
import org.openrewrite.maven.MavenParser;
2624
import org.openrewrite.maven.UpgradeDependencyVersion;
2725
import org.openrewrite.xml.tree.Xml;

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

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@
1515
*/
1616
package org.springframework.sbm.boot.upgrade_27_30.report;
1717

18-
import org.assertj.core.api.Assertions;
1918
import org.junit.jupiter.api.DisplayName;
2019
import org.junit.jupiter.api.Test;
2120
import org.springframework.sbm.boot.properties.SpringApplicationPropertiesPathMatcher;
2221
import org.springframework.sbm.boot.properties.SpringBootApplicationPropertiesRegistrar;
2322
import org.springframework.sbm.engine.context.ProjectContext;
2423
import org.springframework.sbm.project.resource.TestProjectContext;
2524

26-
import java.nio.file.Path;
27-
import java.util.Map;
2825

2926
/**
3027
* @author Fabian Krüger
@@ -44,26 +41,25 @@ void changesToDataPropertiesSection_renders() {
4441
.fromProjectContext(context)
4542
.shouldRenderAs(
4643
"""
47-
=== Changes to Data Properties
48-
Issue: https://github.com/spring-projects-experimental/spring-boot-migrator/issues/441[#441], Contributors: https://github.com/fabapp2[@fabapp2^, role="ext-link"]
49-
50-
==== What Changed
51-
The data prefix has been reserved for Spring Data and any properties under the `data` prefix imply that Spring
52-
Data is required on the classpath.
53-
54-
==== Why is the application affected
55-
The scan found properties with `spring.data` prefix but no dependency matching `org.springframework.data:.*`.
56-
57-
* file://<PATH>/src/main/resources/application.properties[`src/main/resources/application.properties`]
58-
** `spring.data.foo`
59-
* file://<PATH>/src/main/resources/application-another.properties[`src/main/resources/application-another.properties`]
60-
** `spring.data.here`
61-
62-
==== Remediation
63-
Either add `spring-data` dependency, rename the property or remove it in case it's not required anymore.
64-
65-
""",
66-
Map.of("PATH", Path.of(".").toAbsolutePath().resolve(TestProjectContext.getDefaultProjectRoot()).toString()));
44+
=== Changes to Data Properties
45+
Issue: https://github.com/spring-projects-experimental/spring-boot-migrator/issues/441[#441], Contributors: https://github.com/fabapp2[@fabapp2^, role="ext-link"]
46+
47+
==== What Changed
48+
The data prefix has been reserved for Spring Data and any properties under the `data` prefix imply that Spring
49+
Data is required on the classpath.
50+
51+
==== Why is the application affected
52+
The scan found properties with `spring.data` prefix but no dependency matching `org.springframework.data:.*`.
53+
54+
* file://<PATH>/src/main/resources/application.properties[`src/main/resources/application.properties`]
55+
** `spring.data.foo`
56+
* file://<PATH>/src/main/resources/application-another.properties[`src/main/resources/application-another.properties`]
57+
** `spring.data.here`
58+
59+
==== Remediation
60+
Either add `spring-data` dependency, rename the property or remove it in case it's not required anymore.
61+
62+
""");
6763
}
6864

6965
@Test

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.springframework.sbm.engine.recipe.Action;
2222
import org.springframework.sbm.engine.recipe.Recipe;
2323
import org.springframework.sbm.engine.recipe.Recipes;
24+
import org.springframework.sbm.project.resource.TestProjectContext;
2425
import org.springframework.sbm.test.RecipeTestSupport;
2526
import org.springframework.sbm.testhelper.common.utils.TestDiff;
2627
import org.springframework.test.util.ReflectionTestUtils;
@@ -76,7 +77,7 @@ public Assertion(BuilderData builderData) {
7677

7778

7879
public void shouldRenderAs(String expectedOutput) {
79-
shouldRenderAs(expectedOutput, Map.of());
80+
shouldRenderAs(expectedOutput, defaultMap());
8081
}
8182

8283
public void shouldRenderAs(String expectedOutput, Map<String, String> templateVariables) {
@@ -90,7 +91,7 @@ public void shouldNotRender() {
9091
}
9192

9293
public void shouldStartWith(String expectedOutput) {
93-
shouldStartWith(expectedOutput, Map.of());
94+
shouldStartWith(expectedOutput, defaultMap());
9495
}
9596

9697
public void shouldStartWith(String expectedOutput, Map<String, String> templateVariables) {
@@ -99,6 +100,16 @@ public void shouldStartWith(String expectedOutput, Map<String, String> templateV
99100
verify(assertion);
100101
}
101102

103+
104+
private Map<String, String> defaultMap() {
105+
String path = Path
106+
.of(".")
107+
.toAbsolutePath()
108+
.resolve(TestProjectContext.getDefaultProjectRoot()).toString();
109+
110+
return Map.of("PATH", path);
111+
}
112+
102113
private void verifyDoesNotRender() {
103114
if(SectionBuilderData.class.isInstance(builderData)) {
104115
SectionBuilderData sectionBuilderData = SectionBuilderData.class.cast(builderData);
@@ -148,7 +159,6 @@ public void writeReport(String s, Path outputDir, String filename) {
148159
action.apply(reportBuilderData.getContext());
149160
});
150161
} else if(SectionBuilderData.class.isInstance(builderData)) {
151-
SectionBuilderData sectionBuilderData = SectionBuilderData.class.cast(builderData);
152162
withRecipes(recipes -> {
153163
Recipe recipe = recipes.getRecipeByName("boot-2.7-3.0-upgrade-report2").get();
154164
SpringBootUpgradeReportAction action = (SpringBootUpgradeReportAction) recipe.getActions().get(0);

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import org.springframework.sbm.engine.context.ProjectContext;
2222
import org.springframework.sbm.project.resource.TestProjectContext;
2323

24-
import java.nio.file.Path;
25-
import java.util.Map;
2624

2725
public class BannerSupportHelperTest {
2826

@@ -55,7 +53,6 @@ public void rendersBannerSupportInformation() {
5553
==== Remediation
5654
remove image banners and replace it with text-banner with banner.txt file
5755
58-
""",
59-
Map.of("PATH", Path.of(".").toAbsolutePath().resolve(TestProjectContext.getDefaultProjectRoot()).toString()));
56+
""");
6057
}
6158
}

0 commit comments

Comments
 (0)