Commit e53bef73 authored by Phillip Webb's avatar Phillip Webb

Rename property migrator classes

Rename packages and classes to match the new module name.

See gh-11301
parent 1a1a62b7
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.legacyproperties; package org.springframework.boot.context.properties.migrator;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
...@@ -35,19 +35,19 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver; ...@@ -35,19 +35,19 @@ import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
/** /**
* An {@link ApplicationListener} that inspects the {@link ConfigurableEnvironment * An {@link ApplicationListener} that inspects the {@link ConfigurableEnvironment
* environment} for legacy configuration keys. Automatically renames the keys that * environment} for configuration keys that need to be migrated. Automatically renames the
* have a matching replacement and log a report of what was discovered. * keys that have a matching replacement and log a report of what was discovered.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
* @since 2.0.0 * @since 2.0.0
*/ */
public class LegacyPropertiesListener public class PropertiesMigrationListener
implements ApplicationListener<SpringApplicationEvent> { implements ApplicationListener<SpringApplicationEvent> {
private static final Log logger = LogFactory private static final Log logger = LogFactory
.getLog(LegacyPropertiesListener.class); .getLog(PropertiesMigrationListener.class);
private LegacyPropertiesReport report; private PropertiesMigrationReport report;
private boolean reported; private boolean reported;
...@@ -64,7 +64,7 @@ public class LegacyPropertiesListener ...@@ -64,7 +64,7 @@ public class LegacyPropertiesListener
private void onApplicationPreparedEvent(ApplicationPreparedEvent event) { private void onApplicationPreparedEvent(ApplicationPreparedEvent event) {
ConfigurationMetadataRepository repository = loadRepository(); ConfigurationMetadataRepository repository = loadRepository();
LegacyPropertiesReporter reporter = new LegacyPropertiesReporter(repository, PropertiesMigrationReporter reporter = new PropertiesMigrationReporter(repository,
event.getApplicationContext().getEnvironment()); event.getApplicationContext().getEnvironment());
this.report = reporter.getReport(); this.report = reporter.getReport();
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.legacyproperties; package org.springframework.boot.context.properties.migrator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
...@@ -28,21 +28,21 @@ import org.springframework.boot.configurationmetadata.ConfigurationMetadataPrope ...@@ -28,21 +28,21 @@ import org.springframework.boot.configurationmetadata.ConfigurationMetadataPrope
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
* Provides a legacy properties report. * Provides a properties migration report.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
class LegacyPropertiesReport { class PropertiesMigrationReport {
private final Map<String, LegacyProperties> content = new LinkedHashMap<>(); private final Map<String, LegacyProperties> content = new LinkedHashMap<>();
/** /**
* Return a report for all the legacy properties that were automatically renamed. If * Return a report for all the properties that were automatically renamed. If no such
* no such legacy properties were found, return {@code null}. * properties were found, return {@code null}.
* @return a report with the configurations keys that should be renamed * @return a report with the configurations keys that should be renamed
*/ */
public String getWarningReport() { public String getWarningReport() {
Map<String, List<LegacyProperty>> content = getContent( Map<String, List<PropertyMigration>> content = getContent(
LegacyProperties::getRenamed); LegacyProperties::getRenamed);
if (content.isEmpty()) { if (content.isEmpty()) {
return null; return null;
...@@ -61,12 +61,12 @@ class LegacyPropertiesReport { ...@@ -61,12 +61,12 @@ class LegacyPropertiesReport {
} }
/** /**
* Return a report for all the legacy properties that are no longer supported. If no * Return a report for all the properties that are no longer supported. If no such
* such legacy properties were found, return {@code null}. * properties were found, return {@code null}.
* @return a report with the configurations keys that are no longer supported * @return a report with the configurations keys that are no longer supported
*/ */
public String getErrorReport() { public String getErrorReport() {
Map<String, List<LegacyProperty>> content = getContent( Map<String, List<PropertyMigration>> content = getContent(
LegacyProperties::getUnsupported); LegacyProperties::getUnsupported);
if (content.isEmpty()) { if (content.isEmpty()) {
return null; return null;
...@@ -85,8 +85,8 @@ class LegacyPropertiesReport { ...@@ -85,8 +85,8 @@ class LegacyPropertiesReport {
return report.toString(); return report.toString();
} }
private Map<String, List<LegacyProperty>> getContent( private Map<String, List<PropertyMigration>> getContent(
Function<LegacyProperties, List<LegacyProperty>> extractor) { Function<LegacyProperties, List<PropertyMigration>> extractor) {
return this.content.entrySet().stream() return this.content.entrySet().stream()
.filter((entry) -> !extractor.apply(entry.getValue()).isEmpty()) .filter((entry) -> !extractor.apply(entry.getValue()).isEmpty())
.collect(Collectors.toMap(Map.Entry::getKey, .collect(Collectors.toMap(Map.Entry::getKey,
...@@ -94,11 +94,11 @@ class LegacyPropertiesReport { ...@@ -94,11 +94,11 @@ class LegacyPropertiesReport {
} }
private void append(StringBuilder report, private void append(StringBuilder report,
Map<String, List<LegacyProperty>> content, Map<String, List<PropertyMigration>> content,
Function<ConfigurationMetadataProperty, String> deprecationMessage) { Function<ConfigurationMetadataProperty, String> deprecationMessage) {
content.forEach((name, properties) -> { content.forEach((name, properties) -> {
report.append(String.format("Property source '%s':%n", name)); report.append(String.format("Property source '%s':%n", name));
properties.sort(LegacyProperty.COMPARATOR); properties.sort(PropertyMigration.COMPARATOR);
properties.forEach((property) -> { properties.forEach((property) -> {
ConfigurationMetadataProperty metadata = property.getMetadata(); ConfigurationMetadataProperty metadata = property.getMetadata();
report.append(String.format("\tKey: %s%n", metadata.getId())); report.append(String.format("\tKey: %s%n", metadata.getId()));
...@@ -119,19 +119,19 @@ class LegacyPropertiesReport { ...@@ -119,19 +119,19 @@ class LegacyPropertiesReport {
* @param renamed the properties that were renamed * @param renamed the properties that were renamed
* @param unsupported the properties that are no longer supported * @param unsupported the properties that are no longer supported
*/ */
void add(String name, List<LegacyProperty> renamed, void add(String name, List<PropertyMigration> renamed,
List<LegacyProperty> unsupported) { List<PropertyMigration> unsupported) {
this.content.put(name, new LegacyProperties(renamed, unsupported)); this.content.put(name, new LegacyProperties(renamed, unsupported));
} }
private static class LegacyProperties { private static class LegacyProperties {
private final List<LegacyProperty> renamed; private final List<PropertyMigration> renamed;
private final List<LegacyProperty> unsupported; private final List<PropertyMigration> unsupported;
LegacyProperties(List<LegacyProperty> renamed, LegacyProperties(List<PropertyMigration> renamed,
List<LegacyProperty> unsupported) { List<PropertyMigration> unsupported) {
this.renamed = asNewList(renamed); this.renamed = asNewList(renamed);
this.unsupported = asNewList(unsupported); this.unsupported = asNewList(unsupported);
} }
...@@ -140,11 +140,11 @@ class LegacyPropertiesReport { ...@@ -140,11 +140,11 @@ class LegacyPropertiesReport {
return (source == null ? Collections.emptyList() : new ArrayList<>(source)); return (source == null ? Collections.emptyList() : new ArrayList<>(source));
} }
public List<LegacyProperty> getRenamed() { public List<PropertyMigration> getRenamed() {
return this.renamed; return this.renamed;
} }
public List<LegacyProperty> getUnsupported() { public List<PropertyMigration> getUnsupported() {
return this.unsupported; return this.unsupported;
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.legacyproperties; package org.springframework.boot.context.properties.migrator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
...@@ -40,17 +40,17 @@ import org.springframework.util.MultiValueMap; ...@@ -40,17 +40,17 @@ import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
* Report on {@link LegacyProperty legacy properties}. * Report on {@link PropertyMigration legacy properties}.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
class LegacyPropertiesReporter { class PropertiesMigrationReporter {
private final Map<String, ConfigurationMetadataProperty> allProperties; private final Map<String, ConfigurationMetadataProperty> allProperties;
private final ConfigurableEnvironment environment; private final ConfigurableEnvironment environment;
LegacyPropertiesReporter(ConfigurationMetadataRepository metadataRepository, PropertiesMigrationReporter(ConfigurationMetadataRepository metadataRepository,
ConfigurableEnvironment environment) { ConfigurableEnvironment environment) {
this.allProperties = Collections this.allProperties = Collections
.unmodifiableMap(metadataRepository.getAllProperties()); .unmodifiableMap(metadataRepository.getAllProperties());
...@@ -62,9 +62,9 @@ class LegacyPropertiesReporter { ...@@ -62,9 +62,9 @@ class LegacyPropertiesReporter {
* legacy properties if a replacement exists. * legacy properties if a replacement exists.
* @return the analysis * @return the analysis
*/ */
public LegacyPropertiesReport getReport() { public PropertiesMigrationReport getReport() {
LegacyPropertiesReport report = new LegacyPropertiesReport(); PropertiesMigrationReport report = new PropertiesMigrationReport();
Map<String, List<LegacyProperty>> properties = getMatchingProperties( Map<String, List<PropertyMigration>> properties = getMatchingProperties(
deprecatedFilter()); deprecatedFilter());
if (properties.isEmpty()) { if (properties.isEmpty()) {
return report; return report;
...@@ -80,10 +80,10 @@ class LegacyPropertiesReporter { ...@@ -80,10 +80,10 @@ class LegacyPropertiesReporter {
} }
private PropertySource<?> mapPropertiesWithReplacement( private PropertySource<?> mapPropertiesWithReplacement(
LegacyPropertiesReport report, String name, PropertiesMigrationReport report, String name,
List<LegacyProperty> properties) { List<PropertyMigration> properties) {
List<LegacyProperty> renamed = new ArrayList<>(); List<PropertyMigration> renamed = new ArrayList<>();
List<LegacyProperty> unsupported = new ArrayList<>(); List<PropertyMigration> unsupported = new ArrayList<>();
properties.forEach((property) -> properties.forEach((property) ->
(isRenamed(property) ? renamed : unsupported).add(property)); (isRenamed(property) ? renamed : unsupported).add(property));
report.add(name, renamed, unsupported); report.add(name, renamed, unsupported);
...@@ -92,7 +92,7 @@ class LegacyPropertiesReporter { ...@@ -92,7 +92,7 @@ class LegacyPropertiesReporter {
} }
String target = "migrate-" + name; String target = "migrate-" + name;
Map<String, OriginTrackedValue> content = new LinkedHashMap<>(); Map<String, OriginTrackedValue> content = new LinkedHashMap<>();
for (LegacyProperty candidate : renamed) { for (PropertyMigration candidate : renamed) {
OriginTrackedValue value = OriginTrackedValue.of( OriginTrackedValue value = OriginTrackedValue.of(
candidate.getProperty().getValue(), candidate.getProperty().getValue(),
candidate.getProperty().getOrigin()); candidate.getProperty().getOrigin());
...@@ -101,7 +101,7 @@ class LegacyPropertiesReporter { ...@@ -101,7 +101,7 @@ class LegacyPropertiesReporter {
return new OriginTrackedMapPropertySource(target, content); return new OriginTrackedMapPropertySource(target, content);
} }
private boolean isRenamed(LegacyProperty property) { private boolean isRenamed(PropertyMigration property) {
ConfigurationMetadataProperty metadata = property.getMetadata(); ConfigurationMetadataProperty metadata = property.getMetadata();
String replacementId = metadata.getDeprecation().getReplacement(); String replacementId = metadata.getDeprecation().getReplacement();
if (StringUtils.hasText(replacementId)) { if (StringUtils.hasText(replacementId)) {
...@@ -127,9 +127,9 @@ class LegacyPropertiesReporter { ...@@ -127,9 +127,9 @@ class LegacyPropertiesReporter {
return null; return null;
} }
private Map<String, List<LegacyProperty>> getMatchingProperties( private Map<String, List<PropertyMigration>> getMatchingProperties(
Predicate<ConfigurationMetadataProperty> filter) { Predicate<ConfigurationMetadataProperty> filter) {
MultiValueMap<String, LegacyProperty> result = new LinkedMultiValueMap<>(); MultiValueMap<String, PropertyMigration> result = new LinkedMultiValueMap<>();
List<ConfigurationMetadataProperty> candidates = this.allProperties.values() List<ConfigurationMetadataProperty> candidates = this.allProperties.values()
.stream().filter(filter).collect(Collectors.toList()); .stream().filter(filter).collect(Collectors.toList());
getPropertySourcesAsMap().forEach((name, source) -> { getPropertySourcesAsMap().forEach((name, source) -> {
...@@ -139,7 +139,7 @@ class LegacyPropertiesReporter { ...@@ -139,7 +139,7 @@ class LegacyPropertiesReporter {
ConfigurationPropertyName.of(metadata.getId())); ConfigurationPropertyName.of(metadata.getId()));
if (configurationProperty != null) { if (configurationProperty != null) {
result.add(name, result.add(name,
new LegacyProperty(metadata, configurationProperty)); new PropertyMigration(metadata, configurationProperty));
} }
}); });
}); });
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.legacyproperties; package org.springframework.boot.context.properties.migrator;
import java.util.Comparator; import java.util.Comparator;
...@@ -28,9 +28,9 @@ import org.springframework.boot.origin.TextResourceOrigin; ...@@ -28,9 +28,9 @@ import org.springframework.boot.origin.TextResourceOrigin;
* *
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
class LegacyProperty { class PropertyMigration {
public static final Comparator<LegacyProperty> COMPARATOR = Comparator public static final Comparator<PropertyMigration> COMPARATOR = Comparator
.comparing((property) -> property.getMetadata().getId()); .comparing((property) -> property.getMetadata().getId());
private final ConfigurationMetadataProperty metadata; private final ConfigurationMetadataProperty metadata;
...@@ -39,7 +39,7 @@ class LegacyProperty { ...@@ -39,7 +39,7 @@ class LegacyProperty {
private final Integer lineNumber; private final Integer lineNumber;
LegacyProperty(ConfigurationMetadataProperty metadata, PropertyMigration(ConfigurationMetadataProperty metadata,
ConfigurationProperty property) { ConfigurationProperty property) {
this.metadata = metadata; this.metadata = metadata;
this.property = property; this.property = property;
......
...@@ -17,4 +17,4 @@ ...@@ -17,4 +17,4 @@
/** /**
* Support for migrating legacy Spring Boot properties. * Support for migrating legacy Spring Boot properties.
*/ */
package org.springframework.boot.legacyproperties; package org.springframework.boot.context.properties.migrator;
org.springframework.context.ApplicationListener=\ org.springframework.context.ApplicationListener=\
org.springframework.boot.legacyproperties.LegacyPropertiesListener org.springframework.boot.context.properties.migrator.PropertiesMigrationListener
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.legacyproperties; package org.springframework.boot.context.properties.migrator;
import org.junit.After; import org.junit.After;
import org.junit.Rule; import org.junit.Rule;
...@@ -28,11 +28,11 @@ import org.springframework.context.annotation.Configuration; ...@@ -28,11 +28,11 @@ import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for {@link LegacyPropertiesListener}. * Tests for {@link PropertiesMigrationListener}.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
public class LegacyPropertiesListenerTests { public class PropertiesMigrationListenerTests {
@Rule @Rule
public final OutputCapture output = new OutputCapture(); public final OutputCapture output = new OutputCapture();
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.boot.legacyproperties; package org.springframework.boot.context.properties.migrator;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -39,11 +39,11 @@ import org.springframework.mock.env.MockEnvironment; ...@@ -39,11 +39,11 @@ import org.springframework.mock.env.MockEnvironment;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for {@link LegacyPropertiesReporter}. * Tests for {@link PropertiesMigrationReporter}.
* *
* @author Stephane Nicoll * @author Stephane Nicoll
*/ */
public class LegacyPropertiesReporterTests { public class PropertiesMigrationReporterTests {
private ConfigurableEnvironment environment = new MockEnvironment(); private ConfigurableEnvironment environment = new MockEnvironment();
...@@ -172,9 +172,9 @@ public class LegacyPropertiesReporterTests { ...@@ -172,9 +172,9 @@ public class LegacyPropertiesReporterTests {
return createAnalyzer(repository).getReport().getErrorReport(); return createAnalyzer(repository).getReport().getErrorReport();
} }
private LegacyPropertiesReporter createAnalyzer( private PropertiesMigrationReporter createAnalyzer(
ConfigurationMetadataRepository repository) { ConfigurationMetadataRepository repository) {
return new LegacyPropertiesReporter(repository, this.environment); return new PropertiesMigrationReporter(repository, this.environment);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment