diff --git a/spring-boot-project/pom.xml b/spring-boot-project/pom.xml
index d770d9c363b..6c62aa8799f 100644
--- a/spring-boot-project/pom.xml
+++ b/spring-boot-project/pom.xml
@@ -21,7 +21,7 @@
spring-boot-actuator
spring-boot-actuator-autoconfigure
spring-boot-autoconfigure
- spring-boot-configuration-analyzer
+ spring-boot-deprecated-properties-support
spring-boot-devtools
spring-boot-test
spring-boot-test-autoconfigure
diff --git a/spring-boot-project/spring-boot-configuration-analyzer/src/main/resources/META-INF/spring.factories b/spring-boot-project/spring-boot-configuration-analyzer/src/main/resources/META-INF/spring.factories
deleted file mode 100644
index 227d3af3284..00000000000
--- a/spring-boot-project/spring-boot-configuration-analyzer/src/main/resources/META-INF/spring.factories
+++ /dev/null
@@ -1,2 +0,0 @@
-org.springframework.context.ApplicationListener=\
-org.springframework.boot.configurationalayzer.LegacyPropertiesAnalyzerListener
\ No newline at end of file
diff --git a/spring-boot-project/spring-boot-configuration-analyzer/pom.xml b/spring-boot-project/spring-boot-deprecated-properties-support/pom.xml
similarity index 84%
rename from spring-boot-project/spring-boot-configuration-analyzer/pom.xml
rename to spring-boot-project/spring-boot-deprecated-properties-support/pom.xml
index 9058256c78f..1dae21e147e 100644
--- a/spring-boot-project/spring-boot-configuration-analyzer/pom.xml
+++ b/spring-boot-project/spring-boot-deprecated-properties-support/pom.xml
@@ -8,9 +8,9 @@
${revision}
../spring-boot-parent
- spring-boot-configuration-analyzer
- Spring Boot Configuration Analyzer
- Spring Boot Configuration Analyzer
+ spring-boot-deprecated-properties-support
+ Spring Boot Deprecated Properties Support
+ Spring Boot Deprecated Properties Support
${basedir}/../..
diff --git a/spring-boot-project/spring-boot-configuration-analyzer/src/main/java/org/springframework/boot/configurationalayzer/LegacyPropertiesAnalyzerListener.java b/spring-boot-project/spring-boot-deprecated-properties-support/src/main/java/org/springframework/boot/deprecatedproperties/DeprecatedPropertiesListener.java
similarity index 68%
rename from spring-boot-project/spring-boot-configuration-analyzer/src/main/java/org/springframework/boot/configurationalayzer/LegacyPropertiesAnalyzerListener.java
rename to spring-boot-project/spring-boot-deprecated-properties-support/src/main/java/org/springframework/boot/deprecatedproperties/DeprecatedPropertiesListener.java
index e1aa1b79ace..d7949c3773d 100644
--- a/spring-boot-project/spring-boot-configuration-analyzer/src/main/java/org/springframework/boot/configurationalayzer/LegacyPropertiesAnalyzerListener.java
+++ b/spring-boot-project/spring-boot-deprecated-properties-support/src/main/java/org/springframework/boot/deprecatedproperties/DeprecatedPropertiesListener.java
@@ -14,12 +14,10 @@
* limitations under the License.
*/
-package org.springframework.boot.configurationalayzer;
+package org.springframework.boot.deprecatedproperties;
import java.io.IOException;
import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -37,20 +35,21 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
/**
* An {@link ApplicationListener} that inspects the {@link ConfigurableEnvironment
- * environment} for legacy configuration keys. Automatically renames the keys that
- * have a matching replacement and log a report of what was discovered.
+ * environment} for deprecated configuration keys. Automatically renames the keys that
+ * have a matching replacement and log a report of what was discovered.
*
* @author Stephane Nicoll
* @since 2.0.0
*/
-public class LegacyPropertiesAnalyzerListener
+public class DeprecatedPropertiesListener
implements ApplicationListener {
- private static final Log logger = LogFactory.getLog(LegacyPropertiesAnalyzerListener.class);
+ private static final Log logger = LogFactory
+ .getLog(DeprecatedPropertiesListener.class);
- private LegacyPropertiesAnalysis analysis;
+ private DeprecatedPropertiesReport report;
- private boolean analysisLogged;
+ private boolean reported;
@Override
public void onApplicationEvent(SpringApplicationEvent event) {
@@ -65,49 +64,45 @@ public class LegacyPropertiesAnalyzerListener
private void onApplicationPreparedEvent(ApplicationPreparedEvent event) {
ConfigurationMetadataRepository repository = loadRepository();
- ConfigurableEnvironment environment =
- event.getApplicationContext().getEnvironment();
- LegacyPropertiesAnalyzer validator = new LegacyPropertiesAnalyzer(
- repository, environment);
- this.analysis = validator.analyseLegacyProperties();
- }
-
- private void logLegacyPropertiesAnalysis() {
- if (this.analysis == null || this.analysisLogged) {
- return;
- }
- String warningReport = this.analysis.createWarningReport();
- String errorReport = this.analysis.createErrorReport();
- if (warningReport != null) {
- logger.warn(warningReport);
- }
- if (errorReport != null) {
- logger.error(errorReport);
- }
- this.analysisLogged = true;
+ DeprecatedPropertiesReporter reporter = new DeprecatedPropertiesReporter(repository,
+ event.getApplicationContext().getEnvironment());
+ this.report = reporter.getReport();
}
private ConfigurationMetadataRepository loadRepository() {
try {
- ConfigurationMetadataRepositoryJsonBuilder builder = ConfigurationMetadataRepositoryJsonBuilder.create();
- for (InputStream inputStream : getResources()) {
- builder.withJsonResource(inputStream);
- }
- return builder.build();
+ return loadRepository(ConfigurationMetadataRepositoryJsonBuilder.create());
}
catch (IOException ex) {
throw new IllegalStateException("Failed to load metadata", ex);
}
}
- private List getResources() throws IOException {
+ private ConfigurationMetadataRepository loadRepository(
+ ConfigurationMetadataRepositoryJsonBuilder builder) throws IOException {
Resource[] resources = new PathMatchingResourcePatternResolver()
.getResources("classpath*:/META-INF/spring-configuration-metadata.json");
- List result = new ArrayList<>();
for (Resource resource : resources) {
- result.add(resource.getInputStream());
+ try (InputStream inputStream = resource.getInputStream()) {
+ builder.withJsonResource(inputStream);
+ }
+ }
+ return builder.build();
+ }
+
+ private void logLegacyPropertiesAnalysis() {
+ if (this.report == null || this.reported) {
+ return;
+ }
+ String warningReport = this.report.getWarningReport();
+ if (warningReport != null) {
+ logger.warn(warningReport);
+ }
+ String errorReport = this.report.getErrorReport();
+ if (errorReport != null) {
+ logger.error(errorReport);
}
- return result;
+ this.reported = true;
}
}
diff --git a/spring-boot-project/spring-boot-configuration-analyzer/src/main/java/org/springframework/boot/configurationalayzer/LegacyPropertiesAnalysis.java b/spring-boot-project/spring-boot-deprecated-properties-support/src/main/java/org/springframework/boot/deprecatedproperties/DeprecatedPropertiesReport.java
similarity index 53%
rename from spring-boot-project/spring-boot-configuration-analyzer/src/main/java/org/springframework/boot/configurationalayzer/LegacyPropertiesAnalysis.java
rename to spring-boot-project/spring-boot-deprecated-properties-support/src/main/java/org/springframework/boot/deprecatedproperties/DeprecatedPropertiesReport.java
index 0d52564e786..591bfdda041 100644
--- a/spring-boot-project/spring-boot-configuration-analyzer/src/main/java/org/springframework/boot/configurationalayzer/LegacyPropertiesAnalysis.java
+++ b/spring-boot-project/spring-boot-deprecated-properties-support/src/main/java/org/springframework/boot/deprecatedproperties/DeprecatedPropertiesReport.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.springframework.boot.configurationalayzer;
+package org.springframework.boot.deprecatedproperties;
import java.util.ArrayList;
import java.util.Collections;
@@ -28,32 +28,30 @@ import org.springframework.boot.configurationmetadata.ConfigurationMetadataPrope
import org.springframework.util.StringUtils;
/**
- * Describes the outcome of the environment analysis.
+ * Provides a deprecated properties report.
*
* @author Stephane Nicoll
*/
-class LegacyPropertiesAnalysis {
+class DeprecatedPropertiesReport {
- private final Map content = new LinkedHashMap<>();
+ private final Map content = new LinkedHashMap<>();
/**
- * Create a report for all the legacy properties that were automatically renamed. If
+ * Return a report for all the legacy properties that were automatically renamed. If
* no such legacy properties were found, return {@code null}.
* @return a report with the configurations keys that should be renamed
*/
- public String createWarningReport() {
- Map> content = this.content.entrySet().stream()
- .filter(e -> !e.getValue().handledProperties.isEmpty())
- .collect(Collectors.toMap(Map.Entry::getKey,
- e -> new ArrayList<>(e.getValue().handledProperties)));
+ public String getWarningReport() {
+ Map> content = getContent(
+ DeprecatedProperties::getRenamed);
if (content.isEmpty()) {
return null;
}
StringBuilder report = new StringBuilder();
report.append(String.format("%nThe use of configuration keys that have been "
+ "renamed was found in the environment:%n%n"));
- appendProperties(report, content, metadata ->
- "Replacement: " + metadata.getDeprecation().getReplacement());
+ append(report, content, (metadata) -> "Replacement: "
+ + metadata.getDeprecation().getReplacement());
report.append(String.format("%n"));
report.append("Each configuration key has been temporarily mapped to its "
+ "replacement for your convenience. To silence this warning, please "
@@ -63,24 +61,23 @@ class LegacyPropertiesAnalysis {
}
/**
- * Create a report for all the legacy properties that are no longer supported. If
- * no such legacy properties were found, return {@code null}.
+ * Return a report for all the legacy properties that are no longer supported. If no
+ * such legacy properties were found, return {@code null}.
* @return a report with the configurations keys that are no longer supported
*/
- public String createErrorReport() {
- Map> content = this.content.entrySet().stream()
- .filter(e -> !e.getValue().notHandledProperties.isEmpty())
- .collect(Collectors.toMap(Map.Entry::getKey,
- e -> new ArrayList<>(e.getValue().notHandledProperties)));
+ public String getErrorReport() {
+ Map> content = getContent(
+ DeprecatedProperties::getUnsupported);
if (content.isEmpty()) {
return null;
}
StringBuilder report = new StringBuilder();
report.append(String.format("%nThe use of configuration keys that are no longer "
+ "supported was found in the environment:%n%n"));
- appendProperties(report, content, metadata ->
- "Reason: " + (StringUtils.hasText(metadata.getDeprecation().getReason())
- ? metadata.getDeprecation().getReason() : "none"));
+ append(report, content,
+ metadata -> "Reason: "
+ + (StringUtils.hasText(metadata.getDeprecation().getReason())
+ ? metadata.getDeprecation().getReason() : "none"));
report.append(String.format("%n"));
report.append("Please refer to the migration guide or reference guide for "
+ "potential alternatives.");
@@ -88,21 +85,29 @@ class LegacyPropertiesAnalysis {
return report.toString();
}
- private void appendProperties(StringBuilder report,
- Map> content,
+ private Map> getContent(
+ Function> extractor) {
+ return this.content.entrySet().stream()
+ .filter((entry) -> !extractor.apply(entry.getValue()).isEmpty())
+ .collect(Collectors.toMap(Map.Entry::getKey,
+ (entry) -> new ArrayList<>(extractor.apply(entry.getValue()))));
+ }
+
+ private void append(StringBuilder report,
+ Map> content,
Function deprecationMessage) {
content.forEach((name, properties) -> {
report.append(String.format("Property source '%s':%n", name));
- properties.sort(LegacyProperty.COMPARATOR);
+ properties.sort(DeprecatedProperty.COMPARATOR);
properties.forEach((property) -> {
ConfigurationMetadataProperty metadata = property.getMetadata();
report.append(String.format("\tKey: %s%n", metadata.getId()));
if (property.getLineNumber() != null) {
- report.append(String.format("\t\tLine: %d%n",
- property.getLineNumber()));
+ report.append(
+ String.format("\t\tLine: %d%n", property.getLineNumber()));
}
- report.append(String.format("\t\t%s%n",
- deprecationMessage.apply(metadata)));
+ report.append(
+ String.format("\t\t%s%n", deprecationMessage.apply(metadata)));
});
report.append(String.format("%n"));
});
@@ -111,29 +116,36 @@ class LegacyPropertiesAnalysis {
/**
* Register a new property source.
* @param name the name of the property source
- * @param handledProperties the properties that were renamed
- * @param notHandledProperties the properties that are no longer supported
+ * @param renamed the properties that were renamed
+ * @param unsupported the properties that are no longer supported
*/
- void register(String name, List handledProperties,
- List notHandledProperties) {
- List handled = (handledProperties != null
- ? new ArrayList<>(handledProperties) : Collections.emptyList());
- List notHandled = (notHandledProperties != null
- ? new ArrayList<>(notHandledProperties) : Collections.emptyList());
- this.content.put(name, new PropertySourceAnalysis(handled, notHandled));
+ void add(String name, List renamed,
+ List unsupported) {
+ this.content.put(name, new DeprecatedProperties(renamed, unsupported));
}
+ private static class DeprecatedProperties {
- private static class PropertySourceAnalysis {
+ private final List renamed;
- private final List handledProperties;
+ private final List unsupported;
- private final List notHandledProperties;
+ DeprecatedProperties(List renamed,
+ List unsupported) {
+ this.renamed = asNewList(renamed);
+ this.unsupported = asNewList(unsupported);
+ }
+
+ private List asNewList(List source) {
+ return (source == null ? Collections.emptyList() : new ArrayList(source));
+ }
+
+ public List getRenamed() {
+ return this.renamed;
+ }
- PropertySourceAnalysis(List handledProperties,
- List notHandledProperties) {
- this.handledProperties = handledProperties;
- this.notHandledProperties = notHandledProperties;
+ public List getUnsupported() {
+ return this.unsupported;
}
}
diff --git a/spring-boot-project/spring-boot-configuration-analyzer/src/main/java/org/springframework/boot/configurationalayzer/LegacyPropertiesAnalyzer.java b/spring-boot-project/spring-boot-deprecated-properties-support/src/main/java/org/springframework/boot/deprecatedproperties/DeprecatedPropertiesReporter.java
similarity index 68%
rename from spring-boot-project/spring-boot-configuration-analyzer/src/main/java/org/springframework/boot/configurationalayzer/LegacyPropertiesAnalyzer.java
rename to spring-boot-project/spring-boot-deprecated-properties-support/src/main/java/org/springframework/boot/deprecatedproperties/DeprecatedPropertiesReporter.java
index 2b2518d19f4..ef83a0599c7 100644
--- a/spring-boot-project/spring-boot-configuration-analyzer/src/main/java/org/springframework/boot/configurationalayzer/LegacyPropertiesAnalyzer.java
+++ b/spring-boot-project/spring-boot-deprecated-properties-support/src/main/java/org/springframework/boot/deprecatedproperties/DeprecatedPropertiesReporter.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.springframework.boot.configurationalayzer;
+package org.springframework.boot.deprecatedproperties;
import java.util.ArrayList;
import java.util.Collections;
@@ -40,19 +40,20 @@ import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
/**
- * Analyse {@link LegacyProperty legacy properties}.
+ * Report on {@link DeprecatedProperty deprecated properties}.
*
* @author Stephane Nicoll
*/
-class LegacyPropertiesAnalyzer {
+class DeprecatedPropertiesReporter {
private final Map allProperties;
private final ConfigurableEnvironment environment;
- LegacyPropertiesAnalyzer(ConfigurationMetadataRepository metadataRepository,
+ DeprecatedPropertiesReporter(ConfigurationMetadataRepository metadataRepository,
ConfigurableEnvironment environment) {
- this.allProperties = Collections.unmodifiableMap(metadataRepository.getAllProperties());
+ this.allProperties = Collections
+ .unmodifiableMap(metadataRepository.getAllProperties());
this.environment = environment;
}
@@ -61,60 +62,59 @@ class LegacyPropertiesAnalyzer {
* legacy properties if a replacement exists.
* @return the analysis
*/
- public LegacyPropertiesAnalysis analyseLegacyProperties() {
- LegacyPropertiesAnalysis analysis = new LegacyPropertiesAnalysis();
- Map> properties = getMatchingProperties(deprecatedFilter());
+ public DeprecatedPropertiesReport getReport() {
+ DeprecatedPropertiesReport report = new DeprecatedPropertiesReport();
+ Map> properties = getMatchingProperties(
+ deprecatedFilter());
if (properties.isEmpty()) {
- return analysis;
+ return report;
}
properties.forEach((name, candidates) -> {
- PropertySource> propertySource = mapPropertiesWithReplacement(analysis,
+ PropertySource> propertySource = mapPropertiesWithReplacement(report,
name, candidates);
if (propertySource != null) {
this.environment.getPropertySources().addBefore(name, propertySource);
}
});
- return analysis;
+ return report;
}
private PropertySource> mapPropertiesWithReplacement(
- LegacyPropertiesAnalysis analysis, String name,
- List properties) {
- List matches = new ArrayList<>();
- List unhandled = new ArrayList<>();
- for (LegacyProperty property : properties) {
- if (hasValidReplacement(property)) {
- matches.add(property);
- }
- else {
- unhandled.add(property);
- }
- }
- analysis.register(name, matches, unhandled);
- if (matches.isEmpty()) {
+ DeprecatedPropertiesReport report, String name,
+ List properties) {
+ List renamed = new ArrayList<>();
+ List unsupported = new ArrayList<>();
+ properties.forEach((property) -> {
+ (isRenamed(property) ? renamed : unsupported).add(property);
+ });
+ report.add(name, renamed, unsupported);
+ if (renamed.isEmpty()) {
return null;
}
String target = "migrate-" + name;
Map content = new LinkedHashMap<>();
- for (LegacyProperty candidate : matches) {
+ for (DeprecatedProperty candidate : renamed) {
OriginTrackedValue value = OriginTrackedValue.of(
- candidate.getProperty().getValue(), candidate.getProperty().getOrigin());
+ candidate.getProperty().getValue(),
+ candidate.getProperty().getOrigin());
content.put(candidate.getMetadata().getDeprecation().getReplacement(), value);
}
return new OriginTrackedMapPropertySource(target, content);
}
- private boolean hasValidReplacement(LegacyProperty property) {
- String replacementId = property.getMetadata().getDeprecation().getReplacement();
+ private boolean isRenamed(DeprecatedProperty property) {
+ ConfigurationMetadataProperty metadata = property.getMetadata();
+ String replacementId = metadata.getDeprecation().getReplacement();
if (StringUtils.hasText(replacementId)) {
- ConfigurationMetadataProperty replacement = this.allProperties.get(replacementId);
+ ConfigurationMetadataProperty replacement = this.allProperties
+ .get(replacementId);
if (replacement != null) {
- return replacement.getType().equals(property.getMetadata().getType());
+ return replacement.getType().equals(metadata.getType());
}
replacement = getMapProperty(replacementId);
if (replacement != null) {
return replacement.getType().startsWith("java.util.Map")
- && replacement.getType().endsWith(property.getMetadata().getType() + ">");
+ && replacement.getType().endsWith(metadata.getType() + ">");
}
}
return false;
@@ -128,17 +128,19 @@ class LegacyPropertiesAnalyzer {
return null;
}
- private Map> getMatchingProperties(
+ private Map> getMatchingProperties(
Predicate filter) {
- MultiValueMap result = new LinkedMultiValueMap<>();
+ MultiValueMap result = new LinkedMultiValueMap<>();
List candidates = this.allProperties.values()
.stream().filter(filter).collect(Collectors.toList());
getPropertySourcesAsMap().forEach((name, source) -> {
candidates.forEach(metadata -> {
- ConfigurationProperty configurationProperty = source.getConfigurationProperty(
- ConfigurationPropertyName.of(metadata.getId()));
+ ConfigurationProperty configurationProperty = source
+ .getConfigurationProperty(
+ ConfigurationPropertyName.of(metadata.getId()));
if (configurationProperty != null) {
- result.add(name, new LegacyProperty(metadata, configurationProperty));
+ result.add(name,
+ new DeprecatedProperty(metadata, configurationProperty));
}
});
});
@@ -146,14 +148,15 @@ class LegacyPropertiesAnalyzer {
}
private Predicate deprecatedFilter() {
- return p -> p.getDeprecation() != null
- && p.getDeprecation().getLevel() == Deprecation.Level.ERROR;
+ return (property) -> property.getDeprecation() != null
+ && property.getDeprecation().getLevel() == Deprecation.Level.ERROR;
}
private Map getPropertySourcesAsMap() {
Map map = new LinkedHashMap<>();
ConfigurationPropertySources.get(this.environment);
- for (ConfigurationPropertySource source : ConfigurationPropertySources.get(this.environment)) {
+ for (ConfigurationPropertySource source : ConfigurationPropertySources
+ .get(this.environment)) {
map.put(determinePropertySourceName(source), source);
}
return map;
diff --git a/spring-boot-project/spring-boot-configuration-analyzer/src/main/java/org/springframework/boot/configurationalayzer/LegacyProperty.java b/spring-boot-project/spring-boot-deprecated-properties-support/src/main/java/org/springframework/boot/deprecatedproperties/DeprecatedProperty.java
similarity index 80%
rename from spring-boot-project/spring-boot-configuration-analyzer/src/main/java/org/springframework/boot/configurationalayzer/LegacyProperty.java
rename to spring-boot-project/spring-boot-deprecated-properties-support/src/main/java/org/springframework/boot/deprecatedproperties/DeprecatedProperty.java
index 29ca0e12163..eb832f7ef20 100644
--- a/spring-boot-project/spring-boot-configuration-analyzer/src/main/java/org/springframework/boot/configurationalayzer/LegacyProperty.java
+++ b/spring-boot-project/spring-boot-deprecated-properties-support/src/main/java/org/springframework/boot/deprecatedproperties/DeprecatedProperty.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.springframework.boot.configurationalayzer;
+package org.springframework.boot.deprecatedproperties;
import java.util.Comparator;
@@ -28,9 +28,10 @@ import org.springframework.boot.origin.TextResourceOrigin;
*
* @author Stephane Nicoll
*/
-class LegacyProperty {
+class DeprecatedProperty {
- static final LegacyPropertyComparator COMPARATOR = new LegacyPropertyComparator();
+ public static final Comparator COMPARATOR = Comparator
+ .comparing((property) -> property.getMetadata().getId());
private final ConfigurationMetadataProperty metadata;
@@ -38,7 +39,7 @@ class LegacyProperty {
private final Integer lineNumber;
- LegacyProperty(ConfigurationMetadataProperty metadata,
+ DeprecatedProperty(ConfigurationMetadataProperty metadata,
ConfigurationProperty property) {
this.metadata = metadata;
this.property = property;
@@ -68,13 +69,4 @@ class LegacyProperty {
return this.lineNumber;
}
-
- private static class LegacyPropertyComparator implements Comparator {
-
- @Override
- public int compare(LegacyProperty p1, LegacyProperty p2) {
- return p1.getMetadata().getId().compareTo(p2.getMetadata().getId());
- }
- }
-
}
diff --git a/spring-boot-project/spring-boot-configuration-analyzer/src/main/java/org/springframework/boot/configurationalayzer/package-info.java b/spring-boot-project/spring-boot-deprecated-properties-support/src/main/java/org/springframework/boot/deprecatedproperties/package-info.java
similarity index 84%
rename from spring-boot-project/spring-boot-configuration-analyzer/src/main/java/org/springframework/boot/configurationalayzer/package-info.java
rename to spring-boot-project/spring-boot-deprecated-properties-support/src/main/java/org/springframework/boot/deprecatedproperties/package-info.java
index e5767382fc7..cc01f68604b 100644
--- a/spring-boot-project/spring-boot-configuration-analyzer/src/main/java/org/springframework/boot/configurationalayzer/package-info.java
+++ b/spring-boot-project/spring-boot-deprecated-properties-support/src/main/java/org/springframework/boot/deprecatedproperties/package-info.java
@@ -15,6 +15,6 @@
*/
/**
- * Support for analyzing the environment.
+ * Support for migrating deprecated Spring Boot properties.
*/
-package org.springframework.boot.configurationalayzer;
+package org.springframework.boot.deprecatedproperties;
diff --git a/spring-boot-project/spring-boot-deprecated-properties-support/src/main/resources/META-INF/spring.factories b/spring-boot-project/spring-boot-deprecated-properties-support/src/main/resources/META-INF/spring.factories
new file mode 100644
index 00000000000..ae46395649e
--- /dev/null
+++ b/spring-boot-project/spring-boot-deprecated-properties-support/src/main/resources/META-INF/spring.factories
@@ -0,0 +1,2 @@
+org.springframework.context.ApplicationListener=\
+org.springframework.boot.deprecatedproperties.DeprecatedPropertiesListener
diff --git a/spring-boot-project/spring-boot-configuration-analyzer/src/test/java/org/springframework/boot/configurationalayzer/LegacyPropertiesAnalyzerListenerTests.java b/spring-boot-project/spring-boot-deprecated-properties-support/src/test/java/org/springframework/boot/deprecatedproperties/DeprecatedPropertiesListenerTests.java
similarity index 87%
rename from spring-boot-project/spring-boot-configuration-analyzer/src/test/java/org/springframework/boot/configurationalayzer/LegacyPropertiesAnalyzerListenerTests.java
rename to spring-boot-project/spring-boot-deprecated-properties-support/src/test/java/org/springframework/boot/deprecatedproperties/DeprecatedPropertiesListenerTests.java
index 5ec1532963e..946a2bdafd8 100644
--- a/spring-boot-project/spring-boot-configuration-analyzer/src/test/java/org/springframework/boot/configurationalayzer/LegacyPropertiesAnalyzerListenerTests.java
+++ b/spring-boot-project/spring-boot-deprecated-properties-support/src/test/java/org/springframework/boot/deprecatedproperties/DeprecatedPropertiesListenerTests.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.springframework.boot.configurationalayzer;
+package org.springframework.boot.deprecatedproperties;
import org.junit.After;
import org.junit.Rule;
@@ -28,11 +28,11 @@ import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
/**
- * Tests for {@link LegacyPropertiesAnalyzerListener}.
+ * Tests for {@link DeprecatedPropertiesListener}.
*
* @author Stephane Nicoll
*/
-public class LegacyPropertiesAnalyzerListenerTests {
+public class DeprecatedPropertiesListenerTests {
@Rule
public final OutputCapture output = new OutputCapture();
@@ -48,8 +48,7 @@ public class LegacyPropertiesAnalyzerListenerTests {
@Test
public void sampleReport() {
- this.context = createSampleApplication()
- .run("--banner.charset=UTF8");
+ this.context = createSampleApplication().run("--banner.charset=UTF8");
assertThat(this.output.toString()).contains("commandLineArgs")
.contains("spring.banner.charset")
.contains("Each configuration key has been temporarily mapped")
@@ -60,7 +59,6 @@ public class LegacyPropertiesAnalyzerListenerTests {
return new SpringApplication(TestApplication.class);
}
-
@Configuration
public static class TestApplication {
diff --git a/spring-boot-project/spring-boot-configuration-analyzer/src/test/java/org/springframework/boot/configurationalayzer/LegacyPropertiesAnalyzerTests.java b/spring-boot-project/spring-boot-deprecated-properties-support/src/test/java/org/springframework/boot/deprecatedproperties/DeprecatedPropertiesReporterTests.java
similarity index 71%
rename from spring-boot-project/spring-boot-configuration-analyzer/src/test/java/org/springframework/boot/configurationalayzer/LegacyPropertiesAnalyzerTests.java
rename to spring-boot-project/spring-boot-deprecated-properties-support/src/test/java/org/springframework/boot/deprecatedproperties/DeprecatedPropertiesReporterTests.java
index f1ef2ba0891..fdc6f2a637b 100644
--- a/spring-boot-project/spring-boot-configuration-analyzer/src/test/java/org/springframework/boot/configurationalayzer/LegacyPropertiesAnalyzerTests.java
+++ b/spring-boot-project/spring-boot-deprecated-properties-support/src/test/java/org/springframework/boot/deprecatedproperties/DeprecatedPropertiesReporterTests.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.springframework.boot.configurationalayzer;
+package org.springframework.boot.deprecatedproperties;
import java.io.IOException;
import java.util.ArrayList;
@@ -38,13 +38,12 @@ import org.springframework.mock.env.MockEnvironment;
import static org.assertj.core.api.Assertions.assertThat;
-
/**
- * Tests for {@link LegacyPropertiesAnalyzer}.
+ * Tests for {@link DeprecatedPropertiesReporter}.
*
* @author Stephane Nicoll
*/
-public class LegacyPropertiesAnalyzerTests {
+public class DeprecatedPropertiesReporterTests {
private ConfigurableEnvironment environment = new MockEnvironment();
@@ -64,56 +63,53 @@ public class LegacyPropertiesAnalyzerTests {
propertySources.addFirst(one);
propertySources.addAfter("one", two);
assertThat(propertySources).hasSize(3);
- createAnalyzer(loadRepository("metadata/sample-metadata.json"))
- .analyseLegacyProperties();
- assertThat(mapToNames(propertySources)).containsExactly("one",
- "migrate-two", "two", "mockProperties");
- assertMappedProperty(propertySources.get("migrate-two"),
- "test.two", "another", getOrigin(two, "wrong.two"));
+ createAnalyzer(loadRepository("metadata/sample-metadata.json")).getReport();
+ assertThat(mapToNames(propertySources)).containsExactly("one", "migrate-two",
+ "two", "mockProperties");
+ assertMappedProperty(propertySources.get("migrate-two"), "test.two", "another",
+ getOrigin(two, "wrong.two"));
}
@Test
public void warningReport() throws IOException {
- this.environment.getPropertySources().addFirst(loadPropertySource("test",
- "config/config-warnings.properties"));
- this.environment.getPropertySources().addFirst(loadPropertySource("ignore",
- "config/config-error.properties"));
- String report = createWarningReport(loadRepository(
- "metadata/sample-metadata.json"));
+ this.environment.getPropertySources().addFirst(
+ loadPropertySource("test", "config/config-warnings.properties"));
+ this.environment.getPropertySources()
+ .addFirst(loadPropertySource("ignore", "config/config-error.properties"));
+ String report = createWarningReport(
+ loadRepository("metadata/sample-metadata.json"));
assertThat(report).isNotNull();
assertThat(report).containsSubsequence("Property source 'test'",
- "wrong.four.test", "Line: 5", "test.four.test",
- "wrong.two", "Line: 2", "test.two");
+ "wrong.four.test", "Line: 5", "test.four.test", "wrong.two", "Line: 2",
+ "test.two");
assertThat(report).doesNotContain("wrong.one");
}
@Test
public void errorReport() throws IOException {
- this.environment.getPropertySources().addFirst(loadPropertySource("test1",
- "config/config-warnings.properties"));
- this.environment.getPropertySources().addFirst(loadPropertySource("test2",
- "config/config-error.properties"));
- String report = createErrorReport(loadRepository(
- "metadata/sample-metadata.json"));
+ this.environment.getPropertySources().addFirst(
+ loadPropertySource("test1", "config/config-warnings.properties"));
+ this.environment.getPropertySources()
+ .addFirst(loadPropertySource("test2", "config/config-error.properties"));
+ String report = createErrorReport(
+ loadRepository("metadata/sample-metadata.json"));
assertThat(report).isNotNull();
- assertThat(report).containsSubsequence("Property source 'test2'",
- "wrong.one", "Line: 2", "This is no longer supported.");
- assertThat(report).doesNotContain("wrong.four.test")
- .doesNotContain("wrong.two");
+ assertThat(report).containsSubsequence("Property source 'test2'", "wrong.one",
+ "Line: 2", "This is no longer supported.");
+ assertThat(report).doesNotContain("wrong.four.test").doesNotContain("wrong.two");
}
@Test
public void errorReportNoReplacement() throws IOException {
this.environment.getPropertySources().addFirst(loadPropertySource("first",
"config/config-error-no-replacement.properties"));
- this.environment.getPropertySources().addFirst(loadPropertySource("second",
- "config/config-error.properties"));
- String report = createErrorReport(loadRepository(
- "metadata/sample-metadata.json"));
+ this.environment.getPropertySources()
+ .addFirst(loadPropertySource("second", "config/config-error.properties"));
+ String report = createErrorReport(
+ loadRepository("metadata/sample-metadata.json"));
assertThat(report).isNotNull();
- assertThat(report).containsSubsequence(
- "Property source 'first'", "wrong.three", "Line: 6", "none",
- "Property source 'second'", "wrong.one", "Line: 2",
+ assertThat(report).containsSubsequence("Property source 'first'", "wrong.three",
+ "Line: 6", "none", "Property source 'second'", "wrong.one", "Line: 2",
"This is no longer supported.");
assertThat(report).doesNotContain("null").doesNotContain("server.port")
.doesNotContain("debug");
@@ -132,6 +128,7 @@ public class LegacyPropertiesAnalyzerTests {
return ((OriginLookup) propertySource).getOrigin(name);
}
+ @SuppressWarnings("unchecked")
private void assertMappedProperty(PropertySource> propertySource, String name,
Object value, Origin origin) {
assertThat(propertySource.containsProperty(name)).isTrue();
@@ -146,15 +143,16 @@ public class LegacyPropertiesAnalyzerTests {
private PropertySource> loadPropertySource(String name, String path)
throws IOException {
ClassPathResource resource = new ClassPathResource(path);
- PropertySource> propertySource = new PropertiesPropertySourceLoader()
- .load(name, resource, null);
+ PropertySource> propertySource = new PropertiesPropertySourceLoader().load(name,
+ resource, null);
assertThat(propertySource).isNotNull();
return propertySource;
}
private ConfigurationMetadataRepository loadRepository(String... content) {
try {
- ConfigurationMetadataRepositoryJsonBuilder builder = ConfigurationMetadataRepositoryJsonBuilder.create();
+ ConfigurationMetadataRepositoryJsonBuilder builder = ConfigurationMetadataRepositoryJsonBuilder
+ .create();
for (String path : content) {
Resource resource = new ClassPathResource(path);
builder.withJsonResource(resource.getInputStream());
@@ -167,18 +165,16 @@ public class LegacyPropertiesAnalyzerTests {
}
private String createWarningReport(ConfigurationMetadataRepository repository) {
- return createAnalyzer(repository).analyseLegacyProperties()
- .createWarningReport();
+ return createAnalyzer(repository).getReport().getWarningReport();
}
private String createErrorReport(ConfigurationMetadataRepository repository) {
- return createAnalyzer(repository).analyseLegacyProperties()
- .createErrorReport();
+ return createAnalyzer(repository).getReport().getErrorReport();
}
- private LegacyPropertiesAnalyzer createAnalyzer(
+ private DeprecatedPropertiesReporter createAnalyzer(
ConfigurationMetadataRepository repository) {
- return new LegacyPropertiesAnalyzer(repository, this.environment);
+ return new DeprecatedPropertiesReporter(repository, this.environment);
}
}
diff --git a/spring-boot-project/spring-boot-configuration-analyzer/src/test/resources/config/config-error-no-replacement.properties b/spring-boot-project/spring-boot-deprecated-properties-support/src/test/resources/config/config-error-no-replacement.properties
similarity index 100%
rename from spring-boot-project/spring-boot-configuration-analyzer/src/test/resources/config/config-error-no-replacement.properties
rename to spring-boot-project/spring-boot-deprecated-properties-support/src/test/resources/config/config-error-no-replacement.properties
diff --git a/spring-boot-project/spring-boot-configuration-analyzer/src/test/resources/config/config-error.properties b/spring-boot-project/spring-boot-deprecated-properties-support/src/test/resources/config/config-error.properties
similarity index 100%
rename from spring-boot-project/spring-boot-configuration-analyzer/src/test/resources/config/config-error.properties
rename to spring-boot-project/spring-boot-deprecated-properties-support/src/test/resources/config/config-error.properties
diff --git a/spring-boot-project/spring-boot-configuration-analyzer/src/test/resources/config/config-warnings.properties b/spring-boot-project/spring-boot-deprecated-properties-support/src/test/resources/config/config-warnings.properties
similarity index 100%
rename from spring-boot-project/spring-boot-configuration-analyzer/src/test/resources/config/config-warnings.properties
rename to spring-boot-project/spring-boot-deprecated-properties-support/src/test/resources/config/config-warnings.properties
diff --git a/spring-boot-project/spring-boot-configuration-analyzer/src/test/resources/metadata/sample-metadata.json b/spring-boot-project/spring-boot-deprecated-properties-support/src/test/resources/metadata/sample-metadata.json
similarity index 100%
rename from spring-boot-project/spring-boot-configuration-analyzer/src/test/resources/metadata/sample-metadata.json
rename to spring-boot-project/spring-boot-deprecated-properties-support/src/test/resources/metadata/sample-metadata.json