Browse Source

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>
pull/48129/head
Scott Frederick 1 month ago committed by Stéphane Nicoll
parent
commit
78ea236e13
  1. 1
      buildSrc/src/main/java/org/springframework/boot/build/context/properties/CheckAdditionalSpringConfigurationMetadata.java
  2. 1
      buildSrc/src/main/java/org/springframework/boot/build/context/properties/CheckManualSpringConfigurationMetadata.java
  3. 20
      buildSrc/src/main/java/org/springframework/boot/build/context/properties/ConfigurationPropertiesAnalyzer.java
  4. 26
      buildSrc/src/test/java/org/springframework/boot/build/context/properties/ConfigurationPropertiesAnalyzerTests.java
  5. 684
      spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json
  6. 743
      spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json
  7. 51
      spring-boot-project/spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json

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

@ -59,6 +59,7 @@ public abstract class CheckAdditionalSpringConfigurationMetadata extends SourceT @@ -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
buildSrc/src/main/java/org/springframework/boot/build/context/properties/CheckManualSpringConfigurationMetadata.java

@ -66,6 +66,7 @@ public abstract class CheckManualSpringConfigurationMetadata extends DefaultTask @@ -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
buildSrc/src/main/java/org/springframework/boot/build/context/properties/ConfigurationPropertiesAnalyzer.java

@ -133,6 +133,26 @@ class ConfigurationPropertiesAnalyzer { @@ -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
buildSrc/src/test/java/org/springframework/boot/build/context/properties/ConfigurationPropertiesAnalyzerTests.java

@ -115,6 +115,32 @@ class ConfigurationPropertiesAnalyzerTests { @@ -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.");

684
spring-boot-project/spring-boot-actuator-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json

File diff suppressed because it is too large Load Diff

743
spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json

File diff suppressed because it is too large Load Diff

51
spring-boot-project/spring-boot/src/main/resources/META-INF/additional-spring-configuration-metadata.json

@ -42,7 +42,8 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -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 @@ @@ -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"
}
},
{

Loading…
Cancel
Save