This is an automated email from the ASF dual-hosted git repository. anatole pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-tamaya.git
commit 0ddb859d57c71515e417a33e77d69355c753bb9b Merge: d5d3b74 8bcf810 Author: Anatole Tresch <atsti...@gmail.com> AuthorDate: Fri May 10 19:15:10 2019 +0200 Merged with master changes. .../java/org/apache/tamaya/spi/FilterContext.java | 29 ++----- .../main/java/org/apache/tamaya/spi/ListValue.java | 1 + .../java/org/apache/tamaya/spi/ObjectValue.java | 28 +++---- .../java/org/apache/tamaya/spi/PropertyValue.java | 36 ++++++--- .../apache/tamaya/spi/ServiceContextManager.java | 6 +- code/api/src/main/resources/tamaya-banner.txt | 2 +- .../java/org/apache/tamaya/ConfigurationTest.java | 2 +- .../org/apache/tamaya/spi/PropertySourceTest.java | 7 +- .../org/apache/tamaya/spi/PropertyValueTest.java | 22 +++++- code/core/pom.xml | 2 +- .../apache/tamaya/core/internal/BannerManager.java | 2 +- .../core/internal/CoreConfigurationBuilder.java | 1 + .../tamaya/core/internal/OSGIServiceContext.java | 2 +- .../tamaya/core/internal/OSGIServiceLoader.java | 92 ++++++++++------------ .../core/internal/converters/BooleanConverter.java | 2 +- .../core/internal/converters/ByteConverter.java | 2 +- .../core/internal/converters/ClassConverter.java | 2 +- .../internal/converters/DurationConverter.java | 2 +- .../core/internal/converters/FileConverter.java | 2 +- .../core/internal/converters/InstantConverter.java | 2 +- .../internal/converters/LocalDateConverter.java | 2 +- .../converters/LocalDateTimeConverter.java | 2 +- .../internal/converters/LocalTimeConverter.java | 2 +- .../converters/OffsetDateTimeConverter.java | 2 +- .../internal/converters/OffsetTimeConverter.java | 2 +- .../core/internal/converters/PathConverter.java | 2 +- .../core/internal/converters/URIConverter.java | 2 +- .../core/internal/converters/URLConverter.java | 2 +- .../core/propertysource/BasePropertySource.java | 2 +- .../internal/CoreConfigurationProviderTest.java | 7 +- .../core/internal/CoreConfigurationTest.java | 1 + .../propertysource/BasePropertySource.java | 3 +- .../PropertiesResourcePropertySource.java | 2 +- .../propertysource/SystemPropertySource.java | 4 +- .../DefaultConfigurationBuilderTest.java | 3 +- .../DefaultConfigurationSnapshotTest.java | 1 + .../spisupport/DefaultMetaDataProviderTest.java | 7 +- .../PropertySourceChangeSupportTest.java | 3 +- examples/11-distributed/pom.xml | 6 +- examples/pom.xml | 2 - 40 files changed, 161 insertions(+), 140 deletions(-) diff --cc code/api/src/main/java/org/apache/tamaya/spi/ObjectValue.java index 801260c,a640a04..ea244ef --- a/code/api/src/main/java/org/apache/tamaya/spi/ObjectValue.java +++ b/code/api/src/main/java/org/apache/tamaya/spi/ObjectValue.java @@@ -19,8 -19,9 +19,7 @@@ package org.apache.tamaya.spi; import java.util.*; -import java.util.function.Predicate; import java.util.function.Supplier; - import java.util.logging.Logger; -import java.util.stream.Collectors; /** * Class modelling the result of a request for a property value. A property value is basically identified by its key. @@@ -121,7 -93,7 +119,6 @@@ public final class ObjectValue extends * @param valueSupplier the supplier to create a new instance, if no value is present, not null. * @param <T> the target type. * @return the child found or created, never null. - * @throws IllegalArgumentException if multiple getPropertyValues with the given name are existing (ambigous). - * @throws IllegalArgumentException if multiple getValues with the given name are existing (ambigous). * @throws IllegalStateException if the instance is immutable. * @see #isImmutable() */ @@@ -186,13 -132,12 +183,12 @@@ @Override public ListValue toListValue(){ - ListValue array = new ListValue(getParent(), getKey()); - array.setValue(getValue()); + ListValue array = new ListValue(getKey()); + array.setParent(getParent()); array.setMeta(getMeta()); array.setVersion(getVersion()); - int index = 0; for(PropertyValue val:fields.values()){ - array.add(val.deepClone()); + array.addPropertyValue(val.deepClone()); } return array; } @@@ -292,8 -250,8 +288,8 @@@ } /** - * Convert the getValue tree to a property mapProperties. - * @return the corresponding property mapProperties, not null. - * Convert the getValue tree to a property map. ++ * Convert the value tree to a property map. + * @return the corresponding property map, not null. */ @Override public Map<String,String> toMap(){ @@@ -312,28 -268,6 +306,28 @@@ return map; } + /** - * Convert the value tree to a local property mapProperties. - * @return the corresponding local mapProperties, not null. ++ * Convert the value tree to a local property map. ++ * @return the corresponding local map, not null. + */ + @Override + public Map<String,String> toLocalMap(){ + Map<String, String> map = new TreeMap<>(); + for (PropertyValue n : fields.values()) { + switch(n.getValueType()){ + case VALUE: + map.put(n.getKey(), n.getValue()); + break; + default: + for(PropertyValue val:n) { + Map<String,String> valueMap = val.toLocalMap(); + map.putAll(valueMap); + } + } + } + return map; + } + /** * Clones this instance and all it's children, marking as mutable value. diff --cc code/api/src/main/java/org/apache/tamaya/spi/PropertyValue.java index 6fdaadf,22af7e1..712f1d6 --- a/code/api/src/main/java/org/apache/tamaya/spi/PropertyValue.java +++ b/code/api/src/main/java/org/apache/tamaya/spi/PropertyValue.java @@@ -61,6 -62,23 +62,23 @@@ public class PropertyValue implements S VALUE } + - /** - * Creates a new builder instance. - * @param key the key, not {@code null}. - * @param source the source, typically the name of the {@link PropertySource} - * providing the createValue, not {@code null}. - * @return a new builder instance. - * @deprecated Will be removed, use {@link PropertyValue} directly. - */ - @Deprecated - public static PropertyValueBuilder builder(String key, String source){ - Objects.requireNonNull(key, "Key must be given."); - Objects.requireNonNull(source, "Source must be given"); - - return new PropertyValueBuilder(key, null).setSource(source); - } ++// /** ++// * Creates a new builder instance. ++// * @param key the key, not {@code null}. ++// * @param source the source, typically the name of the {@link PropertySource} ++// * providing the createValue, not {@code null}. ++// * @return a new builder instance. ++// * @deprecated Will be removed, use {@link PropertyValue} directly. ++// */ ++// @Deprecated ++// public static PropertyValueBuilder builder(String key, String source){ ++// Objects.requireNonNull(key, "Key must be given."); ++// Objects.requireNonNull(source, "Source must be given"); ++// ++// return new PropertyValueBuilder(key, null).setSource(source); ++// } + /** * Creates a new (invisible) root, which is a node with an empty name. * @return a new empty root, never null. @@@ -143,18 -170,12 +161,18 @@@ Map<String, PropertyValue> result = new HashMap<>(config.size()); for(Map.Entry<String,String> en:config.entrySet()){ - PropertyValue pv = createValue(en.getKey(), en.getValue()) - .setMeta(metaData); + PropertyValue pv = createValue(en.getKey(), en.getValue()); + if(metaData!=null) { + pv.setMeta(metaData); + } if(source!=null){ - pv.setMeta("source", source); + pv.setMeta(SOURCE, source); } - result.put(en.getKey(), pv); + if(prefix==null) { + result.put(en.getKey(), pv); + }else{ + result.put(prefix + en.getKey(), pv.setKey(prefix=en.getKey())); + } } return result; } diff --cc code/api/src/test/java/org/apache/tamaya/spi/PropertyValueTest.java index 1f2e5fd,a94a324..b3f03ff --- a/code/api/src/test/java/org/apache/tamaya/spi/PropertyValueTest.java +++ b/code/api/src/test/java/org/apache/tamaya/spi/PropertyValueTest.java @@@ -29,29 -29,32 +30,46 @@@ import static org.assertj.core.api.Asse @SuppressWarnings("unchecked") public class PropertyValueTest { - @Test(expected = NullPointerException.class) - public void ofDoesNotAcceptNullAsKey() throws Exception { - PropertyValue.of(null, "b", "source"); - } - - @Test - public void ofDoesAcceptNullAsSource() throws Exception { - assertThatCode(() -> PropertyValue.of("a", "b", null)).doesNotThrowAnyException(); - } - - @Test - public void builder() throws Exception { - PropertyValueBuilder b = PropertyValue.builder("a", "b"); - assertThat(b).isNotNull(); - assertThat("a").isEqualTo(b.key); - assertThat("b").isEqualTo(b.source); - } ++// @Test ++// public void builder() throws Exception { ++// PropertyValueBuilder b = PropertyValue.builder("a", "b"); ++// assertThat(b).isNotNull(); ++// assertThat("a").isEqualTo(b.key); ++// assertThat("b").isEqualTo(b.source); ++// } ++// ++// ++// @Test ++// public void builder() throws Exception { ++// PropertyValueBuilder b = PropertyValue.builder("a", "b"); ++// assertThat(b).isNotNull(); ++// assertThat("a").isEqualTo(b.key); ++// assertThat("b").isEqualTo(b.source); ++// } + @Test - public void testOf(){ - assertThat(PropertyValue.of("k", "v", "testGetKey")).isNotNull(); - } - - @Test(expected = NullPointerException.class) - public void getMetaEntryRequiresNonNullValueForKey() { - PropertyValue.of("a", "b", "s").getMeta(null); + public void from(){ + + ObjectValue val = ObjectValue.from(Arrays.asList()); + assertThat(val).isNotNull(); + val = ObjectValue.from(Arrays.asList( + PropertyValue.createObject("o1").setValue("key", "value"), + PropertyValue.createObject("o2").setValue("key2", "value2")) + ); + assertThat(val).isNotNull(); + assertThat(val.getValue("o1")).isNotNull(); + assertThat(val.getValue("o2")).isNotNull(); + assertThat(val.getPropertyValue("o1").toObjectValue().getValue("key")).isEqualTo("value"); + assertThat(val.getPropertyValue("o2").toObjectValue().getValue("key2")).isEqualTo("value2"); + val = ObjectValue.from(Arrays.asList( + PropertyValue.createList("o1").addValue("value"), + new PropertyValue( "o2", "value2")) + ); + assertThat(val).isNotNull(); + assertThat(val.getValue("o1")).isNotNull(); + assertThat(val.getValue("o2")).isNotNull(); + assertThat(val.getPropertyValue("o1").toListValue().getValue(0)).isEqualTo("value"); + assertThat(val.getPropertyValue("o2").getValue()).isEqualTo("value2"); } @Test(expected = NullPointerException.class) diff --cc code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/BasePropertySource.java index dc490b7,d0106aa..68be9d1 --- a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/BasePropertySource.java +++ b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/propertysource/BasePropertySource.java @@@ -18,7 -18,7 +18,6 @@@ */ package org.apache.tamaya.spisupport.propertysource; --import java.util.HashMap; import java.util.Map; import java.util.Objects; import java.util.logging.Level; @@@ -36,10 -36,11 +35,10 @@@ public abstract class BasePropertySourc /** default ordinal that will be used, if no ordinal is provided with the config. */ private int defaultOrdinal; /** Used if the ordinal has been setCurrent explicitly. */ - private volatile Integer ordinal; + private Integer ordinal; /** The name of the property source. */ private String name; - /** The optional prefix. */ - private String prefix; + /** * If true, this property source does not return any properties. This is useful since this * property source is applied by default, but can be switched off by setting the