You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2017/03/05 23:29:22 UTC
[1/5] incubator-tamaya-extensions git commit: TAMAYA-253: Added
replacement policy for raw evaluation.
Repository: incubator-tamaya-extensions
Updated Branches:
refs/heads/master abb34d651 -> 01ba7463e
TAMAYA-253: Added replacement policy for raw evaluation.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/commit/ed226955
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/ed226955
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/ed226955
Branch: refs/heads/master
Commit: ed2269552a61141ca36cb0b6cc2295d6e51444b3
Parents: abb34d6
Author: anatole <an...@apache.org>
Authored: Sun Mar 5 21:24:25 2017 +0100
Committer: anatole <an...@apache.org>
Committed: Sun Mar 5 21:24:25 2017 +0100
----------------------------------------------------------------------
.../tamaya/spisupport/ConfigValueEvaluator.java | 48 ++++++++++++++
.../spisupport/DefaultConfigValueEvaluator.java | 70 ++++++++++++++++++++
2 files changed, 118 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ed226955/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/ConfigValueEvaluator.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/ConfigValueEvaluator.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/ConfigValueEvaluator.java
new file mode 100644
index 0000000..92fd614
--- /dev/null
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/ConfigValueEvaluator.java
@@ -0,0 +1,48 @@
+/*
+ * 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.spisupport;
+
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.PropertyValue;
+
+import java.util.Map;
+
+
+/**
+ * Component SPI which encapsulates the evaluation of a single or full <b>raw</b>value
+ * for a {@link ConfigurationContext}.
+ */
+public interface ConfigValueEvaluator {
+
+ /**
+ * Evaluates single value using a {@link ConfigurationContext}.
+ * @param key the config key, not null.
+ * @param context the context, not null.
+ * @return the value, or null.
+ */
+ PropertyValue evaluteRawValue(String key, ConfigurationContext context);
+
+ /**
+ * Evaluates all property values from a {@link ConfigurationContext}.
+ * @param context the context, not null.
+ * @return the value, or null.
+ */
+ Map<String, PropertyValue> evaluateRawValues(ConfigurationContext context);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ed226955/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigValueEvaluator.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigValueEvaluator.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigValueEvaluator.java
new file mode 100644
index 0000000..cdfcfdc
--- /dev/null
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigValueEvaluator.java
@@ -0,0 +1,70 @@
+/*
+ * 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.spisupport;
+
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * Implementation of the Configuration API. This class uses the current {@link ConfigurationContext} to evaluate the
+ * chain of {@link PropertySource} and {@link PropertyFilter}
+ * instance to evaluate the current Configuration.
+ */
+public class DefaultConfigValueEvaluator implements ConfigValueEvaluator{
+
+ @Override
+ public PropertyValue evaluteRawValue(String key, ConfigurationContext context) {
+ PropertyValue unfilteredValue = null;
+ for (PropertySource propertySource : context.getPropertySources()) {
+ unfilteredValue = context.getPropertyValueCombinationPolicy().
+ collect(unfilteredValue, key, propertySource);
+ }
+ if(unfilteredValue==null || unfilteredValue.getValue()==null){
+ return unfilteredValue;
+ }
+ return unfilteredValue;
+ }
+
+ @Override
+ 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);
+ }
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public String toString() {
+ return "DefaultConfigEvaluator{}";
+ }
+}
[2/5] incubator-tamaya-extensions git commit: TAMAYA-252: Unified
PropertyValue API and usage, also separating key, value,
source and other meta-data and defining a clear builder policy.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ExpressionResolutionFilter.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ExpressionResolutionFilter.java b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ExpressionResolutionFilter.java
index bd90083..2f2de62 100644
--- a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ExpressionResolutionFilter.java
+++ b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ExpressionResolutionFilter.java
@@ -22,6 +22,7 @@ import org.apache.tamaya.ConfigException;
import org.apache.tamaya.resolver.spi.ExpressionEvaluator;
import org.apache.tamaya.spi.FilterContext;
import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertyValue;
import org.apache.tamaya.spi.ServiceContextManager;
import javax.annotation.Priority;
@@ -84,9 +85,13 @@ public class ExpressionResolutionFilter implements PropertyFilter {
* @return the resolved value, or the input in case where no expression was detected.
*/
@Override
- public String filterProperty(String valueToBeFiltered, FilterContext context){
+ public PropertyValue filterProperty(PropertyValue valueToBeFiltered, FilterContext context){
LOG.finest("Resolving " + valueToBeFiltered + "(key=" + context.getKey() + ")");
- return evaluator().evaluateExpression(context.getKey(), valueToBeFiltered, true);
+ String newVal = evaluator().evaluateExpression(context.getKey(), valueToBeFiltered.getValue(), true);
+ if(newVal!=null){
+ return valueToBeFiltered.toBuilder().setValue(newVal).build();
+ }
+ return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/resolver/src/test/java/org/apache/tamaya/resolver/MyTestPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/test/java/org/apache/tamaya/resolver/MyTestPropertySource.java b/modules/resolver/src/test/java/org/apache/tamaya/resolver/MyTestPropertySource.java
index 1c26f31..eee7fa4 100644
--- a/modules/resolver/src/test/java/org/apache/tamaya/resolver/MyTestPropertySource.java
+++ b/modules/resolver/src/test/java/org/apache/tamaya/resolver/MyTestPropertySource.java
@@ -76,6 +76,11 @@ public class MyTestPropertySource implements PropertySource{
}
@Override
+ public int getOrdinal() {
+ return 0;
+ }
+
+ @Override
public String getName() {
return "test";
}
@@ -86,8 +91,12 @@ public class MyTestPropertySource implements PropertySource{
}
@Override
- public Map<String, String> getProperties() {
- return properties;
+ public Map<String, PropertyValue> getProperties() {
+ Map<String, PropertyValue> res = new HashMap<>();
+ for(Map.Entry<String,String> en:properties.entrySet()){
+ res.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), "test"));
+ }
+ return res;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/resources/src/main/java/org/apache/tamaya/resource/AbstractPathPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/resources/src/main/java/org/apache/tamaya/resource/AbstractPathPropertySourceProvider.java b/modules/resources/src/main/java/org/apache/tamaya/resource/AbstractPathPropertySourceProvider.java
index 6a6398a..760e688 100644
--- a/modules/resources/src/main/java/org/apache/tamaya/resource/AbstractPathPropertySourceProvider.java
+++ b/modules/resources/src/main/java/org/apache/tamaya/resource/AbstractPathPropertySourceProvider.java
@@ -126,7 +126,7 @@ public abstract class AbstractPathPropertySourceProvider implements PropertySour
/** The property source's name. */
private final String name;
/** The properties. */
- private final Map<String,String> properties = new HashMap<>();
+ private final Map<String,PropertyValue> properties = new HashMap<>();
/**
* Constructor for a simple properties configuration.
@@ -134,9 +134,10 @@ public abstract class AbstractPathPropertySourceProvider implements PropertySour
* @param props the properties, not null
*/
public PropertiesBasedPropertySource(String name, Properties props) {
- this.name = name;
+ this.name = Objects.requireNonNull(name);
for (Entry<Object, Object> en : props.entrySet()) {
- this.properties.put(en.getKey().toString(), String.valueOf(en.getValue()));
+ this.properties.put(en.getKey().toString(),
+ PropertyValue.of(en.getKey().toString(), String.valueOf(en.getValue()), name));
}
}
@@ -147,7 +148,10 @@ public abstract class AbstractPathPropertySourceProvider implements PropertySour
*/
public PropertiesBasedPropertySource(String name, Map<String,String> props) {
this.name = Objects.requireNonNull(name);
- this.properties.putAll(props);
+ for (Entry<String, String> en : props.entrySet()) {
+ this.properties.put(en.getKey(),
+ PropertyValue.of(en.getKey(), en.getValue(), name));
+ }
}
public int getOrdinal() {
@@ -179,11 +183,11 @@ public abstract class AbstractPathPropertySourceProvider implements PropertySour
@Override
public PropertyValue get(String key) {
- return PropertyValue.of(key, getProperties().get(key), getName());
+ return this.properties.get(key);
}
@Override
- public Map<String, String> getProperties() {
+ public Map<String, PropertyValue> getProperties() {
return properties;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/resources/src/test/java/org/apache/tamaya/resource/AbstractPathPropertySourceProviderTest.java
----------------------------------------------------------------------
diff --git a/modules/resources/src/test/java/org/apache/tamaya/resource/AbstractPathPropertySourceProviderTest.java b/modules/resources/src/test/java/org/apache/tamaya/resource/AbstractPathPropertySourceProviderTest.java
index 8fe1b2b..0dc6c91 100644
--- a/modules/resources/src/test/java/org/apache/tamaya/resource/AbstractPathPropertySourceProviderTest.java
+++ b/modules/resources/src/test/java/org/apache/tamaya/resource/AbstractPathPropertySourceProviderTest.java
@@ -20,7 +20,6 @@ package org.apache.tamaya.resource;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.spi.PropertyValueBuilder;
import org.junit.Test;
import java.net.URL;
@@ -121,7 +120,7 @@ public class AbstractPathPropertySourceProviderTest {
}
@Override
- public Map<String, String> getProperties() {
+ public Map<String, PropertyValue> getProperties() {
return Collections.emptyMap();
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/resources/src/test/java/org/apache/tamaya/resource/internal/PathBasedPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/resources/src/test/java/org/apache/tamaya/resource/internal/PathBasedPropertySourceProvider.java b/modules/resources/src/test/java/org/apache/tamaya/resource/internal/PathBasedPropertySourceProvider.java
index 1299a0c..7e2f622 100644
--- a/modules/resources/src/test/java/org/apache/tamaya/resource/internal/PathBasedPropertySourceProvider.java
+++ b/modules/resources/src/test/java/org/apache/tamaya/resource/internal/PathBasedPropertySourceProvider.java
@@ -21,16 +21,10 @@ package org.apache.tamaya.resource.internal;
import org.apache.tamaya.resource.AbstractPathPropertySourceProvider;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.spi.PropertyValueBuilder;
import java.io.InputStream;
import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
+import java.util.*;
/**
* Created by Anatole on 03.03.2015.
@@ -60,27 +54,35 @@ public class PathBasedPropertySourceProvider extends AbstractPathPropertySourceP
private final static class PropertiesBasedPropertySource implements PropertySource{
private final String name;
- private final Map<String,String> properties = new HashMap<>();
+ private final Map<String,PropertyValue> properties = new HashMap<>();
public PropertiesBasedPropertySource(String name, Properties props) {
- this.name = name;
+ this.name = Objects.requireNonNull(name);
for (Map.Entry en : props.entrySet()) {
- this.properties.put(en.getKey().toString(), String.valueOf(en.getValue()));
+ this.properties.put(en.getKey().toString(),
+ PropertyValue.of(en.getKey().toString(),
+ String.valueOf(en.getValue()),
+ name));
}
}
@Override
+ public int getOrdinal() {
+ return 0;
+ }
+
+ @Override
public String getName() {
return name;
}
@Override
public PropertyValue get(String key) {
- return PropertyValue.of(key,properties.get(key), getName());
+ return properties.get(key);
}
@Override
- public Map<String, String> getProperties() {
+ public Map<String, PropertyValue> getProperties() {
return properties;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/BasePropertySource.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/BasePropertySource.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/BasePropertySource.java
index 9ae130a..685bffa 100644
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/BasePropertySource.java
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/BasePropertySource.java
@@ -135,19 +135,12 @@ public abstract class BasePropertySource implements PropertySource{
@Override
public PropertyValue get(String key) {
- Map<String,String> properties = getProperties();
- String val = properties.get(key);
+ Map<String,PropertyValue> properties = getProperties();
+ PropertyValue val = properties.get(key);
if(val==null){
return null;
}
- PropertyValueBuilder b = new PropertyValueBuilder(key, val, getName());
- String metaKeyStart = "_" + key + ".";
- for(Map.Entry<String,String> en:properties.entrySet()) {
- if(en.getKey().startsWith(metaKeyStart) && en.getValue()!=null){
- b.addContextData(en.getKey().substring(metaKeyStart.length()), en.getValue());
- }
- }
- return b.build();
+ return val;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/CLIPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/CLIPropertySource.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/CLIPropertySource.java
index e8a6077..20a62bb 100644
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/CLIPropertySource.java
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/CLIPropertySource.java
@@ -18,6 +18,8 @@
*/
package org.apache.tamaya.spisupport;
+import org.apache.tamaya.spi.PropertyValue;
+
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -33,7 +35,7 @@ public class CLIPropertySource extends BasePropertySource{
private static String[] args = new String[0];
/** The map of parsed main arguments. */
- private static Map<String,String> mainArgs;
+ private static Map<String,PropertyValue> mainArgs;
/** Initializes the initial state. */
static{
@@ -117,11 +119,16 @@ public class CLIPropertySource extends BasePropertySource{
}
}
}
- CLIPropertySource.mainArgs = Collections.unmodifiableMap(result);
+ Map<String,PropertyValue> finalProps = new HashMap<>();
+ for(Map.Entry<String,String> en:result.entrySet()) {
+ finalProps.put(en.getKey(),
+ PropertyValue.of(en.getKey(), en.getValue(), "main-args"));
+ }
+ CLIPropertySource.mainArgs = Collections.unmodifiableMap(finalProps);
}
@Override
- public Map<String, String> getProperties() {
+ public Map<String, PropertyValue> getProperties() {
return Collections.unmodifiableMap(mainArgs);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java
index 8547a5a..a0a621a 100644
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java
@@ -29,6 +29,7 @@ import org.apache.tamaya.spi.PropertyConverter;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertyValue;
import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
+import org.apache.tamaya.spi.ServiceContextManager;
import java.util.ArrayList;
import java.util.Collections;
@@ -55,6 +56,25 @@ public class DefaultConfiguration implements Configuration {
*/
private final ConfigurationContext configurationContext;
+ /**
+ * EvaluationStrategy
+ */
+ private ConfigValueEvaluator configEvaluator = loadConfigValueEvaluator();
+
+ private ConfigValueEvaluator loadConfigValueEvaluator() {
+ ConfigValueEvaluator eval = null;
+ try{
+ eval = ServiceContextManager.getServiceContext()
+ .getService(ConfigValueEvaluator.class);
+ }catch(Exception e){
+ LOG.log(Level.WARNING, "Failed to load ConfigValueEvaluator from ServiceContext, using default.", e);
+ }
+ if(eval==null){
+ eval = new DefaultConfigValueEvaluator();
+ }
+ return eval;
+ }
+
/**
* Constructor.
@@ -71,11 +91,15 @@ public class DefaultConfiguration implements Configuration {
*/
@Override
public String get(String key) {
- PropertyValue configData = evaluteRawValue(key);
- if(configData==null){
+ PropertyValue value = configEvaluator.evaluteRawValue(key, configurationContext);
+ if(value==null || value.getValue()==null){
return null;
}
- return PropertyFilterManager.applyFilter(key, configData.getConfigEntries(), configurationContext);
+ value = PropertyFilterManager.applyFilter(key, value, configurationContext);
+ if(value!=null){
+ return value.getValue();
+ }
+ return null;
}
/**
@@ -85,16 +109,13 @@ public class DefaultConfiguration implements Configuration {
*/
protected PropertyValue evaluteRawValue(String key) {
List<PropertySource> propertySources = configurationContext.getPropertySources();
- Map<String,String> unfilteredValue = null;
+ PropertyValue filteredValue = null;
PropertyValueCombinationPolicy combinationPolicy = this.configurationContext
.getPropertyValueCombinationPolicy();
for (PropertySource propertySource : propertySources) {
- unfilteredValue = combinationPolicy.collect(unfilteredValue, key, propertySource);
+ filteredValue = combinationPolicy.collect(filteredValue, key, propertySource);
}
- if(unfilteredValue==null){
- return null;
- }
- return PropertyValue.of(key, unfilteredValue.get(key), unfilteredValue.get("_"+key+".source"));
+ return filteredValue;
}
@@ -124,32 +145,21 @@ public class DefaultConfiguration implements Configuration {
*/
@Override
public Map<String, String> getProperties() {
- return PropertyFilterManager.applyFilters(evaluateUnfilteredMap(), configurationContext);
- }
-
- /**
- * Evaluate all properties, but do not apply filtering on the output.
- * @return the unfiltered key, value map.
- */
- protected Map<String, String> evaluateUnfilteredMap() {
- List<PropertySource> propertySources = new ArrayList<>(configurationContext.getPropertySources());
- Collections.reverse(propertySources);
- Map<String, String> result = new HashMap<>();
- for (PropertySource propertySource : propertySources) {
- try {
- int origSize = result.size();
- Map<String, String> otherMap = propertySource.getProperties();
- LOG.log(Level.FINEST, null, "Overriding with properties from " + propertySource.getName());
- result.putAll(otherMap);
- LOG.log(Level.FINEST, null, "Handled properties from " + propertySource.getName() + "(new: " +
- (result.size() - origSize) + ", overrides: " + origSize + ", total: " + result.size());
- } catch (Exception e) {
- LOG.log(Level.SEVERE, "Error adding properties from PropertySource: " + propertySource + ", ignoring PropertySource.", e);
+ Map<String, PropertyValue> filtered = PropertyFiltering.applyFilters(
+ configEvaluator.evaluateRawValues(configurationContext),
+ configurationContext);
+ Map<String,String> result = new HashMap<>();
+ for(PropertyValue val:filtered.values()){
+ if(val.getValue()!=null) {
+ result.put(val.getKey(), val.getValue());
+ // TODO: Discuss metadata handling...
+ result.putAll(val.getMetaEntries());
}
}
return result;
}
+
/**
* Accesses the current String value for the given key and tries to convert it
* using the {@link PropertyConverter} instances provided by the current
@@ -185,7 +195,8 @@ public class DefaultConfiguration implements Configuration {
protected <T> T convertValue(String key, String value, TypeLiteral<T> type) {
if (value != null) {
List<PropertyConverter<T>> converters = configurationContext.getPropertyConverters(type);
- ConversionContext context = new ConversionContext.Builder(this, configurationContext, key, type).build();
+ ConversionContext context = new ConversionContext.Builder(this, this.configurationContext, key, type)
+ .build();
for (PropertyConverter<T> converter : converters) {
try {
T t = converter.convert(value, context);
@@ -196,8 +207,13 @@ public class DefaultConfiguration implements Configuration {
LOG.log(Level.FINEST, "PropertyConverter: " + converter + " failed to convert value: " + value, e);
}
}
+ // if the target type is a String, we can return the value, no conversion required.
+ if(type.equals(TypeLiteral.of(String.class))){
+ return (T)value;
+ }
+ // unsupported type, throw an exception
throw new ConfigException("Unparseable config value for type: " + type.getRawType().getName() + ": " + key +
- ", supported formats: "+context.getSupportedFormats());
+ ", supported formats: " + context.getSupportedFormats());
}
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/EnvironmentPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/EnvironmentPropertySource.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/EnvironmentPropertySource.java
index 1dd4ce7..7cbb713 100644
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/EnvironmentPropertySource.java
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/EnvironmentPropertySource.java
@@ -147,22 +147,21 @@ public class EnvironmentPropertySource extends BasePropertySource {
}
@Override
- public Map<String, String> getProperties() {
+ public Map<String, PropertyValue> getProperties() {
if(disabled){
return Collections.emptyMap();
}
String prefix = this.prefix;
if(prefix==null) {
- Map<String, String> entries = new HashMap<>(System.getenv());
+ Map<String, PropertyValue> entries = new HashMap<>(System.getenv().size());
for (Map.Entry<String, String> entry : System.getenv().entrySet()) {
- entries.put("_" + entry.getKey() + ".source", getName());
+ entries.put(entry.getKey(), PropertyValue.of(entry.getKey(), entry.getValue(), getName()));
}
return entries;
}else{
- Map<String, String> entries = new HashMap<>();
+ Map<String, PropertyValue> entries = new HashMap<>(System.getenv().size());
for (Map.Entry<String, String> entry : System.getenv().entrySet()) {
- entries.put(prefix + entry.getKey(), entry.getValue());
- entries.put("_" + prefix + entry.getKey() + ".source", getName());
+ entries.put(prefix + entry.getKey(), PropertyValue.of(prefix + entry.getKey(), entry.getValue(), getName()));
}
return entries;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/MapPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/MapPropertySource.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/MapPropertySource.java
index de2beef..437cf64 100644
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/MapPropertySource.java
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/MapPropertySource.java
@@ -16,6 +16,8 @@
*/
package org.apache.tamaya.spisupport;
+import org.apache.tamaya.spi.PropertyValue;
+
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -30,7 +32,7 @@ public class MapPropertySource extends BasePropertySource {
/**
* The current properties.
*/
- private final Map<String, String> props = new HashMap<>();
+ private final Map<String, PropertyValue> props = new HashMap<>();
/**
* Creates a new instance, hereby using the default mechanism for evaluating the property source's
@@ -54,10 +56,14 @@ public class MapPropertySource extends BasePropertySource {
public MapPropertySource(String name, Map<String, String> props, String prefix) {
super(name);
if (prefix == null) {
- this.props.putAll(props);
+ for (Map.Entry<String, String> en : props.entrySet()) {
+ this.props.put(en.getKey(),
+ PropertyValue.of(en.getKey(), en.getValue(), name));
+ }
} else {
for (Map.Entry<String, String> en : props.entrySet()) {
- this.props.put(prefix + en.getKey(), en.getValue());
+ this.props.put(prefix + en.getKey(),
+ PropertyValue.of(prefix + en.getKey(), en.getValue(), name));
}
}
}
@@ -89,7 +95,7 @@ public class MapPropertySource extends BasePropertySource {
@Override
- public Map<String, String> getProperties() {
+ public Map<String, PropertyValue> getProperties() {
return Collections.unmodifiableMap(this.props);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFilterManager.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFilterManager.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFilterManager.java
index 611722a..cdef84d 100644
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFilterManager.java
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFilterManager.java
@@ -21,6 +21,7 @@ package org.apache.tamaya.spisupport;
import org.apache.tamaya.spi.ConfigurationContext;
import org.apache.tamaya.spi.FilterContext;
import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertyValue;
import java.util.HashMap;
import java.util.Map;
@@ -48,14 +49,13 @@ public final class PropertyFilterManager {
*/
private PropertyFilterManager(){}
- public static String applyFilter(String key, Map<String,String> configData, ConfigurationContext configurationContext) {
+ public static PropertyValue applyFilter(String key, PropertyValue unfilteredValue, ConfigurationContext configurationContext) {
// Apply filters to values, prevent values filtered to null!
- String unfilteredValue = configData.get(key);
for (int i = 0; i < MAX_FILTER_LOOPS; i++) {
boolean changed = false;
// Apply filters to values, prevent values filtered to null!
for (PropertyFilter filter : configurationContext.getPropertyFilters()) {
- String newValue = filter.filterProperty(unfilteredValue, new FilterContext(key, configData, true));
+ PropertyValue newValue = filter.filterProperty(unfilteredValue, new FilterContext(key, unfilteredValue));
if (newValue != null && !newValue.equals(unfilteredValue)) {
changed = true;
if (LOG.isLoggable(Level.FINEST)) {
@@ -85,17 +85,17 @@ public final class PropertyFilterManager {
return unfilteredValue;
}
- public static Map<String, String> applyFilters(Map<String, String> inputMap, ConfigurationContext configurationContext) {
- Map<String, String> resultMap = new HashMap<>(inputMap);
+ public static Map<String, PropertyValue> applyFilters(Map<String, PropertyValue> inputMap, ConfigurationContext configurationContext) {
+ Map<String, PropertyValue> resultMap = new HashMap<>(inputMap);
// Apply filters to values, prevent values filtered to null!
for (int i = 0; i < MAX_FILTER_LOOPS; i++) {
AtomicInteger changes = new AtomicInteger();
for (PropertyFilter filter : configurationContext.getPropertyFilters()) {
- for (Map.Entry<String, String> entry : inputMap.entrySet()) {
+ for (Map.Entry<String, PropertyValue> entry : inputMap.entrySet()) {
final String k = entry.getKey();
- final String v = entry.getValue();
+ final PropertyValue v = entry.getValue();
- String newValue = filter.filterProperty(v, new FilterContext(k, inputMap, false));
+ PropertyValue newValue = filter.filterProperty(v, new FilterContext(k, inputMap));
if (newValue != null && !newValue.equals(v)) {
changes.incrementAndGet();
LOG.finest("Filter - " + k + ": " + v + " -> " + newValue + " by " + filter);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFiltering.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFiltering.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFiltering.java
index eef758b..f614471 100644
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFiltering.java
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFiltering.java
@@ -21,6 +21,7 @@ package org.apache.tamaya.spisupport;
import org.apache.tamaya.spi.ConfigurationContext;
import org.apache.tamaya.spi.FilterContext;
import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertyValue;
import java.util.HashMap;
import java.util.Map;
@@ -48,14 +49,14 @@ public final class PropertyFiltering{
*/
private PropertyFiltering(){}
- public static String applyFilter(String key, Map<String,String> configData, ConfigurationContext configurationContext) {
+ public static PropertyValue applyFilter(String key, Map<String,PropertyValue> configData, ConfigurationContext configurationContext) {
// Apply filters to values, prevent values filtered to null!
- String unfilteredValue = configData.get(key);
+ PropertyValue unfilteredValue = configData.get(key);
for (int i = 0; i < MAX_FILTER_LOOPS; i++) {
boolean changed = false;
// Apply filters to values, prevent values filtered to null!
for (PropertyFilter filter : configurationContext.getPropertyFilters()) {
- String newValue = filter.filterProperty(unfilteredValue, new FilterContext(key, configData, true));
+ PropertyValue newValue = filter.filterProperty(unfilteredValue, new FilterContext(key, configData));
if (newValue != null && !newValue.equals(unfilteredValue)) {
changed = true;
if (LOG.isLoggable(Level.FINEST)) {
@@ -85,17 +86,17 @@ public final class PropertyFiltering{
return unfilteredValue;
}
- public static Map<String, String> applyFilters(Map<String, String> inputMap, ConfigurationContext configurationContext) {
- Map<String, String> resultMap = new HashMap<>(inputMap);
+ public static Map<String, PropertyValue> applyFilters(Map<String, PropertyValue> inputMap, ConfigurationContext configurationContext) {
+ Map<String, PropertyValue> resultMap = new HashMap<>(inputMap);
// Apply filters to values, prevent values filtered to null!
for (int i = 0; i < MAX_FILTER_LOOPS; i++) {
AtomicInteger changes = new AtomicInteger();
for (PropertyFilter filter : configurationContext.getPropertyFilters()) {
- for (Map.Entry<String, String> entry : inputMap.entrySet()) {
+ for (Map.Entry<String, PropertyValue> entry : inputMap.entrySet()) {
final String k = entry.getKey();
- final String v = entry.getValue();
+ final PropertyValue v = entry.getValue();
- String newValue = filter.filterProperty(v, new FilterContext(k, inputMap, false));
+ PropertyValue newValue = filter.filterProperty(v, new FilterContext(k, inputMap));
if (newValue != null && !newValue.equals(v)) {
changes.incrementAndGet();
LOG.finest("Filter - " + k + ": " + v + " -> " + newValue + " by " + filter);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceComparator.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceComparator.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceComparator.java
index 96fffad..98290b6 100644
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceComparator.java
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceComparator.java
@@ -68,32 +68,32 @@ public class PropertySourceComparator implements Comparator<PropertySource>, Ser
}
public static int getOrdinal(PropertySource propertySource) {
- PropertyValue ordinalValue = propertySource.get(PropertySource.TAMAYA_ORDINAL);
- if(ordinalValue!=null){
- try{
- return Integer.parseInt(ordinalValue.getValue().trim());
- }catch(Exception e){
- LOG.finest("Failed to parse ordinal from " + PropertySource.TAMAYA_ORDINAL +
- " in " + propertySource.getName()+": "+ordinalValue.getValue());
- }
- }
- try {
- Method method = propertySource.getClass().getMethod("getOrdinal");
- if(int.class.equals(method.getReturnType())){
- try {
- return (int)method.invoke(propertySource);
- } catch (Exception e) {
- LOG.log(Level.FINEST, "Error calling int getOrdinal() on " + propertySource.getName(), e);
- }
- }
- } catch (NoSuchMethodException e) {
- LOG.finest("No int getOrdinal() method found in " + propertySource.getName());
- }
- Priority prio = propertySource.getClass().getAnnotation(Priority.class);
- if(prio!=null){
- return prio.value();
- }
- return 0;
+// PropertyValue ordinalValue = propertySource.get(PropertySource.TAMAYA_ORDINAL);
+// if(ordinalValue!=null){
+// try{
+// return Integer.parseInt(ordinalValue.getValue().trim());
+// }catch(Exception e){
+// LOG.finest("Failed to parse ordinal from " + PropertySource.TAMAYA_ORDINAL +
+// " in " + propertySource.getName()+": "+ordinalValue.getValue());
+// }
+// }
+// try {
+// Method method = propertySource.getClass().getMethod("getOrdinal");
+// if(int.class.equals(method.getReturnType())){
+// try {
+// return (int)method.invoke(propertySource);
+// } catch (Exception e) {
+// LOG.log(Level.FINEST, "Error calling int getOrdinal() on " + propertySource.getName(), e);
+// }
+// }
+// } catch (NoSuchMethodException e) {
+// LOG.finest("No int getOrdinal() method found in " + propertySource.getName());
+// }
+// Priority prio = propertySource.getClass().getAnnotation(Priority.class);
+// if(prio!=null){
+// return prio.value();
+// }
+ return propertySource.getOrdinal();
}
@Override
public int compare(PropertySource source1, PropertySource source2) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/RegexPropertyFilter.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/RegexPropertyFilter.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/RegexPropertyFilter.java
index e186015..cb08193 100644
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/RegexPropertyFilter.java
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/RegexPropertyFilter.java
@@ -20,6 +20,7 @@ package org.apache.tamaya.spisupport;
import org.apache.tamaya.spi.FilterContext;
import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertyValue;
import java.util.Arrays;
import java.util.List;
@@ -53,7 +54,7 @@ public final class RegexPropertyFilter implements PropertyFilter{
}
@Override
- public String filterProperty(String valueToBeFiltered, FilterContext context) {
+ public PropertyValue filterProperty(PropertyValue valueToBeFiltered, FilterContext context) {
if(includes!=null){
for(String expression:includes){
if(context.getKey().matches(expression)){
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SimplePropertySource.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SimplePropertySource.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SimplePropertySource.java
index 37e3a7a..f1a5a57 100644
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SimplePropertySource.java
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SimplePropertySource.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.spisupport;
import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.spi.PropertyValue;
import java.io.File;
import java.io.IOException;
@@ -43,7 +44,7 @@ public class SimplePropertySource extends BasePropertySource {
/**
* The current properties.
*/
- private Map<String, String> properties;
+ private Map<String, PropertyValue> properties = new HashMap<>();
/**
* Creates a new Properties based PropertySource based on the given URL.
@@ -78,7 +79,9 @@ public class SimplePropertySource extends BasePropertySource {
*/
public SimplePropertySource(String name, Map<String, String> properties, int defaultOrdinal){
super(name, defaultOrdinal);
- this.properties = new HashMap<>(properties);
+ for(Map.Entry<String,String> en: properties.entrySet()) {
+ this.properties.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), name));
+ }
}
/**
@@ -88,8 +91,7 @@ public class SimplePropertySource extends BasePropertySource {
* @param properties the properties, not null.
*/
public SimplePropertySource(String name, Map<String, String> properties) {
- super(name, 0);
- this.properties = new HashMap<>(properties);
+ this(name, properties, 0);
}
/**
@@ -119,7 +121,7 @@ public class SimplePropertySource extends BasePropertySource {
}
@Override
- public Map<String, String> getProperties() {
+ public Map<String, PropertyValue> getProperties() {
return this.properties;
}
@@ -130,10 +132,10 @@ public class SimplePropertySource extends BasePropertySource {
* @return loaded {@link Properties}
* @throws IllegalStateException in case of an error while reading properties-file
*/
- private static Map<String, String> load(URL propertiesFile) {
+ private static Map<String, PropertyValue> load(URL propertiesFile) {
boolean isXML = isXMLPropertieFiles(propertiesFile);
- Map<String, String> properties = new HashMap<>();
+ Map<String, PropertyValue> properties = new HashMap<>();
try (InputStream stream = propertiesFile.openStream()) {
Properties props = new Properties();
if (stream != null) {
@@ -145,8 +147,7 @@ public class SimplePropertySource extends BasePropertySource {
}
String source = propertiesFile.toString();
for (String key : props.stringPropertyNames()) {
- properties.put(key, props.getProperty(key));
- properties.put("_" + key + ".source", source);
+ properties.put(key, PropertyValue.of(key, props.getProperty(key), source));
}
} catch (IOException e) {
throw new ConfigException("Error loading properties from " + propertiesFile, e);
@@ -167,7 +168,7 @@ public class SimplePropertySource extends BasePropertySource {
private String name;
private Integer defaultOrdinal;
private Integer ordinal;
- private Map<String, String> properties = new HashMap<>();
+ private Map<String, PropertyValue> properties = new HashMap<>();
private Builder() {
}
@@ -254,7 +255,9 @@ public class SimplePropertySource extends BasePropertySource {
* @return a reference to this Builder
*/
public Builder withProperties(Map<String, String> val) {
- this.properties.putAll(val);
+ for(Map.Entry<String,String> en: val.entrySet()) {
+ this.properties.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), name));
+ }
return this;
}
@@ -265,18 +268,7 @@ public class SimplePropertySource extends BasePropertySource {
* @return a reference to this Builder
*/
public Builder withProperty(String key, String val) {
- this.properties.put(key, val);
- return this;
- }
-
- /**
- * Sets the {@code properties} and returns a reference to this Builder so that the methods can be chained together.
- *
- * @param val the {@code properties} to set
- * @return a reference to this Builder
- */
- public Builder withSource(String val) {
- this.properties.put("_source", val);
+ this.properties.put(key, PropertyValue.of(key, val, name));
return this;
}
@@ -286,7 +278,6 @@ public class SimplePropertySource extends BasePropertySource {
* @return a {@code SimplePropertySource} built with parameters of this {@code SimplePropertySource.Builder}
*/
public SimplePropertySource build() {
- this.properties.put("_builtAt", String.valueOf(System.currentTimeMillis()));
return new SimplePropertySource(this);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SystemPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SystemPropertySource.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SystemPropertySource.java
index 25863d6..61aa449 100644
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SystemPropertySource.java
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SystemPropertySource.java
@@ -36,7 +36,7 @@ public class SystemPropertySource extends BasePropertySource {
*/
public static final int DEFAULT_ORDINAL = 1000;
- private volatile Map<String,String> cachedProperties;
+ private volatile Map<String,PropertyValue> cachedProperties;
/**
* previous System.getProperties().hashCode()
@@ -127,18 +127,22 @@ public class SystemPropertySource extends BasePropertySource {
}
- private Map<String, String> loadProperties() {
+ private Map<String, PropertyValue> loadProperties() {
Properties sysProps = System.getProperties();
previousHash = System.getProperties().hashCode();
final String prefix = this.prefix;
- Map<String, String> entries = new HashMap<>();
+ Map<String, PropertyValue> entries = new HashMap<>();
for (Map.Entry<Object,Object> entry : sysProps.entrySet()) {
if(prefix==null) {
- entries.put("_" + entry.getKey() + ".source", getName());
- entries.put((String) entry.getKey(), (String) entry.getValue());
+ entries.put((String) entry.getKey(),
+ PropertyValue.of((String) entry.getKey(),
+ (String) entry.getValue(),
+ getName()));
}else {
- entries.put(prefix + entry.getKey(), (String)entry.getValue());
- entries.put("_" + prefix + entry.getKey() + ".source", getName());
+ entries.put(prefix + entry.getKey(),
+ PropertyValue.of(prefix + entry.getKey(),
+ (String) entry.getValue(),
+ getName()));
}
}
return entries;
@@ -165,7 +169,7 @@ public class SystemPropertySource extends BasePropertySource {
}
@Override
- public Map<String, String> getProperties() {
+ public Map<String, PropertyValue> getProperties() {
if(disabled){
return Collections.emptyMap();
}
@@ -173,7 +177,7 @@ public class SystemPropertySource extends BasePropertySource {
// synchronization was removed, Instance was marked as volatile. In the worst case it
// is reloaded twice, but the values will be the same.
if (previousHash != System.getProperties().hashCode()) {
- Map<String, String> properties = loadProperties();
+ Map<String, PropertyValue> properties = loadProperties();
this.cachedProperties = Collections.unmodifiableMap(properties);
}
return this.cachedProperties;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BasePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BasePropertySourceTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BasePropertySourceTest.java
index 2cdac70..a986b7b 100644
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BasePropertySourceTest.java
+++ b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BasePropertySourceTest.java
@@ -21,13 +21,10 @@ package org.apache.tamaya.spisupport;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.spi.PropertyValueBuilder;
import org.junit.Assert;
import org.junit.Test;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
public class BasePropertySourceTest {
@@ -42,7 +39,7 @@ public class BasePropertySourceTest {
}
@Override
- public Map<String, String> getProperties() {
+ public Map<String, PropertyValue> getProperties() {
return Collections.emptyMap();
}
};
@@ -56,7 +53,7 @@ public class BasePropertySourceTest {
@Test
public void testGet() {
- Assert.assertEquals("1000", new OverriddenOrdinalPropertySource().get(PropertySource.TAMAYA_ORDINAL).get(PropertySource.TAMAYA_ORDINAL));
+ Assert.assertEquals(1000, new OverriddenOrdinalPropertySource().getOrdinal());
}
private static class OverriddenOrdinalPropertySource extends BasePropertySource {
@@ -66,10 +63,10 @@ public class BasePropertySourceTest {
}
@Override
- public Map<String, String> getProperties() {
- Map<String, String> map = new HashMap<>(1);
- map.put(PropertySource.TAMAYA_ORDINAL, "1000");
- return map;
+ public Map<String, PropertyValue> getProperties() {
+ Map<String,PropertyValue> props = new HashMap<>(1);
+ props.put(PropertySource.TAMAYA_ORDINAL, PropertyValue.of(PropertySource.TAMAYA_ORDINAL, "1000", getName()));
+ return props;
}
}
@@ -80,10 +77,10 @@ public class BasePropertySourceTest {
}
@Override
- public Map<String, String> getProperties() {
- Map<String, String> map = new HashMap<>(1);
- map.put(PropertySource.TAMAYA_ORDINAL, "invalid");
- return map;
+ public Map<String, PropertyValue> getProperties() {
+ Map<String,PropertyValue> props = new HashMap<>(1);
+ props.put(PropertySource.TAMAYA_ORDINAL, PropertyValue.of(PropertySource.TAMAYA_ORDINAL, "invalid", getName()));
+ return props;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/CLIPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/CLIPropertySourceTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/CLIPropertySourceTest.java
index 2c2baa4..e08bf80 100644
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/CLIPropertySourceTest.java
+++ b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/CLIPropertySourceTest.java
@@ -35,25 +35,25 @@ public class CLIPropertySourceTest {
assertTrue(ps.getProperties().isEmpty());
CLIPropertySource.initMainArgs("-a", "b");
assertFalse(ps.getProperties().isEmpty());
- assertEquals(ps.getProperties().get("a"), "b");
+ assertEquals(ps.getProperties().get("a").getValue(), "b");
CLIPropertySource.initMainArgs("--c");
assertFalse(ps.getProperties().isEmpty());
- assertEquals(ps.getProperties().get("c"), "c");
+ assertEquals(ps.getProperties().get("c").getValue(), "c");
CLIPropertySource.initMainArgs("sss");
assertFalse(ps.getProperties().isEmpty());
- assertEquals(ps.getProperties().get("sss"), "sss");
+ assertEquals(ps.getProperties().get("sss").getValue(), "sss");
CLIPropertySource.initMainArgs("-a", "b", "--c", "sss", "--val=vvv");
assertFalse(ps.getProperties().isEmpty());
- assertEquals(ps.getProperties().get("a"), "b");
- assertEquals(ps.getProperties().get("c"), "c");
- assertEquals(ps.getProperties().get("sss"), "sss");
+ assertEquals(ps.getProperties().get("a").getValue(), "b");
+ assertEquals(ps.getProperties().get("c").getValue(), "c");
+ assertEquals(ps.getProperties().get("sss").getValue(), "sss");
// getProperties() throws Exception {
System.setProperty("main.args", "-a b\t--c sss ");
ps = new CLIPropertySource();
assertFalse(ps.getProperties().isEmpty());
System.clearProperty("main.args");
- assertEquals(ps.getProperties().get("a"), "b");
- assertEquals(ps.getProperties().get("c"), "c");
- assertEquals(ps.getProperties().get("sss"), "sss");
+ assertEquals(ps.getProperties().get("a").getValue(), "b");
+ assertEquals(ps.getProperties().get("c").getValue(), "c");
+ assertEquals(ps.getProperties().get("sss").getValue(), "sss");
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationContextTest.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationContextTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationContextTest.java
index f1f34c6..5e748ce 100644
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationContextTest.java
+++ b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationContextTest.java
@@ -21,13 +21,7 @@ package org.apache.tamaya.spisupport;
import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.FilterContext;
-import org.apache.tamaya.spi.PropertyConverter;
-import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
+import org.apache.tamaya.spi.*;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -151,7 +145,7 @@ public class DefaultConfigurationContextTest {
PropertyFilter testFilter = new PropertyFilter() {
@Override
- public String filterProperty(String value, FilterContext context) {
+ public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
return value;
}
};
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/EnvironmentPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/EnvironmentPropertySourceTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/EnvironmentPropertySourceTest.java
index a7f0497..877d30d 100644
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/EnvironmentPropertySourceTest.java
+++ b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/EnvironmentPropertySourceTest.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.spisupport;
import org.apache.tamaya.core.propertysource.EnvironmentPropertySource;
+import org.apache.tamaya.spi.PropertyValue;
import org.junit.Test;
import java.util.Map;
@@ -46,16 +47,16 @@ public class EnvironmentPropertySourceTest {
@Test
public void testGet() throws Exception {
for (Map.Entry<String, String> envEntry : System.getenv().entrySet()) {
- assertEquals(envPropertySource.get(envEntry.getKey()).get(envEntry.getKey()), envEntry.getValue());
+ assertEquals(envPropertySource.get(envEntry.getKey()).getValue(), envEntry.getValue());
}
}
@Test
public void testGetProperties() throws Exception {
- Map<String, String> props = envPropertySource.getProperties();
- for(Map.Entry<String,String> en: props.entrySet()){
+ Map<String, PropertyValue> props = envPropertySource.getProperties();
+ for(Map.Entry<String,PropertyValue> en: props.entrySet()){
if(!en.getKey().startsWith("_")){
- assertEquals(System.getenv(en.getKey()), en.getValue());
+ assertEquals(System.getenv(en.getKey()), en.getValue().getValue());
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertiesFilePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertiesFilePropertySourceTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertiesFilePropertySourceTest.java
index 889e905..984be08 100644
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertiesFilePropertySourceTest.java
+++ b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertiesFilePropertySourceTest.java
@@ -35,15 +35,15 @@ public class PropertiesFilePropertySourceTest {
public void testGetOrdinal() {
Assert.assertEquals(0, testfilePropertySource.getOrdinal());
Assert.assertEquals(Integer.parseInt(overrideOrdinalPropertySource.get(PropertySource.TAMAYA_ORDINAL)
- .get(PropertySource.TAMAYA_ORDINAL)),
+ .getValue()),
overrideOrdinalPropertySource.getOrdinal());
}
@Test
public void testGet() {
- Assert.assertEquals("val3", testfilePropertySource.get("key3").get("key3"));
- Assert.assertEquals("myval5", overrideOrdinalPropertySource.get("mykey5").get("mykey5"));
+ Assert.assertEquals("val3", testfilePropertySource.get("key3").getValue());
+ Assert.assertEquals("myval5", overrideOrdinalPropertySource.get("mykey5").getValue());
Assert.assertNull(testfilePropertySource.get("nonpresentkey"));
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java
index 79f2fb9..44364b8 100644
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java
+++ b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.spisupport;
import org.apache.tamaya.spi.FilterContext;
+import org.apache.tamaya.spi.PropertyValue;
import java.util.HashMap;
import java.util.Map;
@@ -34,18 +35,23 @@ public class RegexPropertyFilterTest {
public void testFilterProperty() throws Exception {
RegexPropertyFilter filter = new RegexPropertyFilter();
filter.setIncludes("test1.*");
- Map<String,String> map = new HashMap<>();
- map.put("test1", "test1");
- map.put("test2", "test2");
- map.put("test1.test3", "test.test3");
- assertEquals(filter.filterProperty("test1.", new FilterContext("test1.", map, true)), "test1.");
- assertNull(filter.filterProperty("test2", new FilterContext("test2.", map, true)));
- assertEquals(filter.filterProperty("test1.test3", new FilterContext("test1.test3", map, true)), "test1.test3");
+ Map<String,PropertyValue> map = new HashMap<>();
+ map.put("test1", PropertyValue.of("test1", "test1", "test"));
+ map.put("test2", PropertyValue.of("test2", "test2", "test"));
+ map.put("test1.test3", PropertyValue.of("test1.test3", "test.test3", "test"));
+ assertEquals(filter.filterProperty(PropertyValue.of("test1.", "test1", "test"), new FilterContext("test1.", map)).getValue(), "test1");
+ assertNull(filter.filterProperty(PropertyValue.of("test2", "test2", "test"), new FilterContext("test2.", map)));
+ assertEquals(filter.filterProperty(
+ PropertyValue.of("test1.test3", "testx.test3", "test"),
+ new FilterContext("test1.test3", map)).getValue(), "testx.test3");
+ assertEquals(filter.filterProperty(
+ PropertyValue.of("test1.test3", "testx.test3", "test"),
+ new FilterContext("test1.test3", map)).getValue(), "testx.test3");
filter = new RegexPropertyFilter();
filter.setIncludes("test1.*");
- assertNotNull(filter.filterProperty("test1", new FilterContext("test1", map, true)));
- assertNull(filter.filterProperty("test2", new FilterContext("test2", map, true)));
- assertNull(filter.filterProperty("test.test3", new FilterContext("test.test3", map, true)));
+ assertNotNull(filter.filterProperty(PropertyValue.of("test1", "test1", "test"), new FilterContext("test1", map)));
+ assertNull(filter.filterProperty(PropertyValue.of("test2", "test2", "test"), new FilterContext("test2", map)));
+ assertNull(filter.filterProperty(PropertyValue.of("test.test3", "test1", "test"), new FilterContext("test.test3", map)));
}
@org.junit.Test
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/SimplePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/SimplePropertySourceTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/SimplePropertySourceTest.java
index a7409a4..7ef56c7 100644
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/SimplePropertySourceTest.java
+++ b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/SimplePropertySourceTest.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.spisupport;
import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.spi.PropertyValue;
import org.junit.Test;
import java.net.URL;
@@ -36,9 +37,9 @@ public class SimplePropertySourceTest {
SimplePropertySource source = new SimplePropertySource(resource);
assertThat(source, notNullValue());
- assertThat(source.getProperties(), aMapWithSize(4));
- assertThat(source.getProperties(), hasEntry("a", "b"));
- assertThat(source.getProperties(), hasEntry("b", "1"));
+ assertThat(source.getProperties(), aMapWithSize(2));
+ assertThat(source.getProperties(), hasEntry("a", PropertyValue.of("a","b", source.getName())));
+ assertThat(source.getProperties(), hasEntry("b", PropertyValue.of("b", "1", source.getName())));
}
@@ -80,6 +81,6 @@ public class SimplePropertySourceTest {
SimplePropertySource source = new SimplePropertySource(resource);
assertThat(source, notNullValue());
- assertThat(source.getProperties(), aMapWithSize(10)); // 5 * 2 meta entries.
+ assertThat(source.getProperties(), aMapWithSize(5)); // 5 * 2 meta entries.
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/SystemPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/SystemPropertySourceTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/SystemPropertySourceTest.java
index 54e970c..2e1625a 100644
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/SystemPropertySourceTest.java
+++ b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/SystemPropertySourceTest.java
@@ -39,8 +39,8 @@ public class SystemPropertySourceTest {
Assert.assertEquals(SystemPropertySource.DEFAULT_ORDINAL, testPropertySource.getOrdinal());
// set the ordinal to 1000
- System.setProperty(PropertySource.TAMAYA_ORDINAL, "1000");
- Assert.assertEquals(1000, new SystemPropertySource().getOrdinal());
+ System.setProperty(PropertySource.TAMAYA_ORDINAL, "1001");
+ Assert.assertEquals(1001, new SystemPropertySource().getOrdinal());
// currently its not possible to change ordinal at runtime
// reset it to not destroy other tests!!
@@ -73,30 +73,24 @@ public class SystemPropertySourceTest {
// cleanup
System.clearProperty("test");
-
- // no modifaction
- try {
- testPropertySource.getProperties().put("add.new.keys", "must throw exception");
- Assert.fail(UnsupportedOperationException.class.getName() + " expected");
- }
- catch (UnsupportedOperationException e) {
- // expected -> all is fine
- }
}
- private void checkWithSystemProperties(Map<String, String> toCheck) {
+ private void checkWithSystemProperties(Map<String,PropertyValue> toCheck) {
Properties systemEntries = System.getProperties();
- Assert.assertEquals("size of System.getProperties().entrySet() must be the same as SystemPropertySrouce.getProperties().entrySet()",
- systemEntries.size(), toCheck.size()/2);
+ int num = 0;
- for (Map.Entry<String, String> propertySourceEntry : toCheck.entrySet()) {
+ for (PropertyValue propertySourceEntry : toCheck.values()) {
if(propertySourceEntry.getKey().startsWith("_")){
continue; // meta entry
}
+ num++;
Assert.assertEquals("Entry values for key '" + propertySourceEntry.getKey() + "' do not match",
systemEntries.getProperty(propertySourceEntry.getKey()), propertySourceEntry.getValue());
}
+ Assert.assertEquals("size of System.getProperties().entrySet() must be the same as SystemPropertySrouce.getProperties().entrySet()",
+ systemEntries.size(), num);
+
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/TestPropertyDefaultSource.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/TestPropertyDefaultSource.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/TestPropertyDefaultSource.java
index f55d8e4..33b2462 100644
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/TestPropertyDefaultSource.java
+++ b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/TestPropertyDefaultSource.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.spisupport;
import org.apache.tamaya.core.propertysource.BasePropertySource;
+import org.apache.tamaya.spi.PropertyValue;
import java.util.Collections;
import java.util.HashMap;
@@ -29,12 +30,12 @@ import java.util.Map;
*/
public class TestPropertyDefaultSource extends BasePropertySource{
- private Map<String,String> properties = new HashMap<>();
+ private Map<String,PropertyValue> properties = new HashMap<>();
public TestPropertyDefaultSource() {
super(100);
- properties.put("name","Anatole");
- properties.put("name2","Sabine");
+ properties.put("name",PropertyValue.of("name", "Anatole", "Test"));
+ properties.put("name2",PropertyValue.of("name2", "Sabine", "Test"));
properties = Collections.unmodifiableMap(properties);
}
@@ -44,7 +45,7 @@ public class TestPropertyDefaultSource extends BasePropertySource{
}
@Override
- public Map<String, String> getProperties() {
+ public Map<String, PropertyValue> getProperties() {
return properties;
}
[4/5] incubator-tamaya-extensions git commit: TAMAYA-238: Removed
explicit versions.
Posted by an...@apache.org.
TAMAYA-238: Removed explicit versions.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/commit/0e16f4e4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/0e16f4e4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/0e16f4e4
Branch: refs/heads/master
Commit: 0e16f4e4ba06cc7dd41a004101ad64870067922f
Parents: 9f915b2
Author: anatole <an...@apache.org>
Authored: Sun Mar 5 21:34:54 2017 +0100
Committer: anatole <an...@apache.org>
Committed: Sun Mar 5 21:34:54 2017 +0100
----------------------------------------------------------------------
modules/formats/base/bnd.bnd | 3 +--
modules/formats/json/bnd.bnd | 3 +--
modules/formats/yaml/bnd.bnd | 3 +--
modules/functions/bnd.bnd | 3 +--
modules/injection/injection-api/bnd.bnd | 5 +++--
modules/injection/standalone/bnd.bnd | 3 +--
modules/jndi/bnd.bnd | 6 +++++-
modules/mutable-config/bnd.bnd | 3 +--
modules/optional/bnd.bnd | 3 +--
modules/resolver/bnd.bnd | 3 +--
modules/resources/bnd.bnd | 3 +--
modules/spi-support/bnd.bnd | 3 +--
modules/spring/bnd.bnd | 3 +--
13 files changed, 19 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/0e16f4e4/modules/formats/base/bnd.bnd
----------------------------------------------------------------------
diff --git a/modules/formats/base/bnd.bnd b/modules/formats/base/bnd.bnd
index 0d351d1..610181a 100644
--- a/modules/formats/base/bnd.bnd
+++ b/modules/formats/base/bnd.bnd
@@ -1,5 +1,4 @@
Export-Package: \
org.apache.tamaya.format,\
org.apache.tamaya.format.formats
-Bundle-SymbolicName: org.apache.tamaya.formats
-Bundle-Version: 0.3-INCUBATING-SNAPSHOT
\ No newline at end of file
+Bundle-SymbolicName: org.apache.tamaya.formats
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/0e16f4e4/modules/formats/json/bnd.bnd
----------------------------------------------------------------------
diff --git a/modules/formats/json/bnd.bnd b/modules/formats/json/bnd.bnd
index 62cd3f9..c4251d1 100644
--- a/modules/formats/json/bnd.bnd
+++ b/modules/formats/json/bnd.bnd
@@ -1,4 +1,3 @@
Export-Package: \
org.apache.tamaya.json
-Bundle-SymbolicName: org.apache.tamaya.formats.json
-Bundle-Version: 0.3-INCUBATING-SNAPSHOT
\ No newline at end of file
+Bundle-SymbolicName: org.apache.tamaya.formats.json
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/0e16f4e4/modules/formats/yaml/bnd.bnd
----------------------------------------------------------------------
diff --git a/modules/formats/yaml/bnd.bnd b/modules/formats/yaml/bnd.bnd
index fc92b02..01ab527 100644
--- a/modules/formats/yaml/bnd.bnd
+++ b/modules/formats/yaml/bnd.bnd
@@ -1,4 +1,3 @@
Export-Package: \
org.apache.tamaya.yaml
-Bundle-SymbolicName: org.apache.tamaya.formats.yaml
-Bundle-Version: 0.3-INCUBATING-SNAPSHOT
\ No newline at end of file
+Bundle-SymbolicName: org.apache.tamaya.formats.yaml
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/0e16f4e4/modules/functions/bnd.bnd
----------------------------------------------------------------------
diff --git a/modules/functions/bnd.bnd b/modules/functions/bnd.bnd
index 62bda5d..b12cfd4 100644
--- a/modules/functions/bnd.bnd
+++ b/modules/functions/bnd.bnd
@@ -1,4 +1,3 @@
Export-Package: \
org.apache.tamaya.functions
-Bundle-SymbolicName: org.apache.tamaya.functions
-Bundle-Version: 0.3-INCUBATING-SNAPSHOT
\ No newline at end of file
+Bundle-SymbolicName: org.apache.tamaya.functions
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/0e16f4e4/modules/injection/injection-api/bnd.bnd
----------------------------------------------------------------------
diff --git a/modules/injection/injection-api/bnd.bnd b/modules/injection/injection-api/bnd.bnd
index ea781a8..3516930 100644
--- a/modules/injection/injection-api/bnd.bnd
+++ b/modules/injection/injection-api/bnd.bnd
@@ -2,5 +2,6 @@ Export-Package: \
org.apache.tamaya.inject.api,\
org.apache.tamaya.inject.spi
Bundle-SymbolicName: org.apache.tamaya.inject.api
-Import-Package: org.apache.tamaya;version="[0.3,1)",\
- org.apache.tamaya.inject.api,org.apache.tamaya.spi;version="[0.3,1)"
\ No newline at end of file
+Import-Package: org.apache.tamaya,\
+ org.apache.tamaya.inject.api,\
+ org.apache.tamaya.spi
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/0e16f4e4/modules/injection/standalone/bnd.bnd
----------------------------------------------------------------------
diff --git a/modules/injection/standalone/bnd.bnd b/modules/injection/standalone/bnd.bnd
index e886fba..24ac914 100644
--- a/modules/injection/standalone/bnd.bnd
+++ b/modules/injection/standalone/bnd.bnd
@@ -1,4 +1,3 @@
Export-Package: \
org.apache.tamaya.inject
-Bundle-SymbolicName: org.apache.tamaya.inject-se
-Bundle-Version: 0.3-INCUBATING-SNAPSHOT
\ No newline at end of file
+Bundle-SymbolicName: org.apache.tamaya.inject-se
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/0e16f4e4/modules/jndi/bnd.bnd
----------------------------------------------------------------------
diff --git a/modules/jndi/bnd.bnd b/modules/jndi/bnd.bnd
index f426059..36f5ce3 100644
--- a/modules/jndi/bnd.bnd
+++ b/modules/jndi/bnd.bnd
@@ -1,2 +1,6 @@
Export-Package: \
- org.apache.tamaya.jndi
\ No newline at end of file
+ org.apache.tamaya.jndi
+Bundle-SymbolicName: org.apache.tamaya.jndi
+Import-Package: org.apache.tamaya,\
+ org.apache.tamaya.inject.api,\
+ org.apache.tamaya.spi
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/0e16f4e4/modules/mutable-config/bnd.bnd
----------------------------------------------------------------------
diff --git a/modules/mutable-config/bnd.bnd b/modules/mutable-config/bnd.bnd
index 7df7f7e..20d3f20 100644
--- a/modules/mutable-config/bnd.bnd
+++ b/modules/mutable-config/bnd.bnd
@@ -1,4 +1,3 @@
Export-Package: \
org.apache.tamaya.mutableconfig
-Bundle-SymbolicName: org.apache.tamaya.mutableconfig
-Bundle-Version: 0.3-INCUBATING-SNAPSHOT
\ No newline at end of file
+Bundle-SymbolicName: org.apache.tamaya.mutableconfig
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/0e16f4e4/modules/optional/bnd.bnd
----------------------------------------------------------------------
diff --git a/modules/optional/bnd.bnd b/modules/optional/bnd.bnd
index 5c1ba27..6926446 100644
--- a/modules/optional/bnd.bnd
+++ b/modules/optional/bnd.bnd
@@ -1,4 +1,3 @@
Export-Package: \
org.apache.tamaya.optional
-Bundle-SymbolicName: org.apache.tamaya.optional
-Bundle-Version: 0.3-INCUBATING-SNAPSHOT
\ No newline at end of file
+Bundle-SymbolicName: org.apache.tamaya.optional
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/0e16f4e4/modules/resolver/bnd.bnd
----------------------------------------------------------------------
diff --git a/modules/resolver/bnd.bnd b/modules/resolver/bnd.bnd
index ea2ed8a..4f3761c 100644
--- a/modules/resolver/bnd.bnd
+++ b/modules/resolver/bnd.bnd
@@ -1,5 +1,4 @@
Export-Package: \
org.apache.tamaya.resolver,\
org.apache.tamaya.resolver.spi
-Bundle-SymbolicName: org.apache.tamaya.resolver
-Bundle-Version: 0.3-INCUBATING-SNAPSHOT
\ No newline at end of file
+Bundle-SymbolicName: org.apache.tamaya.resolver
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/0e16f4e4/modules/resources/bnd.bnd
----------------------------------------------------------------------
diff --git a/modules/resources/bnd.bnd b/modules/resources/bnd.bnd
index 98f60ff..bfcdbd1 100644
--- a/modules/resources/bnd.bnd
+++ b/modules/resources/bnd.bnd
@@ -1,4 +1,3 @@
Export-Package: \
org.apache.tamaya.resource
-Bundle-SymbolicName: org.apache.tamaya.resources
-Bundle-Version: 0.3-INCUBATING-SNAPSHOT
\ No newline at end of file
+Bundle-SymbolicName: org.apache.tamaya.resources
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/0e16f4e4/modules/spi-support/bnd.bnd
----------------------------------------------------------------------
diff --git a/modules/spi-support/bnd.bnd b/modules/spi-support/bnd.bnd
index 6dafaa7..e0abd3e 100644
--- a/modules/spi-support/bnd.bnd
+++ b/modules/spi-support/bnd.bnd
@@ -1,4 +1,3 @@
Export-Package: \
org.apache.tamaya.spisupport
-Bundle-SymbolicName: org.apache.tamaya.spisupport
-Bundle-Version: 0.3-INCUBATING-SNAPSHOT
\ No newline at end of file
+Bundle-SymbolicName: org.apache.tamaya.spisupport
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/0e16f4e4/modules/spring/bnd.bnd
----------------------------------------------------------------------
diff --git a/modules/spring/bnd.bnd b/modules/spring/bnd.bnd
index 6ee583f..62e34b1 100644
--- a/modules/spring/bnd.bnd
+++ b/modules/spring/bnd.bnd
@@ -1,4 +1,3 @@
Export-Package: \
org.apache.tamaya.integration.spring
-Bundle-SymbolicName: org.apache.tamaya.spring
-Bundle-Version: 0.3-INCUBATING-SNAPSHOT
\ No newline at end of file
+Bundle-SymbolicName: org.apache.tamaya.spring
\ No newline at end of file
[5/5] incubator-tamaya-extensions git commit: TAMAYA-252: Unified
PropertyValue builder API.
Posted by an...@apache.org.
TAMAYA-252: Unified PropertyValue builder API.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/commit/01ba7463
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/01ba7463
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/01ba7463
Branch: refs/heads/master
Commit: 01ba7463ea705d9f8725bd594aeac6af648df16c
Parents: 0e16f4e
Author: anatole <an...@apache.org>
Authored: Mon Mar 6 00:28:58 2017 +0100
Committer: anatole <an...@apache.org>
Committed: Mon Mar 6 00:28:58 2017 +0100
----------------------------------------------------------------------
.../tamaya/events/RandomPropertySource.java | 2 +-
.../apache/tamaya/events/TestConfigView.java | 2 +-
.../filter/internal/DefaultMetadataFilter.java | 2 +-
.../tamaya/filter/ConfigurationFilterTest.java | 10 +-
.../tamaya/filter/ProgrammableFilterTest.java | 76 ++++++-----
.../integration/cdi/EnvironmentsTest.java | 2 +-
.../internal/ExpressionResolutionFilter.java | 4 +-
.../tamaya/spisupport/DefaultConfiguration.java | 2 +-
.../spisupport/PropertyFilterManager.java | 131 -------------------
.../tamaya/spisupport/PropertyFiltering.java | 110 ++++++++--------
.../spisupport/PropertySourceComparator.java | 4 +-
.../tamaya/spisupport/RegexPropertyFilter.java | 4 +-
.../spisupport/RegexPropertyFilterTest.java | 30 +++--
13 files changed, 125 insertions(+), 254 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/01ba7463/modules/events/src/test/java/org/apache/tamaya/events/RandomPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/RandomPropertySource.java b/modules/events/src/test/java/org/apache/tamaya/events/RandomPropertySource.java
index 041056b..746c5f3 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/RandomPropertySource.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/RandomPropertySource.java
@@ -53,7 +53,7 @@ public class RandomPropertySource implements PropertySource{
@Override
public Map<String, PropertyValue> getProperties() {
synchronized(data) {
- data.put("random.new", new PropertyValueBuilder("random.new", String.valueOf(Math.random()), getName())
+ data.put("random.new", PropertyValue.builder("random.new", String.valueOf(Math.random()), getName())
.addMetaEntry("_random.new.timestamp", String.valueOf(System.currentTimeMillis())).build());
return new HashMap<>(data);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/01ba7463/modules/events/src/test/java/org/apache/tamaya/events/TestConfigView.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/TestConfigView.java b/modules/events/src/test/java/org/apache/tamaya/events/TestConfigView.java
index 8e5b397..0713298 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/TestConfigView.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/TestConfigView.java
@@ -60,7 +60,7 @@ public class TestConfigView implements ConfigOperator{
}
return result;
// return config.getProperties().entrySet().stream().filter(e -> e.getKey().startsWith("test")).collect(
-// Collectors.toMap(en -> en.getKey(), en -> en.getValue()));
+// Collectors.toMap(en -> en.getKey(), en -> en.getProperty()));
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/01ba7463/modules/filter/src/main/java/org/apache/tamaya/filter/internal/DefaultMetadataFilter.java
----------------------------------------------------------------------
diff --git a/modules/filter/src/main/java/org/apache/tamaya/filter/internal/DefaultMetadataFilter.java b/modules/filter/src/main/java/org/apache/tamaya/filter/internal/DefaultMetadataFilter.java
index 5694a9d..e9554a2 100644
--- a/modules/filter/src/main/java/org/apache/tamaya/filter/internal/DefaultMetadataFilter.java
+++ b/modules/filter/src/main/java/org/apache/tamaya/filter/internal/DefaultMetadataFilter.java
@@ -34,7 +34,7 @@ public final class DefaultMetadataFilter implements PropertyFilter{
return valueToBeFiltered;
}
if(ConfigurationFilter.isMetadataFiltered()) {
- if (context.getKey().startsWith("_")) {
+ if (context.getProperty().getKey().startsWith("_")) {
// Hide metadata entries.
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/01ba7463/modules/filter/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java
----------------------------------------------------------------------
diff --git a/modules/filter/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java b/modules/filter/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java
index 6a9e309..a3a75a3 100644
--- a/modules/filter/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java
+++ b/modules/filter/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java
@@ -47,7 +47,7 @@ public class ConfigurationFilterTest {
PropertyFilter testFilter = new PropertyFilter() {
@Override
public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- return PropertyValue.of(context.getKey(), context.getKey() + ":testGetSingleFilters", "test");
+ return value.toBuilder().setValue(value.getKey() + ":testGetSingleFilters").build();
}
};
ConfigurationFilter.getSingleValueFilterContext().addFilter(testFilter);
@@ -63,7 +63,7 @@ public class ConfigurationFilterTest {
PropertyFilter testFilter = new PropertyFilter() {
@Override
public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- return PropertyValue.of(context.getKey(), context.getKey() + ":testGetSingleFilters", "test");
+ return value.toBuilder().setValue(value.getKey() + ":testGetSingleFilters").build();
}
};
ConfigurationFilter.getSingleValueFilterContext().addFilter(testFilter);
@@ -79,7 +79,7 @@ public class ConfigurationFilterTest {
PropertyFilter testFilter = new PropertyFilter() {
@Override
public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- return PropertyValue.of(context.getKey(), context.getKey() + ":testGetMapFilters", "test");
+ return value.toBuilder().setValue(value.getKey() + ":testGetMapFilters").build();
}
};
ConfigurationFilter.getMapFilterContext().addFilter(testFilter);
@@ -95,7 +95,7 @@ public class ConfigurationFilterTest {
PropertyFilter testFilter = new PropertyFilter() {
@Override
public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- return PropertyValue.of(context.getKey(), context.getKey() + ":testGetMapFilters", "test");
+ return value .toBuilder().setValue(value.getKey() + ":testGetMapFilters").build();
}
};
ConfigurationFilter.getMapFilterContext().addFilter(testFilter);
@@ -111,7 +111,7 @@ public class ConfigurationFilterTest {
PropertyFilter testFilter = new PropertyFilter() {
@Override
public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- return PropertyValue.of(context.getKey(), context.getKey() + ":testGetSingleFilters", "test");
+ return value.toBuilder().setValue(value.getKey() + ":testGetSingleFilters").build();
}
};
ConfigurationFilter.getSingleValueFilterContext().addFilter(testFilter);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/01ba7463/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java
----------------------------------------------------------------------
diff --git a/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java b/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java
index 910e089..f886ba0 100644
--- a/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java
+++ b/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java
@@ -18,8 +18,11 @@
*/
package org.apache.tamaya.filter;
+import org.apache.tamaya.spi.ConfigurationContext;
import org.apache.tamaya.spi.PropertyFilter;
import org.apache.tamaya.spi.PropertyValue;
+import org.apache.tamaya.spisupport.DefaultConfigurationContext;
+import org.apache.tamaya.spisupport.DefaultConfigurationContextBuilder;
import org.apache.tamaya.spisupport.RegexPropertyFilter;
import org.junit.Test;
@@ -34,31 +37,32 @@ import static org.junit.Assert.*;
*/
public class ProgrammableFilterTest {
- PropertyValue test1Property = PropertyValue.of("test1","test1","test");
- PropertyValue test2Property = PropertyValue.of("test2","test2","test");
- PropertyValue test3Property = PropertyValue.of("test.test3","test.test3","test");
+ private static ConfigurationContext context = new DefaultConfigurationContextBuilder().build();
+ private static PropertyValue test1Property = PropertyValue.of("test1","test1","test");
+ private static PropertyValue test2Property = PropertyValue.of("test2","test2","test");
+ private static PropertyValue test3Property = PropertyValue.of("test.test3","test.test3","test");
@Test
public void testAddRemoveFilter() throws Exception {
FilterContext filter = new FilterContext();
Map<String,PropertyValue> map = new HashMap<>();
- assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", map)), test1Property);
- assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test2", map)), test2Property);
- assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test.test3", map)), test3Property);
+ assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext(test1Property, map, context)), test1Property);
+ assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext(test2Property, map, context)), test2Property);
+ assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext(test3Property, map, context)), test3Property);
RegexPropertyFilter regexFilter = new RegexPropertyFilter();
regexFilter.setIncludes("test\\..*");
filter.addFilter(regexFilter);
- assertNull(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", map)));
- assertNull(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test2", map)));
- assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test.test3", map)), test3Property);
+ assertNull(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext(test1Property, map, context)));
+ assertNull(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext(test2Property, map, context)));
+ assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext(test3Property, map, context)), test3Property);
filter.removeFilter(0);
- assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", map)), test1Property);
- assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test2", map)), test2Property);
- assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test.test3", map)), test3Property);
+ assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext(test1Property, map, context)), test1Property);
+ assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext(test2Property, map, context)), test2Property);
+ assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext(test3Property, map, context)), test3Property);
filter.addFilter(0, regexFilter);
- assertNull(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", map)));
- assertNull(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test2", map)));
- assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test.test3", map)), test3Property);
+ assertNull(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext(test1Property, map, context)));
+ assertNull(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext(test2Property, map, context)));
+ assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext(test3Property, map, context)), test3Property);
}
@Test
@@ -70,17 +74,17 @@ public class ProgrammableFilterTest {
map.put("test1", "test1");
map.put("test2", "test2");
map.put("test.test3", "test.test3");
- assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", test1Property)), test1Property);
- assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test1.", test2Property)), test2Property);
- assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test1.test3", test3Property)), test3Property);
+ assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext(test1Property, context)), test1Property);
+ assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext(test2Property, context)), test2Property);
+ assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext(test3Property, context)), test3Property);
filter.addFilter(regexFilter);
- assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", test1Property)), test1Property);
- assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test1.", test2Property)), test2Property);
- assertNull(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test.test3", test3Property)));
+ assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext(test1Property, context)), test1Property);
+ assertNull(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext(test2Property, context)));
+ assertNull(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext(test3Property, context)));
filter.clearFilters();
- assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", test1Property)), test1Property);
- assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test2", test2Property)), test2Property);
- assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test.test3", test3Property)), test3Property);
+ assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext(test1Property, context)), test1Property);
+ assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext(test2Property, context)), test2Property);
+ assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext(test3Property, context)), test3Property);
}
@Test
@@ -92,13 +96,13 @@ public class ProgrammableFilterTest {
map.put("test1", test1Property);
map.put("test2", test1Property);
map.put("test.test3", test3Property);
- assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", test1Property)), test1Property);
- assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test2", map)), test2Property);
- assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test.test3", map)), test3Property);
+ assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext(test1Property, context)), test1Property);
+ assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext(test2Property, map, context)), test2Property);
+ assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext(test3Property, map, context)), test3Property);
filter.setFilters(regexFilter);
- assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test.1", map)), test1Property);
- assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test.2", map)), test2Property);
- assertNull(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test3.test3", map)));
+ assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext(test3Property, map, context)), test3Property);
+ assertNull(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext(test2Property, map, context)));
+ assertNull(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext(test1Property, map, context)));
}
@Test
@@ -107,13 +111,13 @@ public class ProgrammableFilterTest {
RegexPropertyFilter regexFilter = new RegexPropertyFilter();
regexFilter.setIncludes("test1.*");
Map<String,String> map = new HashMap<>();
- assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", test1Property)), test1Property);
- assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test2", test2Property)), test2Property);
- assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test1.test3", test3Property)), test3Property);
+ assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext(test1Property, context)), test1Property);
+ assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext(test2Property, context)), test2Property);
+ assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext(test3Property, context)), test3Property);
filter.setFilters(Arrays.asList(new PropertyFilter[]{regexFilter}));
- assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", test1Property)), test1Property);
- assertNull(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test2", test2Property)));
- assertNull(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test.test3", test3Property)));
+ assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext(test1Property, context)), test1Property);
+ assertNull(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext(test2Property, context)));
+ assertNull(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext(test3Property, context)));
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/01ba7463/modules/injection/cdi-ee/src/test/java/org/apache/tamaya/integration/cdi/EnvironmentsTest.java
----------------------------------------------------------------------
diff --git a/modules/injection/cdi-ee/src/test/java/org/apache/tamaya/integration/cdi/EnvironmentsTest.java b/modules/injection/cdi-ee/src/test/java/org/apache/tamaya/integration/cdi/EnvironmentsTest.java
index cb60307..6b73294 100644
--- a/modules/injection/cdi-ee/src/test/java/org/apache/tamaya/integration/cdi/EnvironmentsTest.java
+++ b/modules/injection/cdi-ee/src/test/java/org/apache/tamaya/integration/cdi/EnvironmentsTest.java
@@ -77,7 +77,7 @@ package org.apache.tamaya.integration.cdi;
//
// private static void generateAsserts(Properties test) {
// for (Map.Entry<Object, Object> entry : test.entrySet()) {
-// System.out.printf("assertEquals(\"%s\", test.getProperty(\"%s\"));%n", entry.getValue(), entry.getKey());
+// System.out.printf("assertEquals(\"%s\", test.getProperty(\"%s\"));%n", entry.getProperty(), entry.getKey());
// }
// }
//}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/01ba7463/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ExpressionResolutionFilter.java
----------------------------------------------------------------------
diff --git a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ExpressionResolutionFilter.java b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ExpressionResolutionFilter.java
index 2f2de62..e7d9ff6 100644
--- a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ExpressionResolutionFilter.java
+++ b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ExpressionResolutionFilter.java
@@ -86,8 +86,8 @@ public class ExpressionResolutionFilter implements PropertyFilter {
*/
@Override
public PropertyValue filterProperty(PropertyValue valueToBeFiltered, FilterContext context){
- LOG.finest("Resolving " + valueToBeFiltered + "(key=" + context.getKey() + ")");
- String newVal = evaluator().evaluateExpression(context.getKey(), valueToBeFiltered.getValue(), true);
+ LOG.finest("Resolving " + valueToBeFiltered);
+ String newVal = evaluator().evaluateExpression(valueToBeFiltered.getKey(), valueToBeFiltered.getValue(), true);
if(newVal!=null){
return valueToBeFiltered.toBuilder().setValue(newVal).build();
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/01ba7463/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java
index a0a621a..55399de 100644
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java
@@ -95,7 +95,7 @@ public class DefaultConfiguration implements Configuration {
if(value==null || value.getValue()==null){
return null;
}
- value = PropertyFilterManager.applyFilter(key, value, configurationContext);
+ value = PropertyFiltering.applyFilter(value, configurationContext);
if(value!=null){
return value.getValue();
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/01ba7463/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFilterManager.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFilterManager.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFilterManager.java
deleted file mode 100644
index cdef84d..0000000
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFilterManager.java
+++ /dev/null
@@ -1,131 +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.spisupport;
-
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.FilterContext;
-import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.PropertyValue;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Implementation of the Configuration API. This class uses the current {@link ConfigurationContext} to evaluate the
- * chain of {@link org.apache.tamaya.spi.PropertySource} and {@link PropertyFilter}
- * instance to evaluate the current Configuration.
- */
-public final class PropertyFilterManager {
- /**
- * The logger.
- */
- private static final Logger LOG = Logger.getLogger(PropertyFilterManager.class.getName());
- /**
- * The maximal number of filter cycles performed before aborting.
- */
- private static final int MAX_FILTER_LOOPS = 10;
-
- /**
- * Private singleton constructor.
- */
- private PropertyFilterManager(){}
-
- public static PropertyValue applyFilter(String key, PropertyValue unfilteredValue, ConfigurationContext configurationContext) {
- // Apply filters to values, prevent values filtered to null!
- for (int i = 0; i < MAX_FILTER_LOOPS; i++) {
- boolean changed = false;
- // Apply filters to values, prevent values filtered to null!
- for (PropertyFilter filter : configurationContext.getPropertyFilters()) {
- PropertyValue newValue = filter.filterProperty(unfilteredValue, new FilterContext(key, unfilteredValue));
- if (newValue != null && !newValue.equals(unfilteredValue)) {
- changed = true;
- if (LOG.isLoggable(Level.FINEST)) {
- LOG.finest("Filter - " + key + ": " + unfilteredValue + " -> " + newValue + " by " + filter);
- }
- } else if (unfilteredValue != null && !unfilteredValue.equals(newValue)) {
- changed = true;
- if (LOG.isLoggable(Level.FINEST)) {
- LOG.finest("Filter - " + key + ": " + unfilteredValue + " -> " + newValue + " by " + filter);
- }
- }
- unfilteredValue = newValue;
- }
- if (!changed) {
- LOG.finest("Finishing filter loop, no changes detected.");
- break;
- } else {
- if (i == (MAX_FILTER_LOOPS - 1)) {
- if (LOG.isLoggable(Level.WARNING)) {
- LOG.warning("Maximal filter loop count reached, aborting filter evaluation after cycles: " + i);
- }
- } else {
- LOG.finest("Repeating filter loop, changes detected.");
- }
- }
- }
- return unfilteredValue;
- }
-
- public static Map<String, PropertyValue> applyFilters(Map<String, PropertyValue> inputMap, ConfigurationContext configurationContext) {
- Map<String, PropertyValue> resultMap = new HashMap<>(inputMap);
- // Apply filters to values, prevent values filtered to null!
- for (int i = 0; i < MAX_FILTER_LOOPS; i++) {
- AtomicInteger changes = new AtomicInteger();
- for (PropertyFilter filter : configurationContext.getPropertyFilters()) {
- for (Map.Entry<String, PropertyValue> entry : inputMap.entrySet()) {
- final String k = entry.getKey();
- final PropertyValue v = entry.getValue();
-
- PropertyValue newValue = filter.filterProperty(v, new FilterContext(k, inputMap));
- if (newValue != null && !newValue.equals(v)) {
- changes.incrementAndGet();
- LOG.finest("Filter - " + k + ": " + v + " -> " + newValue + " by " + filter);
- } else if (v != null && !v.equals(newValue)) {
- changes.incrementAndGet();
- LOG.finest("Filter - " + k + ": " + v + " -> " + newValue + " by " + filter);
- }
- // Remove null values
- if (null != newValue) {
- resultMap.put(k, newValue);
- }else{
- resultMap.remove(k);
- }
- }
- }
- if (changes.get() == 0) {
- LOG.finest("Finishing filter loop, no changes detected.");
- break;
- } else {
- if (i == (MAX_FILTER_LOOPS - 1)) {
- if (LOG.isLoggable(Level.WARNING)) {
- LOG.warning("Maximal filter loop count reached, aborting filter evaluation after cycles: " + i);
- }
- } else {
- LOG.finest("Repeating filter loop, changes detected: " + changes.get());
- }
- changes.set(0);
- }
- }
- return resultMap;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/01ba7463/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFiltering.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFiltering.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFiltering.java
index f614471..ee76623 100644
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFiltering.java
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFiltering.java
@@ -49,84 +49,76 @@ public final class PropertyFiltering{
*/
private PropertyFiltering(){}
- public static PropertyValue applyFilter(String key, Map<String,PropertyValue> configData, ConfigurationContext configurationContext) {
+ /**
+ * Filters a single value.
+ * @param value the raw value, not null.
+ * @param context the context
+ * @return the filtered value, inclusing null.
+ */
+ public static PropertyValue applyFilter(PropertyValue value, ConfigurationContext context) {
+ FilterContext filterContext = new FilterContext(value, context);
+ return filterValue(filterContext);
+ }
+
+ /**
+ * Filters all properties.
+ * @param rawProperties the unfiltered properties, not null.
+ * @param context the context
+ * @return the filtered value, inclusing null.
+ */
+ public static Map<String, PropertyValue> applyFilters(Map<String, PropertyValue> rawProperties, ConfigurationContext context) {
+ Map<String, PropertyValue> result = new HashMap<>();
// Apply filters to values, prevent values filtered to null!
- PropertyValue unfilteredValue = configData.get(key);
- for (int i = 0; i < MAX_FILTER_LOOPS; i++) {
- boolean changed = false;
- // Apply filters to values, prevent values filtered to null!
- for (PropertyFilter filter : configurationContext.getPropertyFilters()) {
- PropertyValue newValue = filter.filterProperty(unfilteredValue, new FilterContext(key, configData));
- if (newValue != null && !newValue.equals(unfilteredValue)) {
- changed = true;
- if (LOG.isLoggable(Level.FINEST)) {
- LOG.finest("Filter - " + key + ": " + unfilteredValue + " -> " + newValue + " by " + filter);
- }
- } else if (unfilteredValue != null && !unfilteredValue.equals(newValue)) {
- changed = true;
- if (LOG.isLoggable(Level.FINEST)) {
- LOG.finest("Filter - " + key + ": " + unfilteredValue + " -> " + newValue + " by " + filter);
- }
- }
- unfilteredValue = newValue;
- }
- if (!changed) {
- LOG.finest("Finishing filter loop, no changes detected.");
- break;
- } else {
- if (i == (MAX_FILTER_LOOPS - 1)) {
- if (LOG.isLoggable(Level.WARNING)) {
- LOG.warning("Maximal filter loop count reached, aborting filter evaluation after cycles: " + i);
- }
- } else {
- LOG.finest("Repeating filter loop, changes detected.");
- }
+ for (Map.Entry<String, PropertyValue> entry : rawProperties.entrySet()) {
+ FilterContext filterContext = new FilterContext(entry.getValue(), rawProperties, context);
+ PropertyValue filtered = filterValue(filterContext);
+ if(filtered!=null){
+ result.put(filtered.getKey(), filtered);
}
}
- return unfilteredValue;
+ return result;
}
- public static Map<String, PropertyValue> applyFilters(Map<String, PropertyValue> inputMap, ConfigurationContext configurationContext) {
- Map<String, PropertyValue> resultMap = new HashMap<>(inputMap);
- // Apply filters to values, prevent values filtered to null!
- for (int i = 0; i < MAX_FILTER_LOOPS; i++) {
- AtomicInteger changes = new AtomicInteger();
- for (PropertyFilter filter : configurationContext.getPropertyFilters()) {
- for (Map.Entry<String, PropertyValue> entry : inputMap.entrySet()) {
- final String k = entry.getKey();
- final PropertyValue v = entry.getValue();
+ /**
+ * Basic filter logic.
+ * @param context the filter context, not null.
+ * @return the filtered value.
+ */
+ private static PropertyValue filterValue(FilterContext context) {
+ PropertyValue inputValue = context.getProperty();
+ PropertyValue filteredValue = inputValue;
- PropertyValue newValue = filter.filterProperty(v, new FilterContext(k, inputMap));
- if (newValue != null && !newValue.equals(v)) {
- changes.incrementAndGet();
- LOG.finest("Filter - " + k + ": " + v + " -> " + newValue + " by " + filter);
- } else if (v != null && !v.equals(newValue)) {
- changes.incrementAndGet();
- LOG.finest("Filter - " + k + ": " + v + " -> " + newValue + " by " + filter);
- }
- // Remove null values
- if (null != newValue) {
- resultMap.put(k, newValue);
- }else{
- resultMap.remove(k);
- }
+ for (int i = 0; i < MAX_FILTER_LOOPS; i++) {
+ int changes = 0;
+ for (PropertyFilter filter : context.getContext().getPropertyFilters()) {
+ filteredValue = filter.filterProperty(inputValue, context);
+ if (filteredValue != null && !filteredValue.equals(inputValue)) {
+ changes++;
+ LOG.finest("Filter - " + inputValue + " -> " + filteredValue + " by " + filter);
+ }
+ if(filteredValue==null){
+ LOG.finest("Filter removed entry - " + inputValue + ": " + filter);
+ break;
+ }else{
+ inputValue = filteredValue;
}
}
- if (changes.get() == 0) {
+ if (changes == 0) {
LOG.finest("Finishing filter loop, no changes detected.");
break;
+ } else if (filteredValue == null) {
+ break;
} else {
if (i == (MAX_FILTER_LOOPS - 1)) {
if (LOG.isLoggable(Level.WARNING)) {
LOG.warning("Maximal filter loop count reached, aborting filter evaluation after cycles: " + i);
}
} else {
- LOG.finest("Repeating filter loop, changes detected: " + changes.get());
+ LOG.finest("Repeating filter loop, changes detected: " + changes);
}
- changes.set(0);
}
}
- return resultMap;
+ return filteredValue;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/01ba7463/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceComparator.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceComparator.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceComparator.java
index 98290b6..f4c37ac 100644
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceComparator.java
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceComparator.java
@@ -71,10 +71,10 @@ public class PropertySourceComparator implements Comparator<PropertySource>, Ser
// PropertyValue ordinalValue = propertySource.get(PropertySource.TAMAYA_ORDINAL);
// if(ordinalValue!=null){
// try{
-// return Integer.parseInt(ordinalValue.getValue().trim());
+// return Integer.parseInt(ordinalValue.getProperty().trim());
// }catch(Exception e){
// LOG.finest("Failed to parse ordinal from " + PropertySource.TAMAYA_ORDINAL +
-// " in " + propertySource.getName()+": "+ordinalValue.getValue());
+// " in " + propertySource.getName()+": "+ordinalValue.getProperty());
// }
// }
// try {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/01ba7463/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/RegexPropertyFilter.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/RegexPropertyFilter.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/RegexPropertyFilter.java
index cb08193..1f8cce9 100644
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/RegexPropertyFilter.java
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/RegexPropertyFilter.java
@@ -57,7 +57,7 @@ public final class RegexPropertyFilter implements PropertyFilter{
public PropertyValue filterProperty(PropertyValue valueToBeFiltered, FilterContext context) {
if(includes!=null){
for(String expression:includes){
- if(context.getKey().matches(expression)){
+ if(context.getProperty().getKey().matches(expression)){
return valueToBeFiltered;
}
}
@@ -65,7 +65,7 @@ public final class RegexPropertyFilter implements PropertyFilter{
}
if(excludes!=null){
for(String expression:excludes){
- if(context.getKey().matches(expression)){
+ if(context.getProperty().getKey().matches(expression)){
return null;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/01ba7463/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java
index 44364b8..0b616cd 100644
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java
+++ b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java
@@ -18,6 +18,7 @@
*/
package org.apache.tamaya.spisupport;
+import org.apache.tamaya.spi.ConfigurationContext;
import org.apache.tamaya.spi.FilterContext;
import org.apache.tamaya.spi.PropertyValue;
@@ -31,27 +32,32 @@ import static org.junit.Assert.*;
*/
public class RegexPropertyFilterTest {
+ private static PropertyValue prop1 = PropertyValue.of("test1", "test1", "test");
+ private static PropertyValue prop2 = PropertyValue.of("test2", "test2", "test");
+ private static PropertyValue prop3 = PropertyValue.of("test1.test3", "test.test3", "test");
+ private static ConfigurationContext configContext = new DefaultConfigurationContext();
+
@org.junit.Test
public void testFilterProperty() throws Exception {
RegexPropertyFilter filter = new RegexPropertyFilter();
filter.setIncludes("test1.*");
Map<String,PropertyValue> map = new HashMap<>();
- map.put("test1", PropertyValue.of("test1", "test1", "test"));
- map.put("test2", PropertyValue.of("test2", "test2", "test"));
- map.put("test1.test3", PropertyValue.of("test1.test3", "test.test3", "test"));
- assertEquals(filter.filterProperty(PropertyValue.of("test1.", "test1", "test"), new FilterContext("test1.", map)).getValue(), "test1");
- assertNull(filter.filterProperty(PropertyValue.of("test2", "test2", "test"), new FilterContext("test2.", map)));
+ map.put(prop1.getKey(), prop1);
+ map.put(prop2.getKey(), prop2);
+ map.put(prop3.getKey(), prop3);
+ assertEquals(filter.filterProperty(prop1, new FilterContext(prop1, configContext)), prop1);
+ assertNull(filter.filterProperty(prop2, new FilterContext(prop2, configContext)));
assertEquals(filter.filterProperty(
- PropertyValue.of("test1.test3", "testx.test3", "test"),
- new FilterContext("test1.test3", map)).getValue(), "testx.test3");
+ prop3,
+ new FilterContext(prop3, map, configContext)), prop3);
assertEquals(filter.filterProperty(
- PropertyValue.of("test1.test3", "testx.test3", "test"),
- new FilterContext("test1.test3", map)).getValue(), "testx.test3");
+ prop3,
+ new FilterContext(prop3, map, configContext)), prop3);
filter = new RegexPropertyFilter();
filter.setIncludes("test1.*");
- assertNotNull(filter.filterProperty(PropertyValue.of("test1", "test1", "test"), new FilterContext("test1", map)));
- assertNull(filter.filterProperty(PropertyValue.of("test2", "test2", "test"), new FilterContext("test2", map)));
- assertNull(filter.filterProperty(PropertyValue.of("test.test3", "test1", "test"), new FilterContext("test.test3", map)));
+ assertNotNull(filter.filterProperty(prop1, new FilterContext(prop1, map, configContext)));
+ assertNull(filter.filterProperty(prop2, new FilterContext(prop2, map, configContext)));
+ assertNotNull(filter.filterProperty(prop3, new FilterContext(prop3, map, configContext)));
}
@org.junit.Test
[3/5] incubator-tamaya-extensions git commit: TAMAYA-252: Unified
PropertyValue API and usage, also separating key, value,
source and other meta-data and defining a clear builder policy.
Posted by an...@apache.org.
TAMAYA-252: Unified PropertyValue API and usage, also separating key, value, source and other meta-data and defining a clear builder policy.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/commit/9f915b25
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/9f915b25
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/9f915b25
Branch: refs/heads/master
Commit: 9f915b254b91731f2e9fa1eefe8f459f727f6a7c
Parents: ed22695
Author: anatole <an...@apache.org>
Authored: Sun Mar 5 21:29:02 2017 +0100
Committer: anatole <an...@apache.org>
Committed: Sun Mar 5 21:29:02 2017 +0100
----------------------------------------------------------------------
.../events/FilePropertySourceProvider.java | 7 +-
.../tamaya/events/FrozenPropertySource.java | 17 +++-
.../events/PropertySourceChangeBuilder.java | 18 ++---
.../events/ChangeableGlobalPropertySource.java | 3 +-
.../ChangeableThreadLocalPropertySource.java | 3 +-
.../tamaya/events/FrozenPropertySourceTest.java | 5 +-
.../tamaya/events/RandomPropertySource.java | 15 ++--
.../ObservingPropertySourceProvider.java | 12 +--
.../tamaya/filter/ConfigurationFilter.java | 3 +-
.../org/apache/tamaya/filter/FilterContext.java | 3 +-
.../filter/internal/DefaultMetadataFilter.java | 3 +-
.../tamaya/filter/ConfigurationFilterTest.java | 21 ++---
.../tamaya/filter/ProgrammableFilterTest.java | 81 +++++++++++---------
.../MappedConfigurationDataPropertySource.java | 8 +-
...ppedConfigurationDataPropertySourceTest.java | 16 ++--
.../apache/tamaya/json/JSONPropertySource.java | 17 ++--
.../org/apache/tamaya/json/JSONVisitor.java | 1 +
.../tamaya/yaml/JSONPropertySourceTest.java | 2 +-
.../apache/tamaya/yaml/YAMLPropertySource.java | 17 ++--
.../functions/ConfigWrappingPropertySource.java | 9 ++-
.../functions/EnrichedPropertySource.java | 30 +++++---
.../functions/FilteredPropertySource.java | 17 ++--
.../tamaya/functions/MappedPropertySource.java | 23 +++---
.../functions/PropertySourceFunctions.java | 7 +-
.../functions/ValueMappedPropertySource.java | 15 ++--
.../functions/ConfigurationFunctionsTest.java | 20 +----
.../cdi/cfg/ProvidedPropertySource.java | 12 +--
.../integration/cdi/cfg/TestPropertySource.java | 10 ++-
.../tamaya/inject/TestPropertySource.java | 13 +++-
.../internal/DefaultDynamicValueTest.java | 46 ++++++-----
.../apache/tamaya/jndi/JNDIPropertySource.java | 20 ++++-
.../org.apache.tamaya.spi.PropertySource | 19 +++++
.../tamaya/jndi/JNDIPropertySourceTest.java | 3 +-
.../MutablePropertiesPropertySource.java | 19 +----
.../MutableXmlPropertiesPropertySource.java | 20 ++---
.../internal/ExpressionResolutionFilter.java | 9 ++-
.../tamaya/resolver/MyTestPropertySource.java | 13 +++-
.../AbstractPathPropertySourceProvider.java | 16 ++--
.../AbstractPathPropertySourceProviderTest.java | 3 +-
.../PathBasedPropertySourceProvider.java | 26 ++++---
.../tamaya/spisupport/BasePropertySource.java | 13 +---
.../tamaya/spisupport/CLIPropertySource.java | 13 +++-
.../tamaya/spisupport/DefaultConfiguration.java | 80 +++++++++++--------
.../spisupport/EnvironmentPropertySource.java | 11 ++-
.../tamaya/spisupport/MapPropertySource.java | 14 +++-
.../spisupport/PropertyFilterManager.java | 16 ++--
.../tamaya/spisupport/PropertyFiltering.java | 17 ++--
.../spisupport/PropertySourceComparator.java | 52 ++++++-------
.../tamaya/spisupport/RegexPropertyFilter.java | 3 +-
.../tamaya/spisupport/SimplePropertySource.java | 39 ++++------
.../tamaya/spisupport/SystemPropertySource.java | 22 +++---
.../spisupport/BasePropertySourceTest.java | 25 +++---
.../spisupport/CLIPropertySourceTest.java | 18 ++---
.../DefaultConfigurationContextTest.java | 10 +--
.../EnvironmentPropertySourceTest.java | 9 ++-
.../PropertiesFilePropertySourceTest.java | 6 +-
.../spisupport/RegexPropertyFilterTest.java | 26 ++++---
.../spisupport/SimplePropertySourceTest.java | 9 ++-
.../spisupport/SystemPropertySourceTest.java | 24 +++---
.../spisupport/TestPropertyDefaultSource.java | 9 ++-
60 files changed, 569 insertions(+), 449 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FilePropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FilePropertySourceProvider.java b/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FilePropertySourceProvider.java
index 90c430c..088ffe2 100644
--- a/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FilePropertySourceProvider.java
+++ b/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FilePropertySourceProvider.java
@@ -23,6 +23,7 @@ import org.apache.tamaya.ConfigException;
import org.apache.tamaya.core.propertysource.BasePropertySource;
import org.apache.tamaya.resource.AbstractPathPropertySourceProvider;
import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
import java.io.IOException;
import java.io.InputStream;
@@ -49,9 +50,9 @@ public class FilePropertySourceProvider extends AbstractPathPropertySourceProvid
}
@Override
- public Map<String, String> getProperties() {
+ public Map<String, PropertyValue> getProperties() {
- Map<String, String> properties = new HashMap<>();
+ Map<String, PropertyValue> properties = new HashMap<>();
try (InputStream stream = propertiesFile.openStream()) {
Properties props = new Properties();
if (stream != null) {
@@ -59,7 +60,7 @@ public class FilePropertySourceProvider extends AbstractPathPropertySourceProvid
}
for (String key : props.stringPropertyNames()) {
- properties.put(key, props.getProperty(key));
+ properties.put(key, PropertyValue.of(key, props.getProperty(key), getName()));
}
} catch (IOException e) {
throw new ConfigException("Error loading properties from " + propertiesFile, e);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/events/src/main/java/org/apache/tamaya/events/FrozenPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/FrozenPropertySource.java b/modules/events/src/main/java/org/apache/tamaya/events/FrozenPropertySource.java
index 53f1dda..0bc71ce 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/FrozenPropertySource.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/FrozenPropertySource.java
@@ -40,12 +40,14 @@ public final class FrozenPropertySource implements PropertySource, Serializable
/**
* The properties read.
*/
- private Map<String, String> properties = new HashMap<>();
+ private Map<String, PropertyValue> properties = new HashMap<>();
/**
* The PropertySource's name.
*/
private final String name;
+ private long frozenAt = System.currentTimeMillis();
+
/**
* Constructor.
*
@@ -53,7 +55,6 @@ public final class FrozenPropertySource implements PropertySource, Serializable
*/
private FrozenPropertySource(PropertySource propertySource) {
this.properties.putAll(propertySource.getProperties());
- this.properties.put("[meta]frozenAt", String.valueOf(System.currentTimeMillis()));
this.properties = Collections.unmodifiableMap(this.properties);
this.ordinal = PropertySourceComparator.getOrdinal(propertySource);
this.name = propertySource.getName();
@@ -81,13 +82,21 @@ public final class FrozenPropertySource implements PropertySource, Serializable
return this.ordinal;
}
+ /**
+ * Get the creation timestamp of this instance.
+ * @return the creation timestamp
+ */
+ public long getFrozenAt(){
+ return frozenAt;
+ }
+
@Override
public PropertyValue get(String key) {
- return PropertyValue.of(key, this.properties.get(key), getName());
+ return this.properties.get(key);
}
@Override
- public Map<String, String> getProperties() {
+ public Map<String, PropertyValue> getProperties() {
return properties;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChangeBuilder.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChangeBuilder.java b/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChangeBuilder.java
index 4c873bd..1e58855 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChangeBuilder.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChangeBuilder.java
@@ -89,20 +89,20 @@ public final class PropertySourceChangeBuilder {
*/
public static Collection<PropertyChangeEvent> compare(PropertySource map1, PropertySource map2) {
List<PropertyChangeEvent> changes = new ArrayList<>();
- for (Map.Entry<String, String> en : map1.getProperties().entrySet()) {
+ for (Map.Entry<String, PropertyValue> en : map1.getProperties().entrySet()) {
PropertyValue val = map2.get(en.getKey());
if (val == null) {
- changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue()));
+ changes.add(new PropertyChangeEvent(map1, en.getKey(), null, en.getValue().getValue()));
} else if (!val.equals(en.getValue())) {
- changes.add(new PropertyChangeEvent(map1, en.getKey(), val.getValue(), en.getValue()));
+ changes.add(new PropertyChangeEvent(map1, en.getKey(), val.getValue(), en.getValue().getValue()));
}
}
- for (Map.Entry<String, String> en : map2.getProperties().entrySet()) {
+ for (Map.Entry<String, PropertyValue> en : map2.getProperties().entrySet()) {
PropertyValue val = map1.get(en.getKey());
if (val == null) {
- changes.add(new PropertyChangeEvent(map1, en.getKey(), en.getValue(), null));
+ changes.add(new PropertyChangeEvent(map1, en.getKey(), en.getValue().getValue(), null));
} else if (!val.equals(en.getValue())) {
- changes.add(new PropertyChangeEvent(map1, en.getKey(), en.getValue(), val.getValue()));
+ changes.add(new PropertyChangeEvent(map1, en.getKey(), en.getValue().getValue(), val.getValue()));
}
}
return changes;
@@ -193,7 +193,7 @@ public final class PropertySourceChangeBuilder {
* @return the builder for chaining.
*/
public PropertySourceChangeBuilder putAll(Map<String, String> changes) {
- for (Map.Entry<String, String> en : this.source.getProperties().entrySet()) {
+ for (Map.Entry<String, PropertyValue> en : this.source.getProperties().entrySet()) {
this.delta.put(en.getKey(), new PropertyChangeEvent(this.source, en.getKey(), null, en.getValue()));
}
return this;
@@ -206,8 +206,8 @@ public final class PropertySourceChangeBuilder {
*/
public PropertySourceChangeBuilder deleteAll() {
this.delta.clear();
- for (Map.Entry<String, String> en : this.source.getProperties().entrySet()) {
- this.delta.put(en.getKey(), new PropertyChangeEvent(this.source, en.getKey(), en.getValue(), null));
+ for (Map.Entry<String, PropertyValue> en : this.source.getProperties().entrySet()) {
+ this.delta.put(en.getKey(), new PropertyChangeEvent(this.source, en.getKey(), en.getValue().getValue(), null));
}
return this;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/events/src/test/java/org/apache/tamaya/events/ChangeableGlobalPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/ChangeableGlobalPropertySource.java b/modules/events/src/test/java/org/apache/tamaya/events/ChangeableGlobalPropertySource.java
index 476aaf6..180b36e 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/ChangeableGlobalPropertySource.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/ChangeableGlobalPropertySource.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.events;
import org.apache.tamaya.core.propertysource.BasePropertySource;
+import org.apache.tamaya.spi.PropertyValue;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -36,7 +37,7 @@ public class ChangeableGlobalPropertySource extends BasePropertySource{
}
@Override
- public Map<String, String> getProperties() {
+ public Map<String, PropertyValue> getProperties() {
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/events/src/test/java/org/apache/tamaya/events/ChangeableThreadLocalPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/ChangeableThreadLocalPropertySource.java b/modules/events/src/test/java/org/apache/tamaya/events/ChangeableThreadLocalPropertySource.java
index cc6c812..fe6f973 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/ChangeableThreadLocalPropertySource.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/ChangeableThreadLocalPropertySource.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.events;
import org.apache.tamaya.core.propertysource.BasePropertySource;
+import org.apache.tamaya.spi.PropertyValue;
import java.util.HashMap;
import java.util.Map;
@@ -42,7 +43,7 @@ public class ChangeableThreadLocalPropertySource extends BasePropertySource{
}
@Override
- public Map<String, String> getProperties() {
+ public Map<String, PropertyValue> getProperties() {
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/events/src/test/java/org/apache/tamaya/events/FrozenPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/FrozenPropertySourceTest.java b/modules/events/src/test/java/org/apache/tamaya/events/FrozenPropertySourceTest.java
index dc02127..88cee48 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/FrozenPropertySourceTest.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/FrozenPropertySourceTest.java
@@ -20,6 +20,7 @@ package org.apache.tamaya.events;
import org.apache.tamaya.core.propertysource.SystemPropertySource;
import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertyValue;
import org.apache.tamaya.spisupport.PropertySourceComparator;
import org.junit.Test;
@@ -59,8 +60,8 @@ public class FrozenPropertySourceTest {
public void testGet() throws Exception {
PropertySource ps = FrozenPropertySource.of(myPS);
assertNotNull(ps);
- for (Map.Entry<String, String> e : myPS.getProperties().entrySet()) {
- assertEquals(ps.get(e.getKey()).getValue(), e.getValue());
+ for (Map.Entry<String, PropertyValue> e : myPS.getProperties().entrySet()) {
+ assertEquals(ps.get(e.getKey()).getValue(), e.getValue().getValue());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/events/src/test/java/org/apache/tamaya/events/RandomPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/RandomPropertySource.java b/modules/events/src/test/java/org/apache/tamaya/events/RandomPropertySource.java
index c4414f1..041056b 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/RandomPropertySource.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/RandomPropertySource.java
@@ -20,6 +20,7 @@ package org.apache.tamaya.events;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertyValue;
+import org.apache.tamaya.spi.PropertyValueBuilder;
import java.util.HashMap;
import java.util.Map;
@@ -29,7 +30,12 @@ import java.util.Map;
*/
public class RandomPropertySource implements PropertySource{
- private Map<String, String> data = new HashMap<>();
+ private Map<String, PropertyValue> data = new HashMap<>();
+
+ @Override
+ public int getOrdinal() {
+ return 0;
+ }
@Override
public String getName() {
@@ -45,11 +51,10 @@ public class RandomPropertySource implements PropertySource{
}
@Override
- public Map<String, String> getProperties() {
+ public Map<String, PropertyValue> getProperties() {
synchronized(data) {
- data.put("random.new", String.valueOf(Math.random()));
- data.put("_random.new.source", getName());
- data.put("_random.new.timestamp", String.valueOf(System.currentTimeMillis()));
+ data.put("random.new", new PropertyValueBuilder("random.new", String.valueOf(Math.random()), getName())
+ .addMetaEntry("_random.new.timestamp", String.valueOf(System.currentTimeMillis())).build());
return new HashMap<>(data);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/events/src/test/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java b/modules/events/src/test/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
index 1197746..6142b5a 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
@@ -42,6 +42,7 @@ import java.util.logging.Logger;
import org.apache.tamaya.ConfigException;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertySourceProvider;
+import org.apache.tamaya.spi.PropertyValue;
import org.apache.tamaya.spisupport.BasePropertySource;
/**
@@ -114,10 +115,10 @@ public class ObservingPropertySourceProvider implements PropertySourceProvider,
*/
protected Collection<PropertySource> getPropertySources(final Path file) {
return Arrays.asList(new PropertySource[]{new BasePropertySource(file.toString()) {
- private final Map<String,String> props = readProperties(file);
+ private final Map<String,PropertyValue> props = readProperties(file);
@Override
- public Map<String, String> getProperties() {
+ public Map<String, PropertyValue> getProperties() {
return props;
}
}});
@@ -129,13 +130,14 @@ public class ObservingPropertySourceProvider implements PropertySourceProvider,
* @param file the file, not null.
* @return properties as read from the given file.
*/
- protected static Map<String,String> readProperties(Path file) {
+ protected static Map<String,PropertyValue> readProperties(Path file) {
try (InputStream is = file.toUri().toURL().openStream()){
final Properties props = new Properties();
props.load(is);
- final Map<String,String> result = new HashMap<>();
+ final Map<String,PropertyValue> result = new HashMap<>();
for(final Map.Entry<Object,Object> en:props.entrySet()){
- result.put(String.valueOf(en.getKey()), String.valueOf(en.getValue()));
+ String key = String.valueOf(en.getKey());
+ result.put(key, PropertyValue.of(key, String.valueOf(en.getValue()), file.toString()));
}
return result;
} catch (final Exception e) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/filter/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java
----------------------------------------------------------------------
diff --git a/modules/filter/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java b/modules/filter/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java
index 4848bdc..394fda8 100644
--- a/modules/filter/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java
+++ b/modules/filter/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.filter;
import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertyValue;
/**
@@ -108,7 +109,7 @@ public final class ConfigurationFilter implements PropertyFilter{
}
@Override
- public String filterProperty(String valueToBeFiltered, org.apache.tamaya.spi.FilterContext context) {
+ public PropertyValue filterProperty(PropertyValue valueToBeFiltered, org.apache.tamaya.spi.FilterContext context) {
if(context.isSinglePropertyScoped()){
for(PropertyFilter pred: THREADED_VALUE_FILTERS.get().getFilters()){
valueToBeFiltered = pred.filterProperty(valueToBeFiltered, context);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/filter/src/main/java/org/apache/tamaya/filter/FilterContext.java
----------------------------------------------------------------------
diff --git a/modules/filter/src/main/java/org/apache/tamaya/filter/FilterContext.java b/modules/filter/src/main/java/org/apache/tamaya/filter/FilterContext.java
index 596c67f..35eb987 100644
--- a/modules/filter/src/main/java/org/apache/tamaya/filter/FilterContext.java
+++ b/modules/filter/src/main/java/org/apache/tamaya/filter/FilterContext.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.filter;
import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertyValue;
import java.util.ArrayList;
import java.util.Arrays;
@@ -101,7 +102,7 @@ public final class FilterContext implements PropertyFilter{
}
@Override
- public String filterProperty(String valueToBeFiltered, org.apache.tamaya.spi.FilterContext context) {
+ public PropertyValue filterProperty(PropertyValue valueToBeFiltered, org.apache.tamaya.spi.FilterContext context) {
for(PropertyFilter filter:filters){
valueToBeFiltered = filter.filterProperty(valueToBeFiltered, context);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/filter/src/main/java/org/apache/tamaya/filter/internal/DefaultMetadataFilter.java
----------------------------------------------------------------------
diff --git a/modules/filter/src/main/java/org/apache/tamaya/filter/internal/DefaultMetadataFilter.java b/modules/filter/src/main/java/org/apache/tamaya/filter/internal/DefaultMetadataFilter.java
index 95e9d25..5694a9d 100644
--- a/modules/filter/src/main/java/org/apache/tamaya/filter/internal/DefaultMetadataFilter.java
+++ b/modules/filter/src/main/java/org/apache/tamaya/filter/internal/DefaultMetadataFilter.java
@@ -21,13 +21,14 @@ package org.apache.tamaya.filter.internal;
import org.apache.tamaya.filter.ConfigurationFilter;
import org.apache.tamaya.spi.FilterContext;
import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertyValue;
/**
* Default property filter that hides metadta entries starting with an '_', similar ti {@code etcd}.
*/
public final class DefaultMetadataFilter implements PropertyFilter{
@Override
- public String filterProperty(String valueToBeFiltered, FilterContext context) {
+ public PropertyValue filterProperty(PropertyValue valueToBeFiltered, FilterContext context) {
if(context.isSinglePropertyScoped()){
// When accessing keys explicitly, do not hide anything.
return valueToBeFiltered;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/filter/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java
----------------------------------------------------------------------
diff --git a/modules/filter/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java b/modules/filter/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java
index 73602c8..6a9e309 100644
--- a/modules/filter/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java
+++ b/modules/filter/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java
@@ -22,6 +22,7 @@ import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.spi.FilterContext;
import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertyValue;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -45,8 +46,8 @@ public class ConfigurationFilterTest {
assertNotNull(ConfigurationFilter.getSingleValueFilterContext());
PropertyFilter testFilter = new PropertyFilter() {
@Override
- public String filterProperty(String value, FilterContext context) {
- return context.getKey() + ":testGetSingleFilters";
+ public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
+ return PropertyValue.of(context.getKey(), context.getKey() + ":testGetSingleFilters", "test");
}
};
ConfigurationFilter.getSingleValueFilterContext().addFilter(testFilter);
@@ -61,8 +62,8 @@ public class ConfigurationFilterTest {
assertNotNull(ConfigurationFilter.getSingleValueFilterContext());
PropertyFilter testFilter = new PropertyFilter() {
@Override
- public String filterProperty(String value, FilterContext context) {
- return context.getKey() + ":testGetSingleFilters";
+ public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
+ return PropertyValue.of(context.getKey(), context.getKey() + ":testGetSingleFilters", "test");
}
};
ConfigurationFilter.getSingleValueFilterContext().addFilter(testFilter);
@@ -77,8 +78,8 @@ public class ConfigurationFilterTest {
assertNotNull(ConfigurationFilter.getMapFilterContext());
PropertyFilter testFilter = new PropertyFilter() {
@Override
- public String filterProperty(String value, FilterContext context) {
- return context.getKey() + ":testGetMapFilters";
+ public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
+ return PropertyValue.of(context.getKey(), context.getKey() + ":testGetMapFilters", "test");
}
};
ConfigurationFilter.getMapFilterContext().addFilter(testFilter);
@@ -93,8 +94,8 @@ public class ConfigurationFilterTest {
assertNotNull(ConfigurationFilter.getMapFilterContext());
PropertyFilter testFilter = new PropertyFilter() {
@Override
- public String filterProperty(String value, FilterContext context) {
- return context.getKey() + ":testGetMapFilters";
+ public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
+ return PropertyValue.of(context.getKey(), context.getKey() + ":testGetMapFilters", "test");
}
};
ConfigurationFilter.getMapFilterContext().addFilter(testFilter);
@@ -109,8 +110,8 @@ public class ConfigurationFilterTest {
assertNotNull(ConfigurationFilter.getSingleValueFilterContext());
PropertyFilter testFilter = new PropertyFilter() {
@Override
- public String filterProperty(String value, FilterContext context) {
- return context.getKey() + ":testGetSingleFilters";
+ public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
+ return PropertyValue.of(context.getKey(), context.getKey() + ":testGetSingleFilters", "test");
}
};
ConfigurationFilter.getSingleValueFilterContext().addFilter(testFilter);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java
----------------------------------------------------------------------
diff --git a/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java b/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java
index c236d45..910e089 100644
--- a/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java
+++ b/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.filter;
import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertyValue;
import org.apache.tamaya.spisupport.RegexPropertyFilter;
import org.junit.Test;
@@ -33,27 +34,31 @@ import static org.junit.Assert.*;
*/
public class ProgrammableFilterTest {
+ PropertyValue test1Property = PropertyValue.of("test1","test1","test");
+ PropertyValue test2Property = PropertyValue.of("test2","test2","test");
+ PropertyValue test3Property = PropertyValue.of("test.test3","test.test3","test");
+
@Test
public void testAddRemoveFilter() throws Exception {
FilterContext filter = new FilterContext();
- Map<String,String> map = new HashMap<>();
- assertEquals(filter.filterProperty("test1", new org.apache.tamaya.spi.FilterContext("test1", map, true)), "test1");
- assertEquals(filter.filterProperty("test2", new org.apache.tamaya.spi.FilterContext("test2", map, true)), "test2");
- assertEquals(filter.filterProperty("test.test3", new org.apache.tamaya.spi.FilterContext("test.test3", map, true)), "test.test3");
+ Map<String,PropertyValue> map = new HashMap<>();
+ assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", map)), test1Property);
+ assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test2", map)), test2Property);
+ assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test.test3", map)), test3Property);
RegexPropertyFilter regexFilter = new RegexPropertyFilter();
regexFilter.setIncludes("test\\..*");
filter.addFilter(regexFilter);
- assertNull(filter.filterProperty("test1", new org.apache.tamaya.spi.FilterContext("test1", map, true)));
- assertNull(filter.filterProperty("test2", new org.apache.tamaya.spi.FilterContext("test2", map, true)));
- assertEquals(filter.filterProperty("test.test3", new org.apache.tamaya.spi.FilterContext("test.test3", map, true)), "test.test3");
+ assertNull(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", map)));
+ assertNull(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test2", map)));
+ assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test.test3", map)), test3Property);
filter.removeFilter(0);
- assertEquals(filter.filterProperty("test1", new org.apache.tamaya.spi.FilterContext("test1", map, true)), "test1");
- assertEquals(filter.filterProperty("test2", new org.apache.tamaya.spi.FilterContext("test2", map, true)), "test2");
- assertEquals(filter.filterProperty("test.test3", new org.apache.tamaya.spi.FilterContext("test.test3", map, true)), "test.test3");
+ assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", map)), test1Property);
+ assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test2", map)), test2Property);
+ assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test.test3", map)), test3Property);
filter.addFilter(0, regexFilter);
- assertNull(filter.filterProperty("test1", new org.apache.tamaya.spi.FilterContext("test1", map, true)));
- assertNull(filter.filterProperty("test2", new org.apache.tamaya.spi.FilterContext("test2", map, true)));
- assertEquals(filter.filterProperty("test.test3", new org.apache.tamaya.spi.FilterContext("test.test3", map, true)), "test.test3");
+ assertNull(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", map)));
+ assertNull(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test2", map)));
+ assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test.test3", map)), test3Property);
}
@Test
@@ -65,17 +70,17 @@ public class ProgrammableFilterTest {
map.put("test1", "test1");
map.put("test2", "test2");
map.put("test.test3", "test.test3");
- assertEquals(filter.filterProperty("test1", new org.apache.tamaya.spi.FilterContext("test1", map, true)), "test1");
- assertEquals(filter.filterProperty("test2", new org.apache.tamaya.spi.FilterContext("test1.", map, true)), "test2");
- assertEquals(filter.filterProperty("test.test3", new org.apache.tamaya.spi.FilterContext("test1.test3", map, true)), "test.test3");
+ assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", test1Property)), test1Property);
+ assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test1.", test2Property)), test2Property);
+ assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test1.test3", test3Property)), test3Property);
filter.addFilter(regexFilter);
- assertEquals(filter.filterProperty("test1", new org.apache.tamaya.spi.FilterContext("test1", map, true)), "test1");
- assertEquals(filter.filterProperty("test2", new org.apache.tamaya.spi.FilterContext("test1.", map, true)), "test2");
- assertNull(filter.filterProperty("test.test3", new org.apache.tamaya.spi.FilterContext("test.test3", map, true)));
+ assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", test1Property)), test1Property);
+ assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test1.", test2Property)), test2Property);
+ assertNull(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test.test3", test3Property)));
filter.clearFilters();
- assertEquals(filter.filterProperty("test1", new org.apache.tamaya.spi.FilterContext("test1", map, true)), "test1");
- assertEquals(filter.filterProperty("test2", new org.apache.tamaya.spi.FilterContext("test2", map, true)), "test2");
- assertEquals(filter.filterProperty("test.test3", new org.apache.tamaya.spi.FilterContext("test.test3", map, true)), "test.test3");
+ assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", test1Property)), test1Property);
+ assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test2", test2Property)), test2Property);
+ assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test.test3", test3Property)), test3Property);
}
@Test
@@ -83,17 +88,17 @@ public class ProgrammableFilterTest {
FilterContext filter = new FilterContext();
RegexPropertyFilter regexFilter = new RegexPropertyFilter();
regexFilter.setIncludes("test\\..*");
- Map<String,String> map = new HashMap<>();
- map.put("test1", "test1");
- map.put("test2", "test2");
- map.put("test.test3", "test.test3");
- assertEquals(filter.filterProperty("test1", new org.apache.tamaya.spi.FilterContext("test1", map, true)), "test1");
- assertEquals(filter.filterProperty("test2", new org.apache.tamaya.spi.FilterContext("test2", map, true)), "test2");
- assertEquals(filter.filterProperty("test.test3", new org.apache.tamaya.spi.FilterContext("test.test3", map, true)), "test.test3");
+ Map<String,PropertyValue> map = new HashMap<>();
+ map.put("test1", test1Property);
+ map.put("test2", test1Property);
+ map.put("test.test3", test3Property);
+ assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", test1Property)), test1Property);
+ assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test2", map)), test2Property);
+ assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test.test3", map)), test3Property);
filter.setFilters(regexFilter);
- assertEquals(filter.filterProperty("test1", new org.apache.tamaya.spi.FilterContext("test.1", map, true)), "test1");
- assertEquals(filter.filterProperty("test2", new org.apache.tamaya.spi.FilterContext("test.2", map, true)), "test2");
- assertNull(filter.filterProperty("test.test3", new org.apache.tamaya.spi.FilterContext("test3.test3", map, true)));
+ assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test.1", map)), test1Property);
+ assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test.2", map)), test2Property);
+ assertNull(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test3.test3", map)));
}
@Test
@@ -102,13 +107,13 @@ public class ProgrammableFilterTest {
RegexPropertyFilter regexFilter = new RegexPropertyFilter();
regexFilter.setIncludes("test1.*");
Map<String,String> map = new HashMap<>();
- assertEquals(filter.filterProperty("test1", new org.apache.tamaya.spi.FilterContext("test1", map, true)), "test1");
- assertEquals(filter.filterProperty("test2", new org.apache.tamaya.spi.FilterContext("test2", map, true)), "test2");
- assertEquals(filter.filterProperty("test.test3", new org.apache.tamaya.spi.FilterContext("test1.test3", map, true)), "test.test3");
+ assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", test1Property)), test1Property);
+ assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test2", test2Property)), test2Property);
+ assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test1.test3", test3Property)), test3Property);
filter.setFilters(Arrays.asList(new PropertyFilter[]{regexFilter}));
- assertEquals(filter.filterProperty("test1", new org.apache.tamaya.spi.FilterContext("test1", map, true)), "test1");
- assertNull(filter.filterProperty("test2", new org.apache.tamaya.spi.FilterContext("test2", map, true)));
- assertNull(filter.filterProperty("test.test3", new org.apache.tamaya.spi.FilterContext("test.test3", map, true)));
+ assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext("test1", test1Property)), test1Property);
+ assertNull(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext("test2", test2Property)));
+ assertNull(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext("test.test3", test3Property)));
}
@Test
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/formats/base/src/main/java/org/apache/tamaya/format/MappedConfigurationDataPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/formats/base/src/main/java/org/apache/tamaya/format/MappedConfigurationDataPropertySource.java b/modules/formats/base/src/main/java/org/apache/tamaya/format/MappedConfigurationDataPropertySource.java
index 9266718..e8eef40 100644
--- a/modules/formats/base/src/main/java/org/apache/tamaya/format/MappedConfigurationDataPropertySource.java
+++ b/modules/formats/base/src/main/java/org/apache/tamaya/format/MappedConfigurationDataPropertySource.java
@@ -141,8 +141,12 @@ public class MappedConfigurationDataPropertySource extends BasePropertySource {
}
@Override
- public Map<String, String> getProperties() {
- return Collections.unmodifiableMap(properties);
+ public Map<String, PropertyValue> getProperties() {
+ Map<String, PropertyValue> result = new HashMap<>();
+ for(Map.Entry<String,String> en:this.properties.entrySet()) {
+ result.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), getName()));
+ }
+ return result;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/formats/base/src/test/java/org/apache/tamaya/format/MappedConfigurationDataPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/formats/base/src/test/java/org/apache/tamaya/format/MappedConfigurationDataPropertySourceTest.java b/modules/formats/base/src/test/java/org/apache/tamaya/format/MappedConfigurationDataPropertySourceTest.java
index 1e18187..1d26d3a 100644
--- a/modules/formats/base/src/test/java/org/apache/tamaya/format/MappedConfigurationDataPropertySourceTest.java
+++ b/modules/formats/base/src/test/java/org/apache/tamaya/format/MappedConfigurationDataPropertySourceTest.java
@@ -67,13 +67,13 @@ public class MappedConfigurationDataPropertySourceTest {
@Test
public void testGet() throws Exception {
MappedConfigurationDataPropertySource ps = new MappedConfigurationDataPropertySource(createConfigurationData("test2"));
- assertEquals("aValue", ps.get("a").get("a"));
- assertNotNull(ps.get("section1.sectionKey1").get("section1.sectionKey1"));
- assertNotNull(ps.get("section2.sectionKey1").get("section2.sectionKey1"));
+ assertEquals("aValue", ps.get("a").getValue());
+ assertNotNull(ps.get("section1.sectionKey1").getValue());
+ assertNotNull(ps.get("section2.sectionKey1").getValue());
assertNull(ps.get("sectionKey1"));
ps = new MappedConfigurationDataPropertySource(createConfigurationDataNoDefault("test2"));
- assertEquals("sectionValue11", ps.get("section1.sectionKey1").get("section1.sectionKey1"));
- assertEquals("sectionValue21", ps.get("section2.sectionKey1").get("section2.sectionKey1"));
+ assertEquals("sectionValue11", ps.get("section1.sectionKey1").getValue());
+ assertEquals("sectionValue21", ps.get("section2.sectionKey1").getValue());
assertNull(ps.get("a"));
assertNull(ps.get("section1"));
}
@@ -82,7 +82,7 @@ public class MappedConfigurationDataPropertySourceTest {
public void testGetProperties() throws Exception {
MappedConfigurationDataPropertySource ps = new MappedConfigurationDataPropertySource(createConfigurationData("test3"));
assertNotNull(ps.getProperties());
- assertEquals("aValue", ps.getProperties().get("a"));
+ assertEquals("aValue", ps.getProperties().get("a").getValue());
assertNotNull(ps.getProperties().get("section1.sectionKey1"));
assertNotNull(ps.getProperties().get("section2.sectionKey1"));
assertNull(ps.getProperties().get("section1.sectionKey2"));
@@ -91,8 +91,8 @@ public class MappedConfigurationDataPropertySourceTest {
assertNull(ps.getProperties().get("sectionKey2"));
ps = new MappedConfigurationDataPropertySource(createConfigurationDataNoDefault("test3"));
assertNotNull(ps.getProperties());
- assertEquals("sectionValue11", ps.getProperties().get("section1.sectionKey1"));
- assertEquals("sectionValue21", ps.getProperties().get("section2.sectionKey1"));
+ assertEquals("sectionValue11", ps.getProperties().get("section1.sectionKey1").getValue());
+ assertEquals("sectionValue21", ps.getProperties().get("section2.sectionKey1").getValue());
assertNull(ps.get("section1"));
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/formats/json/src/main/java/org/apache/tamaya/json/JSONPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/formats/json/src/main/java/org/apache/tamaya/json/JSONPropertySource.java b/modules/formats/json/src/main/java/org/apache/tamaya/json/JSONPropertySource.java
index 1ac5ee7..5934210 100644
--- a/modules/formats/json/src/main/java/org/apache/tamaya/json/JSONPropertySource.java
+++ b/modules/formats/json/src/main/java/org/apache/tamaya/json/JSONPropertySource.java
@@ -50,7 +50,7 @@ public class JSONPropertySource implements PropertySource {
/** The underlying resource. */
private final URL urlResource;
/** The values read. */
- private final Map<String, String> values;
+ private final Map<String, PropertyValue> values;
/** The evaluated ordinal. */
private int ordinal;
/** The JSON reader factory used. */
@@ -81,7 +81,7 @@ public class JSONPropertySource implements PropertySource {
this.ordinal = defaultOrdinal; // may be overriden by read...
this.values = readConfig(urlResource);
if (this.values.containsKey(TAMAYA_ORDINAL)) {
- this.ordinal = Integer.parseInt(this.values.get(TAMAYA_ORDINAL));
+ this.ordinal = Integer.parseInt(this.values.get(TAMAYA_ORDINAL).getValue());
}
Map<String, Object> config = new HashMap<>();
config.put(JOHNZON_SUPPORTS_COMMENTS_PROP, true);
@@ -109,11 +109,12 @@ public class JSONPropertySource implements PropertySource {
@Override
public PropertyValue get(String key) {
- return PropertyValue.of(key, getProperties().get(key), getName());
+ return getProperties().get(key);
}
@Override
- public Map<String, String> getProperties() {
+ public Map<String, PropertyValue> getProperties() {
+
return Collections.unmodifiableMap(values);
}
@@ -123,7 +124,7 @@ public class JSONPropertySource implements PropertySource {
* @return the configuration read from the given resource URL.
* @throws ConfigException if resource URL cannot be read.
*/
- protected Map<String, String> readConfig(URL urlResource) throws IOException{
+ protected Map<String, PropertyValue> readConfig(URL urlResource) throws IOException{
try (InputStream is = urlResource.openStream()) {
JsonStructure root = this.readerFactory.createReader(is, Charset.forName("UTF-8")).read();
@@ -135,7 +136,11 @@ public class JSONPropertySource implements PropertySource {
Map<String, String> values = new HashMap<>();
JSONVisitor visitor = new JSONVisitor((JsonObject)root, values);
visitor.run();
- return values;
+ Map<String, PropertyValue> result = new HashMap<>();
+ for(Map.Entry<String,String> en:values.entrySet()){
+ result.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), getName()));
+ }
+ return result;
}catch(IOException ioe){
throw ioe;
}catch (Exception t) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/formats/json/src/main/java/org/apache/tamaya/json/JSONVisitor.java
----------------------------------------------------------------------
diff --git a/modules/formats/json/src/main/java/org/apache/tamaya/json/JSONVisitor.java b/modules/formats/json/src/main/java/org/apache/tamaya/json/JSONVisitor.java
index e1516e5..b7aa532 100644
--- a/modules/formats/json/src/main/java/org/apache/tamaya/json/JSONVisitor.java
+++ b/modules/formats/json/src/main/java/org/apache/tamaya/json/JSONVisitor.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.json;
import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.spi.PropertyValue;
import java.util.*;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/formats/json/src/test/java/org/apache/tamaya/yaml/JSONPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/formats/json/src/test/java/org/apache/tamaya/yaml/JSONPropertySourceTest.java b/modules/formats/json/src/test/java/org/apache/tamaya/yaml/JSONPropertySourceTest.java
index 015ad0a..e2cd404 100644
--- a/modules/formats/json/src/test/java/org/apache/tamaya/yaml/JSONPropertySourceTest.java
+++ b/modules/formats/json/src/test/java/org/apache/tamaya/yaml/JSONPropertySourceTest.java
@@ -39,7 +39,7 @@ public class JSONPropertySourceTest extends CommonJSONTestCaseCollection {
assertThat(configURL, CoreMatchers.notNullValue());
JSONPropertySource source = new JSONPropertySource(configURL, 4);
- assertEquals(source.get(PropertySource.TAMAYA_ORDINAL).getValue(), "16784");
+ assertEquals(source.getOrdinal(), 16784);
}
@Test(expected=IOException.class)
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/formats/yaml/src/main/java/org/apache/tamaya/yaml/YAMLPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/formats/yaml/src/main/java/org/apache/tamaya/yaml/YAMLPropertySource.java b/modules/formats/yaml/src/main/java/org/apache/tamaya/yaml/YAMLPropertySource.java
index ae54624..aef0572 100644
--- a/modules/formats/yaml/src/main/java/org/apache/tamaya/yaml/YAMLPropertySource.java
+++ b/modules/formats/yaml/src/main/java/org/apache/tamaya/yaml/YAMLPropertySource.java
@@ -23,6 +23,7 @@ import org.apache.tamaya.spi.PropertyValue;
import java.net.URL;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.logging.Level;
@@ -37,7 +38,7 @@ public class YAMLPropertySource implements PropertySource {
/** The underlying resource. */
private final URL urlResource;
/** The values read. */
- private final Map<String, String> values;
+ private final Map<String, PropertyValue> values;
/** The evaluated ordinal. */
private int ordinal;
/** The format implementation used for parsing. */
@@ -59,9 +60,13 @@ public class YAMLPropertySource implements PropertySource {
public YAMLPropertySource(URL resource, int defaultOrdinal) {
urlResource = Objects.requireNonNull(resource);
this.ordinal = defaultOrdinal; // may be overriden by read...
- this.values = format.readConfig(urlResource);
- if (this.values.containsKey(TAMAYA_ORDINAL)) {
- this.ordinal = Integer.parseInt(this.values.get(TAMAYA_ORDINAL));
+ Map<String,String> cfg = format.readConfig(urlResource);
+ this.values = new HashMap<>();
+ for(Map.Entry<String,String> en:cfg.entrySet()){
+ this.values.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), getName()));
+ }
+ if (cfg.containsKey(TAMAYA_ORDINAL)) {
+ this.ordinal = Integer.parseInt(cfg.get(TAMAYA_ORDINAL));
}
}
@@ -85,11 +90,11 @@ public class YAMLPropertySource implements PropertySource {
@Override
public PropertyValue get(String key) {
- return PropertyValue.of(key, getProperties().get(key), getName());
+ return getProperties().get(key);
}
@Override
- public Map<String, String> getProperties() {
+ public Map<String, PropertyValue> getProperties() {
return Collections.unmodifiableMap(values);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigWrappingPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigWrappingPropertySource.java b/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigWrappingPropertySource.java
index a4bf810..dbad205 100644
--- a/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigWrappingPropertySource.java
+++ b/modules/functions/src/main/java/org/apache/tamaya/functions/ConfigWrappingPropertySource.java
@@ -22,6 +22,7 @@ import org.apache.tamaya.Configuration;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertyValue;
+import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@@ -63,8 +64,12 @@ final class ConfigWrappingPropertySource implements PropertySource {
}
@Override
- public Map<String, String> getProperties() {
- return config.getProperties();
+ public Map<String, PropertyValue> getProperties() {
+ Map<String,PropertyValue> result = new HashMap<>();
+ for(Map.Entry<String,String> en:config.getProperties().entrySet()){
+ result.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), getName()));
+ }
+ return result;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/functions/src/main/java/org/apache/tamaya/functions/EnrichedPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/EnrichedPropertySource.java b/modules/functions/src/main/java/org/apache/tamaya/functions/EnrichedPropertySource.java
index d00e446..c1367b8 100644
--- a/modules/functions/src/main/java/org/apache/tamaya/functions/EnrichedPropertySource.java
+++ b/modules/functions/src/main/java/org/apache/tamaya/functions/EnrichedPropertySource.java
@@ -22,9 +22,7 @@ import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertyValue;
import org.apache.tamaya.spisupport.PropertySourceComparator;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
/**
* PropertySource, that has values added or overridden.
@@ -33,7 +31,7 @@ class EnrichedPropertySource implements PropertySource {
private final PropertySource basePropertySource;
- private final Map<String, String> addedProperties;
+ private final Map<String, PropertyValue> addedProperties = new HashMap<>();
private final boolean overriding;
@@ -46,11 +44,14 @@ class EnrichedPropertySource implements PropertySource {
*/
EnrichedPropertySource(PropertySource propertySource, Map<String, String> properties, boolean overriding) {
this.basePropertySource = Objects.requireNonNull(propertySource);
- this.addedProperties = Objects.requireNonNull(properties);
+ for(Map.Entry<String,String> en:properties.entrySet()){
+ this.addedProperties.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), propertySource.getName()));
+ }
this.overriding = overriding;
}
+ @Override
public int getOrdinal() {
return PropertySourceComparator.getOrdinal(basePropertySource);
}
@@ -63,9 +64,9 @@ class EnrichedPropertySource implements PropertySource {
@Override
public PropertyValue get(String key) {
if (overriding) {
- String val = addedProperties.get(key);
+ PropertyValue val = addedProperties.get(key);
if (val != null) {
- return PropertyValue.of(key, val, getName());
+ return val;
}
return basePropertySource.get(key);
}
@@ -73,19 +74,24 @@ class EnrichedPropertySource implements PropertySource {
if (val != null) {
return val;
}
- return PropertyValue.of(key, addedProperties.get(key), getName());
+ return addedProperties.get(key);
}
@Override
- public Map<String, String> getProperties() {
- Map<String, String> allProps;
+ public Map<String, PropertyValue> getProperties() {
+ Map<String, PropertyValue> allProps;
if (overriding) {
- allProps = new HashMap<>(basePropertySource.getProperties());
+ allProps = new HashMap<>();
+ for(PropertyValue val:basePropertySource.getProperties().values()){
+ allProps.put(val.getKey(), val);
+ }
allProps.putAll(addedProperties);
} else {
allProps = new HashMap<>(addedProperties);
- allProps.putAll(basePropertySource.getProperties());
+ for(PropertyValue val:basePropertySource.getProperties().values()){
+ allProps.put(val.getKey(), val);
+ }
}
return allProps;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/functions/src/main/java/org/apache/tamaya/functions/FilteredPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/FilteredPropertySource.java b/modules/functions/src/main/java/org/apache/tamaya/functions/FilteredPropertySource.java
index 92c6946..10736aa 100644
--- a/modules/functions/src/main/java/org/apache/tamaya/functions/FilteredPropertySource.java
+++ b/modules/functions/src/main/java/org/apache/tamaya/functions/FilteredPropertySource.java
@@ -44,6 +44,7 @@ class FilteredPropertySource implements PropertySource {
this.filter = Objects.requireNonNull(filter);
}
+ @Override
public int getOrdinal(){
return PropertySourceComparator.getOrdinal(baseSource);
}
@@ -55,15 +56,19 @@ class FilteredPropertySource implements PropertySource {
@Override
public PropertyValue get(String key) {
- return PropertyValue.of(key, getProperties().get(key), getName());
+ PropertyValue val = this.baseSource.get(key);
+ if(val!=null && filter.test(val.getKey())) {
+ return val;
+ }
+ return null;
}
@Override
- public Map<String,String> getProperties(){
- final Map<String,String> result = new HashMap<>();
- for(Map.Entry<String,String> en: this.baseSource.getProperties().entrySet()) {
- if (filter.test(en.getKey())) {
- result.put(en.getKey(), en.getValue());
+ public Map<String, PropertyValue> getProperties(){
+ final Map<String,PropertyValue> result = new HashMap<>();
+ for(PropertyValue val: this.baseSource.getProperties().values()) {
+ if (filter.test(val.getKey())) {
+ result.put(val.getKey(), val);
}
}
return result;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/functions/src/main/java/org/apache/tamaya/functions/MappedPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/MappedPropertySource.java b/modules/functions/src/main/java/org/apache/tamaya/functions/MappedPropertySource.java
index 793c62e..dfef0f9 100644
--- a/modules/functions/src/main/java/org/apache/tamaya/functions/MappedPropertySource.java
+++ b/modules/functions/src/main/java/org/apache/tamaya/functions/MappedPropertySource.java
@@ -22,9 +22,7 @@ import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertyValue;
import org.apache.tamaya.spisupport.PropertySourceComparator;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
/**
* PropertySource implementation that maps certain parts (defined by an {@code UnaryOperator<String>}) to alternate sections.
@@ -53,6 +51,7 @@ class MappedPropertySource implements PropertySource {
this.keyMapper = Objects.requireNonNull(keyMapper);
}
+ @Override
public int getOrdinal() {
return PropertySourceComparator.getOrdinal(this.propertySource);
}
@@ -63,13 +62,12 @@ class MappedPropertySource implements PropertySource {
}
@Override
- public Map<String, String> getProperties() {
- Map<String, String> result = new HashMap<>();
- Map<String, String> map = this.propertySource.getProperties();
- for (Map.Entry<String, String> en : map.entrySet()) {
+ public Map<String, PropertyValue> getProperties() {
+ Map<String,PropertyValue> result = new HashMap<>();
+ for (PropertyValue en : this.propertySource.getProperties().values()) {
String targetKey = keyMapper.mapKey(en.getKey());
if (targetKey != null) {
- result.put(targetKey, en.getValue());
+ result.put(targetKey, PropertyValue.of(targetKey, en.getValue(), getName()));
}
}
return result;
@@ -82,7 +80,14 @@ class MappedPropertySource implements PropertySource {
@Override
public PropertyValue get(String key) {
- return PropertyValue.of(key, getProperties().get(key), getName());
+ PropertyValue result = this.propertySource.get(key);
+ if(result!=null){
+ String targetKey = keyMapper.mapKey(key);
+ if (targetKey != null) {
+ return result.toBuilder().mapKey(targetKey).build();
+ }
+ }
+ return null;
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java b/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java
index c3128c4..4646df5 100644
--- a/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java
+++ b/modules/functions/src/main/java/org/apache/tamaya/functions/PropertySourceFunctions.java
@@ -42,6 +42,11 @@ public final class PropertySourceFunctions {
private static final PropertySource EMPTY_PROPERTYSOURCE = new PropertySource() {
@Override
+ public int getOrdinal() {
+ return 0;
+ }
+
+ @Override
public String getName() {
return "<empty>";
}
@@ -52,7 +57,7 @@ public final class PropertySourceFunctions {
}
@Override
- public Map<String, String> getProperties() {
+ public Map<String, PropertyValue> getProperties() {
return Collections.emptyMap();
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/functions/src/main/java/org/apache/tamaya/functions/ValueMappedPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/main/java/org/apache/tamaya/functions/ValueMappedPropertySource.java b/modules/functions/src/main/java/org/apache/tamaya/functions/ValueMappedPropertySource.java
index eb212f5..6264a43 100644
--- a/modules/functions/src/main/java/org/apache/tamaya/functions/ValueMappedPropertySource.java
+++ b/modules/functions/src/main/java/org/apache/tamaya/functions/ValueMappedPropertySource.java
@@ -22,9 +22,7 @@ import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertyValue;
import org.apache.tamaya.spisupport.PropertySourceComparator;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
/**
@@ -42,6 +40,7 @@ class ValueMappedPropertySource implements PropertySource{
this.source = Objects.requireNonNull(current);
}
+ @Override
public int getOrdinal() {
return PropertySourceComparator.getOrdinal(source);
}
@@ -61,12 +60,12 @@ class ValueMappedPropertySource implements PropertySource{
}
@Override
- public Map<String, String> getProperties() {
- Map<String, String> map = new HashMap<>();
- for(Map.Entry<String,String> entry:source.getProperties().entrySet()) {
- map.put(entry.getKey(), valueFilter.mapProperty(entry.getKey(), entry.getValue()));
+ public Map<String, PropertyValue> getProperties() {
+ Map<String,PropertyValue> result = new HashMap<>();
+ for(PropertyValue val:source.getProperties().values()) {
+ result.put(val.getKey(), val.toBuilder().setValue(valueFilter.mapProperty(val.getKey(), val.getValue())).build());
}
- return map;
+ return result;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/functions/src/test/java/org/apache/tamaya/functions/ConfigurationFunctionsTest.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/test/java/org/apache/tamaya/functions/ConfigurationFunctionsTest.java b/modules/functions/src/test/java/org/apache/tamaya/functions/ConfigurationFunctionsTest.java
index 5aa6995..5850eb4 100644
--- a/modules/functions/src/test/java/org/apache/tamaya/functions/ConfigurationFunctionsTest.java
+++ b/modules/functions/src/test/java/org/apache/tamaya/functions/ConfigurationFunctionsTest.java
@@ -48,7 +48,10 @@ public class ConfigurationFunctionsTest {
@Test
public void testSection() throws Exception {
-// TODO implement test
+ // Tests with/without stripping of keys:
+ // See https://issues.apache.org/jira/browse/TAMAYA-235
+ testSection(false);
+ testSection(true);
}
@Test
@@ -149,21 +152,6 @@ public class ConfigurationFunctionsTest {
assertTrue(ps.getProperties().isEmpty());
}
- /**
- * See https://issues.apache.org/jira/browse/TAMAYA-235
- */
- @Test
- public void testSection_StripKeys() {
- testSection(true);
- }
-
- /**
- * See https://issues.apache.org/jira/browse/TAMAYA-235
- */
- @Test
- public void testSection_NoStripKeys() {
- testSection(false);
- }
private void testSection(boolean stripKeys){
ConfigurationContextBuilder b = ConfigurationProvider.getConfigurationContextBuilder();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/injection/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/ProvidedPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/injection/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/ProvidedPropertySource.java b/modules/injection/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/ProvidedPropertySource.java
index a5a1755..90692f3 100644
--- a/modules/injection/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/ProvidedPropertySource.java
+++ b/modules/injection/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/ProvidedPropertySource.java
@@ -32,14 +32,14 @@ import java.util.Map;
@Vetoed
class ProvidedPropertySource implements PropertySource{
- final Map<String,String> config = new HashMap<>();
+ final Map<String,PropertyValue> config = new HashMap<>();
public ProvidedPropertySource(){
- config.put("a.b.c.key3", "keys current a.b.c.key3");
- config.put("a.b.c.key4", "keys current a.b.c.key4");
- config.put("{meta}source.type:"+getClass().getName(), "PropertySourceProvider");
+ config.put("a.b.c.key3", PropertyValue.of("a.b.c.key3","keys current a.b.c.key3",getName()));
+ config.put("a.b.c.key4", PropertyValue.of("a.b.c.key4","keys current a.b.c.key4", getName()));
}
+ @Override
public int getOrdinal() {
return 10;
}
@@ -51,11 +51,11 @@ class ProvidedPropertySource implements PropertySource{
@Override
public PropertyValue get(String key) {
- return PropertyValue.of(key, config.get(key), getName());
+ return config.get(key);
}
@Override
- public Map<String, String> getProperties() {
+ public Map<String, PropertyValue> getProperties() {
return config;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/injection/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/TestPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/injection/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/TestPropertySource.java b/modules/injection/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/TestPropertySource.java
index ca09065..6e86b8d 100644
--- a/modules/injection/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/TestPropertySource.java
+++ b/modules/injection/cdi-se/src/test/java/org/apache/tamaya/integration/cdi/cfg/TestPropertySource.java
@@ -63,12 +63,16 @@ public class TestPropertySource implements PropertySource{
@Override
public PropertyValue get(String key) {
- return PropertyValue.of(key, config.get(key), getName());
+ String val = this.config.get(key);
+ if(val!=null) {
+ return PropertyValue.of(key, val, getName());
+ }
+ return null;
}
@Override
- public Map<String, String> getProperties() {
- return config;
+ public Map<String, PropertyValue> getProperties() {
+ return PropertyValue.map(config ,getName());
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/TestPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/TestPropertySource.java b/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/TestPropertySource.java
index 4af2f33..20de8e8 100644
--- a/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/TestPropertySource.java
+++ b/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/TestPropertySource.java
@@ -43,6 +43,11 @@ public class TestPropertySource implements PropertySource {
}
@Override
+ public int getOrdinal() {
+ return 0;
+ }
+
+ @Override
public String getName() {
return getClass().getName();
}
@@ -53,8 +58,12 @@ public class TestPropertySource implements PropertySource {
}
@Override
- public Map<String, String> getProperties() {
- return properties;
+ public Map<String, PropertyValue> getProperties() {
+ Map<String,PropertyValue> result = new HashMap<>();
+ for(Map.Entry<String,String> en:properties.entrySet()){
+ result.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), getName()));
+ }
+ return result;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/internal/DefaultDynamicValueTest.java
----------------------------------------------------------------------
diff --git a/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/internal/DefaultDynamicValueTest.java b/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/internal/DefaultDynamicValueTest.java
index 16cc265..3ee690d 100644
--- a/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/internal/DefaultDynamicValueTest.java
+++ b/modules/injection/standalone/src/test/java/org/apache/tamaya/inject/internal/DefaultDynamicValueTest.java
@@ -18,7 +18,6 @@
*/
package org.apache.tamaya.inject.internal;
-import org.apache.tamaya.ConfigException;
import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.inject.api.DynamicValue;
import org.apache.tamaya.inject.api.Config;
@@ -63,22 +62,27 @@ public class DefaultDynamicValueTest {
}
};
- private Map<String,String> properties = new HashMap<>();
+ private Map<String,PropertyValue> properties = new HashMap<>();
private Configuration config = ConfigurationProvider.createConfiguration(
ConfigurationProvider.getConfigurationContextBuilder().addPropertySources(
new PropertySource() {
@Override
+ public int getOrdinal() {
+ return 0;
+ }
+
+ @Override
public String getName() {
return "test";
}
@Override
public PropertyValue get(String key) {
- return PropertyValue.of(key,properties.get(key),getName());
+ return properties.get(key);
}
@Override
- public Map<String, String> getProperties() {
+ public Map<String, PropertyValue> getProperties() {
return properties;
}
@@ -105,7 +109,7 @@ public class DefaultDynamicValueTest {
@Test
public void testCommitAndGet() throws Exception {
- properties.put("a","aValue");
+ properties.put("a",PropertyValue.of("a","aValue","test"));
DynamicValue val = DefaultDynamicValue.of(getClass().getDeclaredField("myValue"),
config);
assertNotNull(val);
@@ -114,7 +118,7 @@ public class DefaultDynamicValueTest {
@Test
public void testCommitAndGets() throws Exception {
- properties.put("a","aValue");
+ properties.put("a",PropertyValue.of("a","aValue","test"));
DynamicValue val = DefaultDynamicValue.of(getClass().getDeclaredField("myValue"),
config);
val.setUpdatePolicy(UpdatePolicy.EXPLICIT);
@@ -122,14 +126,14 @@ public class DefaultDynamicValueTest {
assertEquals("aValue",val.evaluateValue());
// change config
val.get();
- this.properties.put("a", "aValue2");
+ properties.put("a",PropertyValue.of("a","aValue2","test"));
assertTrue(val.updateValue());
assertEquals("aValue2", val.commitAndGet());
}
@Test
public void testCommit() throws Exception {
- properties.put("a", "aValue");
+ properties.put("a",PropertyValue.of("a","aValue","test"));
DynamicValue val = DefaultDynamicValue.of(getClass().getDeclaredField("myValue"),
config);
val.setUpdatePolicy(UpdatePolicy.EXPLICIT);
@@ -137,7 +141,7 @@ public class DefaultDynamicValueTest {
assertEquals("aValue", val.evaluateValue());
// change config
val.get();
- this.properties.put("a", "aValue2");
+ properties.put("a",PropertyValue.of("a","aValue2","test"));
assertEquals("aValue2", val.evaluateValue());
assertTrue(val.updateValue());
val.commit();
@@ -156,37 +160,37 @@ public class DefaultDynamicValueTest {
@Test
public void testAddRemoveListener() throws Exception {
- properties.put("a","aValue");
+ properties.put("a",PropertyValue.of("a","aValue","test"));
DynamicValue val = DefaultDynamicValue.of(getClass().getDeclaredField("myValue"),
config);
val.setUpdatePolicy(UpdatePolicy.IMMEDIATE);
val.addListener(consumer);
// change config
val.get();
- this.properties.put("a", "aValue2");
+ properties.put("a",PropertyValue.of("a","aValue2","test"));
val.get();
assertNotNull(event);
event = null;
val.removeListener(consumer);
- this.properties.put("a", "aValue3");
+ properties.put("a",PropertyValue.of("a","aValue3","test"));
val.updateValue();
assertNull(event);
}
@Test
public void testGet() throws Exception {
- properties.put("a", "aValue");
+ properties.put("a",PropertyValue.of("a","aValue","test"));
DynamicValue val = DefaultDynamicValue.of(getClass().getDeclaredField("myValue"),
config);
val.setUpdatePolicy(UpdatePolicy.IMMEDIATE);
- properties.put("a", "aValue2");
+ properties.put("a",PropertyValue.of("a","aValue2","test"));
val.updateValue();
assertEquals("aValue2", val.get());
}
@Test
public void testUpdateValue() throws Exception {
- properties.put("a","aValue");
+ properties.put("a",PropertyValue.of("a","aValue","test"));
DynamicValue val = DefaultDynamicValue.of(getClass().getDeclaredField("myValue"),
config);
val.setUpdatePolicy(UpdatePolicy.EXPLICIT);
@@ -201,25 +205,25 @@ public class DefaultDynamicValueTest {
@Test
public void testEvaluateValue() throws Exception {
- properties.put("a","aValue");
+ properties.put("a",PropertyValue.of("a","aValue","test"));
DynamicValue val = DefaultDynamicValue.of(getClass().getDeclaredField("myValue"),
config);
val.setUpdatePolicy(UpdatePolicy.EXPLICIT);
assertNotNull(val.get());
assertEquals("aValue",val.evaluateValue());
- properties.put("a", "aValue2");
+ properties.put("a",PropertyValue.of("a","aValue2","test"));
assertEquals("aValue2", val.evaluateValue());
}
@Test
public void testGetNewValue() throws Exception {
- properties.put("a","aValue");
+ properties.put("a",PropertyValue.of("a","aValue","test"));
DynamicValue val = DefaultDynamicValue.of(getClass().getDeclaredField("myValue"),
config);
val.setUpdatePolicy(UpdatePolicy.EXPLICIT);
val.get();
assertNull(val.getNewValue());
- properties.put("a", "aValue2");
+ properties.put("a",PropertyValue.of("a","aValue2","test"));
val.get();
assertNotNull(val.getNewValue());
assertEquals("aValue2", val.getNewValue());
@@ -234,7 +238,7 @@ public class DefaultDynamicValueTest {
@Test
public void testIfPresent() throws Exception {
- properties.put("a","aValue");
+ properties.put("a",PropertyValue.of("a","aValue","test"));
DynamicValue val = DefaultDynamicValue.of(getClass().getDeclaredField("myValue"),
config);
val.setUpdatePolicy(UpdatePolicy.IMMEDIATE);
@@ -250,7 +254,7 @@ public class DefaultDynamicValueTest {
config);
val.setUpdatePolicy(UpdatePolicy.IMMEDIATE);
assertEquals("bla", val.orElse("bla"));
- properties.put("a","aValue");
+ properties.put("a",PropertyValue.of("a","aValue","test"));
val.updateValue();
assertEquals("aValue", val.orElse("bla"));
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/jndi/src/main/java/org/apache/tamaya/jndi/JNDIPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/jndi/src/main/java/org/apache/tamaya/jndi/JNDIPropertySource.java b/modules/jndi/src/main/java/org/apache/tamaya/jndi/JNDIPropertySource.java
index 307f096..a944db7 100644
--- a/modules/jndi/src/main/java/org/apache/tamaya/jndi/JNDIPropertySource.java
+++ b/modules/jndi/src/main/java/org/apache/tamaya/jndi/JNDIPropertySource.java
@@ -22,9 +22,15 @@ import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertyValue;
import org.apache.tamaya.spisupport.BasePropertySource;
-import javax.naming.*;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameClassPair;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.logging.Level;
@@ -36,6 +42,12 @@ import java.util.logging.Logger;
public class JNDIPropertySource extends BasePropertySource {
/** The logger used. */
private static final Logger LOG = Logger.getLogger(JNDIPropertySource.class.getName());
+
+ /**
+ * Default ordinal to be used, as defined by {@link PropertySource#getOrdinal()} documentation.
+ */
+ private static final int DEFAULT_ORDINAL = 200;
+
/** The root context, not null. */
private Context context;
/** The scannable property, default is {@code false}. */
@@ -67,6 +79,7 @@ public class JNDIPropertySource extends BasePropertySource {
*/
public JNDIPropertySource() throws NamingException {
this("jndi");
+ setDefaultOrdinal(DEFAULT_ORDINAL);
}
/**
@@ -80,10 +93,10 @@ public class JNDIPropertySource extends BasePropertySource {
* @return a map representation of the JNDI tree.
*/
@Override
- public Map<String, String> getProperties() {
+ public Map<String, PropertyValue> getProperties() {
if(scannable){
try {
- return toMap(this.context);
+ return PropertyValue.map(toMap(this.context), getName());
} catch (NamingException e) {
LOG.log(Level.WARNING, "Error scanning JNDI tree.", e);
}
@@ -122,6 +135,7 @@ public class JNDIPropertySource extends BasePropertySource {
public String toString() {
return "JNDIPropertySource{" +
"name=" + getName() +
+ ", ordinal=" + getOrdinal() +
", context=" + context +
'}';
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/jndi/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
----------------------------------------------------------------------
diff --git a/modules/jndi/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/modules/jndi/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
new file mode 100644
index 0000000..b587cf7
--- /dev/null
+++ b/modules/jndi/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
@@ -0,0 +1,19 @@
+#
+# 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 current 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.
+#
+org.apache.tamaya.jndi.JNDIPropertySource
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/jndi/src/test/java/org/apache/tamaya/jndi/JNDIPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/jndi/src/test/java/org/apache/tamaya/jndi/JNDIPropertySourceTest.java b/modules/jndi/src/test/java/org/apache/tamaya/jndi/JNDIPropertySourceTest.java
index 00b3514..8d94966 100644
--- a/modules/jndi/src/test/java/org/apache/tamaya/jndi/JNDIPropertySourceTest.java
+++ b/modules/jndi/src/test/java/org/apache/tamaya/jndi/JNDIPropertySourceTest.java
@@ -18,6 +18,7 @@
*/
package org.apache.tamaya.jndi;
+import org.apache.tamaya.spi.PropertyValue;
import org.junit.Test;
import javax.naming.Context;
@@ -55,7 +56,7 @@ public class JNDIPropertySourceTest{
public void testScanContext() throws NamingException, MalformedURLException {
JNDIPropertySource ps = new JNDIPropertySource("jndi-test", getTestDirContext(createFSContext()));
assertFalse(ps.isScannable());
- Map<String,String> props = ps.getProperties();
+ Map<String,PropertyValue> props = ps.getProperties();
assertNotNull(props);
assertTrue(props.isEmpty());
ps.setScannable(true);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java
index fd5bb49..50a1b5f 100644
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java
@@ -89,24 +89,13 @@ implements MutablePropertySource{
@Override
public PropertyValue get(String key) {
- Map<String,String> properties = getProperties();
- String val = properties.get(key);
- if(val==null){
- return null;
- }
- PropertyValueBuilder b = new PropertyValueBuilder(key, val, getName());
- String metaKeyStart = "_" + key + ".";
- for(Map.Entry<String,String> en:properties.entrySet()) {
- if(en.getKey().startsWith(metaKeyStart)){
- b.addContextData(en.getKey().substring(metaKeyStart.length()), en.getValue());
- }
- }
- return b.build();
+ Map<String,PropertyValue> properties = getProperties();
+ return properties.get(key);
}
@Override
- public Map<String, String> getProperties() {
- return Collections.unmodifiableMap(this.properties);
+ public Map<String, PropertyValue> getProperties() {
+ return PropertyValue.map(this.properties, getName());
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/9f915b25/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java
index e5aaea4..3d72d29 100644
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java
@@ -91,24 +91,16 @@ implements MutablePropertySource{
@Override
public PropertyValue get(String key) {
- Map<String,String> properties = getProperties();
- String val = properties.get(key);
- if(val==null){
- return null;
+ String val = this.properties.get(key);
+ if(val!=null) {
+ return PropertyValue.of(key, val, getName());
}
- PropertyValueBuilder b = new PropertyValueBuilder(key, val, getName());
- String metaKeyStart = "_" + key + ".";
- for(Map.Entry<String,String> en:properties.entrySet()) {
- if(en.getKey().startsWith(metaKeyStart)){
- b.addContextData(en.getKey().substring(metaKeyStart.length()), en.getValue());
- }
- }
- return b.build();
+ return null;
}
@Override
- public Map<String, String> getProperties() {
- return Collections.unmodifiableMap(this.properties);
+ public Map<String, PropertyValue> getProperties() {
+ return PropertyValue.map(this.properties,getName());
}
/**