|
|
@ -72,20 +72,41 @@ public class PropertySourcesPropertyValues implements PropertyValues {
|
|
|
|
this.propertySources = propertySources;
|
|
|
|
this.propertySources = propertySources;
|
|
|
|
PropertySourcesPropertyResolver resolver = new PropertySourcesPropertyResolver(
|
|
|
|
PropertySourcesPropertyResolver resolver = new PropertySourcesPropertyResolver(
|
|
|
|
propertySources);
|
|
|
|
propertySources);
|
|
|
|
String[] includes = patterns == null ? new String[0] : patterns
|
|
|
|
String[] includes = toArray(patterns);
|
|
|
|
.toArray(new String[0]);
|
|
|
|
String[] exacts = toArray(names);
|
|
|
|
String[] exacts = names == null ? new String[0] : names.toArray(new String[0]);
|
|
|
|
|
|
|
|
for (PropertySource<?> source : propertySources) {
|
|
|
|
for (PropertySource<?> source : propertySources) {
|
|
|
|
processPropertySource(source, resolver, includes, exacts);
|
|
|
|
processPropertySource(source, resolver, includes, exacts);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String[] toArray(Collection<String> strings) {
|
|
|
|
|
|
|
|
if (strings == null) {
|
|
|
|
|
|
|
|
return new String[0];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return strings.toArray(new String[strings.size()]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void processPropertySource(PropertySource<?> source,
|
|
|
|
private void processPropertySource(PropertySource<?> source,
|
|
|
|
PropertySourcesPropertyResolver resolver, String[] includes, String[] exacts) {
|
|
|
|
PropertySourcesPropertyResolver resolver, String[] includes, String[] exacts) {
|
|
|
|
if (source instanceof EnumerablePropertySource) {
|
|
|
|
if (source instanceof EnumerablePropertySource) {
|
|
|
|
EnumerablePropertySource<?> enumerable = (EnumerablePropertySource<?>) source;
|
|
|
|
processEnumerablePropertySource((EnumerablePropertySource<?>) source,
|
|
|
|
if (enumerable.getPropertyNames().length > 0) {
|
|
|
|
resolver, includes, exacts);
|
|
|
|
for (String propertyName : enumerable.getPropertyNames()) {
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (source instanceof CompositePropertySource) {
|
|
|
|
|
|
|
|
processCompositePropertySource((CompositePropertySource) source, resolver,
|
|
|
|
|
|
|
|
includes, exacts);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
// We can only do exact matches for non-enumerable property names, but
|
|
|
|
|
|
|
|
// that's better than nothing...
|
|
|
|
|
|
|
|
processDefaultPropertySource(source, resolver, includes, exacts);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void processEnumerablePropertySource(EnumerablePropertySource<?> source,
|
|
|
|
|
|
|
|
PropertySourcesPropertyResolver resolver, String[] includes, String[] exacts) {
|
|
|
|
|
|
|
|
if (source.getPropertyNames().length > 0) {
|
|
|
|
|
|
|
|
for (String propertyName : source.getPropertyNames()) {
|
|
|
|
if (this.NON_ENUMERABLE_ENUMERABLES.contains(source.getName())
|
|
|
|
if (this.NON_ENUMERABLE_ENUMERABLES.contains(source.getName())
|
|
|
|
&& !PatternMatchUtils.simpleMatch(includes, propertyName)) {
|
|
|
|
&& !PatternMatchUtils.simpleMatch(includes, propertyName)) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
@ -98,37 +119,18 @@ public class PropertySourcesPropertyValues implements PropertyValues {
|
|
|
|
// Probably could not resolve placeholders, ignore it here
|
|
|
|
// Probably could not resolve placeholders, ignore it here
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!this.propertyValues.containsKey(propertyName)) {
|
|
|
|
if (!this.propertyValues.containsKey(propertyName)) {
|
|
|
|
this.propertyValues.put(propertyName, new PropertyValue(
|
|
|
|
|
|
|
|
propertyName, value));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (source instanceof CompositePropertySource) {
|
|
|
|
|
|
|
|
CompositePropertySource composite = (CompositePropertySource) source;
|
|
|
|
|
|
|
|
for (PropertySource<?> nested : extractSources(composite)) {
|
|
|
|
|
|
|
|
processPropertySource(nested, resolver, includes, exacts);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
// We can only do exact matches for non-enumerable property names, but
|
|
|
|
|
|
|
|
// that's better than nothing...
|
|
|
|
|
|
|
|
for (String propertyName : exacts) {
|
|
|
|
|
|
|
|
Object value;
|
|
|
|
|
|
|
|
value = resolver.getProperty(propertyName);
|
|
|
|
|
|
|
|
if (value != null && !this.propertyValues.containsKey(propertyName)) {
|
|
|
|
|
|
|
|
this.propertyValues.put(propertyName, new PropertyValue(propertyName,
|
|
|
|
this.propertyValues.put(propertyName, new PropertyValue(propertyName,
|
|
|
|
value));
|
|
|
|
value));
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
value = source.getProperty(propertyName.toUpperCase());
|
|
|
|
|
|
|
|
if (value != null && !this.propertyValues.containsKey(propertyName)) {
|
|
|
|
|
|
|
|
this.propertyValues.put(propertyName, new PropertyValue(propertyName,
|
|
|
|
|
|
|
|
value));
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void processCompositePropertySource(CompositePropertySource source,
|
|
|
|
|
|
|
|
PropertySourcesPropertyResolver resolver, String[] includes, String[] exacts) {
|
|
|
|
|
|
|
|
for (PropertySource<?> nested : extractSources(source)) {
|
|
|
|
|
|
|
|
processPropertySource(nested, resolver, includes, exacts);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Collection<PropertySource<?>> extractSources(CompositePropertySource composite) {
|
|
|
|
private Collection<PropertySource<?>> extractSources(CompositePropertySource composite) {
|
|
|
@ -141,9 +143,24 @@ public class PropertySourcesPropertyValues implements PropertyValues {
|
|
|
|
.get(composite);
|
|
|
|
.get(composite);
|
|
|
|
return collection;
|
|
|
|
return collection;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
|
|
|
catch (Exception ex) {
|
|
|
|
throw new IllegalStateException(
|
|
|
|
throw new IllegalStateException(
|
|
|
|
"Cannot extract property sources from composite", e);
|
|
|
|
"Cannot extract property sources from composite", ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void processDefaultPropertySource(PropertySource<?> source,
|
|
|
|
|
|
|
|
PropertySourcesPropertyResolver resolver, String[] includes, String[] exacts) {
|
|
|
|
|
|
|
|
for (String propertyName : exacts) {
|
|
|
|
|
|
|
|
Object value = resolver.getProperty(propertyName);
|
|
|
|
|
|
|
|
if (value == null) {
|
|
|
|
|
|
|
|
value = source.getProperty(propertyName.toUpperCase());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value != null && !this.propertyValues.containsKey(propertyName)) {
|
|
|
|
|
|
|
|
this.propertyValues.put(propertyName, new PropertyValue(propertyName,
|
|
|
|
|
|
|
|
value));
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|