|
|
|
|
@ -17,9 +17,11 @@
@@ -17,9 +17,11 @@
|
|
|
|
|
package org.springframework.boot.context.properties.migrator; |
|
|
|
|
|
|
|
|
|
import java.util.Collections; |
|
|
|
|
import java.util.HashSet; |
|
|
|
|
import java.util.LinkedHashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Set; |
|
|
|
|
import java.util.function.Predicate; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
@ -86,14 +88,26 @@ class PropertiesMigrationReporter {
@@ -86,14 +88,26 @@ class PropertiesMigrationReporter {
|
|
|
|
|
if (renamed.isEmpty()) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
String target = "migrate-" + name; |
|
|
|
|
Map<String, OriginTrackedValue> content = new LinkedHashMap<>(); |
|
|
|
|
for (PropertyMigration candidate : renamed) { |
|
|
|
|
OriginTrackedValue value = OriginTrackedValue.of(candidate.getProperty().getValue(), |
|
|
|
|
candidate.getProperty().getOrigin()); |
|
|
|
|
content.put(candidate.getNewPropertyName(), value); |
|
|
|
|
NameTrackingPropertySource nameTrackingPropertySource = new NameTrackingPropertySource(); |
|
|
|
|
this.environment.getPropertySources().addFirst(nameTrackingPropertySource); |
|
|
|
|
try { |
|
|
|
|
String target = "migrate-" + name; |
|
|
|
|
Map<String, OriginTrackedValue> content = new LinkedHashMap<>(); |
|
|
|
|
for (PropertyMigration candidate : renamed) { |
|
|
|
|
String newPropertyName = candidate.getNewPropertyName(); |
|
|
|
|
Object value = candidate.getProperty().getValue(); |
|
|
|
|
if (nameTrackingPropertySource.isPlaceholderThatAccessesName(value, newPropertyName)) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
OriginTrackedValue originTrackedValue = OriginTrackedValue.of(value, |
|
|
|
|
candidate.getProperty().getOrigin()); |
|
|
|
|
content.put(newPropertyName, originTrackedValue); |
|
|
|
|
} |
|
|
|
|
return new OriginTrackedMapPropertySource(target, content); |
|
|
|
|
} |
|
|
|
|
finally { |
|
|
|
|
this.environment.getPropertySources().remove(nameTrackingPropertySource.getName()); |
|
|
|
|
} |
|
|
|
|
return new OriginTrackedMapPropertySource(target, content); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean isMapType(ConfigurationMetadataProperty property) { |
|
|
|
|
@ -172,4 +186,33 @@ class PropertiesMigrationReporter {
@@ -172,4 +186,33 @@ class PropertiesMigrationReporter {
|
|
|
|
|
return source.getUnderlyingSource().toString(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* {@link PropertySource} used to track accessed properties to protect against |
|
|
|
|
* circular references. |
|
|
|
|
*/ |
|
|
|
|
private class NameTrackingPropertySource extends PropertySource<Object> { |
|
|
|
|
|
|
|
|
|
private final Set<String> accessedNames = new HashSet<>(); |
|
|
|
|
|
|
|
|
|
NameTrackingPropertySource() { |
|
|
|
|
super(NameTrackingPropertySource.class.getName()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
boolean isPlaceholderThatAccessesName(Object value, String name) { |
|
|
|
|
if (value instanceof String) { |
|
|
|
|
this.accessedNames.clear(); |
|
|
|
|
PropertiesMigrationReporter.this.environment.resolvePlaceholders((String) value); |
|
|
|
|
return this.accessedNames.contains(name); |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Object getProperty(String name) { |
|
|
|
|
this.accessedNames.add(name); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|