Skip to content

Commit d9663c1

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 f71b450 commit d9663c1

File tree

7 files changed

+1033
-493
lines changed

7 files changed

+1033
-493
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ void check() throws IOException {
5959
ConfigurationPropertiesAnalyzer analyzer = new ConfigurationPropertiesAnalyzer(getSource().getFiles());
6060
Report report = new Report(this.projectDir);
6161
analyzer.analyzeSort(report);
62+
analyzer.analyzeDeprecationSince(report);
6263
File reportFile = getReportLocation().get().getAsFile();
6364
report.write(reportFile);
6465
if (report.hasProblems()) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ void check() throws IOException {
6666
Report report = new Report(this.projectDir);
6767
analyzer.analyzeSort(report);
6868
analyzer.analyzePropertyDescription(report, getExclusions().get());
69+
analyzer.analyzeDeprecationSince(report);
6970
File reportFile = getReportLocation().get().getAsFile();
7071
report.write(reportFile);
7172
if (report.hasProblems()) {

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,26 @@ private boolean isDescribed(Map<String, Object> property) {
133133
return property.get("description") != null;
134134
}
135135

136+
void analyzeDeprecationSince(Report report) throws IOException {
137+
for (File source : this.sources) {
138+
report.registerAnalysis(source, analyzeDeprecationSince(source));
139+
}
140+
}
141+
142+
@SuppressWarnings("unchecked")
143+
private Analysis analyzeDeprecationSince(File source) throws IOException {
144+
Analysis analysis = new Analysis("The following properties are deprecated without a 'since' version:");
145+
Map<String, Object> json = readJsonContent(source);
146+
List<Map<String, Object>> properties = (List<Map<String, Object>>) json.get("properties");
147+
properties.stream().filter((property) -> property.containsKey("deprecation")).forEach((property) -> {
148+
Map<String, Object> deprecation = (Map<String, Object>) property.get("deprecation");
149+
if (!deprecation.containsKey("since")) {
150+
analysis.addItem(property.get("name").toString());
151+
}
152+
});
153+
return analysis;
154+
}
155+
136156
private Map<String, Object> readJsonContent(File source) throws IOException {
137157
return this.objectMapperSupplier.obtain().readValue(source, new TypeReference<Map<String, Object>>() {
138158
});

buildSrc/src/test/java/org/springframework/boot/build/context/properties/ConfigurationPropertiesAnalyzerTests.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,32 @@ void analyzePropertyDescriptionWithMissingDescription(@TempDir File tempDir) thr
115115
.satisfies(((analysis) -> assertThat(analysis.getItems()).containsExactly("def")));
116116
}
117117

118+
@Test
119+
void analyzeDeprecatedPropertyWithMissingSince(@TempDir File tempDir) throws IOException {
120+
File metadata = new File(tempDir, "metadata.json");
121+
Files.writeString(metadata.toPath(), """
122+
{ "properties": [
123+
{
124+
"name": "abc",
125+
"description": "This is abc.",
126+
"deprecation": { "reason": "abc reason", "since": "3.0.0" }
127+
},
128+
{ "name": "def", "description": "This is def." },
129+
{
130+
"name": "xyz",
131+
"description": "This is xyz.",
132+
"deprecation": { "reason": "xyz reason" }
133+
}
134+
]
135+
}""");
136+
Report report = new Report(tempDir);
137+
ConfigurationPropertiesAnalyzer analyzer = new ConfigurationPropertiesAnalyzer(List.of(metadata));
138+
analyzer.analyzeDeprecationSince(report);
139+
assertThat(report.hasProblems()).isTrue();
140+
assertThat(report.getAnalyses(metadata)).singleElement()
141+
.satisfies(((analysis) -> assertThat(analysis.getItems()).containsExactly("xyz")));
142+
}
143+
118144
@Test
119145
void writeEmptyReport(@TempDir File tempDir) throws IOException {
120146
assertThat(writeToFile(tempDir, new Report(tempDir))).hasContent("No problems found.");

0 commit comments

Comments
 (0)