http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/606f8ec6/code/api/src/test/java/org/apache/tamaya/spi/PropertyValueTest.java ---------------------------------------------------------------------- diff --git a/code/api/src/test/java/org/apache/tamaya/spi/PropertyValueTest.java b/code/api/src/test/java/org/apache/tamaya/spi/PropertyValueTest.java index 0ebfbcc..035c458 100644 --- a/code/api/src/test/java/org/apache/tamaya/spi/PropertyValueTest.java +++ b/code/api/src/test/java/org/apache/tamaya/spi/PropertyValueTest.java @@ -49,12 +49,7 @@ public class PropertyValueTest { @Test(expected = NullPointerException.class) public void getMetaEntryRequiresNonNullValueForKey() { - PropertyValue.of("a", "b", "s").getMeta((String)null); - } - - @Test(expected = NullPointerException.class) - public void getMetaEntryRequiresNonNullValueForKeyClass() { - PropertyValue.of("a", "b", "s").getMeta((Class)null); + PropertyValue.of("a", "b", "s").getMeta(null); } @Test(expected = NullPointerException.class) @@ -64,7 +59,7 @@ public class PropertyValueTest { @Test public void testSetMetaEntries() throws Exception { - Map<String,Object> meta = new HashMap<>(); + Map<String,String> meta = new HashMap<>(); meta.put("1","2"); meta.put("a", "b"); PropertyValue pv = PropertyValue.createObject() @@ -78,12 +73,7 @@ public class PropertyValueTest { @Test(expected = NullPointerException.class) public void removeMetaEntryRequiresNonNullParameter() { - PropertyValue.createObject().removeMeta((String)null); - } - - @Test(expected = NullPointerException.class) - public void removeMetaEntryRequiresNonNullParameterClass() { - PropertyValue.createObject().removeMeta((Class)null); + PropertyValue.createObject().removeMeta(null); } @@ -100,16 +90,16 @@ public class PropertyValueTest { @Test public void testRemoveMetaEntryClass() throws Exception { PropertyValue pv = PropertyValue.createObject("k") - .setMeta(String.class, "v2") + .setMeta("k1", "v2") .setMeta("k2", "v22") - .removeMeta(String.class); + .removeMeta("k1"); assertThat(pv.getMeta().get("k2")).isEqualTo("v22"); - assertThat(pv.getMeta(String.class)).isNull(); + assertThat(pv.getMeta().get("k1")).isNull(); } @Test public void testGetMetaEntries() throws Exception { - Map<String,Object> meta = new HashMap<>(); + Map<String,String> meta = new HashMap<>(); meta.put("1","2"); meta.put("a", "b"); PropertyValue pv = PropertyValue.createObject("k") @@ -192,12 +182,7 @@ public class PropertyValueTest { @Test(expected = NullPointerException.class) public void addMetaEntryRequiresNonNullParameterForKey() { - PropertyValue.createObject("k").setMeta((String)null, "a"); - } - - @Test(expected = NullPointerException.class) - public void addMetaEntryRequiresNonNullParameterForKeyClass() { - PropertyValue.createValue("k", null).setMeta((Class)null, "a"); + PropertyValue.createObject("k").setMeta(null, "a"); } @Test(expected = NullPointerException.class) @@ -245,9 +230,8 @@ public class PropertyValueTest { @Test public void addMeta() { PropertyValue root = PropertyValue.createObject(); - assertNotNull(root.setMeta("a")); root.setMeta("a", Integer.valueOf(3)); - assertEquals(Integer.valueOf(3), root.getMeta("a")); + assertEquals(Integer.valueOf(3).toString(), root.getMeta("a")); } @Test
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/606f8ec6/code/core/pom.xml ---------------------------------------------------------------------- diff --git a/code/core/pom.xml b/code/core/pom.xml index e81015e..52a79a5 100644 --- a/code/core/pom.xml +++ b/code/core/pom.xml @@ -75,6 +75,18 @@ under the License. <build> <plugins> <plugin> + <groupId>org.revapi</groupId> + <artifactId>revapi-maven-plugin</artifactId> + <configuration> + <oldArtifacts> + <artifact>${project.groupId}:${project.artifactId}:0.3-incubating</artifact> + </oldArtifacts> + <newArtifacts> + <artifact>${project.groupId}:${project.artifactId}:${project.version}</artifact> + </newArtifacts> + </configuration> + </plugin> + <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/606f8ec6/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfiguration.java ---------------------------------------------------------------------- diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfiguration.java b/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfiguration.java index cb692e9..93d5b89 100644 --- a/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfiguration.java +++ b/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfiguration.java @@ -21,8 +21,6 @@ package org.apache.tamaya.core.internal; import org.apache.tamaya.spi.ConfigurationBuilder; import org.apache.tamaya.spi.ConfigurationContext; import org.apache.tamaya.spisupport.DefaultConfiguration; -import org.apache.tamaya.spisupport.DefaultConfigurationContext; -import org.apache.tamaya.spisupport.DefaultConfigurationContextBuilder; /** * Default implementation of {@link ConfigurationBuilder}. http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/606f8ec6/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationBuilder.java ---------------------------------------------------------------------- diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationBuilder.java b/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationBuilder.java index 7a5c7ff..425c60c 100644 --- a/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationBuilder.java +++ b/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationBuilder.java @@ -23,10 +23,8 @@ import org.apache.tamaya.TypeLiteral; import org.apache.tamaya.spi.ConfigurationContext; import org.apache.tamaya.spi.ConfigurationBuilder; import org.apache.tamaya.core.internal.converters.*; -import org.apache.tamaya.spisupport.DefaultConfiguration; import org.apache.tamaya.spisupport.DefaultConfigurationBuilder; import org.apache.tamaya.spisupport.DefaultConfigurationContext; -import org.apache.tamaya.spisupport.DefaultConfigurationContextBuilder; import java.io.File; import java.math.BigDecimal; @@ -90,7 +88,6 @@ public final class CoreConfigurationBuilder extends DefaultConfigurationBuilder Configuration cfg = new CoreConfiguration( new DefaultConfigurationContext( serviceContext, - this.combinationPolicy, this.propertyFilters, this.propertySources, this.propertyConverters, http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/606f8ec6/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationProvider.java ---------------------------------------------------------------------- diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationProvider.java b/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationProvider.java index 2a6108d..8a0bb55 100644 --- a/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationProvider.java +++ b/code/core/src/main/java/org/apache/tamaya/core/internal/CoreConfigurationProvider.java @@ -21,10 +21,7 @@ package org.apache.tamaya.core.internal; import org.apache.tamaya.Configuration; import org.apache.tamaya.spi.ConfigurationContext; import org.apache.tamaya.spi.ConfigurationBuilder; -import org.apache.tamaya.spi.ConfigurationContextBuilder; import org.apache.tamaya.spi.ConfigurationProviderSpi; -import org.apache.tamaya.spisupport.DefaultConfiguration; -import org.apache.tamaya.spisupport.DefaultConfigurationContextBuilder; import org.osgi.service.component.annotations.Component; import java.util.Map; @@ -81,11 +78,6 @@ public class CoreConfigurationProvider implements ConfigurationProviderSpi { } @Override - public ConfigurationContextBuilder getConfigurationContextBuilder() { - return new DefaultConfigurationContextBuilder(); - } - - @Override public void setConfiguration(Configuration config, ClassLoader classLoader) { Objects.requireNonNull(config.getContext()); Configuration old = this.configurations.put(classLoader, Objects.requireNonNull(config)); @@ -99,22 +91,4 @@ public class CoreConfigurationProvider implements ConfigurationProviderSpi { return true; } - /** - * @deprecated use {@link Configuration#getContext()} instead. - */ - @Deprecated - @Override - public ConfigurationContext getConfigurationContext() { - return getConfiguration(Thread.currentThread().getContextClassLoader()).getContext(); - } - - /** - * @deprecated the context should be given upon creation of the {@link Configuration} - */ - @Deprecated - @Override - public void setConfigurationContext(ConfigurationContext context){ - setConfiguration(new CoreConfigurationBuilder(context).build(), Thread.currentThread().getContextClassLoader()); - } - } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/606f8ec6/code/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java ---------------------------------------------------------------------- diff --git a/code/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java b/code/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java new file mode 100644 index 0000000..1fb4537 --- /dev/null +++ b/code/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java @@ -0,0 +1,174 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.core.propertysource; + +import org.apache.tamaya.spi.PropertySource; +import org.apache.tamaya.spi.PropertyValue; + +import java.util.Map; +import java.util.Objects; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Abstract {@link PropertySource} that allows setting a default ordinal to be used, if no + * ordinal is provided with the config. + * @deprecated Use {@link org.apache.tamaya.spisupport.propertysource.BasePropertySource} + */ +@Deprecated +public abstract class BasePropertySource implements PropertySource{ + /** 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; + /** The name of the property source. */ + private String name; + + /** + * Constructor. + * @param name the (unique) property source name, not {@code null}. + */ + protected BasePropertySource(String name){ + this.name = Objects.requireNonNull(name); + this.defaultOrdinal = 0; + } + + /** + * Constructor. + * @param defaultOrdinal default ordinal that will be used, if no ordinal is provided with the config. + */ + protected BasePropertySource(int defaultOrdinal){ + this.name = getClass().getSimpleName(); + this.defaultOrdinal = defaultOrdinal; + } + + /** + * Constructor. + * @param name the (unique) property source name, not {@code null}. + * @param defaultOrdinal default ordinal that will be used, if no ordinal is provided with the config. + */ + protected BasePropertySource(String name, int defaultOrdinal){ + this.name = Objects.requireNonNull(name); + this.defaultOrdinal = defaultOrdinal; + } + + + /** + * Constructor, using a default ordinal of 0. + */ + protected BasePropertySource(){ + this(0); + } + + @Override + public String getName() { + return name; + } + + /** + * Sets the property source's (unique) name. + * @param name the name, not {@code null}. + */ + public void setName(String name){ + this.name = Objects.requireNonNull(name); + } + + /** + * Allows setting the ordinal of this property source explicitly. This will override any evaluated + * ordinal, or default ordinal. To reset an explicit ordinal call {@code setOrdinal(null);}. + * @param ordinal the explicit ordinal, or {@code null}. + */ + public void setOrdinal(Integer ordinal){ + this.ordinal = ordinal; + } + + /** + * Allows setting the ordinal of this property source explicitly. This will override any evaluated + * ordinal, or default ordinal. To reset an explicit ordinal call {@code setOrdinal(null);}. + * @param defaultOrdinal the default ordinal, or {@code null}. + */ + public void setDefaultOrdinal(Integer defaultOrdinal){ + this.defaultOrdinal = defaultOrdinal; + } + + public int getOrdinal() { + Integer ordinal = this.ordinal; + if(ordinal!=null){ + Logger.getLogger(getClass().getName()).finest( + "Using explicit ordinal '"+ordinal+"' for property source: " + getName()); + return ordinal; + } + PropertyValue configuredOrdinal = get(TAMAYA_ORDINAL); + if(configuredOrdinal!=null){ + try { + return Integer.parseInt(configuredOrdinal.getValue()); + } catch (Exception e) { + Logger.getLogger(getClass().getName()).log(Level.WARNING, + "Configured ordinal is not an int number: " + configuredOrdinal, e); + } + } + return getDefaultOrdinal(); + } + + /** + * Returns the default ordinal used, when no ordinal is setCurrent, or the ordinal was not parseable to an int createValue. + * @return the default ordinal used, by default 0. + */ + public int getDefaultOrdinal(){ + return defaultOrdinal; + } + + @Override + public PropertyValue get(String key) { + Map<String,PropertyValue> properties = getProperties(); + PropertyValue val = properties.get(key); + if(val==null){ + return null; + } + return val; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + BasePropertySource that = (BasePropertySource) o; + + return name.equals(that.name); + } + + @Override + public int hashCode() { + return name.hashCode(); + } + + @Override + public String toString() { + return getClass().getSimpleName() + "{" + + toStringValues() + + '}'; + } + + protected String toStringValues() { + return " defaultOrdinal=" + defaultOrdinal + '\n' + + " ordinal=" + ordinal + '\n' + + " name='" + name + '\'' + '\n'; + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/606f8ec6/code/core/src/test/java/org/apache/tamaya/core/ConfigurationBuilderTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/ConfigurationBuilderTest.java b/code/core/src/test/java/org/apache/tamaya/core/ConfigurationBuilderTest.java index b8cea0d..8a687d7 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/ConfigurationBuilderTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/ConfigurationBuilderTest.java @@ -275,16 +275,6 @@ public class ConfigurationBuilderTest { } @Test - public void setPropertyValueCombinationPolicy() throws Exception { - PropertyValueCombinationPolicy combPol = (currentValue, key, propertySource) -> currentValue; - ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder() - .setPropertyValueCombinationPolicy(combPol); - Configuration cfg = b.build(); - ConfigurationContext ctx = cfg.getContext(); - assertThat(combPol).isEqualTo(ctx.getPropertyValueCombinationPolicy()); - } - - @Test public void increasePriority(){ ConfigurationBuilder b = ConfigurationProvider.getConfigurationBuilder(); TestPropertySource[] propertySources = new TestPropertySource[10]; http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/606f8ec6/code/core/src/test/java/org/apache/tamaya/core/ConfigurationContextBuilderTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/ConfigurationContextBuilderTest.java b/code/core/src/test/java/org/apache/tamaya/core/ConfigurationContextBuilderTest.java deleted file mode 100644 index 611f337..0000000 --- a/code/core/src/test/java/org/apache/tamaya/core/ConfigurationContextBuilderTest.java +++ /dev/null @@ -1,424 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tamaya.core; - -import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; -import org.apache.tamaya.TypeLiteral; -import org.apache.tamaya.spi.*; -import org.apache.tamaya.spisupport.DefaultConfigurationContextBuilder; -import org.junit.Test; - -import java.util.Arrays; -import java.util.Comparator; - -import static org.assertj.core.api.Assertions.*; - -/** - * Tests for {@link ConfigurationContextBuilder} by atsticks on 06.09.16. - */ -@Deprecated -public class ConfigurationContextBuilderTest { - - private TestPropertySource testPropertySource = new TestPropertySource(){}; - - @Test - public void setContext() throws Exception { - ConfigurationContext context = Configuration.current().getContext(); - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder() - .setContext(context); - assertThat(b.build()).isEqualTo(context); - } - - @Test - public void addPropertySources_Array() throws Exception { - PropertySource testPS2 = new TestPropertySource("addPropertySources_Array", 1); - ConfigurationContextBuilder b = new DefaultConfigurationContextBuilder() - .addPropertySources(testPropertySource, testPS2); - ConfigurationContext ctx = b.build(); - assertThat(ctx.getPropertySources()).hasSize(2); - assertThat(ctx.getPropertySources().contains(testPropertySource)).isTrue(); - assertThat(ctx.getPropertySources().contains(testPS2)).isTrue(); - // Ensure no sorting happens during add, so switch ordinals! - testPS2 = new TestPropertySource("addPropertySources_Array", 1); - b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertySources(testPS2, testPropertySource); - ctx = b.build(); - assertThat(ctx.getPropertySources()).hasSize(2); - assertThat(ctx.getPropertySources().contains(testPropertySource)).isTrue(); - assertThat(ctx.getPropertySources().contains(testPS2)).isTrue(); - assertThat("TestPropertySource").isEqualTo(ctx.getPropertySources().get(1).getName()); - assertThat("addPropertySources_Array").isEqualTo(ctx.getPropertySources().get(0).getName()); - } - - @Test - public void addPropertySources_Collection() throws Exception { - PropertySource testPS2 = new TestPropertySource("addPropertySources_Collection", 1); - ConfigurationContextBuilder b = new DefaultConfigurationContextBuilder() - .addPropertySources(Arrays.asList(new PropertySource[]{testPropertySource, testPS2})); - ConfigurationContext ctx = b.build(); - assertThat(ctx.getPropertySources()).hasSize(2); - assertThat(ctx.getPropertySources().contains(testPropertySource)).isTrue(); - assertThat(ctx.getPropertySources().contains(testPS2)).isTrue(); - assertThat("TestPropertySource").isEqualTo(ctx.getPropertySources().get(0).getName()); - assertThat("addPropertySources_Collection").isEqualTo(ctx.getPropertySources().get(1).getName()); - // Ensure no sorting happens during add, so switch ordinals! - testPS2 = new TestPropertySource("addPropertySources_Collection", 1); - b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertySources(Arrays.asList(new PropertySource[]{testPS2, testPropertySource})); - ctx = b.build(); - assertThat(ctx.getPropertySources()).hasSize(2); - assertThat(ctx.getPropertySources().contains(testPropertySource)).isTrue(); - assertThat(ctx.getPropertySources().contains(testPS2)).isTrue(); - assertThat("TestPropertySource").isEqualTo(ctx.getPropertySources().get(1).getName()); - assertThat("addPropertySources_Collection").isEqualTo(ctx.getPropertySources().get(0).getName()); - } - - @Test - public void removePropertySources_Array() throws Exception { - PropertySource testPS2 = new TestPropertySource("removePropertySources_Array", 1); - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertySources(testPropertySource, testPS2); - ConfigurationContext ctx = b.build(); - assertThat(ctx.getPropertySources()).hasSize(2); - assertThat(ctx.getPropertySources().contains(testPropertySource)).isTrue(); - assertThat(ctx.getPropertySources().contains(testPS2)).isTrue(); - b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertySources(testPropertySource, testPS2); - b.removePropertySources(testPropertySource); - ctx = b.build(); - assertThat(ctx.getPropertySources().contains(testPropertySource)).isFalse(); - assertThat(ctx.getPropertySources().contains(testPS2)).isTrue(); - assertThat(ctx.getPropertySources()).hasSize(1); - } - - @Test - public void removePropertySources_Collection() throws Exception { - PropertySource testPS2 = new TestPropertySource("removePropertySources_Array", 1); - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertySources(testPropertySource, testPS2); - ConfigurationContext ctx = b.build(); - assertThat(ctx.getPropertySources()).hasSize(2); - assertThat(ctx.getPropertySources().contains(testPropertySource)).isTrue(); - assertThat(ctx.getPropertySources().contains(testPS2)).isTrue(); - b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertySources(testPropertySource, testPS2); - b.removePropertySources(testPropertySource); - ctx = b.build(); - assertThat(ctx.getPropertySources()).hasSize(1); - assertThat(ctx.getPropertySources().contains(testPropertySource)).isFalse(); - assertThat(ctx.getPropertySources().contains(testPS2)).isTrue(); - } - - @Test - public void addPropertyFilters_Array() throws Exception { - PropertyFilter filter1 = (value, ctx) -> value; - PropertyFilter filter2 = (value, ctx) -> value; - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder(); - b.addPropertyFilters(filter1, filter2); - ConfigurationContext ctx = b.build(); - assertThat(ctx.getPropertyFilters().contains(filter1)).isTrue(); - assertThat(ctx.getPropertyFilters().contains(filter2)).isTrue(); - assertThat(ctx.getPropertyFilters()).hasSize(2); - b = ConfigurationProvider.getConfigurationContextBuilder(); - b.addPropertyFilters(filter1, filter2); - b.addPropertyFilters(filter1, filter2); - assertThat(ctx.getPropertyFilters()).hasSize(2); - } - - @Test - public void addPropertyFilters_Collection() throws Exception { - PropertyFilter filter1 = (value, ctx) -> value; - PropertyFilter filter2 = (value, ctx) -> value; - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder(); - b.addPropertyFilters(Arrays.asList(new PropertyFilter[]{filter1, filter2})); - ConfigurationContext ctx = b.build(); - assertThat(ctx.getPropertyFilters().contains(filter1)).isTrue(); - assertThat(ctx.getPropertyFilters().contains(filter2)).isTrue(); - assertThat(ctx.getPropertyFilters()).hasSize(2); - b = ConfigurationProvider.getConfigurationContextBuilder(); - b.addPropertyFilters(filter1, filter2); - b.addPropertyFilters(filter1, filter2); - assertThat(ctx.getPropertyFilters()).hasSize(2); - } - - @Test - public void removePropertyFilters_Array() throws Exception { - PropertyFilter filter1 = (value, ctx) -> value; - PropertyFilter filter2 = (value, ctx) -> value; - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertyFilters(filter1, filter2); - ConfigurationContext ctx = b.build(); - assertThat(ctx.getPropertyFilters().contains(filter1)).isTrue(); - assertThat(ctx.getPropertyFilters().contains(filter2)).isTrue(); - assertThat(ctx.getPropertyFilters()).hasSize(2); - b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertyFilters(filter1, filter2); - b.removePropertyFilters(filter1); - ctx = b.build(); - assertThat(ctx.getPropertyFilters()).hasSize(1); - assertThat(ctx.getPropertyFilters().contains(filter1)).isFalse(); - assertThat(ctx.getPropertyFilters().contains(filter2)).isTrue(); - } - - @Test - public void removePropertyFilters_Collection() throws Exception { - PropertyFilter filter1 = (value, ctx) -> value; - PropertyFilter filter2 = (value, ctx) -> value; - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertyFilters(Arrays.asList(new PropertyFilter[]{filter1, filter2})); - ConfigurationContext ctx = b.build(); - assertThat(ctx.getPropertyFilters().contains(filter1)).isTrue(); - assertThat(ctx.getPropertyFilters().contains(filter2)).isTrue(); - assertThat(ctx.getPropertyFilters()).hasSize(2); - b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertyFilters(Arrays.asList(new PropertyFilter[]{filter1, filter2})); - b.removePropertyFilters(filter1); - ctx = b.build(); - assertThat(ctx.getPropertyFilters()).hasSize(1); - assertThat(ctx.getPropertyFilters().contains(filter1)).isFalse(); - assertThat(ctx.getPropertyFilters().contains(filter2)).isTrue(); - } - - @Test - @SuppressWarnings({ "rawtypes", "unchecked" }) - public void addPropertyConverters_Array() throws Exception { - PropertyConverter converter = (value, ctx) -> value.toLowerCase(); - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), converter); - ConfigurationContext ctx = b.build(); - assertThat(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter)).isTrue(); - assertThat(ctx.getPropertyConverters()).hasSize(1); - b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), converter); - b.addPropertyConverters(TypeLiteral.of(String.class), converter); - assertThat(ctx.getPropertyConverters()).hasSize(1); - } - - @Test - @SuppressWarnings({ "rawtypes", "unchecked" }) - public void addPropertyConverters_Collection() throws Exception { - PropertyConverter converter = (value, ctx) -> value.toLowerCase(); - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), - Arrays.<PropertyConverter<Object>>asList(new PropertyConverter[]{converter})); - ConfigurationContext ctx = b.build(); - assertThat(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter)).isTrue(); - assertThat(1).isEqualTo(ctx.getPropertyConverters().size()); - b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), - Arrays.<PropertyConverter<Object>>asList(new PropertyConverter[]{converter})); - b.addPropertyConverters(TypeLiteral.of(String.class), converter); - assertThat(1).isEqualTo(ctx.getPropertyConverters().size()); - } - - @Test - @SuppressWarnings({ "rawtypes", "unchecked" }) - public void removePropertyConverters_Array() throws Exception { - PropertyConverter converter = (value, ctx) -> value.toLowerCase(); - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), converter); - ConfigurationContext ctx = b.build(); - assertThat(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter)).isTrue(); - assertThat(ctx.getPropertyConverters(TypeLiteral.of(String.class))).hasSize(1); - b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), converter); - b.removePropertyConverters(TypeLiteral.of(String.class), converter); - ctx = b.build(); - assertThat(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter)).isFalse(); - assertThat(ctx.getPropertyConverters(TypeLiteral.of(String.class)).isEmpty()).isTrue(); - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Test - public void removePropertyConverters_Collection() throws Exception { - PropertyConverter converter = (value, ctx) -> value.toLowerCase(); - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), Arrays.<PropertyConverter<Object>>asList(new PropertyConverter[]{converter})); - ConfigurationContext ctx = b.build(); - assertThat(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter)).isTrue(); - assertThat(ctx.getPropertyConverters(TypeLiteral.of(String.class))).hasSize(1); - b = ConfigurationProvider.getConfigurationContextBuilder() - .addPropertyConverters(TypeLiteral.of(String.class), Arrays.<PropertyConverter<Object>>asList(new PropertyConverter[]{converter})); - b.removePropertyConverters(TypeLiteral.of(String.class), Arrays.<PropertyConverter<Object>>asList(new PropertyConverter[]{converter})); - ctx = b.build(); - assertThat(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(converter)).isFalse(); - assertThat(ctx.getPropertyConverters(TypeLiteral.of(String.class)).isEmpty()).isTrue(); - } - - @Test - public void setPropertyValueCombinationPolicy() throws Exception { - PropertyValueCombinationPolicy combPol = (currentValue, key, propertySource) -> currentValue; - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder() - .setPropertyValueCombinationPolicy(combPol); - ConfigurationContext ctx = b.build(); - assertThat(combPol).isEqualTo(ctx.getPropertyValueCombinationPolicy()); - } - - @Test - public void increasePriority(){ - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder(); - TestPropertySource[] propertySources = new TestPropertySource[10]; - for(int i=0;i<propertySources.length;i++){ - propertySources[i] = new TestPropertySource("ps"+i,i); - } - b.addPropertySources(propertySources); - b.increasePriority(propertySources[propertySources.length-1]); - for(int i=0;i<propertySources.length;i++){ - assertThat(b.getPropertySources().get(i)).isEqualTo(propertySources[i]); - } - b.increasePriority(propertySources[propertySources.length-2]); - for(int i=0;i<propertySources.length-2;i++){ - assertThat(b.getPropertySources().get(i)).isEqualTo(propertySources[i]); - } - assertThat(b.getPropertySources().get(propertySources.length-2)).isEqualTo(propertySources[propertySources.length-1]); - assertThat(b.getPropertySources().get(propertySources.length-1)).isEqualTo(propertySources[propertySources.length-2]); - } - - @Test - public void decreasePriority(){ - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder(); - TestPropertySource[] propertySources = new TestPropertySource[10]; - for(int i=0;i<propertySources.length;i++){ - propertySources[i] = new TestPropertySource("ps"+i,i); - } - b.addPropertySources(propertySources); - b.decreasePriority(propertySources[0]); - for(int i=0;i<propertySources.length;i++){ - assertThat(b.getPropertySources().get(i)).isEqualTo(propertySources[i]); - } - b.decreasePriority(propertySources[1]); - for(int i=2;i<propertySources.length;i++){ - assertThat(b.getPropertySources().get(i)).isEqualTo(propertySources[i]); - } - assertThat(b.getPropertySources().get(1)).isEqualTo(propertySources[0]); - assertThat(b.getPropertySources().get(0)).isEqualTo(propertySources[1]); - } - - @Test - public void lowestPriority(){ - // setup - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder(); - TestPropertySource[] propertySources = new TestPropertySource[10]; - for(int i=0;i<propertySources.length;i++){ - propertySources[i] = new TestPropertySource("ps"+i,i); - } - b.addPropertySources(propertySources); - // test - b.lowestPriority(propertySources[0]); - for(int i=0;i<propertySources.length;i++){ - assertThat(b.getPropertySources().get(i)).isEqualTo(propertySources[i]); - } - b.lowestPriority(propertySources[1]); - for(int i=2;i<propertySources.length;i++){ - assertThat(b.getPropertySources().get(i)).isEqualTo(propertySources[i]); - } - assertThat(b.getPropertySources().get(1)).isEqualTo(propertySources[0]); - assertThat(b.getPropertySources().get(0)).isEqualTo(propertySources[1]); - b.lowestPriority(propertySources[5]); - assertThat(b.getPropertySources().get(0)).isEqualTo(propertySources[5]); - } - - @Test - public void highestPriority(){ - // setup - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder(); - TestPropertySource[] propertySources = new TestPropertySource[10]; - for(int i=0;i<propertySources.length;i++){ - propertySources[i] = new TestPropertySource("ps"+i,i); - } - b.addPropertySources(propertySources); - // test - b.highestPriority(propertySources[propertySources.length-1]); - for(int i=0;i<propertySources.length;i++){ - assertThat(b.getPropertySources().get(i)).isEqualTo(propertySources[i]); - } - b.highestPriority(propertySources[propertySources.length-2]); - for(int i=0;i<propertySources.length-2;i++){ - assertThat(b.getPropertySources().get(i)).isEqualTo(propertySources[i]); - } - assertThat(b.getPropertySources().get(propertySources.length-1)).isEqualTo(propertySources[propertySources.length-2]); - assertThat(b.getPropertySources().get(propertySources.length-2)).isEqualTo(propertySources[propertySources.length-1]); - b.highestPriority(propertySources[5]); - assertThat(b.getPropertySources().get(propertySources.length-1)).isEqualTo(propertySources[5]); - } - - @Test - public void sortPropertySources(){ - // setup - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder(); - TestPropertySource[] propertySources = new TestPropertySource[10]; - for(int i=0;i<propertySources.length;i++){ - propertySources[i] = new TestPropertySource("ps"+i,i); - } - b.addPropertySources(propertySources); - Comparator<PropertySource> psComp = (o1, o2) -> o1.toString().compareTo(o2.toString()); - // test - b.sortPropertySources(psComp); - Arrays.sort(propertySources, psComp); - for(int i=0;i<propertySources.length;i++){ - assertThat(b.getPropertySources().get(i)).isEqualTo(propertySources[i]); - } - } - - @Test - public void sortPropertyFilter(){ - // setup - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder(); - PropertyFilter[] propertyFilters = new PropertyFilter[10]; - for(int i=0;i<propertyFilters.length;i++){ - propertyFilters[i] = (value, ctx) -> value.setValue(toString() + " - "); - } - b.addPropertyFilters(propertyFilters); - Comparator<PropertyFilter> pfComp = (o1, o2) -> o1.toString().compareTo(o2.toString()); - // test - b.sortPropertyFilter(pfComp); - Arrays.sort(propertyFilters, pfComp); - for(int i=0;i<propertyFilters.length;i++){ - assertThat(b.getPropertyFilters().get(i)).isEqualTo(propertyFilters[i]); - } - } - - @Test - public void build() throws Exception { - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder(); - ConfigurationContext ctx = b.build(); - assertThat(ctx).isNotNull(); - assertThat(ctx.getPropertySources().isEmpty()).isTrue(); - assertThat(ctx.getPropertyFilters().isEmpty()).isTrue(); - } - - @Test - public void testRemoveAllFilters() throws Exception { - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder(); - b.addPropertyFilters((value, ctx) -> value.setValue(toString() + " - ")); - assertThat(b.getPropertyFilters().isEmpty()).isFalse(); - b.removePropertyFilters(b.getPropertyFilters()); - assertThat(b.getPropertyFilters().isEmpty()).isTrue(); - } - - @Test - public void testRemoveAllSources() throws Exception { - ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder(); - b.addPropertySources(new TestPropertySource()); - assertThat(b.getPropertySources().isEmpty()).isFalse(); - b.removePropertySources(b.getPropertySources()); - assertThat(b.getPropertyFilters().isEmpty()).isTrue(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/606f8ec6/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationBuilderTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationBuilderTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationBuilderTest.java index bb96089..caba173 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationBuilderTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationBuilderTest.java @@ -167,16 +167,6 @@ public class CoreConfigurationBuilderTest { } @Test - public void setPropertyValueCombinationPolicy() throws Exception { - PropertyValueCombinationPolicy combPol = (currentValue, key, propertySource) -> currentValue; - ConfigurationBuilder b = new CoreConfigurationBuilder() - .setPropertyValueCombinationPolicy(combPol); - Configuration cfg = b.build(); - ConfigurationContext ctx = cfg.getContext(); - assertThat(combPol).isEqualTo(ctx.getPropertyValueCombinationPolicy()); - } - - @Test public void build() throws Exception { assertThat(new CoreConfigurationBuilder().build()).isNotNull(); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/606f8ec6/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationProviderTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationProviderTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationProviderTest.java index 8e5cac0..01e1bdb 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationProviderTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationProviderTest.java @@ -46,32 +46,11 @@ public class CoreConfigurationProviderTest { } @Test - public void getConfigurationContext() throws Exception { - assertThat(new CoreConfigurationProvider().getConfigurationContext()).isNotNull(); - assertThat(new CoreConfigurationProvider().getConfigurationContext()).isEqualTo( - new CoreConfigurationProvider().getConfiguration(getClass().getClassLoader()).getContext()); - } - - @Test - public void getConfigurationContextBuilder() throws Exception { - assertThat(new CoreConfigurationProvider().getConfigurationContextBuilder()).isNotNull(); - } - - @Test public void getConfigurationBuilder() throws Exception { assertThat(new CoreConfigurationProvider().getConfigurationBuilder()).isNotNull(); } @SuppressWarnings("deprecation") - @Test - public void setConfigurationContext() throws Exception { - new CoreConfigurationProvider() - .setConfigurationContext(new CoreConfigurationProvider().getConfiguration( - getClass().getClassLoader() - ).getContext()); - } - - @SuppressWarnings("deprecation") @Test public void setConfiguration() throws Exception { new CoreConfigurationProvider() @@ -82,12 +61,6 @@ public class CoreConfigurationProviderTest { } @SuppressWarnings("deprecation") - @Test - public void isConfigurationContextSettable() throws Exception { - assertThat(new CoreConfigurationProvider().isConfigurationContextSettable()).isTrue(); - } - - @SuppressWarnings("deprecation") @Test public void isConfigurationSettable() throws Exception { assertThat(new CoreConfigurationProvider().isConfigurationSettable( http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/606f8ec6/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationTest.java ---------------------------------------------------------------------- diff --git a/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationTest.java b/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationTest.java index 4f19f07..0c0149f 100644 --- a/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationTest.java +++ b/code/core/src/test/java/org/apache/tamaya/core/internal/CoreConfigurationTest.java @@ -33,10 +33,11 @@ public class CoreConfigurationTest { @Test public void addPropertySources() throws Exception { - Configuration cfg = new CoreConfigurationBuilder().build(); TestPropertyDefaultSource def = new TestPropertyDefaultSource(); + Configuration cfg = new CoreConfigurationBuilder().build(); assertThat(cfg.getContext().getPropertySources().contains(def)).isFalse(); - cfg.getContext().addPropertySources(def); + cfg = new CoreConfigurationBuilder() + .addPropertySources(def).build(); assertThat(cfg.getContext().getPropertySources().contains(def)).isTrue(); } @@ -92,20 +93,19 @@ public class CoreConfigurationTest { } }; assertThat(cfg.getContext().getPropertyConverters(TypeLiteral.of(String.class)).contains(testConverter)).isFalse(); - cfg.getContext().addPropertyConverter(TypeLiteral.of(String.class), testConverter); + cfg = new CoreConfigurationBuilder().addPropertyConverters(TypeLiteral.of(String.class), testConverter).build(); assertThat(cfg.getContext().getPropertyConverters(TypeLiteral.of(String.class)).contains(testConverter)).isTrue(); } @Test public void getPropertyConverters() throws Exception { - Configuration cfg = new CoreConfigurationBuilder().build(); PropertyConverter testConverter = new PropertyConverter() { @Override public Object convert(String value, ConversionContext ctx) { return ""; } }; - cfg.getContext().addPropertyConverter(TypeLiteral.of(String.class), testConverter); + Configuration cfg = new CoreConfigurationBuilder().addPropertyConverters(TypeLiteral.of(String.class), testConverter).build(); assertThat(cfg.getContext().getPropertyConverters()).isNotNull(); assertThat(cfg.getContext().getPropertyConverters().containsKey(TypeLiteral.of(String.class))).isTrue(); assertThat(cfg.getContext().getPropertyConverters().get(TypeLiteral.of(String.class)).contains(testConverter)).isTrue(); @@ -115,7 +115,7 @@ public class CoreConfigurationTest { return Integer.valueOf(5); } }; - cfg.getContext().addPropertyConverter(TypeLiteral.of(Integer.class), testConverter); + cfg = new CoreConfigurationBuilder().addPropertyConverters(TypeLiteral.of(Integer.class), testConverter).build(); assertThat(cfg.getContext().getPropertyConverters().containsKey(TypeLiteral.of(Integer.class))).isTrue(); assertThat(cfg.getContext().getPropertyConverters().get(TypeLiteral.of(Integer.class)).contains(testConverter)).isTrue(); } @@ -131,7 +131,8 @@ public class CoreConfigurationTest { }; assertThat(cfg.getContext().getPropertyConverters(TypeLiteral.of(String.class))).isNotNull(); assertThat(0).isEqualTo(cfg.getContext().getPropertyConverters(TypeLiteral.of(String.class)).size()); - cfg.getContext().addPropertyConverter(TypeLiteral.of(String.class), testConverter); + + cfg = new CoreConfigurationBuilder().addPropertyConverters(TypeLiteral.of(String.class), testConverter).build(); assertThat(cfg.getContext().getPropertyConverters(TypeLiteral.of(String.class))).isNotNull(); assertThat(1).isEqualTo(cfg.getContext().getPropertyConverters(TypeLiteral.of(String.class)).size()); assertThat(cfg.getContext().getPropertyConverters(TypeLiteral.of(String.class)).contains(testConverter)).isTrue(); @@ -155,14 +156,6 @@ public class CoreConfigurationTest { } @Test - public void getPropertyValueCombinationPolicy() throws Exception { - Configuration cfg = new CoreConfigurationBuilder().build(); - assertThat(cfg.getContext().getPropertyValueCombinationPolicy()).isNotNull(); - assertThat(cfg.getContext().getPropertyValueCombinationPolicy()) - .isEqualTo(PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_POLICY); - } - - @Test public void toBuilder() throws Exception { assertThat(new CoreConfigurationBuilder().build().toBuilder()).isNotNull(); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/606f8ec6/code/spi-support/pom.xml ---------------------------------------------------------------------- diff --git a/code/spi-support/pom.xml b/code/spi-support/pom.xml index 9172575..3415d1a 100644 --- a/code/spi-support/pom.xml +++ b/code/spi-support/pom.xml @@ -33,6 +33,23 @@ under the License. implementation.</description> <packaging>jar</packaging> + <build> + <plugins> + <plugin> + <groupId>org.revapi</groupId> + <artifactId>revapi-maven-plugin</artifactId> + <configuration> + <oldArtifacts> + <artifact>${project.groupId}:${project.artifactId}:0.3-incubating</artifact> + </oldArtifacts> + <newArtifacts> + <artifact>${project.groupId}:${project.artifactId}:${project.version}</artifact> + </newArtifacts> + </configuration> + </plugin> + </plugins> + </build> + <dependencies> <dependency> <groupId>org.apache.tamaya</groupId> http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/606f8ec6/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigValueEvaluator.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigValueEvaluator.java b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigValueEvaluator.java index 38c6055..22b0dfc 100644 --- a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigValueEvaluator.java +++ b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigValueEvaluator.java @@ -38,10 +38,13 @@ public class DefaultConfigValueEvaluator implements ConfigValueEvaluator{ public PropertyValue evaluteRawValue(String key, ConfigurationContext context) { PropertyValue unfilteredValue = null; for (PropertySource propertySource : context.getPropertySources()) { - unfilteredValue = context.getPropertyValueCombinationPolicy(). - collect(unfilteredValue, key, propertySource); + PropertyValue val = propertySource.get(key); + if(val!=null){ + unfilteredValue = val; + } } - if(unfilteredValue==null || unfilteredValue.getValue()==null){ + if(unfilteredValue==null || + (unfilteredValue.getValueType()== PropertyValue.ValueType.VALUE && unfilteredValue.getValue()==null)){ return null; } return unfilteredValue; @@ -51,18 +54,27 @@ public class DefaultConfigValueEvaluator implements ConfigValueEvaluator{ public Map<String, PropertyValue> evaluateRawValues(ConfigurationContext context) { Map<String, PropertyValue> result = new HashMap<>(); for (PropertySource propertySource : context.getPropertySources()) { - for (Map.Entry<String,PropertyValue> propEntry: propertySource.getProperties().entrySet()) { - PropertyValue unfilteredValue = result.get(propEntry.getKey()); - unfilteredValue = context.getPropertyValueCombinationPolicy(). - collect(unfilteredValue, propEntry.getKey(), propertySource); - if(unfilteredValue!=null){ - result.put(unfilteredValue.getKey(), unfilteredValue); + for (PropertyValue val: propertySource.getProperties().values()) { + if (val!=null && (val.getValueType() != PropertyValue.ValueType.VALUE || val.getValue() != null)){ + result.put(val.getKey(), val); } } } return result; } + /** + * Default overriding policy. + * @param currentValue the + * @param key + * @param propertySource + * @return + */ + private PropertyValue collect(PropertyValue currentValue, String key, PropertySource propertySource) { + PropertyValue value = propertySource.get(key); + return value!=null?value:currentValue; + } + @Override public String toString() { return "DefaultConfigEvaluator{}"; http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/606f8ec6/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java index 0939128..f5f65e3 100644 --- a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java +++ b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java @@ -50,6 +50,7 @@ public class DefaultConfiguration implements Configuration { */ private ConfigValueEvaluator configEvaluator; + private ConfigValueEvaluator loadConfigValueEvaluator() { ConfigValueEvaluator eval = null; try{ @@ -115,19 +116,14 @@ public class DefaultConfiguration implements Configuration { /** - * Evaluates the raw createValue using the context's {@link PropertyValueCombinationPolicy}. + * Evaluates the raw value. * @param key the key, not null. * @return the createValue, before filtering is applied. + * @deprecated Use {@link ConfigValueEvaluator#evaluteRawValue(String, ConfigurationContext)}. */ + @Deprecated protected PropertyValue evaluteRawValue(String key) { - List<PropertySource> propertySources = configurationContext.getPropertySources(); - PropertyValue filteredValue = null; - PropertyValueCombinationPolicy combinationPolicy = this.configurationContext - .getPropertyValueCombinationPolicy(); - for (PropertySource propertySource : propertySources) { - filteredValue = combinationPolicy.collect(filteredValue, key, propertySource); - } - return filteredValue; + return configEvaluator.evaluteRawValue(key, configurationContext); } @@ -169,7 +165,6 @@ public class DefaultConfiguration implements Configuration { for(PropertyValue val:filtered.values()){ if(val.getValue()!=null) { result.put(val.getKey(), val.getValue()); - // TODO: Discuss metadata handling... } } return result; http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/606f8ec6/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java index 6a7439c..7be4fd8 100644 --- a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java +++ b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java @@ -42,7 +42,6 @@ public class DefaultConfigurationBuilder implements ConfigurationBuilder { protected ServiceContext serviceContext = ServiceContextManager.getServiceContext(); protected List<PropertyFilter> propertyFilters = new ArrayList<>(); protected List<PropertySource> propertySources = new ArrayList<>(); - protected PropertyValueCombinationPolicy combinationPolicy = PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_POLICY; protected Map<TypeLiteral<?>, Collection<PropertyConverter<?>>> propertyConverters = new HashMap<>(); protected MetadataProvider metaDataProvider = serviceContext.create(MetadataProvider.class, DefaultMetaDataProvider::new); @@ -69,7 +68,6 @@ public class DefaultConfigurationBuilder implements ConfigurationBuilder { for(PropertySource ps:context.getPropertySources()) { addPropertySources(ps); } - this.combinationPolicy = context.getPropertyValueCombinationPolicy(); } /** @@ -120,7 +118,6 @@ public class DefaultConfigurationBuilder implements ConfigurationBuilder { } this.propertyConverters.clear(); this.propertyConverters.putAll(context.getPropertyConverters()); - this.combinationPolicy = context.getPropertyValueCombinationPolicy(); return this; } @@ -292,13 +289,6 @@ public class DefaultConfigurationBuilder implements ConfigurationBuilder { } @Override - public ConfigurationBuilder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy combinationPolicy){ - checkBuilderState(); - this.combinationPolicy = Objects.requireNonNull(combinationPolicy); - return this; - } - - @Override public <T> ConfigurationBuilder addPropertyConverters(TypeLiteral<T> type, Collection<PropertyConverter<T>> propertyConverters){ checkBuilderState(); Objects.requireNonNull(type); @@ -329,7 +319,6 @@ public class DefaultConfigurationBuilder implements ConfigurationBuilder { Configuration cfg = new DefaultConfiguration( new DefaultConfigurationContext( serviceContext, - this.combinationPolicy, this.propertyFilters, this.propertySources, this.propertyConverters, @@ -362,7 +351,6 @@ public class DefaultConfigurationBuilder implements ConfigurationBuilder { protected ConfigurationBuilder loadDefaults() { checkBuilderState(); - this.combinationPolicy = PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR; addDefaultPropertySources(); addDefaultPropertyFilters(); addDefaultPropertyConverters(); http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/606f8ec6/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContext.java ---------------------------------------------------------------------- diff --git a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContext.java b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContext.java index 8a5362d..f24be88 100644 --- a/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContext.java +++ b/code/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContext.java @@ -22,7 +22,6 @@ import org.apache.tamaya.TypeLiteral; import org.apache.tamaya.spi.*; import java.util.*; -import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.logging.Logger; @@ -50,12 +49,6 @@ public class DefaultConfigurationContext implements ConfigurationContext { */ private List<PropertyFilter> immutablePropertyFilters; - /** - * The overriding policy used when combining PropertySources registered to evalute the final configuration - * values. - */ - private PropertyValueCombinationPolicy propertyValueCombinationPolicy; - /** The corresponding classLoader for this instance. */ private ServiceContext serviceContext; @@ -66,9 +59,9 @@ public class DefaultConfigurationContext implements ConfigurationContext { private final ReentrantReadWriteLock propertySourceLock = new ReentrantReadWriteLock(); @SuppressWarnings("unchecked") - protected DefaultConfigurationContext(DefaultConfigurationContextBuilder builder) { - this.serviceContext = builder.getServiceContext(); - this.metaDataProvider = Objects.requireNonNull(builder.getMetaDataProvider()); + protected DefaultConfigurationContext(DefaultConfigurationBuilder builder) { + this.serviceContext = builder.serviceContext; + this.metaDataProvider = Objects.requireNonNull(builder.metaDataProvider); this.metaDataProvider.init(this); propertyConverterManager = new PropertyConverterManager(serviceContext); List<PropertySource> propertySources = new ArrayList<>(); @@ -89,22 +82,12 @@ public class DefaultConfigurationContext implements ConfigurationContext { } LOG.info("Registered " + propertyConverterManager.getPropertyConverters().size() + " property converters: " + propertyConverterManager.getPropertyConverters()); - - this.propertyValueCombinationPolicy = builder.combinationPolicy; - if(this.propertyValueCombinationPolicy==null){ - this.propertyValueCombinationPolicy = getServiceContext().getService(PropertyValueCombinationPolicy.class); - } - if(this.propertyValueCombinationPolicy==null){ - this.propertyValueCombinationPolicy = PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR; - } - LOG.info("Using PropertyValueCombinationPolicy: " + this.propertyValueCombinationPolicy); } - public DefaultConfigurationContext(ServiceContext serviceContext, PropertyValueCombinationPolicy combinationPolicy, + public DefaultConfigurationContext(ServiceContext serviceContext, List<PropertyFilter> propertyFilters, List<PropertySource> propertySources, Map<TypeLiteral<?>, Collection<PropertyConverter<?>>> propertyConverters, MetadataProvider metaDataProvider) { - this.propertyValueCombinationPolicy = Objects.requireNonNull(combinationPolicy); this.serviceContext = Objects.requireNonNull(serviceContext); this.immutablePropertyFilters = Collections.unmodifiableList(new ArrayList<>(propertyFilters)); this.immutablePropertySources = Collections.unmodifiableList(new ArrayList<>(propertySources)); @@ -120,7 +103,7 @@ public class DefaultConfigurationContext implements ConfigurationContext { @Override - public Map<String,String> getMetadata() { + public Map<String,String> getMetaData() { return metaDataProvider.getMetaData(); } @@ -129,22 +112,6 @@ public class DefaultConfigurationContext implements ConfigurationContext { return serviceContext; } - @Deprecated - @Override - public void addPropertySources(PropertySource... propertySourcesToAdd) { - Lock writeLock = propertySourceLock.writeLock(); - try { - writeLock.lock(); - List<PropertySource> newPropertySources = new ArrayList<>(this.immutablePropertySources); - newPropertySources.addAll(Arrays.asList(propertySourcesToAdd)); - Collections.sort(newPropertySources, PropertySourceComparator.getInstance()); - - this.immutablePropertySources = Collections.unmodifiableList(newPropertySources); - } finally { - writeLock.unlock(); - } - } - @Override public boolean equals(Object o) { if (this == o) { @@ -165,7 +132,7 @@ public class DefaultConfigurationContext implements ConfigurationContext { if (!immutablePropertyFilters.equals(that.immutablePropertyFilters)) { return false; } - return getPropertyValueCombinationPolicy().equals(that.getPropertyValueCombinationPolicy()); + return true; } @@ -174,7 +141,6 @@ public class DefaultConfigurationContext implements ConfigurationContext { int result = propertyConverterManager.hashCode(); result = 31 * result + immutablePropertySources.hashCode(); result = 31 * result + immutablePropertyFilters.hashCode(); - result = 31 * result + getPropertyValueCombinationPolicy().hashCode(); return result; } @@ -240,9 +206,7 @@ public class DefaultConfigurationContext implements ConfigurationContext { b.append('\n'); } } - b.append("\n\n"); - b.append(" PropertyValueCombinationPolicy: " + getPropertyValueCombinationPolicy().getClass().getName()).append('\n'); - b.append('}'); + b.append("\n}"); return b.toString(); } @@ -285,12 +249,6 @@ public class DefaultConfigurationContext implements ConfigurationContext { } @Override - public <T> void addPropertyConverter(TypeLiteral<T> typeToConvert, PropertyConverter<T> propertyConverter) { - propertyConverterManager.register(typeToConvert, propertyConverter); - LOG.info("Added PropertyConverter: " + propertyConverter.getClass().getName()); - } - - @Override public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() { return propertyConverterManager.getPropertyConverters(); } @@ -305,14 +263,4 @@ public class DefaultConfigurationContext implements ConfigurationContext { return immutablePropertyFilters; } - @Override - public PropertyValueCombinationPolicy getPropertyValueCombinationPolicy(){ - return propertyValueCombinationPolicy; - } - - @Override - public ConfigurationContextBuilder toBuilder() { - return new DefaultConfigurationContextBuilder(this); - } - }
