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