Polish
This commit is contained in:
parent
461cca3269
commit
d4f87ae74e
|
@ -90,8 +90,8 @@ public class DataSourceBuilder {
|
||||||
ConfigurationPropertySource source = new MapConfigurationPropertySource(
|
ConfigurationPropertySource source = new MapConfigurationPropertySource(
|
||||||
this.properties);
|
this.properties);
|
||||||
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
||||||
aliases.addAlaises("url", "jdbc-url");
|
aliases.addAliases("url", "jdbc-url");
|
||||||
aliases.addAlaises("username", "user");
|
aliases.addAliases("username", "user");
|
||||||
Binder binder = new Binder(source.withAliases(aliases));
|
Binder binder = new Binder(source.withAliases(aliases));
|
||||||
binder.bind(ConfigurationPropertyName.EMPTY, Bindable.ofInstance(result));
|
binder.bind(ConfigurationPropertyName.EMPTY, Bindable.ofInstance(result));
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,7 +124,7 @@ public class XADataSourceAutoConfiguration implements BeanClassLoaderAware {
|
||||||
source.put("url", this.properties.determineUrl());
|
source.put("url", this.properties.determineUrl());
|
||||||
source.putAll(dataSourceProperties.getXa().getProperties());
|
source.putAll(dataSourceProperties.getXa().getProperties());
|
||||||
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
||||||
aliases.addAlaises("user", "username");
|
aliases.addAliases("user", "username");
|
||||||
return source.withAliases(aliases);
|
return source.withAliases(aliases);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class ConfigurationBeanFactoryMetaData implements BeanFactoryPostProcesso
|
||||||
|
|
||||||
private ConfigurableListableBeanFactory beanFactory;
|
private ConfigurableListableBeanFactory beanFactory;
|
||||||
|
|
||||||
private Map<String, MetaData> beans = new HashMap<>();
|
private final Map<String, MetaData> beans = new HashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
|
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
|
||||||
|
@ -96,9 +96,9 @@ public class ConfigurationBeanFactoryMetaData implements BeanFactoryPostProcesso
|
||||||
|
|
||||||
private static class MetaData {
|
private static class MetaData {
|
||||||
|
|
||||||
private String bean;
|
private final String bean;
|
||||||
|
|
||||||
private String method;
|
private final String method;
|
||||||
|
|
||||||
MetaData(String bean, String method) {
|
MetaData(String bean, String method) {
|
||||||
this.bean = bean;
|
this.bean = bean;
|
||||||
|
|
|
@ -465,7 +465,7 @@ public class ConfigurationPropertiesBindingPostProcessor implements BeanPostProc
|
||||||
*/
|
*/
|
||||||
private static class ChainingValidator implements Validator {
|
private static class ChainingValidator implements Validator {
|
||||||
|
|
||||||
private Validator[] validators;
|
private final Validator[] validators;
|
||||||
|
|
||||||
ChainingValidator(Validator... validators) {
|
ChainingValidator(Validator... validators) {
|
||||||
Assert.notNull(validators, "Validators must not be null");
|
Assert.notNull(validators, "Validators must not be null");
|
||||||
|
|
|
@ -29,7 +29,7 @@ interface BeanBinder {
|
||||||
/**
|
/**
|
||||||
* Return a bound bean instance or {@code null} if the {@link BeanBinder} does not
|
* Return a bound bean instance or {@code null} if the {@link BeanBinder} does not
|
||||||
* support the specified {@link Bindable}.
|
* support the specified {@link Bindable}.
|
||||||
* @param target the binable to bind
|
* @param target the bindable to bind
|
||||||
* @param hasKnownBindableProperties if this binder has known bindable elements. If
|
* @param hasKnownBindableProperties if this binder has known bindable elements. If
|
||||||
* names from underlying {@link ConfigurationPropertySource} cannot be iterated this
|
* names from underlying {@link ConfigurationPropertySource} cannot be iterated this
|
||||||
* method can be {@code false}, even though binding may ultimately succeed.
|
* method can be {@code false}, even though binding may ultimately succeed.
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class BindException extends RuntimeException implements OriginProvider {
|
||||||
StringBuilder message = new StringBuilder();
|
StringBuilder message = new StringBuilder();
|
||||||
message.append("Failed to bind properties");
|
message.append("Failed to bind properties");
|
||||||
message.append(name == null ? "" : " under '" + name + "'");
|
message.append(name == null ? "" : " under '" + name + "'");
|
||||||
message.append(" to " + target.getType());
|
message.append(" to ").append(target.getType());
|
||||||
return message.toString();
|
return message.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ import org.springframework.boot.context.properties.source.ConfigurationPropertyN
|
||||||
public interface BindHandler {
|
public interface BindHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default no-op bind hander.
|
* Default no-op bind handler.
|
||||||
*/
|
*/
|
||||||
BindHandler DEFAULT = new BindHandler() {
|
BindHandler DEFAULT = new BindHandler() {
|
||||||
|
|
||||||
|
|
|
@ -161,7 +161,7 @@ public final class BindResult<T> {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
return (BindResult<T>) UNBOUND;
|
return (BindResult<T>) UNBOUND;
|
||||||
}
|
}
|
||||||
return new BindResult<T>(value);
|
return new BindResult<>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,7 +129,7 @@ public final class Bindable<T> {
|
||||||
* @return an updated {@link Bindable}
|
* @return an updated {@link Bindable}
|
||||||
*/
|
*/
|
||||||
public Bindable<T> withAnnotations(Annotation... annotations) {
|
public Bindable<T> withAnnotations(Annotation... annotations) {
|
||||||
return new Bindable<T>(this.type, this.boxedType, this.value,
|
return new Bindable<>(this.type, this.boxedType, this.value,
|
||||||
(annotations == null ? NO_ANNOTATIONS : annotations));
|
(annotations == null ? NO_ANNOTATIONS : annotations));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,7 +226,7 @@ public final class Bindable<T> {
|
||||||
Class<?> wrapperType = Array.get(array, 0).getClass();
|
Class<?> wrapperType = Array.get(array, 0).getClass();
|
||||||
return ResolvableType.forClass(wrapperType);
|
return ResolvableType.forClass(wrapperType);
|
||||||
}
|
}
|
||||||
if (resolved.isArray()) {
|
if (resolved != null && resolved.isArray()) {
|
||||||
return ResolvableType.forArrayComponent(box(type.getComponentType()));
|
return ResolvableType.forArrayComponent(box(type.getComponentType()));
|
||||||
}
|
}
|
||||||
return type;
|
return type;
|
||||||
|
|
|
@ -287,7 +287,7 @@ public class Binder {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object bindBean(ConfigurationPropertyName name, Bindable<?> target,
|
private Object bindBean(ConfigurationPropertyName name, Bindable<?> target,
|
||||||
BindHandler handler, Context context) throws Exception {
|
BindHandler handler, Context context) {
|
||||||
boolean hasKnownBindableProperties = context.streamSources()
|
boolean hasKnownBindableProperties = context.streamSources()
|
||||||
.flatMap((s) -> s.filter(name::isAncestorOf).stream()).findAny()
|
.flatMap((s) -> s.filter(name::isAncestorOf).stream()).findAny()
|
||||||
.isPresent();
|
.isPresent();
|
||||||
|
|
|
@ -44,12 +44,12 @@ class JavaBeanBinder implements BeanBinder {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
BeanSupplier<T> beanSupplier = bean.getSupplier(target);
|
BeanSupplier<T> beanSupplier = bean.getSupplier(target);
|
||||||
boolean bound = bind(target, propertyBinder, bean, beanSupplier);
|
boolean bound = bind(propertyBinder, bean, beanSupplier);
|
||||||
return (bound ? beanSupplier.get() : null);
|
return (bound ? beanSupplier.get() : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> boolean bind(Bindable<T> target, BeanPropertyBinder propertyBinder,
|
private <T> boolean bind(BeanPropertyBinder propertyBinder, Bean<T> bean,
|
||||||
Bean<T> bean, BeanSupplier<T> beanSupplier) {
|
BeanSupplier<T> beanSupplier) {
|
||||||
boolean bound = false;
|
boolean bound = false;
|
||||||
for (Map.Entry<String, BeanProperty> entry : bean.getProperties().entrySet()) {
|
for (Map.Entry<String, BeanProperty> entry : bean.getProperties().entrySet()) {
|
||||||
bound |= bind(beanSupplier, propertyBinder, entry.getValue());
|
bound |= bind(beanSupplier, propertyBinder, entry.getValue());
|
||||||
|
@ -151,7 +151,7 @@ class JavaBeanBinder implements BeanBinder {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public BeanSupplier<T> getSupplier(Bindable<T> target) {
|
public BeanSupplier<T> getSupplier(Bindable<T> target) {
|
||||||
return new BeanSupplier<T>(() -> {
|
return new BeanSupplier<>(() -> {
|
||||||
T instance = null;
|
T instance = null;
|
||||||
if (target.getValue() != null) {
|
if (target.getValue() != null) {
|
||||||
instance = target.getValue().get();
|
instance = target.getValue().get();
|
||||||
|
@ -168,7 +168,7 @@ class JavaBeanBinder implements BeanBinder {
|
||||||
boolean useExistingValueForType) {
|
boolean useExistingValueForType) {
|
||||||
Class<?> type = bindable.getType().resolve();
|
Class<?> type = bindable.getType().resolve();
|
||||||
Supplier<T> value = bindable.getValue();
|
Supplier<T> value = bindable.getValue();
|
||||||
if (value == null && !isInstantiatable(type)) {
|
if (value == null && !isInstantiable(type)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (useExistingValueForType && value != null) {
|
if (useExistingValueForType && value != null) {
|
||||||
|
@ -183,7 +183,7 @@ class JavaBeanBinder implements BeanBinder {
|
||||||
return (Bean<T>) bean;
|
return (Bean<T>) bean;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isInstantiatable(Class<?> type) {
|
private static boolean isInstantiable(Class<?> type) {
|
||||||
if (type.isInterface()) {
|
if (type.isInterface()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ class MapBinder extends AggregateBinder<Map<Object, Object>> {
|
||||||
public void bindEntries(ConfigurationPropertySource source,
|
public void bindEntries(ConfigurationPropertySource source,
|
||||||
Map<Object, Object> map) {
|
Map<Object, Object> map) {
|
||||||
for (ConfigurationPropertyName name : source) {
|
for (ConfigurationPropertyName name : source) {
|
||||||
Bindable<?> valueBindable = getValueBindable(source, name);
|
Bindable<?> valueBindable = getValueBindable(name);
|
||||||
ConfigurationPropertyName entryName = getEntryName(source, name);
|
ConfigurationPropertyName entryName = getEntryName(source, name);
|
||||||
Object key = getContext().getConversionService()
|
Object key = getContext().getConversionService()
|
||||||
.convert(getKeyName(entryName), this.keyType);
|
.convert(getKeyName(entryName), this.keyType);
|
||||||
|
@ -93,8 +93,7 @@ class MapBinder extends AggregateBinder<Map<Object, Object>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Bindable<?> getValueBindable(ConfigurationPropertySource source,
|
private Bindable<?> getValueBindable(ConfigurationPropertyName name) {
|
||||||
ConfigurationPropertyName name) {
|
|
||||||
if (isMultiElementName(name) && isValueTreatedAsNestedMap()) {
|
if (isMultiElementName(name) && isValueTreatedAsNestedMap()) {
|
||||||
return Bindable.of(this.mapType);
|
return Bindable.of(this.mapType);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,9 +33,9 @@ import org.springframework.util.SystemPropertyUtils;
|
||||||
*/
|
*/
|
||||||
public class PropertySourcesPlaceholdersResolver implements PlaceholdersResolver {
|
public class PropertySourcesPlaceholdersResolver implements PlaceholdersResolver {
|
||||||
|
|
||||||
private PropertySources sources;
|
private final PropertySources sources;
|
||||||
|
|
||||||
private PropertyPlaceholderHelper helper;
|
private final PropertyPlaceholderHelper helper;
|
||||||
|
|
||||||
public PropertySourcesPlaceholdersResolver(Environment environment) {
|
public PropertySourcesPlaceholdersResolver(Environment environment) {
|
||||||
this(getSources(environment), null);
|
this(getSources(environment), null);
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class ValidationBindHandler extends AbstractBindHandler {
|
||||||
|
|
||||||
private boolean validate;
|
private boolean validate;
|
||||||
|
|
||||||
private Set<ConfigurationProperty> boundProperties = new LinkedHashSet<>();
|
private final Set<ConfigurationProperty> boundProperties = new LinkedHashSet<>();
|
||||||
|
|
||||||
public ValidationBindHandler(Validator... validators) {
|
public ValidationBindHandler(Validator... validators) {
|
||||||
super();
|
super();
|
||||||
|
|
|
@ -141,7 +141,7 @@ public final class ConfigurationPropertyName
|
||||||
* Returns {@code true} if this element is an ancestor (immediate or nested parent) or
|
* Returns {@code true} if this element is an ancestor (immediate or nested parent) or
|
||||||
* the specified name.
|
* the specified name.
|
||||||
* @param name the name to check
|
* @param name the name to check
|
||||||
* @return {@code true} if this name is an ancessor
|
* @return {@code true} if this name is an ancestor
|
||||||
*/
|
*/
|
||||||
public boolean isAncestorOf(ConfigurationPropertyName name) {
|
public boolean isAncestorOf(ConfigurationPropertyName name) {
|
||||||
ConfigurationPropertyName candidate = (name == null ? null : name.getParent());
|
ConfigurationPropertyName candidate = (name == null ? null : name.getParent());
|
||||||
|
@ -231,8 +231,8 @@ public final class ConfigurationPropertyName
|
||||||
public static ConfigurationPropertyName of(String name)
|
public static ConfigurationPropertyName of(String name)
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
Assert.notNull(name, "Name must not be null");
|
Assert.notNull(name, "Name must not be null");
|
||||||
Assert.isTrue(!name.toString().startsWith("."), "Name must not start with '.'");
|
Assert.isTrue(!name.startsWith("."), "Name must not start with '.'");
|
||||||
Assert.isTrue(!name.toString().endsWith("."), "Name must not end with '.'");
|
Assert.isTrue(!name.endsWith("."), "Name must not end with '.'");
|
||||||
if (StringUtils.isEmpty(name)) {
|
if (StringUtils.isEmpty(name)) {
|
||||||
return EMPTY;
|
return EMPTY;
|
||||||
}
|
}
|
||||||
|
@ -308,7 +308,7 @@ public final class ConfigurationPropertyName
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String string = getValue(Form.CONFIGURATION).toString();
|
String string = getValue(Form.CONFIGURATION);
|
||||||
return (this.indexed ? "[" + string + "]" : string);
|
return (this.indexed ? "[" + string + "]" : string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ import org.springframework.util.LinkedMultiValueMap;
|
||||||
import org.springframework.util.MultiValueMap;
|
import org.springframework.util.MultiValueMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maintains a mapping of {@link ConfigurationPropertyName} alaises.
|
* Maintains a mapping of {@link ConfigurationPropertyName} aliases.
|
||||||
*
|
*
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
* @author Madhura Bhave
|
* @author Madhura Bhave
|
||||||
|
@ -41,23 +41,23 @@ public final class ConfigurationPropertyNameAliases {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigurationPropertyNameAliases(String name, String... aliases) {
|
public ConfigurationPropertyNameAliases(String name, String... aliases) {
|
||||||
addAlaises(name, aliases);
|
addAliases(name, aliases);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigurationPropertyNameAliases(ConfigurationPropertyName name,
|
public ConfigurationPropertyNameAliases(ConfigurationPropertyName name,
|
||||||
ConfigurationPropertyName... aliases) {
|
ConfigurationPropertyName... aliases) {
|
||||||
addAlaises(name, aliases);
|
addAliases(name, aliases);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAlaises(String name, String... aliases) {
|
public void addAliases(String name, String... aliases) {
|
||||||
Assert.notNull(name, "Name must not be null");
|
Assert.notNull(name, "Name must not be null");
|
||||||
Assert.notNull(aliases, "Aliases must not be null");
|
Assert.notNull(aliases, "Aliases must not be null");
|
||||||
addAlaises(ConfigurationPropertyName.of(name),
|
addAliases(ConfigurationPropertyName.of(name),
|
||||||
Arrays.stream(aliases).map(ConfigurationPropertyName::of)
|
Arrays.stream(aliases).map(ConfigurationPropertyName::of)
|
||||||
.toArray(ConfigurationPropertyName[]::new));
|
.toArray(ConfigurationPropertyName[]::new));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAlaises(ConfigurationPropertyName name,
|
public void addAliases(ConfigurationPropertyName name,
|
||||||
ConfigurationPropertyName... aliases) {
|
ConfigurationPropertyName... aliases) {
|
||||||
Assert.notNull(name, "Name must not be null");
|
Assert.notNull(name, "Name must not be null");
|
||||||
Assert.notNull(aliases, "Aliases must not be null");
|
Assert.notNull(aliases, "Aliases must not be null");
|
||||||
|
|
|
@ -77,7 +77,7 @@ public interface ConfigurationPropertySource extends Iterable<ConfigurationPrope
|
||||||
/**
|
/**
|
||||||
* Return a variant of this source that supports name aliases.
|
* Return a variant of this source that supports name aliases.
|
||||||
* @param aliases a function that returns a stream of aliases for any given name
|
* @param aliases a function that returns a stream of aliases for any given name
|
||||||
* @return a {@link ConfigurationPropertySource} instance supporting name alaises
|
* @return a {@link ConfigurationPropertySource} instance supporting name aliases
|
||||||
*/
|
*/
|
||||||
default ConfigurationPropertySource withAliases(
|
default ConfigurationPropertySource withAliases(
|
||||||
ConfigurationPropertyNameAliases aliases) {
|
ConfigurationPropertyNameAliases aliases) {
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class ConfigurationPropertySources
|
||||||
/**
|
/**
|
||||||
* The name of the {@link PropertySource} {@link #adapt adapter}.
|
* The name of the {@link PropertySource} {@link #adapt adapter}.
|
||||||
*/
|
*/
|
||||||
public static final String PROPERTY_SOURCE_NAME = "configurationPropertes";
|
public static final String PROPERTY_SOURCE_NAME = "configurationProperties";
|
||||||
|
|
||||||
private final PropertySources propertySources;
|
private final PropertySources propertySources;
|
||||||
|
|
||||||
|
|
|
@ -37,9 +37,9 @@ class DefaultPropertyMapper implements PropertyMapper {
|
||||||
|
|
||||||
public static final PropertyMapper INSTANCE = new DefaultPropertyMapper();
|
public static final PropertyMapper INSTANCE = new DefaultPropertyMapper();
|
||||||
|
|
||||||
private Cache<ConfigurationPropertyName> configurationPropertySourceCache = new Cache<>();
|
private final Cache<ConfigurationPropertyName> configurationPropertySourceCache = new Cache<>();
|
||||||
|
|
||||||
private Cache<String> propertySourceCache = new Cache<>();
|
private final Cache<String> propertySourceCache = new Cache<>();
|
||||||
|
|
||||||
private final ConfigurationPropertyNameBuilder nameBuilder = new ConfigurationPropertyNameBuilder();
|
private final ConfigurationPropertyNameBuilder nameBuilder = new ConfigurationPropertyNameBuilder();
|
||||||
|
|
||||||
|
@ -59,12 +59,7 @@ class DefaultPropertyMapper implements PropertyMapper {
|
||||||
@Override
|
@Override
|
||||||
public List<PropertyMapping> map(PropertySource<?> propertySource,
|
public List<PropertyMapping> map(PropertySource<?> propertySource,
|
||||||
String propertySourceName) {
|
String propertySourceName) {
|
||||||
List<PropertyMapping> mapping = this.propertySourceCache.get(propertySourceName);
|
return this.propertySourceCache.computeIfAbsent(propertySourceName, this::tryMap);
|
||||||
if (mapping == null) {
|
|
||||||
mapping = tryMap(propertySourceName);
|
|
||||||
this.propertySourceCache.put(propertySourceName, mapping);
|
|
||||||
}
|
|
||||||
return mapping;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<PropertyMapping> tryMap(String propertySourceName) {
|
private List<PropertyMapping> tryMap(String propertySourceName) {
|
||||||
|
@ -94,10 +89,7 @@ class DefaultPropertyMapper implements PropertyMapper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean removeEldestEntry(Map.Entry<K, List<PropertyMapping>> eldest) {
|
protected boolean removeEldestEntry(Map.Entry<K, List<PropertyMapping>> eldest) {
|
||||||
if (size() < this.capacity) {
|
return size() >= this.capacity;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class MapConfigurationPropertySource implements ConfigurationPropertySour
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add all enties from the specified map.
|
* Add all entries from the specified map.
|
||||||
* @param map the source map
|
* @param map the source map
|
||||||
*/
|
*/
|
||||||
public void putAll(Map<?, ?> map) {
|
public void putAll(Map<?, ?> map) {
|
||||||
|
|
|
@ -145,7 +145,7 @@ class PropertySourceConfigurationPropertySource implements ConfigurationProperty
|
||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
List<PropertyMapping> mappings = getPropertyMappings();
|
List<PropertyMapping> mappings = getPropertyMappings();
|
||||||
names = new ArrayList<ConfigurationPropertyName>(mappings.size());
|
names = new ArrayList<>(mappings.size());
|
||||||
for (PropertyMapping mapping : mappings) {
|
for (PropertyMapping mapping : mappings) {
|
||||||
names.add(mapping.getConfigurationPropertyName());
|
names.add(mapping.getConfigurationPropertyName());
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ class PropertySourceConfigurationPropertySource implements ConfigurationProperty
|
||||||
}
|
}
|
||||||
String[] names = ((EnumerablePropertySource<?>) this.propertySource)
|
String[] names = ((EnumerablePropertySource<?>) this.propertySource)
|
||||||
.getPropertyNames();
|
.getPropertyNames();
|
||||||
mappings = new ArrayList<PropertyMapping>(names.length);
|
mappings = new ArrayList<>(names.length);
|
||||||
for (String name : names) {
|
for (String name : names) {
|
||||||
mappings.addAll(this.mapper.map(this.propertySource, name));
|
mappings.addAll(this.mapper.map(this.propertySource, name));
|
||||||
}
|
}
|
||||||
|
@ -238,8 +238,6 @@ class PropertySourceConfigurationPropertySource implements ConfigurationProperty
|
||||||
|
|
||||||
private static class Cache {
|
private static class Cache {
|
||||||
|
|
||||||
private ConfigurationPropertyName knownMissingName;
|
|
||||||
|
|
||||||
private List<ConfigurationPropertyName> names;
|
private List<ConfigurationPropertyName> names;
|
||||||
|
|
||||||
private List<PropertyMapping> mappings;
|
private List<PropertyMapping> mappings;
|
||||||
|
|
|
@ -45,7 +45,7 @@ import org.springframework.util.StringUtils;
|
||||||
*/
|
*/
|
||||||
class SystemEnvironmentPropertyMapper implements PropertyMapper {
|
class SystemEnvironmentPropertyMapper implements PropertyMapper {
|
||||||
|
|
||||||
public static PropertyMapper INSTANCE = new SystemEnvironmentPropertyMapper();
|
public static final PropertyMapper INSTANCE = new SystemEnvironmentPropertyMapper();
|
||||||
|
|
||||||
private final ConfigurationPropertyNameBuilder nameBuilder = new ConfigurationPropertyNameBuilder(
|
private final ConfigurationPropertyNameBuilder nameBuilder = new ConfigurationPropertyNameBuilder(
|
||||||
this::createElement);
|
this::createElement);
|
||||||
|
@ -104,10 +104,9 @@ class SystemEnvironmentPropertyMapper implements PropertyMapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String convertName(ConfigurationPropertyName configurationPropertyName) {
|
private String convertName(ConfigurationPropertyName configurationPropertyName) {
|
||||||
String propertyName = configurationPropertyName.stream()
|
return configurationPropertyName.stream()
|
||||||
.map(name -> name.getValue(Form.UNIFORM).toUpperCase())
|
.map(name -> name.getValue(Form.UNIFORM).toUpperCase())
|
||||||
.collect(Collectors.joining("_"));
|
.collect(Collectors.joining("_"));
|
||||||
return propertyName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isListShortcutPossible(ConfigurationPropertyName name) {
|
private boolean isListShortcutPossible(ConfigurationPropertyName name) {
|
||||||
|
|
|
@ -86,7 +86,7 @@ public class TextResourceOrigin implements Origin {
|
||||||
result.append(this.resource == null ? "unknown resource [?]"
|
result.append(this.resource == null ? "unknown resource [?]"
|
||||||
: this.resource.getDescription());
|
: this.resource.getDescription());
|
||||||
if (this.location != null) {
|
if (this.location != null) {
|
||||||
result.append(":" + this.location);
|
result.append(":").append(this.location);
|
||||||
}
|
}
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class ConfigurationPropertyNameAliasesTests {
|
||||||
@Test
|
@Test
|
||||||
public void addAliasesFromStringShouldAddMapping() throws Exception {
|
public void addAliasesFromStringShouldAddMapping() throws Exception {
|
||||||
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
||||||
aliases.addAlaises("foo", "bar", "baz");
|
aliases.addAliases("foo", "bar", "baz");
|
||||||
assertThat(aliases.getAliases(ConfigurationPropertyName.of("foo")))
|
assertThat(aliases.getAliases(ConfigurationPropertyName.of("foo")))
|
||||||
.containsExactly(ConfigurationPropertyName.of("bar"),
|
.containsExactly(ConfigurationPropertyName.of("bar"),
|
||||||
ConfigurationPropertyName.of("baz"));
|
ConfigurationPropertyName.of("baz"));
|
||||||
|
@ -71,7 +71,7 @@ public class ConfigurationPropertyNameAliasesTests {
|
||||||
@Test
|
@Test
|
||||||
public void addAlaisesFromNameShouldAddMapping() throws Exception {
|
public void addAlaisesFromNameShouldAddMapping() throws Exception {
|
||||||
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
||||||
aliases.addAlaises(ConfigurationPropertyName.of("foo"),
|
aliases.addAliases(ConfigurationPropertyName.of("foo"),
|
||||||
ConfigurationPropertyName.of("bar"), ConfigurationPropertyName.of("baz"));
|
ConfigurationPropertyName.of("bar"), ConfigurationPropertyName.of("baz"));
|
||||||
assertThat(aliases.getAliases(ConfigurationPropertyName.of("foo")))
|
assertThat(aliases.getAliases(ConfigurationPropertyName.of("foo")))
|
||||||
.containsExactly(ConfigurationPropertyName.of("bar"),
|
.containsExactly(ConfigurationPropertyName.of("bar"),
|
||||||
|
@ -81,8 +81,8 @@ public class ConfigurationPropertyNameAliasesTests {
|
||||||
@Test
|
@Test
|
||||||
public void addWhenHasExistingShouldAddAdditionalMappings() throws Exception {
|
public void addWhenHasExistingShouldAddAdditionalMappings() throws Exception {
|
||||||
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
||||||
aliases.addAlaises("foo", "bar");
|
aliases.addAliases("foo", "bar");
|
||||||
aliases.addAlaises("foo", "baz");
|
aliases.addAliases("foo", "baz");
|
||||||
assertThat(aliases.getAliases(ConfigurationPropertyName.of("foo")))
|
assertThat(aliases.getAliases(ConfigurationPropertyName.of("foo")))
|
||||||
.containsExactly(ConfigurationPropertyName.of("bar"),
|
.containsExactly(ConfigurationPropertyName.of("bar"),
|
||||||
ConfigurationPropertyName.of("baz"));
|
ConfigurationPropertyName.of("baz"));
|
||||||
|
@ -97,7 +97,7 @@ public class ConfigurationPropertyNameAliasesTests {
|
||||||
@Test
|
@Test
|
||||||
public void getAliasesWhenMappedShouldReturnMapping() throws Exception {
|
public void getAliasesWhenMappedShouldReturnMapping() throws Exception {
|
||||||
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
||||||
aliases.addAlaises("foo", "bar");
|
aliases.addAliases("foo", "bar");
|
||||||
assertThat(aliases.getAliases(ConfigurationPropertyName.of("foo")))
|
assertThat(aliases.getAliases(ConfigurationPropertyName.of("foo")))
|
||||||
.containsExactly(ConfigurationPropertyName.of("bar"));
|
.containsExactly(ConfigurationPropertyName.of("bar"));
|
||||||
}
|
}
|
||||||
|
@ -105,8 +105,8 @@ public class ConfigurationPropertyNameAliasesTests {
|
||||||
@Test
|
@Test
|
||||||
public void getNameForAliasWhenHasMappingShouldReturnName() throws Exception {
|
public void getNameForAliasWhenHasMappingShouldReturnName() throws Exception {
|
||||||
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
||||||
aliases.addAlaises("foo", "bar");
|
aliases.addAliases("foo", "bar");
|
||||||
aliases.addAlaises("foo", "baz");
|
aliases.addAliases("foo", "baz");
|
||||||
assertThat((Object) aliases.getNameForAlias(ConfigurationPropertyName.of("bar")))
|
assertThat((Object) aliases.getNameForAlias(ConfigurationPropertyName.of("bar")))
|
||||||
.isEqualTo(ConfigurationPropertyName.of("foo"));
|
.isEqualTo(ConfigurationPropertyName.of("foo"));
|
||||||
assertThat((Object) aliases.getNameForAlias(ConfigurationPropertyName.of("baz")))
|
assertThat((Object) aliases.getNameForAlias(ConfigurationPropertyName.of("baz")))
|
||||||
|
@ -116,7 +116,7 @@ public class ConfigurationPropertyNameAliasesTests {
|
||||||
@Test
|
@Test
|
||||||
public void getNameForAliasWhenNotMappedShouldReturnNull() throws Exception {
|
public void getNameForAliasWhenNotMappedShouldReturnNull() throws Exception {
|
||||||
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases();
|
||||||
aliases.addAlaises("foo", "bar");
|
aliases.addAliases("foo", "bar");
|
||||||
assertThat((Object) aliases.getNameForAlias(ConfigurationPropertyName.of("baz")))
|
assertThat((Object) aliases.getNameForAlias(ConfigurationPropertyName.of("baz")))
|
||||||
.isNull();
|
.isNull();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue