mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-10-10 19:39:01 +00:00
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. See gh-47980 Signed-off-by: Scott Frederick <scottyfred@gmail.com>
This commit is contained in:
committed by
Stéphane Nicoll
parent
e1c33a7e3a
commit
78ea236e13
+1
@@ -59,6 +59,7 @@ public abstract class CheckAdditionalSpringConfigurationMetadata extends SourceT
|
||||
ConfigurationPropertiesAnalyzer analyzer = new ConfigurationPropertiesAnalyzer(getSource().getFiles());
|
||||
Report report = new Report(this.projectDir);
|
||||
analyzer.analyzeSort(report);
|
||||
analyzer.analyzeDeprecationSince(report);
|
||||
File reportFile = getReportLocation().get().getAsFile();
|
||||
report.write(reportFile);
|
||||
if (report.hasProblems()) {
|
||||
|
||||
+1
@@ -66,6 +66,7 @@ public abstract class CheckManualSpringConfigurationMetadata extends DefaultTask
|
||||
Report report = new Report(this.projectDir);
|
||||
analyzer.analyzeSort(report);
|
||||
analyzer.analyzePropertyDescription(report, getExclusions().get());
|
||||
analyzer.analyzeDeprecationSince(report);
|
||||
File reportFile = getReportLocation().get().getAsFile();
|
||||
report.write(reportFile);
|
||||
if (report.hasProblems()) {
|
||||
|
||||
+20
@@ -133,6 +133,26 @@ class ConfigurationPropertiesAnalyzer {
|
||||
return property.get("description") != null;
|
||||
}
|
||||
|
||||
void analyzeDeprecationSince(Report report) throws IOException {
|
||||
for (File source : this.sources) {
|
||||
report.registerAnalysis(source, analyzeDeprecationSince(source));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Analysis analyzeDeprecationSince(File source) throws IOException {
|
||||
Analysis analysis = new Analysis("The following properties are deprecated without a 'since' version:");
|
||||
Map<String, Object> json = readJsonContent(source);
|
||||
List<Map<String, Object>> properties = (List<Map<String, Object>>) json.get("properties");
|
||||
properties.stream().filter((property) -> property.containsKey("deprecation")).forEach((property) -> {
|
||||
Map<String, Object> deprecation = (Map<String, Object>) property.get("deprecation");
|
||||
if (!deprecation.containsKey("since")) {
|
||||
analysis.addItem(property.get("name").toString());
|
||||
}
|
||||
});
|
||||
return analysis;
|
||||
}
|
||||
|
||||
private Map<String, Object> readJsonContent(File source) throws IOException {
|
||||
return this.objectMapperSupplier.obtain().readValue(source, new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
|
||||
+26
@@ -115,6 +115,32 @@ class ConfigurationPropertiesAnalyzerTests {
|
||||
.satisfies(((analysis) -> assertThat(analysis.getItems()).containsExactly("def")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void analyzeDeprecatedPropertyWithMissingSince(@TempDir File tempDir) throws IOException {
|
||||
File metadata = new File(tempDir, "metadata.json");
|
||||
Files.writeString(metadata.toPath(), """
|
||||
{ "properties": [
|
||||
{
|
||||
"name": "abc",
|
||||
"description": "This is abc.",
|
||||
"deprecation": { "reason": "abc reason", "since": "3.0.0" }
|
||||
},
|
||||
{ "name": "def", "description": "This is def." },
|
||||
{
|
||||
"name": "xyz",
|
||||
"description": "This is xyz.",
|
||||
"deprecation": { "reason": "xyz reason" }
|
||||
}
|
||||
]
|
||||
}""");
|
||||
Report report = new Report(tempDir);
|
||||
ConfigurationPropertiesAnalyzer analyzer = new ConfigurationPropertiesAnalyzer(List.of(metadata));
|
||||
analyzer.analyzeDeprecationSince(report);
|
||||
assertThat(report.hasProblems()).isTrue();
|
||||
assertThat(report.getAnalyses(metadata)).singleElement()
|
||||
.satisfies(((analysis) -> assertThat(analysis.getItems()).containsExactly("xyz")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void writeEmptyReport(@TempDir File tempDir) throws IOException {
|
||||
assertThat(writeToFile(tempDir, new Report(tempDir))).hasContent("No problems found.");
|
||||
|
||||
+456
-228
File diff suppressed because it is too large
Load Diff
+495
-248
File diff suppressed because it is too large
Load Diff
+34
-17
@@ -42,7 +42,8 @@
|
||||
"description": "Log file name (for instance, `myapp.log`). Names can be an exact location or relative to the current directory.",
|
||||
"deprecation": {
|
||||
"replacement": "logging.file.name",
|
||||
"level": "error"
|
||||
"level": "error",
|
||||
"since": "2.2.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -52,7 +53,8 @@
|
||||
"sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener",
|
||||
"defaultValue": false,
|
||||
"deprecation": {
|
||||
"replacement": "logging.logback.rollingpolicy.clean-history-on-start"
|
||||
"replacement": "logging.logback.rollingpolicy.clean-history-on-start",
|
||||
"since": "2.4.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -62,7 +64,8 @@
|
||||
"sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener",
|
||||
"defaultValue": 7,
|
||||
"deprecation": {
|
||||
"replacement": "logging.logback.rollingpolicy.max-history"
|
||||
"replacement": "logging.logback.rollingpolicy.max-history",
|
||||
"since": "2.4.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -72,7 +75,8 @@
|
||||
"sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener",
|
||||
"defaultValue": "10MB",
|
||||
"deprecation": {
|
||||
"replacement": "logging.logback.rollingpolicy.max-file-size"
|
||||
"replacement": "logging.logback.rollingpolicy.max-file-size",
|
||||
"since": "2.4.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -94,7 +98,8 @@
|
||||
"sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener",
|
||||
"defaultValue": "0B",
|
||||
"deprecation": {
|
||||
"replacement": "logging.logback.rollingpolicy.total-size-cap"
|
||||
"replacement": "logging.logback.rollingpolicy.total-size-cap",
|
||||
"since": "2.4.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -169,7 +174,8 @@
|
||||
"description": "Location of the log file. For instance, `/var/log`.",
|
||||
"deprecation": {
|
||||
"replacement": "logging.file.path",
|
||||
"level": "error"
|
||||
"level": "error",
|
||||
"since": "2.2.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -211,7 +217,8 @@
|
||||
"sourceType": "org.springframework.boot.context.logging.LoggingApplicationListener",
|
||||
"defaultValue": "${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz",
|
||||
"deprecation": {
|
||||
"replacement": "logging.logback.rollingpolicy.file-name-pattern"
|
||||
"replacement": "logging.logback.rollingpolicy.file-name-pattern",
|
||||
"since": "2.4.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -349,7 +356,8 @@
|
||||
"description": "Application index.",
|
||||
"deprecation": {
|
||||
"level": "error",
|
||||
"reason": "Application context ids are now unique by default."
|
||||
"reason": "Application context ids are now unique by default.",
|
||||
"since": "2.0.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -374,7 +382,8 @@
|
||||
"type": "java.lang.Integer",
|
||||
"deprecation": {
|
||||
"level": "error",
|
||||
"reason": "Support for image banners has been removed."
|
||||
"reason": "Support for image banners has been removed.",
|
||||
"since": "3.0.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -382,7 +391,8 @@
|
||||
"type": "java.lang.Integer",
|
||||
"deprecation": {
|
||||
"level": "error",
|
||||
"reason": "Support for image banners has been removed."
|
||||
"reason": "Support for image banners has been removed.",
|
||||
"since": "3.0.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -390,7 +400,8 @@
|
||||
"type": "java.lang.Boolean",
|
||||
"deprecation": {
|
||||
"level": "error",
|
||||
"reason": "Support for image banners has been removed."
|
||||
"reason": "Support for image banners has been removed.",
|
||||
"since": "3.0.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -398,7 +409,8 @@
|
||||
"type": "org.springframework.core.io.Resource",
|
||||
"deprecation": {
|
||||
"level": "error",
|
||||
"reason": "Support for image banners has been removed."
|
||||
"reason": "Support for image banners has been removed.",
|
||||
"since": "3.0.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -406,7 +418,8 @@
|
||||
"type": "java.lang.Integer",
|
||||
"deprecation": {
|
||||
"level": "error",
|
||||
"reason": "Support for image banners has been removed."
|
||||
"reason": "Support for image banners has been removed.",
|
||||
"since": "3.0.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -414,7 +427,8 @@
|
||||
"type": "org.springframework.boot.ImageBanner$PixelMode",
|
||||
"deprecation": {
|
||||
"level": "error",
|
||||
"reason": "Support for image banners has been removed."
|
||||
"reason": "Support for image banners has been removed.",
|
||||
"since": "3.0.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -422,7 +436,8 @@
|
||||
"type": "java.lang.Integer",
|
||||
"deprecation": {
|
||||
"level": "error",
|
||||
"reason": "Support for image banners has been removed."
|
||||
"reason": "Support for image banners has been removed.",
|
||||
"since": "3.0.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -541,7 +556,8 @@
|
||||
"description": "Display the banner when the application runs.",
|
||||
"defaultValue": true,
|
||||
"deprecation": {
|
||||
"replacement": "spring.main.banner-mode"
|
||||
"replacement": "spring.main.banner-mode",
|
||||
"since": "1.3.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -562,7 +578,8 @@
|
||||
"sourceType": "org.springframework.boot.SpringApplication",
|
||||
"description": "Run the application in a web environment (auto-detected by default).",
|
||||
"deprecation": {
|
||||
"replacement": "spring.main.web-application-type"
|
||||
"replacement": "spring.main.web-application-type",
|
||||
"since": "2.0.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user