Skip to content

Commit 3f58fcb

Browse files
Add since to deprecations in config metadata JSON files
Add the `since` field to all deprecated properties in all additional-spring-configuration-metadata.json files in the project. Add to the CheckAdditionalSpringConfigurationMetadata build task to ensure that all deprecated properties have a non-empty `since` field. Signed-off-by: Scott Frederick <[email protected]>
1 parent 4460dcf commit 3f58fcb

File tree

4 files changed

+1004
-501
lines changed

4 files changed

+1004
-501
lines changed

buildSrc/src/main/java/org/springframework/boot/build/context/properties/CheckAdditionalSpringConfigurationMetadata.java

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
import java.util.List;
2929
import java.util.Map;
3030

31-
import com.fasterxml.jackson.core.JsonParseException;
32-
import com.fasterxml.jackson.databind.JsonMappingException;
3331
import com.fasterxml.jackson.databind.ObjectMapper;
3432
import org.gradle.api.file.FileTree;
3533
import org.gradle.api.file.RegularFileProperty;
@@ -65,7 +63,7 @@ public FileTree getSource() {
6563
}
6664

6765
@TaskAction
68-
void check() throws JsonParseException, IOException {
66+
void check() throws IOException {
6967
Report report = createReport();
7068
File reportFile = getReportLocation().get().getAsFile();
7169
Files.write(reportFile.toPath(), report, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
@@ -76,21 +74,22 @@ void check() throws JsonParseException, IOException {
7674
}
7775

7876
@SuppressWarnings("unchecked")
79-
private Report createReport() throws IOException, JsonParseException, JsonMappingException {
77+
private Report createReport() throws IOException {
8078
ObjectMapper objectMapper = new ObjectMapper();
8179
Report report = new Report();
8280
for (File file : getSource().getFiles()) {
8381
Analysis analysis = report.analysis(this.projectDir.toPath().relativize(file.toPath()));
8482
Map<String, Object> json = objectMapper.readValue(file, Map.class);
85-
check("groups", json, analysis);
86-
check("properties", json, analysis);
87-
check("hints", json, analysis);
83+
checkSorting("groups", json, analysis);
84+
checkSorting("properties", json, analysis);
85+
checkSorting("hints", json, analysis);
86+
checkPropertyDeprecationSince(json, analysis);
8887
}
8988
return report;
9089
}
9190

9291
@SuppressWarnings("unchecked")
93-
private void check(String key, Map<String, Object> json, Analysis analysis) {
92+
private void checkSorting(String key, Map<String, Object> json, Analysis analysis) {
9493
List<Map<String, Object>> groups = (List<Map<String, Object>>) json.getOrDefault(key, Collections.emptyList());
9594
List<String> names = groups.stream().map((group) -> (String) group.get("name")).toList();
9695
List<String> sortedNames = sortedCopy(names);
@@ -110,6 +109,18 @@ private List<String> sortedCopy(Collection<String> original) {
110109
return copy;
111110
}
112111

112+
@SuppressWarnings("unchecked")
113+
private void checkPropertyDeprecationSince(Map<String, Object> json, Analysis analysis) {
114+
List<Map<String, Object>> properties = (List<Map<String, Object>>) json.get("properties");
115+
properties.stream().filter((property) -> property.containsKey("deprecation")).forEach((property) -> {
116+
Map<String, Object> deprecation = (Map<String, Object>) property.get("deprecation");
117+
if (!deprecation.containsKey("since")) {
118+
analysis.problems.add("Property with name '" + property.get("name")
119+
+ "' contains 'deprecation' without 'since' attribute");
120+
}
121+
});
122+
}
123+
113124
private static final class Report implements Iterable<String> {
114125

115126
private final List<Analysis> analyses = new ArrayList<>();

0 commit comments

Comments
 (0)