Merge branch '2.0.x'

pull/14975/head
Phillip Webb 6 years ago
commit c393f6262e

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -174,7 +174,6 @@ class PropertiesMigrationReporter {
private Map<String, ConfigurationPropertySource> getPropertySourcesAsMap() {
Map<String, ConfigurationPropertySource> map = new LinkedHashMap<>();
ConfigurationPropertySources.get(this.environment);
for (ConfigurationPropertySource source : ConfigurationPropertySources
.get(this.environment)) {
map.put(determinePropertySourceName(source), source);

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -65,6 +65,15 @@ class AliasedConfigurationPropertySource implements ConfigurationPropertySource
return aliasResult;
}
}
for (ConfigurationPropertyName from : getAliases()) {
for (ConfigurationPropertyName alias : getAliases().getAliases(from)) {
if (name.isAncestorOf(alias)) {
if (this.source.getConfigurationProperty(from) != null) {
return ConfigurationPropertyState.PRESENT;
}
}
}
}
return ConfigurationPropertyState.ABSENT;
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -18,6 +18,7 @@ package org.springframework.boot.context.properties.source;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -33,7 +34,8 @@ import org.springframework.util.MultiValueMap;
* @since 2.0.0
* @see ConfigurationPropertySource#withAliases(ConfigurationPropertyNameAliases)
*/
public final class ConfigurationPropertyNameAliases {
public final class ConfigurationPropertyNameAliases
implements Iterable<ConfigurationPropertyName> {
private final MultiValueMap<ConfigurationPropertyName, ConfigurationPropertyName> aliases = new LinkedMultiValueMap<>();
@ -74,4 +76,9 @@ public final class ConfigurationPropertyNameAliases {
.findFirst().orElse(null);
}
@Override
public Iterator<ConfigurationPropertyName> iterator() {
return this.aliases.keySet().iterator();
}
}

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

@ -16,6 +16,8 @@
package org.springframework.boot.context.properties.source;
import java.util.Collections;
import org.junit.Test;
import org.mockito.Answers;
@ -111,6 +113,16 @@ public class AliasedConfigurationPropertySourceTests {
.isEqualTo(ConfigurationPropertyState.PRESENT);
}
@Test
public void containsDescendantOfWhenPresentInAliasShouldReturnPresent() {
ConfigurationPropertySource source = new MapConfigurationPropertySource(
Collections.singletonMap("foo.bar", "foobar"));
ConfigurationPropertySource aliased = source
.withAliases(new ConfigurationPropertyNameAliases("foo.bar", "baz.foo"));
assertThat(aliased.containsDescendantOf(ConfigurationPropertyName.of("baz")))
.isEqualTo(ConfigurationPropertyState.PRESENT);
}
private Object getValue(ConfigurationPropertySource source, String name) {
ConfigurationProperty property = source
.getConfigurationProperty(ConfigurationPropertyName.of(name));

Loading…
Cancel
Save