|
|
@ -20,9 +20,9 @@ import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Objects;
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
import java.util.function.Function;
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.env.RandomValuePropertySource;
|
|
|
|
|
|
|
|
import org.springframework.boot.origin.Origin;
|
|
|
|
import org.springframework.boot.origin.Origin;
|
|
|
|
import org.springframework.boot.origin.PropertySourceOrigin;
|
|
|
|
import org.springframework.boot.origin.PropertySourceOrigin;
|
|
|
|
import org.springframework.core.env.EnumerablePropertySource;
|
|
|
|
import org.springframework.core.env.EnumerablePropertySource;
|
|
|
@ -61,24 +61,24 @@ class SpringConfigurationPropertySource implements ConfigurationPropertySource {
|
|
|
|
|
|
|
|
|
|
|
|
private final PropertyMapper mapper;
|
|
|
|
private final PropertyMapper mapper;
|
|
|
|
|
|
|
|
|
|
|
|
private final Function<ConfigurationPropertyName, ConfigurationPropertyState> containsDescendantOfMethod;
|
|
|
|
private final Function<ConfigurationPropertyName, ConfigurationPropertyState> containsDescendantOf;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Create a new {@link SpringConfigurationPropertySource} implementation.
|
|
|
|
* Create a new {@link SpringConfigurationPropertySource} implementation.
|
|
|
|
* @param propertySource the source property source
|
|
|
|
* @param propertySource the source property source
|
|
|
|
* @param mapper the property mapper
|
|
|
|
* @param mapper the property mapper
|
|
|
|
* @param containsDescendantOfMethod function used to implement
|
|
|
|
* @param containsDescendantOf function used to implement
|
|
|
|
* {@link #containsDescendantOf(ConfigurationPropertyName)} (may be {@code null})
|
|
|
|
* {@link #containsDescendantOf(ConfigurationPropertyName)} (may be {@code null})
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
SpringConfigurationPropertySource(PropertySource<?> propertySource,
|
|
|
|
SpringConfigurationPropertySource(PropertySource<?> propertySource,
|
|
|
|
PropertyMapper mapper,
|
|
|
|
PropertyMapper mapper,
|
|
|
|
Function<ConfigurationPropertyName, ConfigurationPropertyState> containsDescendantOfMethod) {
|
|
|
|
Function<ConfigurationPropertyName, ConfigurationPropertyState> containsDescendantOf) {
|
|
|
|
Assert.notNull(propertySource, "PropertySource must not be null");
|
|
|
|
Assert.notNull(propertySource, "PropertySource must not be null");
|
|
|
|
Assert.notNull(mapper, "Mapper must not be null");
|
|
|
|
Assert.notNull(mapper, "Mapper must not be null");
|
|
|
|
this.propertySource = propertySource;
|
|
|
|
this.propertySource = propertySource;
|
|
|
|
this.mapper = new ExceptionSwallowingPropertyMapper(mapper);
|
|
|
|
this.mapper = new ExceptionSwallowingPropertyMapper(mapper);
|
|
|
|
this.containsDescendantOfMethod = (containsDescendantOfMethod != null
|
|
|
|
this.containsDescendantOf = (containsDescendantOf != null ? containsDescendantOf
|
|
|
|
? containsDescendantOfMethod : (n) -> ConfigurationPropertyState.UNKNOWN);
|
|
|
|
: (n) -> ConfigurationPropertyState.UNKNOWN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -91,7 +91,7 @@ class SpringConfigurationPropertySource implements ConfigurationPropertySource {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public ConfigurationPropertyState containsDescendantOf(
|
|
|
|
public ConfigurationPropertyState containsDescendantOf(
|
|
|
|
ConfigurationPropertyName name) {
|
|
|
|
ConfigurationPropertyName name) {
|
|
|
|
return this.containsDescendantOfMethod.apply(name);
|
|
|
|
return this.containsDescendantOf.apply(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -146,7 +146,7 @@ class SpringConfigurationPropertySource implements ConfigurationPropertySource {
|
|
|
|
(EnumerablePropertySource<?>) source, mapper);
|
|
|
|
(EnumerablePropertySource<?>) source, mapper);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new SpringConfigurationPropertySource(source, mapper,
|
|
|
|
return new SpringConfigurationPropertySource(source, mapper,
|
|
|
|
getContainsDescendantOfMethod(source));
|
|
|
|
getContainsDescendantOfForSource(source));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static PropertyMapper getPropertyMapper(PropertySource<?> source) {
|
|
|
|
private static PropertyMapper getPropertyMapper(PropertySource<?> source) {
|
|
|
@ -178,16 +178,22 @@ class SpringConfigurationPropertySource implements ConfigurationPropertySource {
|
|
|
|
return source;
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static Function<ConfigurationPropertyName, ConfigurationPropertyState> getContainsDescendantOfMethod(
|
|
|
|
private static Function<ConfigurationPropertyName, ConfigurationPropertyState> getContainsDescendantOfForSource(
|
|
|
|
PropertySource<?> source) {
|
|
|
|
PropertySource<?> source) {
|
|
|
|
if (source instanceof RandomValuePropertySource) {
|
|
|
|
if (source.getSource() instanceof Random) {
|
|
|
|
return (name) -> (name.isAncestorOf(RANDOM) || name.equals(RANDOM)
|
|
|
|
return SpringConfigurationPropertySource::containsDescendantOfForRandom;
|
|
|
|
? ConfigurationPropertyState.PRESENT
|
|
|
|
|
|
|
|
: ConfigurationPropertyState.ABSENT);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static ConfigurationPropertyState containsDescendantOfForRandom(
|
|
|
|
|
|
|
|
ConfigurationPropertyName name) {
|
|
|
|
|
|
|
|
if (name.isAncestorOf(RANDOM) || name.equals(RANDOM)) {
|
|
|
|
|
|
|
|
return ConfigurationPropertyState.PRESENT;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ConfigurationPropertyState.ABSENT;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* {@link PropertyMapper} that swallows exceptions when the mapping fails.
|
|
|
|
* {@link PropertyMapper} that swallows exceptions when the mapping fails.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|