Fix package tangle in properties source

Update `SpringConfigurationPropertySource` so that it no longer
references types in `org.springframework.boot.env`.

Closes gh-10592
This commit is contained in:
Phillip Webb 2017-10-11 10:57:36 -07:00
parent f48550aa44
commit 97afe8e938

View File

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