diff --git a/buildSrc/src/main/java/org/springframework/boot/build/context/properties/DocumentConfigurationProperties.java b/buildSrc/src/main/java/org/springframework/boot/build/context/properties/DocumentConfigurationProperties.java index a07ea58611b..c14fcaf1202 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/context/properties/DocumentConfigurationProperties.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/context/properties/DocumentConfigurationProperties.java @@ -106,7 +106,7 @@ public abstract class DocumentConfigurationProperties extends DefaultTask { config.accept("spring.ssl"); config.accept("spring.task"); config.accept("spring.threads"); - config.accept("spring.tools.properties-migrator"); + config.accept("spring.properties"); config.accept("spring.validation"); config.accept("spring.mandatory-file-encoding"); config.accept("info"); diff --git a/core/spring-boot-properties-migrator/src/main/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationListener.java b/core/spring-boot-properties-migrator/src/main/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationListener.java index a1b8803a36a..89aa869c30a 100644 --- a/core/spring-boot-properties-migrator/src/main/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationListener.java +++ b/core/spring-boot-properties-migrator/src/main/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationListener.java @@ -18,7 +18,7 @@ package org.springframework.boot.context.properties.migrator; import java.io.IOException; import java.io.InputStream; -import java.util.Locale; +import java.util.function.Predicate; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -35,6 +35,7 @@ import org.springframework.context.ApplicationListener; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.util.Assert; /** * An {@link ApplicationListener} that inspects the {@link ConfigurableEnvironment @@ -49,7 +50,7 @@ class PropertiesMigrationListener implements ApplicationListener false; - case ON_ERROR -> report.getErrorReport() != null; - case ON_WARNING -> report.getErrorReport() != null || report.getWarningReport() != null; - }; - } - /** * Conditions under which property migration should cause application startup to fail. */ - enum Fail { + public enum Fail { /** * Do not fail application startup due to migration warnings or errors. */ - NEVER, + NEVER((report) -> false), /** * Fail application startup if the migration report contains errors. */ - ON_ERROR, + ON_ERROR((report) -> report.getErrorReport() != null), /** * Fail application startup if the migration report contains warnings or errors. */ - ON_WARNING + ON_WARNING((report) -> report.getErrorReport() != null || report.getWarningReport() != null); + + private final Predicate predicate; + + Fail(Predicate predicate) { + this.predicate = predicate; + } + + void check(PropertiesMigrationReport report) { + boolean failed = this.predicate.test(report); + Assert.state(!failed, "Found configuration keys that need to be migrated"); + } } diff --git a/core/spring-boot-properties-migrator/src/main/resources/META-INF/spring-configuration-metadata.json b/core/spring-boot-properties-migrator/src/main/resources/META-INF/spring-configuration-metadata.json index d48f7b2461b..f71b7151d9d 100644 --- a/core/spring-boot-properties-migrator/src/main/resources/META-INF/spring-configuration-metadata.json +++ b/core/spring-boot-properties-migrator/src/main/resources/META-INF/spring-configuration-metadata.json @@ -1,7 +1,7 @@ { "properties": [ { - "name": "spring.tools.properties-migrator.fail", + "name": "spring.properties.migrator.fail", "type": "org.springframework.boot.context.properties.migrator.PropertiesMigrationListener$Fail", "description": "When the application should fail to start because of configuration keys that need to be migrated.", "sourceType": "org.springframework.boot.context.properties.migrator.PropertiesMigrationListener", diff --git a/core/spring-boot-properties-migrator/src/test/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationListenerTests.java b/core/spring-boot-properties-migrator/src/test/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationListenerTests.java index 364d201a539..5548e96f72f 100644 --- a/core/spring-boot-properties-migrator/src/test/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationListenerTests.java +++ b/core/spring-boot-properties-migrator/src/test/java/org/springframework/boot/context/properties/migrator/PropertiesMigrationListenerTests.java @@ -61,37 +61,37 @@ class PropertiesMigrationListenerTests { @Test void failNeverWithRenamedKeyStarts() { assertThatNoException().isThrownBy(() -> this.context = createSampleApplication() - .run("--spring.tools.properties-migrator.fail=never", "--logging.file=test.log")); + .run("--spring.properties.migrator.fail=never", "--logging.file=test.log")); } @Test void failNeverWithUnsupportedKeyStarts() { assertThatNoException().isThrownBy(() -> this.context = createSampleApplication() - .run("--spring.tools.properties-migrator.fail=never", "--spring.banner.image.width=10")); + .run("--spring.properties.migrator.fail=never", "--spring.banner.image.width=10")); } @Test void failOnErrorWithRenamedKeyStarts() { assertThatNoException().isThrownBy(() -> this.context = createSampleApplication() - .run("--spring.tools.properties-migrator.fail=on-error", "--logging.file=test.log")); + .run("--spring.properties.migrator.fail=on-error", "--logging.file=test.log")); } @Test void failOnErrorWithUnsupportedKeyFails() { assertThatIllegalStateException().isThrownBy(() -> createSampleApplication() - .run("--spring.tools.properties-migrator.fail=on-error", "--spring.banner.image.width=10")); + .run("--spring.properties.migrator.fail=on-error", "--spring.banner.image.width=10")); } @Test void failOnWarningWithRenamedKeyFails() { assertThatIllegalStateException().isThrownBy(() -> createSampleApplication() - .run("--spring.tools.properties-migrator.fail=on-warning", "--logging.file=test.log")); + .run("--spring.properties.migrator.fail=on-warning", "--logging.file=test.log")); } @Test void failOnWarningWithUnsupportedKeyFails() { assertThatIllegalStateException().isThrownBy(() -> createSampleApplication() - .run("--spring.tools.properties-migrator.fail=on-warning", "--spring.banner.image.width=10")); + .run("--spring.properties.migrator.fail=on-warning", "--spring.banner.image.width=10")); } private SpringApplication createSampleApplication() { diff --git a/documentation/spring-boot-docs/src/docs/antora/modules/ROOT/pages/upgrading.adoc b/documentation/spring-boot-docs/src/docs/antora/modules/ROOT/pages/upgrading.adoc index a1724a03b20..0c92464755d 100644 --- a/documentation/spring-boot-docs/src/docs/antora/modules/ROOT/pages/upgrading.adoc +++ b/documentation/spring-boot-docs/src/docs/antora/modules/ROOT/pages/upgrading.adoc @@ -49,7 +49,7 @@ To enable that feature, add the following dependency to your project: ---- -The configprop:spring.tools.properties-migrator.fail[] property controls whether migration warnings or errors cause the application to fail to start: +The configprop:spring.properties.migrator.fail[] property controls whether migration warnings or errors cause the application to fail to start: * `never`: do not fail application startup because of migration warnings or errors (default). * `on-error`: fail when properties that are no longer supported are found.