You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by st...@apache.org on 2015/01/07 23:21:34 UTC
[1/9] incubator-tamaya git commit: TAMAYA-49 make getOptional default
interfaces
Repository: incubator-tamaya
Updated Branches:
refs/heads/master 7985c039c -> 585167aa8
TAMAYA-49 make getOptional default interfaces
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/3d6456d2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/3d6456d2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/3d6456d2
Branch: refs/heads/master
Commit: 3d6456d255eb741936d027afcd81b356c2b11168
Parents: b4bde92
Author: Mark Struberg <st...@apache.org>
Authored: Tue Jan 6 23:34:54 2015 +0100
Committer: Mark Struberg <st...@apache.org>
Committed: Wed Jan 7 23:17:58 2015 +0100
----------------------------------------------------------------------
.../java/org/apache/tamaya/Configuration.java | 16 ++++++-------
.../org/apache/tamaya/TestConfiguration.java | 25 ++++++++++----------
.../core/internal/DefaultConfiguration.java | 11 +++++----
3 files changed, 26 insertions(+), 26 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3d6456d2/java8/api/src/main/java/org/apache/tamaya/Configuration.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/Configuration.java b/java8/api/src/main/java/org/apache/tamaya/Configuration.java
index d5bd4f7..b86c94f 100644
--- a/java8/api/src/main/java/org/apache/tamaya/Configuration.java
+++ b/java8/api/src/main/java/org/apache/tamaya/Configuration.java
@@ -50,9 +50,7 @@ public interface Configuration {
* @param key the property's key, not null.
* @return the property's value or {@code null}.
*/
- default String get(String key) {
- return getOptional(key).orElse(null);
- }
+ String get(String key);
/**
* Get the property keys as type T. This will implicitly require a corresponding {@link
@@ -65,9 +63,7 @@ public interface Configuration {
* @return the property value, never null..
* @throws ConfigException if the keys could not be converted to the required target type.
*/
- default <T> T get(String key, Class<T> type) {
- return getOptional(key, type).orElse(null);
- }
+ <T> T get(String key, Class<T> type);
/**
* Access a property.
@@ -75,7 +71,9 @@ public interface Configuration {
* @param key the property's key, not null.
* @return the property's keys.
*/
- Optional<String> getOptional(String key);
+ default Optional<String> getOptional(String key) {
+ return Optional.ofNullable(get(key));
+ }
/**
* Get the property keys as type T. This will implicitly require a corresponding {@link
@@ -88,7 +86,9 @@ public interface Configuration {
* @return the property value, never null..
* @throws ConfigException if the keys could not be converted to the required target type.
*/
- <T> Optional<T> getOptional(String key, Class<T> type);
+ default <T> Optional<T> getOptional(String key, Class<T> type) {
+ return Optional.ofNullable(get(key, type));
+ }
/**
* Access all current known Configuration properties as a full {@code Map<String,String>}.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3d6456d2/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
----------------------------------------------------------------------
diff --git a/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java b/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
index 459cb9f..ac3b646 100644
--- a/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
+++ b/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
@@ -20,7 +20,6 @@ package org.apache.tamaya;
import java.util.HashMap;
import java.util.Map;
-import java.util.Optional;
/**
* Test Configuration class, that is used to testdata the default methods provided by the API.
@@ -42,40 +41,40 @@ public class TestConfiguration implements Configuration {
}
@Override
- public Optional<String> getOptional(String key) {
- return Optional.ofNullable(VALUES.get(key));
+ public String get(String key) {
+ return VALUES.get(key);
}
@Override
- public <T> Optional<T> getOptional(String key, Class<T> type) {
+ public <T> T get(String key, Class<T> type) {
if(type.equals(Long.class)){
- return Optional.class.cast(Optional.ofNullable(Long.MAX_VALUE));
+ return (T)(Object)Long.MAX_VALUE;
}
else if(type.equals(Integer.class)){
- return Optional.class.cast(Optional.ofNullable(Integer.MAX_VALUE));
+ return (T)(Object) Integer.MAX_VALUE;
}
else if(type.equals(Double.class)){
- return Optional.class.cast(Optional.ofNullable(Double.MAX_VALUE));
+ return (T)(Object) Double.MAX_VALUE;
}
else if(type.equals(Float.class)){
- return Optional.class.cast(Optional.ofNullable(Float.MAX_VALUE));
+ return (T)(Object) Float.MAX_VALUE;
}
else if(type.equals(Short.class)){
- return Optional.class.cast(Optional.ofNullable(Short.MAX_VALUE));
+ return (T)(Object) Short.MAX_VALUE;
}
else if(type.equals(Byte.class)){
- return Optional.class.cast(Optional.ofNullable(Byte.MAX_VALUE));
+ return (T)(Object) Byte.MAX_VALUE;
}
else if(type.equals(Boolean.class)){
if("booleanTrue".equals(key)) {
- return Optional.class.cast(Optional.ofNullable(Boolean.TRUE));
+ return (T)(Object) Boolean.TRUE;
}
else{
- return Optional.class.cast(Optional.ofNullable(Boolean.FALSE));
+ return (T)(Object) Boolean.FALSE;
}
}
else if(type.equals(String.class)){
- return Optional.class.cast(Optional.ofNullable("aStringValue"));
+ return (T)(Object) "aStringValue";
}
throw new ConfigException("No such property: " + key);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/3d6456d2/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
index a0bf190..e862d02 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
@@ -68,7 +68,7 @@ public class DefaultConfiguration implements Configuration {
* @return the optional configuration value, never null.
*/
@Override
- public Optional<String> getOptional(String key) {
+ public String get(String key) {
List<PropertySource> propertySources = configurationContext.getPropertySources();
String unfilteredValue = null;
for (PropertySource propertySource : propertySources) {
@@ -78,7 +78,7 @@ public class DefaultConfiguration implements Configuration {
break;
}
}
- return Optional.ofNullable(applyFilter(key, unfilteredValue));
+ return applyFilter(key, unfilteredValue);
}
/**
@@ -204,7 +204,7 @@ public class DefaultConfiguration implements Configuration {
* @return the converted value, never null.
*/
@Override
- public <T> Optional<T> getOptional(String key, Class<T> type) {
+ public <T> T get(String key, Class<T> type) {
Optional<String> value = getOptional(key);
if (value.isPresent()) {
List<PropertyConverter<T>> converters = configurationContext.getPropertyConverters(type);
@@ -212,7 +212,7 @@ public class DefaultConfiguration implements Configuration {
try {
T t = converter.convert(value.get());
if (t != null) {
- return Optional.of(t);
+ return t;
}
} catch (Exception e) {
LOG.log(Level.FINEST, e, () -> "PropertyConverter: " + converter +
@@ -221,6 +221,7 @@ public class DefaultConfiguration implements Configuration {
}
throw new ConfigException("Unparseable config value for type: " + type.getName() + ": " + key);
}
- return Optional.empty();
+
+ return null;
}
}
[3/9] incubator-tamaya git commit: TAMAYA-49 move api and core to
java8 module
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertiesFileLoader.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertiesFileLoader.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertiesFileLoader.java
new file mode 100644
index 0000000..b79a756
--- /dev/null
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertiesFileLoader.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.Set;
+
+public final class PropertiesFileLoader {
+
+
+ private PropertiesFileLoader() {
+ // no instantiation
+ }
+
+
+ /**
+ * loads all properties-files with the given name.
+ * If the name do not end with {@code .properties} it will be appended
+ *
+ * @param name of the properties file
+ *
+ * @return URLs of properties-files or
+ * an empty {@link Set} if no files has been found
+ *
+ * @throws IOException in case of problems loading the properties-files
+ */
+ public static Set<URL> resolvePropertiesFiles(String name) throws IOException {
+ Objects.requireNonNull(name);
+
+ if (!name.endsWith(".properties")) {
+ name = name + ".properties";
+ }
+
+ Set<URL> urls = new HashSet<>();
+
+ Enumeration<URL> files = Thread.currentThread().getContextClassLoader().getResources(name);
+ while (files.hasMoreElements()) {
+ urls.add(files.nextElement());
+ }
+
+ return urls;
+ }
+
+
+ /**
+ * loads the Properties from the given URL
+ *
+ * @param propertiesFile {@link URL} to load Properties from
+ *
+ * @return loaded {@link Properties}
+ *
+ * @throws IllegalStateException in case of an error while reading properties-file
+ */
+ public static Properties load(URL propertiesFile) {
+
+ Properties properties = new Properties();
+
+ InputStream stream = null;
+ try {
+ stream = propertiesFile.openStream();
+
+ if (stream != null) {
+ properties.load(stream);
+ }
+ } catch (IOException e) {
+ throw new IllegalStateException("Error loading Properties " + propertiesFile, e);
+ } finally {
+ if (stream != null) {
+ try {
+ stream.close();
+ } catch (IOException e) {
+ // bad luck -> stream is already closed
+ }
+ }
+ }
+
+ return properties;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
new file mode 100644
index 0000000..5c7ae02
--- /dev/null
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
@@ -0,0 +1,247 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.ZoneId;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Currency;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.StampedLock;
+import java.util.logging.Logger;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.spi.PropertyConverter;
+
+/**
+ * Manager that deals with {@link org.apache.tamaya.spi.PropertyConverter} instances.
+ * This class is thread-safe.
+ */
+public class PropertyConverterManager {
+ /** The logger used. */
+ private static final Logger LOG = Logger.getLogger(PropertyConverterManager.class.getName());
+ /** The registered converters. */
+ private Map<Class<?>, List<PropertyConverter<?>>> converters = new ConcurrentHashMap<>();
+ /** The lock used. */
+ private StampedLock lock = new StampedLock();
+ private static final String CHAR_NULL_ERROR = "Cannot convert null property";
+ /**
+ * Constructor.
+ */
+ public PropertyConverterManager() {
+ initDefaultConverters();
+ }
+
+ private static final PropertyConverter<Character> CHAR_CONVERTER =
+ (s) -> Objects.requireNonNull(s,CHAR_NULL_ERROR).charAt(0);
+
+ /**
+ * Registers the default converters provided out of the box.
+ */
+ protected void initDefaultConverters() {
+ // Add default converters
+ register(char.class, CHAR_CONVERTER);
+ register(byte.class, Byte::parseByte);
+ register(short.class, Short::parseShort);
+ register(int.class, Integer::parseInt);
+ register(long.class, Long::parseLong);
+ register(boolean.class, Boolean::parseBoolean);
+ register(float.class, Float::parseFloat); //X TODO not good enough as this is Locale dependent!
+ register(double.class, Double::parseDouble); //X TODO not good enough as this is Locale dependent!
+
+ register(Character.class, CHAR_CONVERTER);
+ register(Byte.class, Byte::valueOf);
+ register(Short.class, Short::valueOf);
+ register(Integer.class, Integer::valueOf);
+ register(Long.class, Long::valueOf);
+ register(Boolean.class, Boolean::valueOf);
+ register(Float.class, Float::valueOf); //X TODO not good enough as this is Locale dependent!
+ register(Double.class, Double::valueOf); //X TODO not good enough as this is Locale dependent!
+ register(BigDecimal.class, BigDecimal::new); //X TODO not good enough as this is Locale dependent!
+ register(BigInteger.class, BigInteger::new); //X TODO not good enough as this is Locale dependent!
+
+ register(Currency.class, Currency::getInstance);
+
+ register(LocalDate.class, LocalDate::parse);
+ register(LocalTime.class, LocalTime::parse);
+ register(LocalDateTime.class, LocalDateTime::parse);
+ register(ZoneId.class, ZoneId::of);
+ }
+
+ /**
+ * Registers a ew converter instance.
+ *
+ * @param targetType the target type, not null.
+ * @param converter the converter, not null.
+ * @param <T> the type.
+ */
+ public <T> void register(Class<T> targetType, PropertyConverter<T> converter) {
+ Objects.requireNonNull(converter);
+ Lock writeLock = lock.asWriteLock();
+ try {
+ writeLock.lock();
+ List<PropertyConverter<T>> converters = List.class.cast(this.converters.get(targetType));
+ List<PropertyConverter<T>> newConverters = new ArrayList<>();
+ if (converters != null) {
+ newConverters.addAll(converters);
+ }
+ newConverters.add(converter);
+ this.converters.put(targetType, Collections.unmodifiableList(newConverters));
+ } finally {
+ writeLock.unlock();
+ }
+ }
+
+ /**
+ * Allows to evaluate if a given target type is supported.
+ *
+ * @param targetType the target type, not null.
+ * @return true, if a converter for the given type is registered, or a default one can be created.
+ */
+ public boolean isTargetTypeSupported(Class<?> targetType) {
+ return converters.containsKey(targetType)
+ || createDefaultPropertyConverter(targetType) != null;
+ }
+
+ /**
+ * Get a map of all property converters currently registered. This will not contain the converters that
+ * may be created, when an instance is adapted, which provides a String constructor or compatible
+ * factory methods taking a single String instance.
+ *
+ * @return the current map of instantiated and registered converters.
+ * @see #createDefaultPropertyConverter(Class)
+ */
+ public Map<Class<?>, List<PropertyConverter<?>>> getPropertyConverters() {
+ Lock readLock = lock.asReadLock();
+ try {
+ readLock.lock();
+ return new HashMap<>(this.converters);
+ } finally {
+ readLock.unlock();
+ }
+ }
+
+ /**
+ * Get the list of all current registered converters for the given target type.
+ * If not converters are registered, they component tries to create and register a dynamic
+ * converter based on String costructor or static factory methods available.
+ *
+ * @param targetType the target type, not null.
+ * @param <T> the type class
+ * @return the ordered list of converters (may be empty for not convertible types).
+ * @see #createDefaultPropertyConverter(Class)
+ */
+ public <T> List<PropertyConverter<T>> getPropertyConverters(Class<T> targetType) {
+ Lock readLock = lock.asReadLock();
+ List<PropertyConverter<T>> converters;
+ try {
+ readLock.lock();
+ converters = List.class.cast(this.converters.get(targetType));
+ } finally {
+ readLock.unlock();
+ }
+ if (converters != null) {
+ return converters;
+ }
+ PropertyConverter<T> defaultConverter = createDefaultPropertyConverter(targetType);
+ if (defaultConverter != null) {
+ register(targetType, defaultConverter);
+ try {
+ converters = List.class.cast(this.converters.get(targetType));
+ } finally {
+ readLock.unlock();
+ }
+ }
+ if (converters != null) {
+ return converters;
+ }
+ return Collections.emptyList();
+ }
+
+ /**
+ * Creates a dynamic PropertyConverter for the given target type.
+ *
+ * @param targetType the target type
+ * @param <T> the type class
+ * @return a new converter, or null.
+ */
+ protected <T> PropertyConverter<T> createDefaultPropertyConverter(Class<T> targetType) {
+ PropertyConverter<T> converter = null;
+ Method factoryMethod = getFactoryMethod(targetType, "of", "valueOf", "instanceOf", "getInstance", "from", "fromString", "parse");
+ if (factoryMethod != null) {
+ converter = (s) -> {
+ try {
+ factoryMethod.setAccessible(true);
+ return targetType.cast(factoryMethod.invoke(s));
+ } catch (Exception e) {
+ throw new ConfigException("Failed to decode '" + s + "'", e);
+ }
+ };
+ }
+ if (converter == null) {
+ try {
+ Constructor<T> constr = targetType.getDeclaredConstructor(String.class);
+ converter = (s) -> {
+ try {
+ constr.setAccessible(true);
+ return constr.newInstance(s);
+ } catch (Exception e) {
+ throw new ConfigException("Failed to decode '" + s + "'", e);
+ }
+ };
+ } catch (Exception e) {
+ LOG.finest(() -> "Failed to construct instance of type: " + targetType.getName()+": " + e);
+ }
+ }
+ return converter;
+ }
+
+ /**
+ * Tries to evaluate a factory method that can be used to create an instance based on a String.
+ *
+ * @param type the target type
+ * @param methodNames the possible static method names
+ * @return the first method found, or null.
+ */
+ private Method getFactoryMethod(Class<?> type, String... methodNames) {
+ Method m;
+ for (String name : methodNames) {
+ try {
+ m = type.getDeclaredMethod(name, String.class);
+ return m;
+ } catch (Exception e) {
+ LOG.finest(() -> "No such factory method found on type: " + type.getName()+", methodName: " + name);
+ }
+ }
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java b/java8/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
new file mode 100644
index 0000000..e58be54
--- /dev/null
+++ b/java8/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.propertysource;
+
+import org.apache.tamaya.spi.PropertySource;
+
+import java.util.Objects;
+import java.util.Optional;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A base class for {@link PropertySource}s. It provides a {@link #initializeOrdinal(int)} method that
+ * reads the ordinal from the config source itself, allowing the ordinal to be "self-configured" by
+ * the configuration read.
+ */
+public abstract class BasePropertySource implements PropertySource {
+
+ private static final Logger LOG = Logger.getLogger(BasePropertySource.class.getName());
+
+
+ private int ordinal = DefaultOrdinal.PROPERTY_SOURCE;
+
+
+ @Override
+ public int getOrdinal() {
+ return ordinal;
+ }
+
+
+ @Override
+ public Optional<String> get(String key) {
+ Objects.requireNonNull(key, "key must not be null");
+ return Optional.ofNullable(getProperties().get(key));
+ }
+
+
+ /**
+ * Initializing the ordinal of this {@link PropertySource} with the given defaultOrdinal.
+ *
+ * If {@link PropertySource#TAMAYA_ORDINAL} is present via {@link #get(String)} and the
+ * value is a valid {@link Integer} then, the defaultOrdinal will be overridden.
+ *
+ * @param defaultOrdinal of the {@link PropertySource}
+ */
+ protected void initializeOrdinal(final int defaultOrdinal) {
+ this.ordinal = defaultOrdinal;
+
+ Optional<String> ordinal = get(PropertySource.TAMAYA_ORDINAL);
+ if (ordinal.isPresent()) {
+
+ try {
+ this.ordinal = Integer.valueOf(ordinal.get());
+ } catch (NumberFormatException e) {
+ LOG.log(Level.WARNING,
+ "Specified {0} is not a valid Integer value: {1} - using defaultOrdinal {2}",
+ new Object[]{PropertySource.TAMAYA_ORDINAL, ordinal.get(), defaultOrdinal});
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/main/java/org/apache/tamaya/core/propertysource/DefaultOrdinal.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/propertysource/DefaultOrdinal.java b/java8/core/src/main/java/org/apache/tamaya/core/propertysource/DefaultOrdinal.java
new file mode 100644
index 0000000..ff35e3f
--- /dev/null
+++ b/java8/core/src/main/java/org/apache/tamaya/core/propertysource/DefaultOrdinal.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.propertysource;
+
+
+/**
+ * This interface defines the default ordinals for the 'standard'
+ * {@link org.apache.tamaya.spi.PropertySource}s
+ *
+ * DefaultOrdinals can be overwritten via {@link org.apache.tamaya.spi.PropertySource#TAMAYA_ORDINAL}
+ */
+public final class DefaultOrdinal {
+
+ /** Private constructor. */
+ private DefaultOrdinal(){}
+
+ /**
+ * default ordinal for {@link org.apache.tamaya.core.propertysource.BasePropertySource} if
+ * not overriden in each class
+ */
+ public static final int PROPERTY_SOURCE = 1000;
+
+ /**
+ * default ordinal for {@link org.apache.tamaya.core.propertysource.SystemPropertySource}
+ */
+ public static final int SYSTEM_PROPERTIES = 400;
+
+ /**
+ * default ordinal for {@link org.apache.tamaya.core.propertysource.EnvironmentPropertySource}
+ */
+ public static final int ENVIRONMENT_PROPERTIES = 300;
+
+ /**
+ * default ordinal for {@link org.apache.tamaya.core.propertysource.PropertiesFilePropertySource}
+ */
+ public static final int FILE_PROPERTIES = 100;
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java b/java8/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
new file mode 100644
index 0000000..596ea73
--- /dev/null
+++ b/java8/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.propertysource;
+
+import java.util.Map;
+
+/**
+ * This {@link org.apache.tamaya.spi.PropertySource} provides all Properties which are set
+ * via <br />
+ * {@code export myprop=myval} on UNIX Systems or<br />
+ * {@code set myprop=myval} on Windows
+ */
+public class EnvironmentPropertySource extends BasePropertySource {
+
+ public EnvironmentPropertySource() {
+ initializeOrdinal(DefaultOrdinal.ENVIRONMENT_PROPERTIES);
+ }
+
+
+ @Override
+ public String getName() {
+ return "environment-properties";
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return System.getenv(); // already a map and unmodifiable
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySource.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySource.java b/java8/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySource.java
new file mode 100644
index 0000000..e117a12
--- /dev/null
+++ b/java8/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySource.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.propertysource;
+
+import org.apache.tamaya.core.internal.PropertiesFileLoader;
+
+import java.net.URL;
+
+/**
+ * {@link org.apache.tamaya.spi.PropertySource} for properties-files
+ */
+public class PropertiesFilePropertySource extends PropertiesPropertySource {
+
+
+ private String fileName;
+
+
+ public PropertiesFilePropertySource(URL propertiesFile) {
+ super(PropertiesFileLoader.load(propertiesFile));
+
+ initializeOrdinal(DefaultOrdinal.FILE_PROPERTIES);
+ this.fileName = propertiesFile.toExternalForm();
+ }
+
+
+ @Override
+ public String getName() {
+ return fileName;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesPropertySource.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesPropertySource.java b/java8/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesPropertySource.java
new file mode 100644
index 0000000..cf68bd6
--- /dev/null
+++ b/java8/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesPropertySource.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.propertysource;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * base class for {@link org.apache.tamaya.spi.PropertySource}s which are based on
+ * {@link java.util.Properties}
+ */
+abstract class PropertiesPropertySource extends BasePropertySource {
+
+ protected Map<String, String> properties;
+
+
+ // package private to not expose this class
+ PropertiesPropertySource(Properties properties) {
+ Map<String, String> props = new HashMap<>();
+
+ for (String key : properties.stringPropertyNames()) {
+ props.put(key, properties.getProperty(key));
+ }
+
+ this.properties = Collections.unmodifiableMap(props);
+ }
+
+
+ @Override
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java b/java8/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
new file mode 100644
index 0000000..50d788d
--- /dev/null
+++ b/java8/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.propertysource;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * This {@link org.apache.tamaya.spi.PropertySource} manages the system properties.
+ */
+public class SystemPropertySource extends PropertiesPropertySource {
+
+ /**
+ * previous System.getProperties().hashCode()
+ * so we can check if we need to reload
+ */
+ private int previousHash;
+
+
+ public SystemPropertySource() {
+ super(System.getProperties());
+ previousHash = System.getProperties().hashCode();
+ initializeOrdinal(DefaultOrdinal.SYSTEM_PROPERTIES);
+ }
+
+
+ @Override
+ public String getName() {
+ return "system-properties";
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+
+ // only need to reload and fill our map if something has changed
+ if (previousHash != System.getProperties().hashCode()) {
+
+ synchronized (this) {
+
+ if (previousHash != System.getProperties().hashCode()) {
+
+ Properties systemProperties = System.getProperties();
+ Map<String, String> properties = new HashMap<>();
+
+ for (String propertyName : systemProperties.stringPropertyNames()) {
+ properties.put(propertyName, System.getProperty(propertyName));
+ }
+
+ this.properties = Collections.unmodifiableMap(properties);
+ previousHash = systemProperties.hashCode();
+ }
+ }
+ }
+
+ return super.getProperties();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java b/java8/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
new file mode 100644
index 0000000..0341c0e
--- /dev/null
+++ b/java8/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.provider;
+
+import org.apache.tamaya.core.internal.PropertiesFileLoader;
+import org.apache.tamaya.core.propertysource.PropertiesFilePropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * Provider which reads all {@code javaconfiguration.properties} files from classpath
+ */
+public class JavaConfigurationProvider implements PropertySourceProvider {
+
+
+ @Override
+ public Collection<PropertySource> getPropertySources() {
+
+ List<PropertySource> propertySources = new ArrayList<>();
+
+ //X TODO maybe put javaconf... in META-INF
+
+ try {
+ propertySources.addAll(
+ PropertiesFileLoader.resolvePropertiesFiles("javaconfiguration.properties")
+ .stream()
+ .map(PropertiesFilePropertySource::new)
+ .collect(Collectors.toList()));
+
+
+ } catch (IOException e) {
+ throw new IllegalStateException("error loading javaconfiguration.properties", e);
+ }
+
+ return Collections.unmodifiableList(propertySources);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/main/resources/META-INF/services/org.apache.tamaya.Configuration
----------------------------------------------------------------------
diff --git a/java8/core/src/main/resources/META-INF/services/org.apache.tamaya.Configuration b/java8/core/src/main/resources/META-INF/services/org.apache.tamaya.Configuration
new file mode 100644
index 0000000..0db8402
--- /dev/null
+++ b/java8/core/src/main/resources/META-INF/services/org.apache.tamaya.Configuration
@@ -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.core.internal.DefaultConfiguration
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resources.ResourceLoader
----------------------------------------------------------------------
diff --git a/java8/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resources.ResourceLoader b/java8/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resources.ResourceLoader
new file mode 100644
index 0000000..a964d3c
--- /dev/null
+++ b/java8/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resources.ResourceLoader
@@ -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.resource.internal.DefaultResourceLoader
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext
----------------------------------------------------------------------
diff --git a/java8/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext b/java8/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext
new file mode 100644
index 0000000..32b4302
--- /dev/null
+++ b/java8/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext
@@ -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.core.internal.DefaultConfigurationContext
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
----------------------------------------------------------------------
diff --git a/java8/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext b/java8/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
new file mode 100644
index 0000000..2721eff
--- /dev/null
+++ b/java8/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
@@ -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.core.internal.DefaultServiceContext
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java b/java8/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
new file mode 100644
index 0000000..5a6fc70
--- /dev/null
+++ b/java8/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core;
+
+import org.apache.tamaya.Configuration;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+/**
+ * This tests checks if the combination of 2 prioritized PropertySource return valid results on the final Configuration.
+ */
+public class ConfigurationTest {
+
+ @Test
+ public void testAccess(){
+ assertNotNull(Configuration.current());
+ }
+
+ @Test
+ public void testContent(){
+ assertEquals("Robin", Configuration.current().get("name").get());
+ assertEquals("Sabine", Configuration.current().get("name2").get()); // from default
+ assertEquals("Mapped to name: Robin", Configuration.current().get("name3").get()); // oderridden default, mapped by filter to name property
+ assertEquals("Sereina(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)", Configuration.current().get("name4").get()); // final only
+ assertNull(Configuration.current().get("name5").orElse(null)); // final only, but removed from filter
+
+ System.out.println("name : " + Configuration.current().get("name").get());
+ System.out.println("name2: " + Configuration.current().get("name2").get());
+ System.out.println("name3: " + Configuration.current().get("name3").get());
+ System.out.println("name4: " + Configuration.current().get("name4").get());
+ System.out.println("name5: " + Configuration.current().get("name5").orElse(null));
+
+ System.out.println("ALL :");
+ Configuration.current().getProperties().entrySet().forEach(e ->
+ System.out.println(" " + e.getKey()+" = " + e.getValue()));
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/test/java/org/apache/tamaya/core/test/internal/PropetiesFileLoaderTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/test/internal/PropetiesFileLoaderTest.java b/java8/core/src/test/java/org/apache/tamaya/core/test/internal/PropetiesFileLoaderTest.java
new file mode 100644
index 0000000..985b5d5
--- /dev/null
+++ b/java8/core/src/test/java/org/apache/tamaya/core/test/internal/PropetiesFileLoaderTest.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.test.internal;
+
+import org.apache.tamaya.core.internal.PropertiesFileLoader;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.net.URL;
+import java.util.Properties;
+import java.util.Set;
+
+public class PropetiesFileLoaderTest {
+
+
+ @Test
+ public void testResolvePropertiesFiles() throws Exception {
+ Properties expectedProperties = PropertiesFileLoader.load(Thread.currentThread().getContextClassLoader().getResource("testfile.properties"));
+
+ {
+ // with .properties
+ Set<URL> urls = PropertiesFileLoader.resolvePropertiesFiles("testfile.properties");
+ Assert.assertNotNull(urls);
+ Assert.assertFalse(urls.isEmpty());
+
+ Properties properties = PropertiesFileLoader.load(urls.iterator().next());
+ Assert.assertEquals(expectedProperties.size(), properties.size());
+ }
+
+ {
+ // without .properties
+ Set<URL> urls = PropertiesFileLoader.resolvePropertiesFiles("testfile");
+ Assert.assertNotNull(urls);
+ Assert.assertFalse(urls.isEmpty());
+
+ Properties properties = PropertiesFileLoader.load(urls.iterator().next());
+ Assert.assertEquals(expectedProperties.size(), properties.size());
+ }
+
+ {
+ // with a while which doesn't exist
+ Set<URL> urls = PropertiesFileLoader.resolvePropertiesFiles("nonexistingfile.properties");
+ Assert.assertNotNull(urls);
+ Assert.assertTrue(urls.isEmpty());
+ }
+
+ }
+
+ @Test
+ public void testLoad() {
+ Properties properties = PropertiesFileLoader.load(Thread.currentThread().getContextClassLoader().getResource("testfile.properties"));
+
+ Assert.assertNotNull(properties);
+ Assert.assertEquals(5, properties.size());
+
+ for (int i = 1; i < 6; i++) {
+ Assert.assertEquals(properties.getProperty("key" + i), "val" + i);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java b/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java
new file mode 100644
index 0000000..d6dc867
--- /dev/null
+++ b/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.test.propertysource;
+
+import org.apache.tamaya.core.propertysource.BasePropertySource;
+import org.apache.tamaya.core.propertysource.DefaultOrdinal;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+public class BasePropertySourceTest {
+
+ @Test
+ public void testGetOrdinal() {
+
+ PropertySource defaultPropertySource = new BasePropertySource() {
+
+ @Override
+ public String getName() {
+ return "testWithDefault";
+ }
+
+ @Override
+ public Optional<String> get(String key) {
+ return Optional.ofNullable(null);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return Collections.emptyMap();
+ }
+ };
+
+ Assert.assertEquals(DefaultOrdinal.PROPERTY_SOURCE, defaultPropertySource.getOrdinal());
+ Assert.assertEquals(1000, new OverriddenOrdinalPropertySource().getOrdinal());
+
+ // propertySource with invalid ordinal
+ Assert.assertEquals(1, new OverriddenInvalidOrdinalPropertySource().getOrdinal());
+ }
+
+ @Test
+ public void testGet() {
+ Assert.assertEquals("1000", new OverriddenOrdinalPropertySource().get(PropertySource.TAMAYA_ORDINAL).get());
+ }
+
+ private static class OverriddenOrdinalPropertySource extends BasePropertySource {
+
+ private OverriddenOrdinalPropertySource() {
+ initializeOrdinal(250);
+ }
+
+ @Override
+ public String getName() {
+ return "overriddenOrdinal";
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ Map<String, String> map = new HashMap<>(1);
+ map.put(PropertySource.TAMAYA_ORDINAL, "1000");
+ return map;
+ }
+ }
+
+ private static class OverriddenInvalidOrdinalPropertySource extends BasePropertySource {
+
+ private OverriddenInvalidOrdinalPropertySource() {
+ initializeOrdinal(1);
+ }
+
+ @Override
+ public String getName() {
+ return "overriddenInvalidOrdinal";
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ Map<String, String> map = new HashMap<>(1);
+ map.put(PropertySource.TAMAYA_ORDINAL, "invalid");
+ return map;
+ }
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java b/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
new file mode 100644
index 0000000..6a1c9e7
--- /dev/null
+++ b/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.test.propertysource;
+
+import org.apache.tamaya.core.internal.PropertiesFileLoader;
+import org.apache.tamaya.core.propertysource.DefaultOrdinal;
+import org.apache.tamaya.core.propertysource.PropertiesFilePropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.net.URL;
+import java.util.Map;
+import java.util.Properties;
+
+public class PropertiesFilePropertySourceTest {
+
+ private PropertiesFilePropertySource testfilePropertySource;
+ private PropertiesFilePropertySource overrideOrdinalPropertySource;
+
+
+ @Before
+ public void initTest() {
+ testfilePropertySource = new PropertiesFilePropertySource(Thread.currentThread().getContextClassLoader().getResource("testfile.properties"));
+ overrideOrdinalPropertySource = new PropertiesFilePropertySource(Thread.currentThread().getContextClassLoader().getResource("overrideOrdinal.properties"));
+ }
+
+
+ @Test
+ public void testGetOrdinal() {
+ Assert.assertEquals(DefaultOrdinal.FILE_PROPERTIES, testfilePropertySource.getOrdinal());
+ Assert.assertEquals(Integer.parseInt(overrideOrdinalPropertySource.get(PropertySource.TAMAYA_ORDINAL).get()), overrideOrdinalPropertySource.getOrdinal());
+ }
+
+
+ @Test
+ public void testGet() {
+ Assert.assertEquals("val3", testfilePropertySource.get("key3").get());
+ Assert.assertEquals("myval5", overrideOrdinalPropertySource.get("mykey5").get());
+ Assert.assertFalse(testfilePropertySource.get("nonpresentkey").isPresent());
+ }
+
+
+ @Test
+ public void testGetProperties() throws Exception {
+ Properties expectedProperties = PropertiesFileLoader.load(new URL(testfilePropertySource.getName()));
+
+ Assert.assertEquals(expectedProperties.size(), testfilePropertySource.getProperties().size());
+
+ for (Map.Entry<String, String> entry : testfilePropertySource.getProperties().entrySet()) {
+ Assert.assertEquals(expectedProperties.getProperty(entry.getKey()), entry.getValue());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java b/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java
new file mode 100644
index 0000000..a7712db
--- /dev/null
+++ b/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.test.propertysource;
+
+import org.apache.tamaya.core.propertysource.DefaultOrdinal;
+import org.apache.tamaya.core.propertysource.SystemPropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.Properties;
+
+public class SystemPropertySourceTest {
+
+ private SystemPropertySource testPropertySource = new SystemPropertySource();
+
+
+ @Test
+ public void testGetOrdinal() throws Exception {
+
+ // test the default ordinal
+ Assert.assertEquals(DefaultOrdinal.SYSTEM_PROPERTIES, testPropertySource.getOrdinal());
+
+ // set the ordinal to 1000
+ System.setProperty(PropertySource.TAMAYA_ORDINAL, "1000");
+ Assert.assertEquals(1000, new SystemPropertySource().getOrdinal()); // currently its not possible to change ordinal at runtime
+
+ // reset it to not destroy other tests!!
+ System.clearProperty(PropertySource.TAMAYA_ORDINAL);
+ }
+
+ @Test
+ public void testGetName() throws Exception {
+ Assert.assertEquals("system-properties", new SystemPropertySource().getName());
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ String propertyKeyToCheck = System.getProperties().stringPropertyNames().iterator().next();
+
+ Optional<String> property = testPropertySource.get(propertyKeyToCheck);
+ Assert.assertTrue("Property '" + propertyKeyToCheck + "' is not present in " + SystemPropertySource.class.getSimpleName(),
+ property.isPresent());
+ Assert.assertEquals(System.getProperty(propertyKeyToCheck), property.get());
+
+
+ }
+
+ @Test
+ public void testGetProperties() throws Exception {
+ checkWithSystemProperties(testPropertySource.getProperties());
+
+ // modify system properties
+ System.setProperty("test", "myTestVal");
+
+ checkWithSystemProperties(testPropertySource.getProperties());
+
+ // 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) {
+ Properties systemEntries = System.getProperties();
+
+ Assert.assertEquals("size of System.getProperties().entrySet() must be the same as SystemPropertySrouce.getProperties().entrySet()",
+ systemEntries.entrySet().size(), toCheck.size());
+
+ for (Map.Entry<String, String> propertySourceEntry : toCheck.entrySet()) {
+
+ Assert.assertEquals("Entry values for key '" + propertySourceEntry.getKey() + "' do not match",
+ systemEntries.getProperty(propertySourceEntry.getKey()), propertySourceEntry.getValue());
+ }
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java b/java8/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
new file mode 100644
index 0000000..5c5fefc
--- /dev/null
+++ b/java8/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.test.provider;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.core.provider.JavaConfigurationProvider;
+import org.apache.tamaya.spi.PropertySource;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.Collection;
+
+public class JavaConfigurationProviderTest {
+
+ @Test
+ public void testJavaConfigurationProvider() {
+
+ Collection<PropertySource> propertySources = new JavaConfigurationProvider().getPropertySources();
+
+ Assert.assertNotNull(propertySources);
+ Assert.assertEquals(1, propertySources.size());
+
+ PropertySource propertySource = propertySources.iterator().next();
+ for (int i = 1; i < 6; i++) {
+ String key = "confkey" + i;
+ String value = "javaconf-value" + i;
+
+ Assert.assertEquals(value, propertySource.get(key).get());
+
+ // check if we had our key in configuration.current
+ Assert.assertTrue(Configuration.current().getProperties().containsKey(key));
+ Assert.assertEquals(value, Configuration.current().get(key).get());
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java b/java8/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java
new file mode 100644
index 0000000..b67d17e
--- /dev/null
+++ b/java8/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.testdata;
+
+import org.apache.tamaya.core.propertysource.BasePropertySource;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Test provider reading properties from classpath:cfg/defaults/**.properties.
+ */
+public class TestPropertyDefaultSource extends BasePropertySource{
+
+ private Map<String,String> properties = new HashMap<>();
+
+ public TestPropertyDefaultSource() {
+ initializeOrdinal(100);
+ properties.put("name","Anatole");
+ properties.put("name2","Sabine");
+ properties = Collections.unmodifiableMap(properties);
+ }
+
+ @Override
+ public String getName() {
+ return "default-testdata-properties";
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java b/java8/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java
new file mode 100644
index 0000000..0713fee
--- /dev/null
+++ b/java8/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.testdata;
+
+import org.apache.tamaya.spi.PropertyFilter;
+
+import javax.annotation.Priority;
+import java.util.function.Function;
+
+/**
+ * Simple PropertyFilter that filters exact one value, registered using ServiceLoader.
+ */
+@Priority(100)
+public class TestPropertyFilter implements PropertyFilter{
+ @Override
+ public String filterProperty(String key, String valueToBeFiltered) {
+ if("name4".equals(key)){
+ return valueToBeFiltered + "(filtered)";
+ }
+ return valueToBeFiltered;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java b/java8/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java
new file mode 100644
index 0000000..0244d6a
--- /dev/null
+++ b/java8/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.testdata;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.spi.PropertyFilter;
+
+import javax.annotation.Priority;
+import java.util.function.Function;
+
+/**
+ * Simple PropertyFilter that filters exact one value, registered using ServiceLoader.
+ */
+@Priority(200)
+public class TestPropertyFilterRemoving implements PropertyFilter{
+ @Override
+ public String filterProperty(String key, String valueToBeFiltered) {
+ if("name5".equals(key)){
+ return null;
+ }
+ else if("name3".equals(key)){
+ return "Mapped to name: " + Configuration.current().get("name").orElse("NoName found!");
+ }
+ return valueToBeFiltered;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java b/java8/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java
new file mode 100644
index 0000000..902027b
--- /dev/null
+++ b/java8/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.testdata;
+
+import org.apache.tamaya.core.propertysource.BasePropertySource;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Test provider reading properties from classpath:cfg/final/**.properties.
+ */
+public class TestPropertySourceProvider implements PropertySourceProvider {
+
+ private List<PropertySource> list = new ArrayList<>();
+
+ public TestPropertySourceProvider(){
+ list.add(new MyPropertySource());
+ list = Collections.unmodifiableList(list);
+ }
+
+ @Override
+ public Collection<PropertySource> getPropertySources() {
+ return list;
+ }
+
+ private static class MyPropertySource extends BasePropertySource {
+
+ private Map<String, String> properties = new HashMap<>();
+
+ public MyPropertySource() {
+ initializeOrdinal(200);
+ properties.put("name", "Robin");
+ properties.put("name3", "Lukas");
+ properties.put("name4", "Sereina");
+ properties.put("name5", "Benjamin");
+ properties = Collections.unmodifiableMap(properties);
+ }
+
+ @Override
+ public String getName() {
+ return "final-testdata-properties";
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
----------------------------------------------------------------------
diff --git a/java8/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter b/java8/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
new file mode 100644
index 0000000..4e7d068
--- /dev/null
+++ b/java8/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
@@ -0,0 +1,20 @@
+#
+# 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.core.testdata.TestPropertyFilter
+org.apache.tamaya.core.testdata.TestPropertyFilterRemoving
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
----------------------------------------------------------------------
diff --git a/java8/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/java8/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
new file mode 100644
index 0000000..1effc9e
--- /dev/null
+++ b/java8/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
@@ -0,0 +1,21 @@
+#
+# 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.core.testdata.TestPropertyDefaultSource
+org.apache.tamaya.core.propertysource.SystemPropertySource
+org.apache.tamaya.core.propertysource.EnvironmentPropertySource
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
----------------------------------------------------------------------
diff --git a/java8/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider b/java8/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
new file mode 100644
index 0000000..afc8910
--- /dev/null
+++ b/java8/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
@@ -0,0 +1,20 @@
+#
+# 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.core.testdata.TestPropertySourceProvider
+org.apache.tamaya.core.provider.JavaConfigurationProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/test/resources/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/java8/core/src/test/resources/javaconfiguration.properties b/java8/core/src/test/resources/javaconfiguration.properties
new file mode 100644
index 0000000..b461414
--- /dev/null
+++ b/java8/core/src/test/resources/javaconfiguration.properties
@@ -0,0 +1,22 @@
+# 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.
+
+confkey1=javaconf-value1
+confkey2=javaconf-value2
+confkey3=javaconf-value3
+confkey4=javaconf-value4
+confkey5=javaconf-value5
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/test/resources/overrideOrdinal.properties
----------------------------------------------------------------------
diff --git a/java8/core/src/test/resources/overrideOrdinal.properties b/java8/core/src/test/resources/overrideOrdinal.properties
new file mode 100644
index 0000000..96935a8
--- /dev/null
+++ b/java8/core/src/test/resources/overrideOrdinal.properties
@@ -0,0 +1,25 @@
+# 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.
+
+#override ordinal
+tamaya.ordinal=16784
+
+mykey1=myval1
+mykey2=myval2
+mykey3=myval3
+mykey4=myval4
+mykey5=myval5
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/test/resources/testfile.properties
----------------------------------------------------------------------
diff --git a/java8/core/src/test/resources/testfile.properties b/java8/core/src/test/resources/testfile.properties
new file mode 100644
index 0000000..abd7ee8
--- /dev/null
+++ b/java8/core/src/test/resources/testfile.properties
@@ -0,0 +1,22 @@
+# 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.
+
+key1=val1
+key2=val2
+key3=val3
+key4=val4
+key5=val5
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/pom.xml
----------------------------------------------------------------------
diff --git a/java8/pom.xml b/java8/pom.xml
new file mode 100644
index 0000000..52ce40a
--- /dev/null
+++ b/java8/pom.xml
@@ -0,0 +1,37 @@
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-all</artifactId>
+ <version>0.2-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>tamaya-java8</artifactId>
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>api</module>
+ <module>core</module>
+ </modules>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 2a34a1d..07b22f3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -189,8 +189,7 @@ under the License.
</developers>
<modules>
- <module>api</module>
- <module>core</module>
+ <module>java8</module>
<module>modules</module>
</modules>
[9/9] incubator-tamaya git commit: TAMAYA-49 fix test which I broke
Posted by st...@apache.org.
TAMAYA-49 fix test which I broke
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/585167aa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/585167aa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/585167aa
Branch: refs/heads/master
Commit: 585167aa8dbcf695399977e889b5681e49e82f1d
Parents: 3d6456d
Author: Mark Struberg <st...@apache.org>
Authored: Wed Jan 7 23:19:34 2015 +0100
Committer: Mark Struberg <st...@apache.org>
Committed: Wed Jan 7 23:19:34 2015 +0100
----------------------------------------------------------------------
.../org/apache/tamaya/modules/json/JSONPropertySourceTest.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/585167aa/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceTest.java b/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceTest.java
index 8935857..0c48534 100644
--- a/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceTest.java
+++ b/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceTest.java
@@ -32,6 +32,7 @@ import java.net.URL;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
+import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.fail;
@@ -150,7 +151,7 @@ public class JSONPropertySourceTest {
JSONPropertySource source = new JSONPropertySource(configFile, 10);
- assertThat(source.get(PropertySource.TAMAYA_ORDINAL).isPresent(), is(false));
+ assertThat(source.get(PropertySource.TAMAYA_ORDINAL), nullValue());
}
@Test
[5/9] incubator-tamaya git commit: TAMAYA-49 move api and core to
java8 module
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java b/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
deleted file mode 100644
index b6acae5..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.PropertyConverter;
-import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
-import org.apache.tamaya.spi.ServiceContext;
-
-import javax.annotation.Priority;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.StampedLock;
-
-/**
- * Default Implementation of a simple ConfigurationContext.
- */
-public class DefaultConfigurationContext implements ConfigurationContext {
- /**
- * Cubcomponent handling {@link org.apache.tamaya.spi.PropertyConverter} instances.
- */
- private PropertyConverterManager propertyConverterManager = new PropertyConverterManager();
-
- /**
- * The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertySource} instances.
- */
- private List<PropertySource> immutablePropertySources;
-
- /**
- * The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertyFilter} instances.
- */
- private List<PropertyFilter> immutablePropertyFilters;
-
- /**
- * Lock for internal synchronization.
- */
- private StampedLock propertySourceLock = new StampedLock();
-
-
- /**
- * The first time the Configuration system gets invoked we do initialize
- * all our {@link org.apache.tamaya.spi.PropertySource}s and
- * {@link org.apache.tamaya.spi.PropertyFilter}s which are known at startup.
- */
- public DefaultConfigurationContext() {
- List<PropertySource> propertySources = new ArrayList<>();
-
- // first we load all PropertySources which got registered via java.util.ServiceLoader
- propertySources.addAll(ServiceContext.getInstance().getServices(PropertySource.class));
-
- // after that we add all PropertySources which get dynamically registered via their PropertySourceProviders
- propertySources.addAll(evaluatePropertySourcesFromProviders());
-
- // now sort them according to their ordinal values
- Collections.sort(propertySources, this::comparePropertySources);
-
- immutablePropertySources = Collections.unmodifiableList(propertySources);
-
- // as next step we pick up the PropertyFilters pretty much the same way
- List<PropertyFilter> propertyFilters = new ArrayList<>();
- propertyFilters.addAll(ServiceContext.getInstance().getServices(PropertyFilter.class));
- Collections.sort(propertyFilters, this::comparePropertyFilters);
-
- immutablePropertyFilters = Collections.unmodifiableList(propertyFilters);
- }
-
- /**
- * Pick up all {@link org.apache.tamaya.spi.PropertySourceProvider}s and return all the
- * {@link org.apache.tamaya.spi.PropertySource}s they like to register.
- */
- private Collection<? extends PropertySource> evaluatePropertySourcesFromProviders() {
- List<PropertySource> propertySources = new ArrayList<>();
- List<PropertySourceProvider> propertySourceProviders = ServiceContext.getInstance().getServices(PropertySourceProvider.class);
- for (PropertySourceProvider propertySourceProvider : propertySourceProviders) {
- propertySources.addAll(propertySourceProvider.getPropertySources());
- }
-
- return propertySources;
- }
-
- @Override
- public void addPropertySources(PropertySource... propertySourcesToAdd) {
- Lock writeLock = propertySourceLock.asWriteLock();
- try {
- writeLock.lock();
- List<PropertySource> newPropertySources = new ArrayList<>(this.immutablePropertySources);
- newPropertySources.addAll(Arrays.asList(propertySourcesToAdd));
- Collections.sort(newPropertySources, this::comparePropertySources);
-
- this.immutablePropertySources = Collections.unmodifiableList(newPropertySources);
- } finally {
- writeLock.unlock();
- }
- }
-
- /**
- * Order property source reversely, the most important come first.
- *
- * @param source1 the first PropertySource
- * @param source2 the second PropertySource
- * @return the comparison result.
- */
- private int comparePropertySources(PropertySource source1, PropertySource source2) {
- if (source1.getOrdinal() < source2.getOrdinal()) {
- return 1;
- } else if (source1.getOrdinal() > source2.getOrdinal()) {
- return -1;
- } else {
- return source2.getClass().getName().compareTo(source1.getClass().getName());
- }
- }
-
- /**
- * Compare 2 filters for ordering the filter chain.
- *
- * @param filter1 the first filter
- * @param filter2 the second filter
- * @return the comparison result
- */
- private int comparePropertyFilters(PropertyFilter filter1, PropertyFilter filter2) {
- Priority prio1 = filter1.getClass().getAnnotation(Priority.class);
- Priority prio2 = filter2.getClass().getAnnotation(Priority.class);
- int ord1 = prio1 != null ? prio1.value() : 0;
- int ord2 = prio2 != null ? prio2.value() : 0;
-
- if (ord1 < ord2) {
- return -1;
- } else if (ord1 > ord2) {
- return 1;
- } else {
- return filter1.getClass().getName().compareTo(filter2.getClass().getName());
- }
- }
-
- @Override
- public List<PropertySource> getPropertySources() {
- return immutablePropertySources;
- }
-
- @Override
- public <T> void addPropertyConverter(Class<T> typeToConvert, PropertyConverter<T> propertyConverter) {
- propertyConverterManager.register(typeToConvert, propertyConverter);
- }
-
- @Override
- public Map<Class<?>, List<PropertyConverter<?>>> getPropertyConverters() {
- return propertyConverterManager.getPropertyConverters();
- }
-
- @Override
- public <T> List<PropertyConverter<T>> getPropertyConverters(Class<T> targetType) {
- return propertyConverterManager.getPropertyConverters(targetType);
- }
-
- @Override
- public List<PropertyFilter> getPropertyFilters() {
- return immutablePropertyFilters;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java b/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
deleted file mode 100644
index 8e27d4a..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import org.apache.tamaya.spi.ServiceContext;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.ServiceLoader;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * This class implements the (default) {@link org.apache.tamaya.spi.ServiceContext} interface and hereby uses the JDK
- * {@link java.util.ServiceLoader} to load the services required.
- */
-public final class DefaultServiceContext implements ServiceContext {
- /**
- * List current services loaded, per class.
- */
- private final ConcurrentHashMap<Class, List<Object>> servicesLoaded = new ConcurrentHashMap<>();
- /**
- * Singletons.
- */
- private final Map<Class, Optional<?>> singletons = new ConcurrentHashMap<>();
-
- @Override
- public <T> Optional<T> getService(Class<T> serviceType) {
- Optional<T> cached = Optional.class.cast(singletons.get(serviceType));
- if (cached == null) {
- List<? extends T> services = getServices(serviceType);
- if (services.isEmpty()) {
- cached = Optional.empty();
- } else {
- cached = Optional.of(services.get(0));
- }
- singletons.put(serviceType, cached);
- }
- return cached;
- }
-
- /**
- * Loads and registers services.
- *
- * @param serviceType The service type.
- * @param <T> the concrete type.
- * @return the items found, never {@code null}.
- */
- @Override
- public <T> List<T> getServices(final Class<T> serviceType) {
- List<T> found = List.class.cast(servicesLoaded.get(serviceType));
- if (found != null) {
- return found;
- }
- List<T> services = new ArrayList<>();
- try {
- for (T t : ServiceLoader.load(serviceType)) {
- services.add(t);
- }
- services = Collections.unmodifiableList(services);
- } catch (Exception e) {
- Logger.getLogger(DefaultServiceContext.class.getName()).log(Level.WARNING,
- "Error loading services current type " + serviceType, e);
- }
- final List<T> previousServices = List.class.cast(servicesLoaded.putIfAbsent(serviceType, (List<Object>) services));
- return previousServices != null ? previousServices : services;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/main/java/org/apache/tamaya/core/internal/PropertiesFileLoader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/PropertiesFileLoader.java b/core/src/main/java/org/apache/tamaya/core/internal/PropertiesFileLoader.java
deleted file mode 100644
index b79a756..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/PropertiesFileLoader.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Objects;
-import java.util.Properties;
-import java.util.Set;
-
-public final class PropertiesFileLoader {
-
-
- private PropertiesFileLoader() {
- // no instantiation
- }
-
-
- /**
- * loads all properties-files with the given name.
- * If the name do not end with {@code .properties} it will be appended
- *
- * @param name of the properties file
- *
- * @return URLs of properties-files or
- * an empty {@link Set} if no files has been found
- *
- * @throws IOException in case of problems loading the properties-files
- */
- public static Set<URL> resolvePropertiesFiles(String name) throws IOException {
- Objects.requireNonNull(name);
-
- if (!name.endsWith(".properties")) {
- name = name + ".properties";
- }
-
- Set<URL> urls = new HashSet<>();
-
- Enumeration<URL> files = Thread.currentThread().getContextClassLoader().getResources(name);
- while (files.hasMoreElements()) {
- urls.add(files.nextElement());
- }
-
- return urls;
- }
-
-
- /**
- * loads the Properties from the given URL
- *
- * @param propertiesFile {@link URL} to load Properties from
- *
- * @return loaded {@link Properties}
- *
- * @throws IllegalStateException in case of an error while reading properties-file
- */
- public static Properties load(URL propertiesFile) {
-
- Properties properties = new Properties();
-
- InputStream stream = null;
- try {
- stream = propertiesFile.openStream();
-
- if (stream != null) {
- properties.load(stream);
- }
- } catch (IOException e) {
- throw new IllegalStateException("Error loading Properties " + propertiesFile, e);
- } finally {
- if (stream != null) {
- try {
- stream.close();
- } catch (IOException e) {
- // bad luck -> stream is already closed
- }
- }
- }
-
- return properties;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java b/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
deleted file mode 100644
index 5c7ae02..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/PropertyConverterManager.java
+++ /dev/null
@@ -1,247 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.time.LocalDate;
-import java.time.LocalDateTime;
-import java.time.LocalTime;
-import java.time.ZoneId;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Currency;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.StampedLock;
-import java.util.logging.Logger;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.spi.PropertyConverter;
-
-/**
- * Manager that deals with {@link org.apache.tamaya.spi.PropertyConverter} instances.
- * This class is thread-safe.
- */
-public class PropertyConverterManager {
- /** The logger used. */
- private static final Logger LOG = Logger.getLogger(PropertyConverterManager.class.getName());
- /** The registered converters. */
- private Map<Class<?>, List<PropertyConverter<?>>> converters = new ConcurrentHashMap<>();
- /** The lock used. */
- private StampedLock lock = new StampedLock();
- private static final String CHAR_NULL_ERROR = "Cannot convert null property";
- /**
- * Constructor.
- */
- public PropertyConverterManager() {
- initDefaultConverters();
- }
-
- private static final PropertyConverter<Character> CHAR_CONVERTER =
- (s) -> Objects.requireNonNull(s,CHAR_NULL_ERROR).charAt(0);
-
- /**
- * Registers the default converters provided out of the box.
- */
- protected void initDefaultConverters() {
- // Add default converters
- register(char.class, CHAR_CONVERTER);
- register(byte.class, Byte::parseByte);
- register(short.class, Short::parseShort);
- register(int.class, Integer::parseInt);
- register(long.class, Long::parseLong);
- register(boolean.class, Boolean::parseBoolean);
- register(float.class, Float::parseFloat); //X TODO not good enough as this is Locale dependent!
- register(double.class, Double::parseDouble); //X TODO not good enough as this is Locale dependent!
-
- register(Character.class, CHAR_CONVERTER);
- register(Byte.class, Byte::valueOf);
- register(Short.class, Short::valueOf);
- register(Integer.class, Integer::valueOf);
- register(Long.class, Long::valueOf);
- register(Boolean.class, Boolean::valueOf);
- register(Float.class, Float::valueOf); //X TODO not good enough as this is Locale dependent!
- register(Double.class, Double::valueOf); //X TODO not good enough as this is Locale dependent!
- register(BigDecimal.class, BigDecimal::new); //X TODO not good enough as this is Locale dependent!
- register(BigInteger.class, BigInteger::new); //X TODO not good enough as this is Locale dependent!
-
- register(Currency.class, Currency::getInstance);
-
- register(LocalDate.class, LocalDate::parse);
- register(LocalTime.class, LocalTime::parse);
- register(LocalDateTime.class, LocalDateTime::parse);
- register(ZoneId.class, ZoneId::of);
- }
-
- /**
- * Registers a ew converter instance.
- *
- * @param targetType the target type, not null.
- * @param converter the converter, not null.
- * @param <T> the type.
- */
- public <T> void register(Class<T> targetType, PropertyConverter<T> converter) {
- Objects.requireNonNull(converter);
- Lock writeLock = lock.asWriteLock();
- try {
- writeLock.lock();
- List<PropertyConverter<T>> converters = List.class.cast(this.converters.get(targetType));
- List<PropertyConverter<T>> newConverters = new ArrayList<>();
- if (converters != null) {
- newConverters.addAll(converters);
- }
- newConverters.add(converter);
- this.converters.put(targetType, Collections.unmodifiableList(newConverters));
- } finally {
- writeLock.unlock();
- }
- }
-
- /**
- * Allows to evaluate if a given target type is supported.
- *
- * @param targetType the target type, not null.
- * @return true, if a converter for the given type is registered, or a default one can be created.
- */
- public boolean isTargetTypeSupported(Class<?> targetType) {
- return converters.containsKey(targetType)
- || createDefaultPropertyConverter(targetType) != null;
- }
-
- /**
- * Get a map of all property converters currently registered. This will not contain the converters that
- * may be created, when an instance is adapted, which provides a String constructor or compatible
- * factory methods taking a single String instance.
- *
- * @return the current map of instantiated and registered converters.
- * @see #createDefaultPropertyConverter(Class)
- */
- public Map<Class<?>, List<PropertyConverter<?>>> getPropertyConverters() {
- Lock readLock = lock.asReadLock();
- try {
- readLock.lock();
- return new HashMap<>(this.converters);
- } finally {
- readLock.unlock();
- }
- }
-
- /**
- * Get the list of all current registered converters for the given target type.
- * If not converters are registered, they component tries to create and register a dynamic
- * converter based on String costructor or static factory methods available.
- *
- * @param targetType the target type, not null.
- * @param <T> the type class
- * @return the ordered list of converters (may be empty for not convertible types).
- * @see #createDefaultPropertyConverter(Class)
- */
- public <T> List<PropertyConverter<T>> getPropertyConverters(Class<T> targetType) {
- Lock readLock = lock.asReadLock();
- List<PropertyConverter<T>> converters;
- try {
- readLock.lock();
- converters = List.class.cast(this.converters.get(targetType));
- } finally {
- readLock.unlock();
- }
- if (converters != null) {
- return converters;
- }
- PropertyConverter<T> defaultConverter = createDefaultPropertyConverter(targetType);
- if (defaultConverter != null) {
- register(targetType, defaultConverter);
- try {
- converters = List.class.cast(this.converters.get(targetType));
- } finally {
- readLock.unlock();
- }
- }
- if (converters != null) {
- return converters;
- }
- return Collections.emptyList();
- }
-
- /**
- * Creates a dynamic PropertyConverter for the given target type.
- *
- * @param targetType the target type
- * @param <T> the type class
- * @return a new converter, or null.
- */
- protected <T> PropertyConverter<T> createDefaultPropertyConverter(Class<T> targetType) {
- PropertyConverter<T> converter = null;
- Method factoryMethod = getFactoryMethod(targetType, "of", "valueOf", "instanceOf", "getInstance", "from", "fromString", "parse");
- if (factoryMethod != null) {
- converter = (s) -> {
- try {
- factoryMethod.setAccessible(true);
- return targetType.cast(factoryMethod.invoke(s));
- } catch (Exception e) {
- throw new ConfigException("Failed to decode '" + s + "'", e);
- }
- };
- }
- if (converter == null) {
- try {
- Constructor<T> constr = targetType.getDeclaredConstructor(String.class);
- converter = (s) -> {
- try {
- constr.setAccessible(true);
- return constr.newInstance(s);
- } catch (Exception e) {
- throw new ConfigException("Failed to decode '" + s + "'", e);
- }
- };
- } catch (Exception e) {
- LOG.finest(() -> "Failed to construct instance of type: " + targetType.getName()+": " + e);
- }
- }
- return converter;
- }
-
- /**
- * Tries to evaluate a factory method that can be used to create an instance based on a String.
- *
- * @param type the target type
- * @param methodNames the possible static method names
- * @return the first method found, or null.
- */
- private Method getFactoryMethod(Class<?> type, String... methodNames) {
- Method m;
- for (String name : methodNames) {
- try {
- m = type.getDeclaredMethod(name, String.class);
- return m;
- } catch (Exception e) {
- LOG.finest(() -> "No such factory method found on type: " + type.getName()+", methodName: " + name);
- }
- }
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java b/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
deleted file mode 100644
index e58be54..0000000
--- a/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.propertysource;
-
-import org.apache.tamaya.spi.PropertySource;
-
-import java.util.Objects;
-import java.util.Optional;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * A base class for {@link PropertySource}s. It provides a {@link #initializeOrdinal(int)} method that
- * reads the ordinal from the config source itself, allowing the ordinal to be "self-configured" by
- * the configuration read.
- */
-public abstract class BasePropertySource implements PropertySource {
-
- private static final Logger LOG = Logger.getLogger(BasePropertySource.class.getName());
-
-
- private int ordinal = DefaultOrdinal.PROPERTY_SOURCE;
-
-
- @Override
- public int getOrdinal() {
- return ordinal;
- }
-
-
- @Override
- public Optional<String> get(String key) {
- Objects.requireNonNull(key, "key must not be null");
- return Optional.ofNullable(getProperties().get(key));
- }
-
-
- /**
- * Initializing the ordinal of this {@link PropertySource} with the given defaultOrdinal.
- *
- * If {@link PropertySource#TAMAYA_ORDINAL} is present via {@link #get(String)} and the
- * value is a valid {@link Integer} then, the defaultOrdinal will be overridden.
- *
- * @param defaultOrdinal of the {@link PropertySource}
- */
- protected void initializeOrdinal(final int defaultOrdinal) {
- this.ordinal = defaultOrdinal;
-
- Optional<String> ordinal = get(PropertySource.TAMAYA_ORDINAL);
- if (ordinal.isPresent()) {
-
- try {
- this.ordinal = Integer.valueOf(ordinal.get());
- } catch (NumberFormatException e) {
- LOG.log(Level.WARNING,
- "Specified {0} is not a valid Integer value: {1} - using defaultOrdinal {2}",
- new Object[]{PropertySource.TAMAYA_ORDINAL, ordinal.get(), defaultOrdinal});
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/main/java/org/apache/tamaya/core/propertysource/DefaultOrdinal.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/propertysource/DefaultOrdinal.java b/core/src/main/java/org/apache/tamaya/core/propertysource/DefaultOrdinal.java
deleted file mode 100644
index ff35e3f..0000000
--- a/core/src/main/java/org/apache/tamaya/core/propertysource/DefaultOrdinal.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.propertysource;
-
-
-/**
- * This interface defines the default ordinals for the 'standard'
- * {@link org.apache.tamaya.spi.PropertySource}s
- *
- * DefaultOrdinals can be overwritten via {@link org.apache.tamaya.spi.PropertySource#TAMAYA_ORDINAL}
- */
-public final class DefaultOrdinal {
-
- /** Private constructor. */
- private DefaultOrdinal(){}
-
- /**
- * default ordinal for {@link org.apache.tamaya.core.propertysource.BasePropertySource} if
- * not overriden in each class
- */
- public static final int PROPERTY_SOURCE = 1000;
-
- /**
- * default ordinal for {@link org.apache.tamaya.core.propertysource.SystemPropertySource}
- */
- public static final int SYSTEM_PROPERTIES = 400;
-
- /**
- * default ordinal for {@link org.apache.tamaya.core.propertysource.EnvironmentPropertySource}
- */
- public static final int ENVIRONMENT_PROPERTIES = 300;
-
- /**
- * default ordinal for {@link org.apache.tamaya.core.propertysource.PropertiesFilePropertySource}
- */
- public static final int FILE_PROPERTIES = 100;
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java b/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
deleted file mode 100644
index 596ea73..0000000
--- a/core/src/main/java/org/apache/tamaya/core/propertysource/EnvironmentPropertySource.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.propertysource;
-
-import java.util.Map;
-
-/**
- * This {@link org.apache.tamaya.spi.PropertySource} provides all Properties which are set
- * via <br />
- * {@code export myprop=myval} on UNIX Systems or<br />
- * {@code set myprop=myval} on Windows
- */
-public class EnvironmentPropertySource extends BasePropertySource {
-
- public EnvironmentPropertySource() {
- initializeOrdinal(DefaultOrdinal.ENVIRONMENT_PROPERTIES);
- }
-
-
- @Override
- public String getName() {
- return "environment-properties";
- }
-
- @Override
- public Map<String, String> getProperties() {
- return System.getenv(); // already a map and unmodifiable
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySource.java b/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySource.java
deleted file mode 100644
index e117a12..0000000
--- a/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesFilePropertySource.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.propertysource;
-
-import org.apache.tamaya.core.internal.PropertiesFileLoader;
-
-import java.net.URL;
-
-/**
- * {@link org.apache.tamaya.spi.PropertySource} for properties-files
- */
-public class PropertiesFilePropertySource extends PropertiesPropertySource {
-
-
- private String fileName;
-
-
- public PropertiesFilePropertySource(URL propertiesFile) {
- super(PropertiesFileLoader.load(propertiesFile));
-
- initializeOrdinal(DefaultOrdinal.FILE_PROPERTIES);
- this.fileName = propertiesFile.toExternalForm();
- }
-
-
- @Override
- public String getName() {
- return fileName;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesPropertySource.java b/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesPropertySource.java
deleted file mode 100644
index cf68bd6..0000000
--- a/core/src/main/java/org/apache/tamaya/core/propertysource/PropertiesPropertySource.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.propertysource;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- * base class for {@link org.apache.tamaya.spi.PropertySource}s which are based on
- * {@link java.util.Properties}
- */
-abstract class PropertiesPropertySource extends BasePropertySource {
-
- protected Map<String, String> properties;
-
-
- // package private to not expose this class
- PropertiesPropertySource(Properties properties) {
- Map<String, String> props = new HashMap<>();
-
- for (String key : properties.stringPropertyNames()) {
- props.put(key, properties.getProperty(key));
- }
-
- this.properties = Collections.unmodifiableMap(props);
- }
-
-
- @Override
- public Map<String, String> getProperties() {
- return properties;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java b/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
deleted file mode 100644
index 50d788d..0000000
--- a/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.propertysource;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- * This {@link org.apache.tamaya.spi.PropertySource} manages the system properties.
- */
-public class SystemPropertySource extends PropertiesPropertySource {
-
- /**
- * previous System.getProperties().hashCode()
- * so we can check if we need to reload
- */
- private int previousHash;
-
-
- public SystemPropertySource() {
- super(System.getProperties());
- previousHash = System.getProperties().hashCode();
- initializeOrdinal(DefaultOrdinal.SYSTEM_PROPERTIES);
- }
-
-
- @Override
- public String getName() {
- return "system-properties";
- }
-
- @Override
- public Map<String, String> getProperties() {
-
- // only need to reload and fill our map if something has changed
- if (previousHash != System.getProperties().hashCode()) {
-
- synchronized (this) {
-
- if (previousHash != System.getProperties().hashCode()) {
-
- Properties systemProperties = System.getProperties();
- Map<String, String> properties = new HashMap<>();
-
- for (String propertyName : systemProperties.stringPropertyNames()) {
- properties.put(propertyName, System.getProperty(propertyName));
- }
-
- this.properties = Collections.unmodifiableMap(properties);
- previousHash = systemProperties.hashCode();
- }
- }
- }
-
- return super.getProperties();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java b/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
deleted file mode 100644
index 0341c0e..0000000
--- a/core/src/main/java/org/apache/tamaya/core/provider/JavaConfigurationProvider.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.provider;
-
-import org.apache.tamaya.core.internal.PropertiesFileLoader;
-import org.apache.tamaya.core.propertysource.PropertiesFilePropertySource;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * Provider which reads all {@code javaconfiguration.properties} files from classpath
- */
-public class JavaConfigurationProvider implements PropertySourceProvider {
-
-
- @Override
- public Collection<PropertySource> getPropertySources() {
-
- List<PropertySource> propertySources = new ArrayList<>();
-
- //X TODO maybe put javaconf... in META-INF
-
- try {
- propertySources.addAll(
- PropertiesFileLoader.resolvePropertiesFiles("javaconfiguration.properties")
- .stream()
- .map(PropertiesFilePropertySource::new)
- .collect(Collectors.toList()));
-
-
- } catch (IOException e) {
- throw new IllegalStateException("error loading javaconfiguration.properties", e);
- }
-
- return Collections.unmodifiableList(propertySources);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/main/resources/META-INF/services/org.apache.tamaya.Configuration
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.Configuration b/core/src/main/resources/META-INF/services/org.apache.tamaya.Configuration
deleted file mode 100644
index 0db8402..0000000
--- a/core/src/main/resources/META-INF/services/org.apache.tamaya.Configuration
+++ /dev/null
@@ -1,19 +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 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.core.internal.DefaultConfiguration
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resources.ResourceLoader
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resources.ResourceLoader b/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resources.ResourceLoader
deleted file mode 100644
index a964d3c..0000000
--- a/core/src/main/resources/META-INF/services/org.apache.tamaya.core.resources.ResourceLoader
+++ /dev/null
@@ -1,19 +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 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.resource.internal.DefaultResourceLoader
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext b/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext
deleted file mode 100644
index 32b4302..0000000
--- a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ConfigurationContext
+++ /dev/null
@@ -1,19 +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 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.core.internal.DefaultConfigurationContext
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
----------------------------------------------------------------------
diff --git a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext b/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
deleted file mode 100644
index 2721eff..0000000
--- a/core/src/main/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
+++ /dev/null
@@ -1,19 +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 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.core.internal.DefaultServiceContext
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java b/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
deleted file mode 100644
index 5a6fc70..0000000
--- a/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core;
-
-import org.apache.tamaya.Configuration;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-/**
- * This tests checks if the combination of 2 prioritized PropertySource return valid results on the final Configuration.
- */
-public class ConfigurationTest {
-
- @Test
- public void testAccess(){
- assertNotNull(Configuration.current());
- }
-
- @Test
- public void testContent(){
- assertEquals("Robin", Configuration.current().get("name").get());
- assertEquals("Sabine", Configuration.current().get("name2").get()); // from default
- assertEquals("Mapped to name: Robin", Configuration.current().get("name3").get()); // oderridden default, mapped by filter to name property
- assertEquals("Sereina(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)", Configuration.current().get("name4").get()); // final only
- assertNull(Configuration.current().get("name5").orElse(null)); // final only, but removed from filter
-
- System.out.println("name : " + Configuration.current().get("name").get());
- System.out.println("name2: " + Configuration.current().get("name2").get());
- System.out.println("name3: " + Configuration.current().get("name3").get());
- System.out.println("name4: " + Configuration.current().get("name4").get());
- System.out.println("name5: " + Configuration.current().get("name5").orElse(null));
-
- System.out.println("ALL :");
- Configuration.current().getProperties().entrySet().forEach(e ->
- System.out.println(" " + e.getKey()+" = " + e.getValue()));
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/test/java/org/apache/tamaya/core/test/internal/PropetiesFileLoaderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/test/internal/PropetiesFileLoaderTest.java b/core/src/test/java/org/apache/tamaya/core/test/internal/PropetiesFileLoaderTest.java
deleted file mode 100644
index 985b5d5..0000000
--- a/core/src/test/java/org/apache/tamaya/core/test/internal/PropetiesFileLoaderTest.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.test.internal;
-
-import org.apache.tamaya.core.internal.PropertiesFileLoader;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.net.URL;
-import java.util.Properties;
-import java.util.Set;
-
-public class PropetiesFileLoaderTest {
-
-
- @Test
- public void testResolvePropertiesFiles() throws Exception {
- Properties expectedProperties = PropertiesFileLoader.load(Thread.currentThread().getContextClassLoader().getResource("testfile.properties"));
-
- {
- // with .properties
- Set<URL> urls = PropertiesFileLoader.resolvePropertiesFiles("testfile.properties");
- Assert.assertNotNull(urls);
- Assert.assertFalse(urls.isEmpty());
-
- Properties properties = PropertiesFileLoader.load(urls.iterator().next());
- Assert.assertEquals(expectedProperties.size(), properties.size());
- }
-
- {
- // without .properties
- Set<URL> urls = PropertiesFileLoader.resolvePropertiesFiles("testfile");
- Assert.assertNotNull(urls);
- Assert.assertFalse(urls.isEmpty());
-
- Properties properties = PropertiesFileLoader.load(urls.iterator().next());
- Assert.assertEquals(expectedProperties.size(), properties.size());
- }
-
- {
- // with a while which doesn't exist
- Set<URL> urls = PropertiesFileLoader.resolvePropertiesFiles("nonexistingfile.properties");
- Assert.assertNotNull(urls);
- Assert.assertTrue(urls.isEmpty());
- }
-
- }
-
- @Test
- public void testLoad() {
- Properties properties = PropertiesFileLoader.load(Thread.currentThread().getContextClassLoader().getResource("testfile.properties"));
-
- Assert.assertNotNull(properties);
- Assert.assertEquals(5, properties.size());
-
- for (int i = 1; i < 6; i++) {
- Assert.assertEquals(properties.getProperty("key" + i), "val" + i);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java b/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java
deleted file mode 100644
index d6dc867..0000000
--- a/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.test.propertysource;
-
-import org.apache.tamaya.core.propertysource.BasePropertySource;
-import org.apache.tamaya.core.propertysource.DefaultOrdinal;
-import org.apache.tamaya.spi.PropertySource;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
-
-public class BasePropertySourceTest {
-
- @Test
- public void testGetOrdinal() {
-
- PropertySource defaultPropertySource = new BasePropertySource() {
-
- @Override
- public String getName() {
- return "testWithDefault";
- }
-
- @Override
- public Optional<String> get(String key) {
- return Optional.ofNullable(null);
- }
-
- @Override
- public Map<String, String> getProperties() {
- return Collections.emptyMap();
- }
- };
-
- Assert.assertEquals(DefaultOrdinal.PROPERTY_SOURCE, defaultPropertySource.getOrdinal());
- Assert.assertEquals(1000, new OverriddenOrdinalPropertySource().getOrdinal());
-
- // propertySource with invalid ordinal
- Assert.assertEquals(1, new OverriddenInvalidOrdinalPropertySource().getOrdinal());
- }
-
- @Test
- public void testGet() {
- Assert.assertEquals("1000", new OverriddenOrdinalPropertySource().get(PropertySource.TAMAYA_ORDINAL).get());
- }
-
- private static class OverriddenOrdinalPropertySource extends BasePropertySource {
-
- private OverriddenOrdinalPropertySource() {
- initializeOrdinal(250);
- }
-
- @Override
- public String getName() {
- return "overriddenOrdinal";
- }
-
- @Override
- public Map<String, String> getProperties() {
- Map<String, String> map = new HashMap<>(1);
- map.put(PropertySource.TAMAYA_ORDINAL, "1000");
- return map;
- }
- }
-
- private static class OverriddenInvalidOrdinalPropertySource extends BasePropertySource {
-
- private OverriddenInvalidOrdinalPropertySource() {
- initializeOrdinal(1);
- }
-
- @Override
- public String getName() {
- return "overriddenInvalidOrdinal";
- }
-
- @Override
- public Map<String, String> getProperties() {
- Map<String, String> map = new HashMap<>(1);
- map.put(PropertySource.TAMAYA_ORDINAL, "invalid");
- return map;
- }
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java b/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
deleted file mode 100644
index 6a1c9e7..0000000
--- a/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.test.propertysource;
-
-import org.apache.tamaya.core.internal.PropertiesFileLoader;
-import org.apache.tamaya.core.propertysource.DefaultOrdinal;
-import org.apache.tamaya.core.propertysource.PropertiesFilePropertySource;
-import org.apache.tamaya.spi.PropertySource;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.net.URL;
-import java.util.Map;
-import java.util.Properties;
-
-public class PropertiesFilePropertySourceTest {
-
- private PropertiesFilePropertySource testfilePropertySource;
- private PropertiesFilePropertySource overrideOrdinalPropertySource;
-
-
- @Before
- public void initTest() {
- testfilePropertySource = new PropertiesFilePropertySource(Thread.currentThread().getContextClassLoader().getResource("testfile.properties"));
- overrideOrdinalPropertySource = new PropertiesFilePropertySource(Thread.currentThread().getContextClassLoader().getResource("overrideOrdinal.properties"));
- }
-
-
- @Test
- public void testGetOrdinal() {
- Assert.assertEquals(DefaultOrdinal.FILE_PROPERTIES, testfilePropertySource.getOrdinal());
- Assert.assertEquals(Integer.parseInt(overrideOrdinalPropertySource.get(PropertySource.TAMAYA_ORDINAL).get()), overrideOrdinalPropertySource.getOrdinal());
- }
-
-
- @Test
- public void testGet() {
- Assert.assertEquals("val3", testfilePropertySource.get("key3").get());
- Assert.assertEquals("myval5", overrideOrdinalPropertySource.get("mykey5").get());
- Assert.assertFalse(testfilePropertySource.get("nonpresentkey").isPresent());
- }
-
-
- @Test
- public void testGetProperties() throws Exception {
- Properties expectedProperties = PropertiesFileLoader.load(new URL(testfilePropertySource.getName()));
-
- Assert.assertEquals(expectedProperties.size(), testfilePropertySource.getProperties().size());
-
- for (Map.Entry<String, String> entry : testfilePropertySource.getProperties().entrySet()) {
- Assert.assertEquals(expectedProperties.getProperty(entry.getKey()), entry.getValue());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java b/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java
deleted file mode 100644
index a7712db..0000000
--- a/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.test.propertysource;
-
-import org.apache.tamaya.core.propertysource.DefaultOrdinal;
-import org.apache.tamaya.core.propertysource.SystemPropertySource;
-import org.apache.tamaya.spi.PropertySource;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.Map;
-import java.util.Optional;
-import java.util.Properties;
-
-public class SystemPropertySourceTest {
-
- private SystemPropertySource testPropertySource = new SystemPropertySource();
-
-
- @Test
- public void testGetOrdinal() throws Exception {
-
- // test the default ordinal
- Assert.assertEquals(DefaultOrdinal.SYSTEM_PROPERTIES, testPropertySource.getOrdinal());
-
- // set the ordinal to 1000
- System.setProperty(PropertySource.TAMAYA_ORDINAL, "1000");
- Assert.assertEquals(1000, new SystemPropertySource().getOrdinal()); // currently its not possible to change ordinal at runtime
-
- // reset it to not destroy other tests!!
- System.clearProperty(PropertySource.TAMAYA_ORDINAL);
- }
-
- @Test
- public void testGetName() throws Exception {
- Assert.assertEquals("system-properties", new SystemPropertySource().getName());
- }
-
- @Test
- public void testGet() throws Exception {
- String propertyKeyToCheck = System.getProperties().stringPropertyNames().iterator().next();
-
- Optional<String> property = testPropertySource.get(propertyKeyToCheck);
- Assert.assertTrue("Property '" + propertyKeyToCheck + "' is not present in " + SystemPropertySource.class.getSimpleName(),
- property.isPresent());
- Assert.assertEquals(System.getProperty(propertyKeyToCheck), property.get());
-
-
- }
-
- @Test
- public void testGetProperties() throws Exception {
- checkWithSystemProperties(testPropertySource.getProperties());
-
- // modify system properties
- System.setProperty("test", "myTestVal");
-
- checkWithSystemProperties(testPropertySource.getProperties());
-
- // 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) {
- Properties systemEntries = System.getProperties();
-
- Assert.assertEquals("size of System.getProperties().entrySet() must be the same as SystemPropertySrouce.getProperties().entrySet()",
- systemEntries.entrySet().size(), toCheck.size());
-
- for (Map.Entry<String, String> propertySourceEntry : toCheck.entrySet()) {
-
- Assert.assertEquals("Entry values for key '" + propertySourceEntry.getKey() + "' do not match",
- systemEntries.getProperty(propertySourceEntry.getKey()), propertySourceEntry.getValue());
- }
-
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java b/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
deleted file mode 100644
index 5c5fefc..0000000
--- a/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.test.provider;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.core.provider.JavaConfigurationProvider;
-import org.apache.tamaya.spi.PropertySource;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.Collection;
-
-public class JavaConfigurationProviderTest {
-
- @Test
- public void testJavaConfigurationProvider() {
-
- Collection<PropertySource> propertySources = new JavaConfigurationProvider().getPropertySources();
-
- Assert.assertNotNull(propertySources);
- Assert.assertEquals(1, propertySources.size());
-
- PropertySource propertySource = propertySources.iterator().next();
- for (int i = 1; i < 6; i++) {
- String key = "confkey" + i;
- String value = "javaconf-value" + i;
-
- Assert.assertEquals(value, propertySource.get(key).get());
-
- // check if we had our key in configuration.current
- Assert.assertTrue(Configuration.current().getProperties().containsKey(key));
- Assert.assertEquals(value, Configuration.current().get(key).get());
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java b/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java
deleted file mode 100644
index b67d17e..0000000
--- a/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyDefaultSource.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.testdata;
-
-import org.apache.tamaya.core.propertysource.BasePropertySource;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Test provider reading properties from classpath:cfg/defaults/**.properties.
- */
-public class TestPropertyDefaultSource extends BasePropertySource{
-
- private Map<String,String> properties = new HashMap<>();
-
- public TestPropertyDefaultSource() {
- initializeOrdinal(100);
- properties.put("name","Anatole");
- properties.put("name2","Sabine");
- properties = Collections.unmodifiableMap(properties);
- }
-
- @Override
- public String getName() {
- return "default-testdata-properties";
- }
-
- @Override
- public Map<String, String> getProperties() {
- return properties;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java b/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java
deleted file mode 100644
index 0713fee..0000000
--- a/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilter.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.testdata;
-
-import org.apache.tamaya.spi.PropertyFilter;
-
-import javax.annotation.Priority;
-import java.util.function.Function;
-
-/**
- * Simple PropertyFilter that filters exact one value, registered using ServiceLoader.
- */
-@Priority(100)
-public class TestPropertyFilter implements PropertyFilter{
- @Override
- public String filterProperty(String key, String valueToBeFiltered) {
- if("name4".equals(key)){
- return valueToBeFiltered + "(filtered)";
- }
- return valueToBeFiltered;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java b/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java
deleted file mode 100644
index 0244d6a..0000000
--- a/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.testdata;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.spi.PropertyFilter;
-
-import javax.annotation.Priority;
-import java.util.function.Function;
-
-/**
- * Simple PropertyFilter that filters exact one value, registered using ServiceLoader.
- */
-@Priority(200)
-public class TestPropertyFilterRemoving implements PropertyFilter{
- @Override
- public String filterProperty(String key, String valueToBeFiltered) {
- if("name5".equals(key)){
- return null;
- }
- else if("name3".equals(key)){
- return "Mapped to name: " + Configuration.current().get("name").orElse("NoName found!");
- }
- return valueToBeFiltered;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java b/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java
deleted file mode 100644
index 902027b..0000000
--- a/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertySourceProvider.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.testdata;
-
-import org.apache.tamaya.core.propertysource.BasePropertySource;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Test provider reading properties from classpath:cfg/final/**.properties.
- */
-public class TestPropertySourceProvider implements PropertySourceProvider {
-
- private List<PropertySource> list = new ArrayList<>();
-
- public TestPropertySourceProvider(){
- list.add(new MyPropertySource());
- list = Collections.unmodifiableList(list);
- }
-
- @Override
- public Collection<PropertySource> getPropertySources() {
- return list;
- }
-
- private static class MyPropertySource extends BasePropertySource {
-
- private Map<String, String> properties = new HashMap<>();
-
- public MyPropertySource() {
- initializeOrdinal(200);
- properties.put("name", "Robin");
- properties.put("name3", "Lukas");
- properties.put("name4", "Sereina");
- properties.put("name5", "Benjamin");
- properties = Collections.unmodifiableMap(properties);
- }
-
- @Override
- public String getName() {
- return "final-testdata-properties";
- }
-
- @Override
- public Map<String, String> getProperties() {
- return properties;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
----------------------------------------------------------------------
diff --git a/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter b/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
deleted file mode 100644
index 4e7d068..0000000
--- a/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter
+++ /dev/null
@@ -1,20 +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 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.core.testdata.TestPropertyFilter
-org.apache.tamaya.core.testdata.TestPropertyFilterRemoving
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
----------------------------------------------------------------------
diff --git a/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource b/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
deleted file mode 100644
index 1effc9e..0000000
--- a/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySource
+++ /dev/null
@@ -1,21 +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 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.core.testdata.TestPropertyDefaultSource
-org.apache.tamaya.core.propertysource.SystemPropertySource
-org.apache.tamaya.core.propertysource.EnvironmentPropertySource
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
----------------------------------------------------------------------
diff --git a/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider b/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
deleted file mode 100644
index afc8910..0000000
--- a/core/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider
+++ /dev/null
@@ -1,20 +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 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.core.testdata.TestPropertySourceProvider
-org.apache.tamaya.core.provider.JavaConfigurationProvider
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/test/resources/javaconfiguration.properties
----------------------------------------------------------------------
diff --git a/core/src/test/resources/javaconfiguration.properties b/core/src/test/resources/javaconfiguration.properties
deleted file mode 100644
index b461414..0000000
--- a/core/src/test/resources/javaconfiguration.properties
+++ /dev/null
@@ -1,22 +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.
-
-confkey1=javaconf-value1
-confkey2=javaconf-value2
-confkey3=javaconf-value3
-confkey4=javaconf-value4
-confkey5=javaconf-value5
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/test/resources/overrideOrdinal.properties
----------------------------------------------------------------------
diff --git a/core/src/test/resources/overrideOrdinal.properties b/core/src/test/resources/overrideOrdinal.properties
deleted file mode 100644
index 96935a8..0000000
--- a/core/src/test/resources/overrideOrdinal.properties
+++ /dev/null
@@ -1,25 +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.
-
-#override ordinal
-tamaya.ordinal=16784
-
-mykey1=myval1
-mykey2=myval2
-mykey3=myval3
-mykey4=myval4
-mykey5=myval5
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/test/resources/testfile.properties
----------------------------------------------------------------------
diff --git a/core/src/test/resources/testfile.properties b/core/src/test/resources/testfile.properties
deleted file mode 100644
index abd7ee8..0000000
--- a/core/src/test/resources/testfile.properties
+++ /dev/null
@@ -1,22 +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.
-
-key1=val1
-key2=val2
-key3=val3
-key4=val4
-key5=val5
\ No newline at end of file
[7/9] incubator-tamaya git commit: TAMAYA-49 ipmlement java7 api as
well
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONPropertySource.java b/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONPropertySource.java
index bff8004..6a1a11b 100644
--- a/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONPropertySource.java
+++ b/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONPropertySource.java
@@ -31,7 +31,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
-import java.util.Optional;
import static java.lang.String.format;
@@ -74,10 +73,10 @@ public class JSONPropertySource
}
@Override
- public Optional<String> get(String key) {
+ public String get(String key) {
Objects.requireNonNull(key, "Key must not be null");
- return Optional.ofNullable(getProperties().get(key));
+ return getProperties().get(key);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/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 d19c05f..750ca8d 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
@@ -22,7 +22,6 @@ import org.apache.tamaya.spi.PropertySource;
import java.util.HashMap;
import java.util.Map;
-import java.util.Optional;
/**
* Created by Anatole on 04.01.2015.
@@ -52,8 +51,8 @@ public class MyTestPropertySource implements PropertySource{
}
@Override
- public Optional<String> get(String key) {
- return Optional.ofNullable(properties.get(key));
+ public String get(String key) {
+ return properties.get(key);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 07b22f3..6cb1699 100644
--- a/pom.xml
+++ b/pom.xml
@@ -189,6 +189,7 @@ under the License.
</developers>
<modules>
+ <module>java7</module>
<module>java8</module>
<module>modules</module>
</modules>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/toolchains.xml
----------------------------------------------------------------------
diff --git a/toolchains.xml b/toolchains.xml
new file mode 100644
index 0000000..98617b2
--- /dev/null
+++ b/toolchains.xml
@@ -0,0 +1,27 @@
+<toolchains xmlns="http://maven.apache.org/TOOLCHAINS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/TOOLCHAINS/1.1.0 http://maven.apache.org/xsd/toolchains-1.1.0.xsd">
+
+ <!-- jdk-1.7 -->
+ <toolchain>
+ <type>jdk</type>
+ <provides>
+ <version>1.7</version>
+ <vendor>Oracle</vendor>
+ </provides>
+ <configuration>
+ <jdkHome>/path/to/jdk/1.7</jdkHome>
+ </configuration>
+ </toolchain>
+
+ <!-- jdk-1.8 -->
+ <toolchain>
+ <type>jdk</type>
+ <provides>
+ <version>1.8</version>
+ <vendor>Oracle</vendor>
+ </provides>
+ <configuration>
+ <jdkHome>/path/to/jdk/1.8</jdkHome>
+ </configuration>
+ </toolchain>
+</toolchains>
[8/9] incubator-tamaya git commit: TAMAYA-49 ipmlement java7 api as
well
Posted by st...@apache.org.
TAMAYA-49 ipmlement java7 api as well
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/67855faa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/67855faa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/67855faa
Branch: refs/heads/master
Commit: 67855faa5e8f18bcccf11cb05f0d055949598208
Parents: 328a4ac
Author: Mark Struberg <st...@apache.org>
Authored: Tue Jan 6 22:19:11 2015 +0100
Committer: Mark Struberg <st...@apache.org>
Committed: Wed Jan 7 23:17:58 2015 +0100
----------------------------------------------------------------------
README.md | 15 ++
java7/api/pom.xml | 43 ++++++
.../java/org/apache/tamaya/ConfigException.java | 44 ++++++
.../java/org/apache/tamaya/Configuration.java | 72 ++++++++++
.../apache/tamaya/ConfigurationProvider.java | 32 +++++
.../apache/tamaya/spi/ConfigurationContext.java | 140 +++++++++++++++++++
.../apache/tamaya/spi/PropertyConverter.java | 41 ++++++
.../org/apache/tamaya/spi/PropertyFilter.java | 49 +++++++
.../org/apache/tamaya/spi/PropertySource.java | 125 +++++++++++++++++
.../tamaya/spi/PropertySourceProvider.java | 43 ++++++
.../org/apache/tamaya/spi/ServiceContext.java | 57 ++++++++
.../tamaya/spi/ServiceContextManager.java | 109 +++++++++++++++
.../org/apache/tamaya/ConfigurationTest.java | 64 +++++++++
.../org/apache/tamaya/TestConfiguration.java | 86 ++++++++++++
.../apache/tamaya/spi/ServiceContextTest.java | 95 +++++++++++++
.../apache/tamaya/spi/TestServiceContext.java | 89 ++++++++++++
.../services/org.apache.tamaya.Configuration | 19 +++
.../org.apache.tamaya.spi.ServiceContext | 1 +
java7/pom.xml | 68 +++++++++
.../java/org/apache/tamaya/Configuration.java | 54 +++++--
.../apache/tamaya/ConfigurationProvider.java | 34 +++++
.../org/apache/tamaya/spi/PropertyFilter.java | 2 +-
.../org/apache/tamaya/spi/PropertySource.java | 5 +-
.../tamaya/spi/ServiceContextManager.java | 2 +-
.../org/apache/tamaya/TestConfiguration.java | 6 +-
.../core/internal/DefaultConfiguration.java | 14 +-
.../core/propertysource/BasePropertySource.java | 13 +-
.../apache/tamaya/core/ConfigurationTest.java | 22 +--
.../propertysource/BasePropertySourceTest.java | 7 +-
.../PropertiesFilePropertySourceTest.java | 8 +-
.../SystemPropertySourceTest.java | 7 +-
.../provider/JavaConfigurationProviderTest.java | 4 +-
.../testdata/TestPropertyFilterRemoving.java | 3 +-
.../apache/tamaya/format/PropertiesFormat.java | 5 +-
.../tamaya/format/PropertiesXmlFormat.java | 5 +-
.../tamaya/modules/json/JSONPropertySource.java | 5 +-
.../tamaya/resolver/MyTestPropertySource.java | 5 +-
pom.xml | 1 +
toolchains.xml | 27 ++++
39 files changed, 1345 insertions(+), 76 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..d23963e
--- /dev/null
+++ b/README.md
@@ -0,0 +1,15 @@
+Building Apache Tamaya (incubating)
+
+
+
+The Apache Tamaya project contains classes which are intended to be built with Java7 and others
+which are for Java8. This means you need to have both JDK-1.7 and JDK-1.8 installed on your computer.
+
+To tell maven which JDK it should use for each of the projects we do leverage the
+maven-toolchains-plugin and Mavens toolchains support.
+
+See the following links for more information
+http://maven.apache.org/ref/3.2.5/maven-core/toolchains.html
+http://maven.apache.org/guides/mini/guide-using-toolchains.html
+
+Please copy the provided toolchains.xml sample to ~.m2/toolchains.xml
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/pom.xml
----------------------------------------------------------------------
diff --git a/java7/api/pom.xml b/java7/api/pom.xml
new file mode 100644
index 0000000..3dbfa4c
--- /dev/null
+++ b/java7/api/pom.xml
@@ -0,0 +1,43 @@
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-java7</artifactId>
+ <version>0.2-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>tamaya-java7-api</artifactId>
+ <description>
+ The API defines a complete Java7 based API for reading of configuration data.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/main/java/org/apache/tamaya/ConfigException.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/ConfigException.java b/java7/api/src/main/java/org/apache/tamaya/ConfigException.java
new file mode 100644
index 0000000..bac2ef4
--- /dev/null
+++ b/java7/api/src/main/java/org/apache/tamaya/ConfigException.java
@@ -0,0 +1,44 @@
+/*
+ * 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;
+
+/**
+ * Exception class (runtime exception) for configuration issues.
+ */
+public class ConfigException extends RuntimeException{
+
+ private static final long serialVersionUID = -5886094818057522680L;
+
+ /**
+ * Creates a new configuration exception.
+ * @param message the exception message, not null.
+ */
+ public ConfigException(String message){
+ super(message);
+ }
+
+ /**
+ * Creates a new configuration exception.
+ * @param message the exception message, not null.
+ * @param t the throwable.
+ */
+ public ConfigException(String message, Throwable t){
+ super(message, t);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/main/java/org/apache/tamaya/Configuration.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/Configuration.java b/java7/api/src/main/java/org/apache/tamaya/Configuration.java
new file mode 100644
index 0000000..291fb78
--- /dev/null
+++ b/java7/api/src/main/java/org/apache/tamaya/Configuration.java
@@ -0,0 +1,72 @@
+/*
+ * 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;
+
+import java.util.Map;
+
+
+/**
+ * A configuration models a aggregated set current properties, identified by a unique key, but adds higher level access functions to
+ * a {@link org.apache.tamaya.spi.PropertySource}. Hereby in most cases a configuration is a wrapper around a composite
+ * {@link org.apache.tamaya.spi.PropertySource} instance, which may combine multiple child config in well defined tree like structure,
+ * where nodes define logically the rules current priority, filtering, combination and overriding.
+ * <br/>
+ * <h3>Implementation Requirements</h3>
+ * Implementations current this interface must be
+ * <ul>
+ * <li>Thread safe.
+ * <li>Immutable
+ * </ul>
+ * It is not recommended that implementations also are serializable, since the any configuration can be <i>freezed</i>
+ * by reading out its complete configuration map into a serializable and remotable structure. This helps significantly
+ * simplifying the development current this interface, e.g. for being backed up by systems and stores that are not part current
+ * this library at all.
+ */
+public interface Configuration {
+
+ /**
+ * Access a property.
+ *
+ * @param key the property's key, not null.
+ * @return the property's keys.
+ */
+ String get(String key);
+
+ /**
+ * Get the property keys as type T. This will implicitly require a corresponding {@link
+ * org.apache.tamaya.spi.PropertyConverter} to be available that is capable current providing type T
+ * fromMap the given String keys.
+ *
+ * @param key the property's absolute, or relative path, e.g. @code
+ * a/b/c/d.myProperty}.
+ * @param type The target type required, not null.
+ * @return the property value, never null..
+ * @throws ConfigException if the keys could not be converted to the required target type.
+ */
+ <T> T get(String key, Class<T> type);
+
+ /**
+ * Access all current known Configuration properties as a full {@code Map<String,String>}.
+ * Be aware that entries from non scannable parts of the registered {@link org.apache.tamaya.spi.PropertySource}
+ * instances may not be contained in the result, but nevertheless be accessible calling one of the
+ * {@code get(...)} methods.
+ */
+ Map<String,String> getProperties();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java b/java7/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
new file mode 100644
index 0000000..1293f49
--- /dev/null
+++ b/java7/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+import org.apache.tamaya.spi.ServiceContextManager;
+
+/**
+ * Static access to the {@link Configuration} for the very application.
+ */
+public final class ConfigurationProvider {
+ private ConfigurationProvider() {
+ // just to prevent initialisation
+ }
+
+ public static Configuration getConfiguration() {
+ return ServiceContextManager.getServiceContext().getService(Configuration.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java b/java7/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
new file mode 100644
index 0000000..efad465
--- /dev/null
+++ b/java7/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
@@ -0,0 +1,140 @@
+/*
+ * 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.spi;
+
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Central SPI for programmatically dealing with the setup of the configuration system.
+ * This includes adding and enlisting {@link org.apache.tamaya.spi.PropertySource}s,
+ * managing {@link org.apache.tamaya.spi.PropertyConverter}s, ConfigFilters, etc.
+ */
+public interface ConfigurationContext {
+
+ /**
+ * This method can be used for programmatically adding {@link PropertySource}s.
+ * It is not needed for normal 'usage' by end users, but only for Extension Developers!
+ *
+ * @param propertySourcesToAdd the PropertySources to add
+ */
+ void addPropertySources(PropertySource... propertySourcesToAdd);
+
+ /**
+ * This method returns the current list of registered PropertySources ordered via their ordinal.
+ * PropertySources with a lower ordinal come last. The PropertySource with the
+ * highest ordinal comes first.
+ * If two PropertySources have the same ordinal number they will get sorted
+ * using their class name just to ensure the user at least gets the same ordering
+ * after a JVM restart, hereby names before are added last.
+ * PropertySources are loaded when this method is called the first time, which basically is
+ * when the first time configuration is accessed.
+ *
+ * @return a sorted list of registered PropertySources. The returned list need not be modifiable
+ */
+ List<PropertySource> getPropertySources();
+
+
+ /**
+ * This method can be used for programmatically adding {@link PropertyConverter}s.
+ * It is not needed for normal 'usage' by end users, but only for Extension Developers!
+ *
+ * @param typeToConvert the type which the converter is for
+ * @param propertyConverter the PropertyConverters to add for this type
+ */
+ <T> void addPropertyConverter(Class<T> typeToConvert, PropertyConverter<T> propertyConverter);
+
+ /**
+ * <p>
+ * This method returns the Map of registered PropertyConverters
+ * per type.
+ * The List for each type is ordered via their {@link javax.annotation.Priority} and
+ * cladd name. Refer also to {@link #getPropertyConverters()}.
+ * </p>
+ * <p>
+ * A simplified scenario could be like:
+ * <pre>
+ * {
+ * Date.class -> {StandardDateConverter, TimezoneDateConverter, MyCustomDateConverter }
+ * Boolean.class -> {StandardBooleanConverter, FrenchBooleanConverter}
+ * Integer.class -> {DynamicDefaultConverter}
+ * }
+ * </pre>
+ * </p>
+ *
+ * @return map with sorted list of registered PropertySources per type.
+ */
+ Map<Class<?>, List<PropertyConverter<?>>> getPropertyConverters();
+
+ /**
+ * <p>
+ * This method returns the registered PropertyConverters for a given type.
+ * The List for each type is ordered via their {@link javax.annotation.Priority}.
+ * </p>
+ *
+ * <p>
+ * PropertyConverters with a higher Priority come first. The PropertyConverter with the
+ * lowest Priority comes last.
+ * If two PropertyConverter have the same ordinal number they will get sorted
+ * using their class name just to ensure the user at least gets the same ordering
+ * after a JVM restart.
+ * </p>
+ *
+ * <p>
+ * Additionally if a PropertyProvider is accessed, which is not registered the implementation
+ * should try to figure out, if there could be a default implementation as follows:
+ * <ol>
+ * <le>Look for static factory methods: {@code of(String), valueOf(String), getInstance(String),
+ * instanceOf(String), fomr(String)}</le>
+ * <le>Look for a matching constructor: {@code T(String)}.</le>
+ * </ol>
+ * If a correspoding factory method or constructor could be found, a corresponding
+ * PropertyConverter should be created and registered automatically for the given
+ * type.
+ * </p>
+ *
+ * <p>
+ * The scenario could be like:
+ * <pre>
+ * {
+ * Date.class -> {MyCustomDateConverter,StandardDateConverter, TimezoneDateConverter}
+ * Boolean.class -> {StandardBooleanConverter, FrenchBooleanConverter}
+ * Integer.class -> {DynamicDefaultConverter}
+ * }
+ * </pre>
+ * </p>
+ *
+ * <p>
+ * The converters returned for a type should be used as a chain, whereas the result of the
+ * first converter that is able to convert the configured value, is taken as the chain's result.
+ * No more converters are called after a converter has successfully converted the input into
+ * the required target type.
+ * </p>
+ *
+ * @return a sorted list of registered PropertySources per type.
+ */
+ <T> List<PropertyConverter<T>> getPropertyConverters(Class<T> type);
+
+ /**
+ * Access the current PropertyFilter instances.
+ * @return the list of registered PropertyFilters, never null.
+ */
+ List<PropertyFilter> getPropertyFilters();
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/main/java/org/apache/tamaya/spi/PropertyConverter.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/spi/PropertyConverter.java b/java7/api/src/main/java/org/apache/tamaya/spi/PropertyConverter.java
new file mode 100644
index 0000000..167e0a8
--- /dev/null
+++ b/java7/api/src/main/java/org/apache/tamaya/spi/PropertyConverter.java
@@ -0,0 +1,41 @@
+/*
+ * 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.spi;
+
+
+/**
+ * Interface for an property that converts a configured String into something else.
+ * This is used for implementing type conversion from a property (String) to a certain target
+ * type. Hereby the target type can be multivalued (eg collections) or complex if needed.
+ */
+public interface PropertyConverter<T>{
+
+ /**
+ * Convert the given configuration keys from it' String representation into the required target type.
+ * @param value the configuration keys
+ * @return converted keys
+ */
+ T convert(String value);
+
+ //X TODO probably add some diagnostic info which explains what kind of
+ //X format(s) is supported.
+ //X This could be useful if e.g. no converter in the chain felt responsible
+ //X because a wrongly formatted configuration string had been used.
+ //X This could probably also be handled via an additional Annotation on the converter.
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java b/java7/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java
new file mode 100644
index 0000000..55f4295
--- /dev/null
+++ b/java7/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java
@@ -0,0 +1,49 @@
+/*
+ * 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.spi;
+
+
+/**
+ * <p>Interface for filtering the current map of properties during the evaluation of the chain of PropertySources.
+ * Filters can be registered using the {@link org.apache.tamaya.spi.ServiceContext}. The ordinal
+ * hereby is defined by the corresponding {@code @Priority} annotation.</p>
+ * <p>Filters </p>
+ */
+public interface PropertyFilter {
+
+ /**
+ * <p>Maps the current {@code valueToBeFiltered} value to a new value. The resulting value will be used as the result
+ * passed to the user.</p>
+ * <p>If a filter is currently not available, it should just pass the input map to the method's
+ * output.</p>
+ * <p>Returning {@code null} will remove the entry.</p>
+ * <h3>Implementation specification</h3>
+ * Implementations of this class must be
+ * <ul>
+ * <li>reentrant</li>
+ * <li>thread-safe</li>
+ * </ul>
+ *
+ * @param key the key accessed, not null.
+ * @param valueToBeFiltered the value to be filtered, not null.
+ * @return the filtered value, or {@code null} if the value should be removed alltogether.
+ */
+ String filterProperty(String key, String valueToBeFiltered);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/spi/PropertySource.java b/java7/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
new file mode 100644
index 0000000..4457919
--- /dev/null
+++ b/java7/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
@@ -0,0 +1,125 @@
+/*
+* 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.spi;
+
+
+import java.util.Map;
+
+
+/**
+ * This interface models a provider that serves configuration properties. The contained
+ * properties may be read fromMap single or several sources (composite).<br/>
+ * PropertySources are the building blocks of the final configuration.
+ * <p/>
+ * <h3>Implementation Requirements</h3>
+ * <p></p>Implementations current this interface must be
+ * <ul>
+ * <li>Thread safe.</li>
+ * </ul>
+ * </p>
+ * <p>
+ * <p>A PropertySourceProvider will get picked up via the
+ * {@link java.util.ServiceLoader} mechanism and can be registered via
+ * META-INF/services/org.apache.tamaya.spi.PropertySource
+ * </p>
+ * <p>
+ * If you like to register multiple PropertySources at the same time
+ * you can use the {@link org.apache.tamaya.spi.PropertySourceProvider}
+ * interface.
+ * </p>
+ */
+public interface PropertySource {
+
+ /**
+ * property name to override default tamaya ordinals
+ */
+ static final String TAMAYA_ORDINAL = "tamaya.ordinal";
+
+
+ /**
+ * Lookup order:
+ * TODO rethink whole default PropertySources and ordering:
+ * TODO introduce default values or constants for ordinals
+ * <ol>
+ * <li>System properties (ordinal 400)</li>
+ * <li>Environment properties (ordinal 300)</li>
+ * <li>JNDI values (ordinal 200)</li>
+ * <li>Properties file values (/META-INF/applicationConfiguration.properties) (ordinal 100)</li>
+ * </ol>
+ * <p/>
+ * <p><b>Important Hints for custom implementations</b>:</p>
+ * <p>
+ * If a custom implementation should be invoked <b>before</b> the default implementations, use a value > 400
+ * </p>
+ * <p>
+ * If a custom implementation should be invoked <b>after</b> the default implementations, use a value < 100
+ * </p>
+ * <p/>
+ * <p>Reordering of the default order of the config-sources:</p>
+ * <p>Example: If the properties file/s should be used <b>before</b> the other implementations,
+ * you have to configure an ordinal > 400. That means, you have to add e.g. deltaspike_ordinal=401 to
+ * /META-INF/apache-deltaspike.properties . Hint: In case of property files every file is handled as independent
+ * config-source, but all of them have ordinal 400 by default (and can be reordered in a fine-grained manner.</p>
+ *
+ * @return the 'importance' aka ordinal of the configured values. The higher, the more important.
+ * //X TODO think about making this a default method which returns default priority
+ */
+ int getOrdinal();
+
+
+ /**
+ * Get the name of the property source. The name should be unique for the type of source, whereas the id is used
+ * to ensure unique identity, either locally or remotely.
+ * @return the configuration's name, never null.
+ */
+ String getName();
+
+ /**
+ * Access a property.
+ *
+ * //X TODO discuss if the key can be null
+ * @param key the property's key, not null.
+ * @return the property's keys.
+ */
+ String get(String key);
+
+ /**
+ * Access the current properties as Map. The resulting Map may not return all items accessible, e.g.
+ * when the underlying storage does not support iteration of its entries.
+ *
+ * @return the a corresponding map, never null.
+ * //X TODO or should we just do getPropertyKeys()? Think about security (key) vs easier merging (full map)?
+ */
+ Map<String,String> getProperties();
+
+ /**
+ * Determines if this config source could be scanned for its list of properties.
+ *
+ * <p>
+ * PropertySources which are not scannable might not be able to find all the
+ * configured values to provide via {@link #getProperties()}. This can e.g. happen
+ * if the underlying storage doesn't support listing.
+ * </p>
+ *
+ * @return {@code true} if this PropertySource could be scanned for its list of properties,
+ * {@code false} if it should not be scanned.
+ */
+ boolean isScannable();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/main/java/org/apache/tamaya/spi/PropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/spi/PropertySourceProvider.java b/java7/api/src/main/java/org/apache/tamaya/spi/PropertySourceProvider.java
new file mode 100644
index 0000000..42e3b4d
--- /dev/null
+++ b/java7/api/src/main/java/org/apache/tamaya/spi/PropertySourceProvider.java
@@ -0,0 +1,43 @@
+/*
+ * 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.spi;
+
+import java.util.Collection;
+
+/**
+ * <p>Implement this interfaces to provide a PropertySource provider which
+ * is able to register multiple PropertySources. This is e.g. needed if
+ * there are multiple property files of a given config file name.</p>
+ *
+ * <p>If a PropertySource like JNDI only exists once, then there is no need
+ * to implement it via the PropertySourceProvider but should directly
+ * expose a {@link PropertySource}.</p>
+ *
+ * <p>A PropertySourceProvider will get picked up via the
+ * {@link java.util.ServiceLoader} mechanism and must get registered via
+ * META-INF/services/org.apache.tamaya.spi.PropertySourceProvider</p>
+ */
+public interface PropertySourceProvider {
+
+ /**
+ * @return For each e.g. property file, we return a single PropertySource
+ * or an empty list if no PropertySource exists.
+ */
+ Collection<PropertySource> getPropertySources();
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java b/java7/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java
new file mode 100644
index 0000000..ad73575
--- /dev/null
+++ b/java7/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java
@@ -0,0 +1,57 @@
+/*
+ * 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.spi;
+
+import java.util.List;
+
+
+/**
+ * This class models the component that is managing the lifecycle current the
+ * services used by the Configuration API.
+ */
+public interface ServiceContext {
+
+ /**
+ * @return ordinal of the ServiceContext. The one with the highest ordinal will be taken.
+ */
+ int ordinal();
+
+ /**
+ * Access a service singleton via its type.
+ * If multiple implementations for the very serviceType exist then
+ * the one with the highest {@link javax.annotation.Priority} will be used.
+ *
+ * @param serviceType the service type.
+ * @return The instance to be used, never {@code null}
+ * @throws org.apache.tamaya.ConfigException if there are multiple service implementations with the maximum priority.
+ */
+ <T> T getService(Class<T> serviceType);
+
+ /**
+ * Access a list current services, given its type. The bootstrap mechanism should
+ * order the instance for precedence, hereby the most significant should be
+ * first in order.
+ *
+ * @param serviceType
+ * the service type.
+ * @return The instance to be used, never {@code null}
+ */
+ <T> List<T> getServices(Class<T> serviceType);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/main/java/org/apache/tamaya/spi/ServiceContextManager.java
----------------------------------------------------------------------
diff --git a/java7/api/src/main/java/org/apache/tamaya/spi/ServiceContextManager.java b/java7/api/src/main/java/org/apache/tamaya/spi/ServiceContextManager.java
new file mode 100644
index 0000000..11648a4
--- /dev/null
+++ b/java7/api/src/main/java/org/apache/tamaya/spi/ServiceContextManager.java
@@ -0,0 +1,109 @@
+/*
+ * 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.spi;
+
+import java.util.Objects;
+import java.util.ServiceLoader;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.tamaya.ConfigException;
+
+
+/**
+ * This singleton provides access to the services available in the current {@link ServiceContext}. The
+ * behaviour can be adapted, by calling {@link ServiceContextManager#set(ServiceContext)} before accessing any
+ * services.
+ */
+public final class ServiceContextManager {
+ /**
+ * The ServiceProvider used.
+ */
+ private static volatile ServiceContext serviceContextProviderDelegate;
+
+ /**
+ * Private singletons constructor.
+ */
+ private ServiceContextManager() {
+ }
+
+ /**
+ * Load the {@link ServiceContext} to be used.
+ *
+ * @return {@link ServiceContext} to be used for loading the services.
+ */
+ private static ServiceContext loadDefaultServiceProvider() {
+ ServiceContext highestServiceContext = null;
+ try {
+ int highestOrdinal = 0;
+ for (ServiceContext serviceContext : ServiceLoader.load(ServiceContext.class)) {
+ if (serviceContext.ordinal() > highestOrdinal) {
+ highestServiceContext = serviceContext;
+ }
+ }
+ } catch (Exception e) {
+ throw new ConfigException("ServiceContext not loadable", e);
+ }
+ if(highestServiceContext==null){
+ throw new ConfigException("No ServiceContext found");
+ }
+ return highestServiceContext;
+ }
+
+ /**
+ * Replace the current {@link ServiceContext} in use.
+ *
+ * @param serviceContextProvider the new {@link ServiceContext}, not null.
+ */
+ public static ServiceContext set(ServiceContext serviceContextProvider) {
+ ServiceContext currentContext = ServiceContextManager.serviceContextProviderDelegate;
+ Objects.requireNonNull(serviceContextProvider);
+ synchronized (ServiceContextManager.class) {
+ if (ServiceContextManager.serviceContextProviderDelegate == null) {
+ ServiceContextManager.serviceContextProviderDelegate = serviceContextProvider;
+ Logger.getLogger(ServiceContextManager.class.getName())
+ .log(Level.INFO, "Using ServiceProvider: " + serviceContextProvider.getClass().getName());
+ } else {
+ Logger.getLogger(ServiceContextManager.class.getName())
+ .log(Level.WARNING, "Replacing ServiceProvider " +
+ ServiceContextManager.serviceContextProviderDelegate.getClass().getName() +
+ " with: " + serviceContextProvider.getClass().getName());
+ ServiceContextManager.serviceContextProviderDelegate = serviceContextProvider;
+ }
+ }
+ return currentContext;
+ }
+
+ /**
+ * Ge {@link ServiceContext}. If necessary the {@link ServiceContext} will be laziliy loaded.
+ *
+ * @return the {@link ServiceContext} used.
+ */
+ public static ServiceContext getServiceContext() {
+ if (serviceContextProviderDelegate == null) {
+ synchronized (ServiceContextManager.class) {
+ if (serviceContextProviderDelegate == null) {
+ serviceContextProviderDelegate = loadDefaultServiceProvider();
+ }
+ }
+ }
+ return serviceContextProviderDelegate;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/java7/api/src/test/java/org/apache/tamaya/ConfigurationTest.java b/java7/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
new file mode 100644
index 0000000..11a16b9
--- /dev/null
+++ b/java7/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ * Test class that tests the default methods implemented on {@link org.apache.tamaya.Configuration}. The provided
+ * {@link org.apache.tamaya.TestConfiguration} is implemeted with maximal use of the default methods.
+ */
+public class ConfigurationTest {
+
+ @Test
+ public void testget() throws Exception {
+ assertEquals(Boolean.TRUE, ConfigurationProvider.getConfiguration().get("booleanTrue", Boolean.class));
+ assertEquals(Boolean.FALSE, ConfigurationProvider.getConfiguration().get("booleanFalse", Boolean.class));
+ assertEquals((int)Byte.MAX_VALUE, (int)ConfigurationProvider.getConfiguration().get("byte", Byte.class));
+ assertEquals((int)Integer.MAX_VALUE, (int)ConfigurationProvider.getConfiguration().get("int", Integer.class));
+ assertEquals((long)Long.MAX_VALUE, (long)ConfigurationProvider.getConfiguration().get("long", Long.class));
+ assertEquals((double)Float.MAX_VALUE, (double)ConfigurationProvider.getConfiguration().get("float", Float.class), 0.0d);
+ assertEquals((double)Double.MAX_VALUE, (double)ConfigurationProvider.getConfiguration().get("double", Double.class), 0.0d);
+ }
+
+ @Test
+ public void testGetBoolean() throws Exception {
+ assertTrue(ConfigurationProvider.getConfiguration().get("booleanTrue", Boolean.class));
+ assertFalse(ConfigurationProvider.getConfiguration().get("booleanFalse", Boolean.class));
+ assertFalse(ConfigurationProvider.getConfiguration().get("foorBar", Boolean.class));
+ }
+
+ @Test
+ public void testGetInteger() throws Exception {
+ assertEquals(Integer.MAX_VALUE,(int) ConfigurationProvider.getConfiguration().get("int", Integer.class));
+ }
+
+ @Test
+ public void testGetLong() throws Exception {
+ assertEquals(Long.MAX_VALUE,(long) ConfigurationProvider.getConfiguration().get("long", Long.class));
+ }
+
+ @Test
+ public void testGetDouble() throws Exception {
+ assertEquals(Double.MAX_VALUE,(double) ConfigurationProvider.getConfiguration().get("double", Double.class), 0.0d);
+ }
+
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/test/java/org/apache/tamaya/TestConfiguration.java
----------------------------------------------------------------------
diff --git a/java7/api/src/test/java/org/apache/tamaya/TestConfiguration.java b/java7/api/src/test/java/org/apache/tamaya/TestConfiguration.java
new file mode 100644
index 0000000..863bd93
--- /dev/null
+++ b/java7/api/src/test/java/org/apache/tamaya/TestConfiguration.java
@@ -0,0 +1,86 @@
+/*
+ * 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;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Test Configuration class, that is used to testdata the default methods provided by the API.
+ */
+public class TestConfiguration implements Configuration{
+
+ private static final Map<String, String> VALUES;
+ static {
+ VALUES = new HashMap<String, String>();
+ VALUES.put("long", String.valueOf(Long.MAX_VALUE));
+ VALUES.put("int", String.valueOf(Integer.MAX_VALUE));
+ VALUES.put("double", String.valueOf(Double.MAX_VALUE));
+ VALUES.put("float", String.valueOf(Float.MAX_VALUE));
+ VALUES.put("short", String.valueOf(Short.MAX_VALUE));
+ VALUES.put("byte", String.valueOf(Byte.MAX_VALUE));
+ VALUES.put("booleanTrue", "true");
+ VALUES.put("booleanFalse", "false");
+ VALUES.put("String", "aStringValue");
+ }
+
+ @Override
+ public String get(String key) {
+ return VALUES.get(key);
+ }
+
+ @Override
+ public <T> T get(String key, Class<T> type) {
+ if(type.equals(Long.class)){
+ return (T)(Object)Long.MAX_VALUE;
+ }
+ else if(type.equals(Integer.class)){
+ return (T)(Object) Integer.MAX_VALUE;
+ }
+ else if(type.equals(Double.class)){
+ return (T)(Object) Double.MAX_VALUE;
+ }
+ else if(type.equals(Float.class)){
+ return (T)(Object) Float.MAX_VALUE;
+ }
+ else if(type.equals(Short.class)){
+ return (T)(Object) Short.MAX_VALUE;
+ }
+ else if(type.equals(Byte.class)){
+ return (T)(Object) Byte.MAX_VALUE;
+ }
+ else if(type.equals(Boolean.class)){
+ if("booleanTrue".equals(key)) {
+ return (T)(Object) Boolean.TRUE;
+ }
+ else{
+ return (T)(Object) Boolean.FALSE;
+ }
+ }
+ else if(type.equals(String.class)){
+ return (T)(Object) "aStringValue";
+ }
+ throw new ConfigException("No such property: " + key);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java
----------------------------------------------------------------------
diff --git a/java7/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java b/java7/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java
new file mode 100644
index 0000000..0269c4c
--- /dev/null
+++ b/java7/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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.spi;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+
+public class ServiceContextTest {
+
+ private ServiceContext serviceContext = new ServiceContext(){
+
+ @Override
+ public int ordinal() {
+ return 1;
+ }
+
+ @Override
+ public <T> T getService(Class<T> serviceType) {
+ if(String.class.equals(serviceType)){
+ return serviceType.cast("ServiceContextTest");
+ }
+ return null;
+ }
+
+ @Override
+ public <T> List<T> getServices(Class<T> serviceType) {
+ if(String.class.equals(serviceType)){
+ List<String> list = new ArrayList<>();
+ list.add("ServiceContextTest");
+ return List.class.cast(list);
+ }
+ return Collections.EMPTY_LIST;
+ }
+ };
+
+ @Test
+ public void testOrdinal() throws Exception {
+ assertEquals(1, serviceContext.ordinal());
+ }
+
+ @Test
+ public void testgetService() throws Exception {
+ assertEquals("ServiceContextTest", serviceContext.getService(String.class));
+ assertNull(serviceContext.getService(Integer.class));
+ }
+
+ @Test
+ public void testGetService() throws Exception {
+ String service = serviceContext.getService(String.class);
+ assertNotNull(service);
+ assertEquals("ServiceContextTest", service);
+ Integer intService = serviceContext.getService(Integer.class);
+ assertNull(intService);
+ }
+
+ @Test
+ public void testGetServices() throws Exception {
+ Collection<String> services = serviceContext.getServices(String.class);
+ assertNotNull(services);
+ assertFalse(services.isEmpty());
+ assertEquals("ServiceContextTest", services.iterator().next());
+ Collection<Integer> intServices = serviceContext.getServices(Integer.class);
+ assertNotNull(intServices);
+ assertTrue(intServices.isEmpty());
+ }
+
+ @Test
+ public void testGetInstance() throws Exception {
+ assertNotNull(ServiceContextManager.getServiceContext());
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java
----------------------------------------------------------------------
diff --git a/java7/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java b/java7/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java
new file mode 100644
index 0000000..8790945
--- /dev/null
+++ b/java7/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java
@@ -0,0 +1,89 @@
+/*
+ * 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.spi;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.ServiceLoader;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * This class implements the (default) {@link org.apache.tamaya.spi.ServiceContext} interface and hereby uses the JDK
+ * {@link java.util.ServiceLoader} to load the services required.
+ */
+public final class TestServiceContext implements ServiceContext {
+ /** List current services loaded, per class. */
+ private final ConcurrentHashMap<Class, List<Object>> servicesLoaded = new ConcurrentHashMap<>();
+
+ private final Map<Class, Object> singletons = new ConcurrentHashMap<>();
+
+ @Override
+ public int ordinal() {
+ return 1;
+ }
+
+ @Override
+ public <T> T getService(Class<T> serviceType) {
+ T cached = (T) singletons.get(serviceType);
+ if(cached==null) {
+ List<? extends T> services = getServices(serviceType);
+ if (services.isEmpty()) {
+ cached = (T) Object.class; // as marker for 'nothing here'
+ }
+ else{
+ cached = services.get(0);
+ }
+ singletons.put((Class)serviceType, cached);
+ }
+ if (cached == Object.class) {
+ cached = null;
+ }
+ return cached;
+ }
+
+ /**
+ * Loads and registers services.
+ *
+ * @param serviceType The service type.
+ * @param <T> the concrete type.
+ *
+ * @return the items found, never {@code null}.
+ */
+ @Override
+ public <T> List<T> getServices(Class<T> serviceType) {
+ try {
+ List<T> services = new ArrayList<>();
+ for (T t : ServiceLoader.load(serviceType)) {
+ services.add(t);
+ }
+ services = Collections.unmodifiableList(services);
+ final List<T> previousServices = List.class.cast(servicesLoaded.putIfAbsent(serviceType, (List<Object>)services));
+ return previousServices != null ? previousServices : services;
+ } catch (Exception e) {
+ Logger.getLogger(TestServiceContext.class.getName()).log(Level.WARNING,
+ "Error loading services current type " + serviceType, e);
+ return Collections.EMPTY_LIST;
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.Configuration
----------------------------------------------------------------------
diff --git a/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.Configuration b/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.Configuration
new file mode 100644
index 0000000..1f42438
--- /dev/null
+++ b/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.Configuration
@@ -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.TestConfiguration
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
----------------------------------------------------------------------
diff --git a/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext b/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
new file mode 100644
index 0000000..0f7abe9
--- /dev/null
+++ b/java7/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
@@ -0,0 +1 @@
+org.apache.tamaya.spi.TestServiceContext
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java7/pom.xml
----------------------------------------------------------------------
diff --git a/java7/pom.xml b/java7/pom.xml
new file mode 100644
index 0000000..df137c2
--- /dev/null
+++ b/java7/pom.xml
@@ -0,0 +1,68 @@
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-all</artifactId>
+ <version>0.2-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>tamaya-java7</artifactId>
+ <packaging>pom</packaging>
+
+ <properties>
+ <jdkVersion>1.7</jdkVersion>
+ </properties>
+
+ <modules>
+ <module>api</module>
+<!--
+ <module>core</module>
+-->
+ </modules>
+
+ <build>
+ <plugins>
+ <plugin>
+ <!-- use java7 to compile the modules in this tree -->
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-toolchains-plugin</artifactId>
+ <version>1.1</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>toolchain</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <toolchains>
+ <jdk>
+ <version>[1.7,)</version>
+ </jdk>
+ </toolchains>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/api/src/main/java/org/apache/tamaya/Configuration.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/Configuration.java b/java8/api/src/main/java/org/apache/tamaya/Configuration.java
index 2786af7..d5bd4f7 100644
--- a/java8/api/src/main/java/org/apache/tamaya/Configuration.java
+++ b/java8/api/src/main/java/org/apache/tamaya/Configuration.java
@@ -48,17 +48,34 @@ public interface Configuration {
* Access a property.
*
* @param key the property's key, not null.
- * @return the property's keys.
+ * @return the property's value or {@code null}.
*/
- Optional<String> get(String key);
+ default String get(String key) {
+ return getOptional(key).orElse(null);
+ }
/**
- * Access all current known Configuration properties as a full {@code Map<String,String>}.
- * Be aware that entries from non scannable parts of the registered {@link org.apache.tamaya.spi.PropertySource}
- * instances may not be contained in the result, but nevertheless be accessible calling one of the
- * {@code get(...)} methods.
+ * Get the property keys as type T. This will implicitly require a corresponding {@link
+ * org.apache.tamaya.spi.PropertyConverter} to be available that is capable current providing type T
+ * fromMap the given String keys.
+ *
+ * @param key the property's absolute, or relative path, e.g. @code
+ * a/b/c/d.myProperty}.
+ * @param type The target type required, not null.
+ * @return the property value, never null..
+ * @throws ConfigException if the keys could not be converted to the required target type.
*/
- Map<String,String> getProperties();
+ default <T> T get(String key, Class<T> type) {
+ return getOptional(key, type).orElse(null);
+ }
+
+ /**
+ * Access a property.
+ *
+ * @param key the property's key, not null.
+ * @return the property's keys.
+ */
+ Optional<String> getOptional(String key);
/**
* Get the property keys as type T. This will implicitly require a corresponding {@link
@@ -69,10 +86,17 @@ public interface Configuration {
* a/b/c/d.myProperty}.
* @param type The target type required, not null.
* @return the property value, never null..
- * @throws ConfigException if the keys could not be converted to the required target
- * type.
+ * @throws ConfigException if the keys could not be converted to the required target type.
*/
- <T> Optional<T> get(String key, Class<T> type);
+ <T> Optional<T> getOptional(String key, Class<T> type);
+
+ /**
+ * Access all current known Configuration properties as a full {@code Map<String,String>}.
+ * Be aware that entries from non scannable parts of the registered {@link org.apache.tamaya.spi.PropertySource}
+ * instances may not be contained in the result, but nevertheless be accessible calling one of the
+ * {@code get(...)} methods.
+ */
+ Map<String,String> getProperties();
/**
* Get the property keys as type {@code Class<T>}.
@@ -92,7 +116,7 @@ public interface Configuration {
* type, or no such property exists.
*/
default <T> Optional<T> get(String key, PropertyConverter<T> converter) {
- Optional<String> value = get(key);
+ Optional<String> value = getOptional(key);
if (value.isPresent()) {
return Optional.ofNullable(converter.convert(value.get()));
}
@@ -109,7 +133,7 @@ public interface Configuration {
* @throws ConfigException if the configured value could not be converted to the target type.
*/
default Boolean getBoolean(String key) {
- Optional<Boolean> val = get(key, Boolean.class);
+ Optional<Boolean> val = getOptional(key, Boolean.class);
if (val.isPresent()) {
return val.get();
}
@@ -125,7 +149,7 @@ public interface Configuration {
* @throws ConfigException if the configured value could not be converted to the target type.
*/
default OptionalInt getInteger(String key) {
- Optional<Integer> val = get(key, Integer.class);
+ Optional<Integer> val = getOptional(key, Integer.class);
if (val.isPresent()){
return OptionalInt.of(val.get());
}
@@ -142,7 +166,7 @@ public interface Configuration {
* @throws ConfigException if the configured value could not be converted to the target type.
*/
default OptionalLong getLong(String key) {
- Optional<Long> val = get(key, Long.class);
+ Optional<Long> val = getOptional(key, Long.class);
if (val.isPresent()){
return OptionalLong.of(val.get());
}
@@ -160,7 +184,7 @@ public interface Configuration {
*/
default OptionalDouble getDouble(String key) {
- Optional<Double> val = get(key, Double.class);
+ Optional<Double> val = getOptional(key, Double.class);
if (val.isPresent()){
return OptionalDouble.of(val.get());
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java b/java8/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
new file mode 100644
index 0000000..199e686
--- /dev/null
+++ b/java8/api/src/main/java/org/apache/tamaya/ConfigurationProvider.java
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+import org.apache.tamaya.spi.ServiceContextManager;
+
+/**
+ * Static access to the {@link org.apache.tamaya.Configuration} for the very application.
+ *
+ * Exists for Java7 backward compatibility
+ */
+public final class ConfigurationProvider {
+ private ConfigurationProvider() {
+ // just to prevent initialisation
+ }
+
+ public static Configuration getConfiguration() {
+ return ServiceContextManager.getServiceContext().getService(Configuration.class).get();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java b/java8/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java
index 50a03dd..d106e70 100644
--- a/java8/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java
+++ b/java8/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java
@@ -42,7 +42,7 @@ public interface PropertyFilter{
*
* @param key the key accessed, not null.
* @param valueToBeFiltered the value to be filtered, not null.
- * @return the filtered map, never null.
+ * @return the filtered value, or {@code null} if the value should be removed alltogether.
*/
String filterProperty(String key, String valueToBeFiltered);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/spi/PropertySource.java b/java8/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
index ae80159..350759e 100644
--- a/java8/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
+++ b/java8/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
@@ -20,7 +20,6 @@ package org.apache.tamaya.spi;
import java.util.Map;
-import java.util.Optional;
/**
@@ -96,9 +95,9 @@ public interface PropertySource {
*
* //X TODO discuss if the key can be null
* @param key the property's key, not null.
- * @return the property's keys.
+ * @return the value assigned to the property or {@code null}. An empty String will kind of 'erase' previous values.
*/
- Optional<String> get(String key);
+ String get(String key);
/**
* Access the current properties as Map. The resulting Map may not return all items accessible, e.g.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/api/src/main/java/org/apache/tamaya/spi/ServiceContextManager.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/spi/ServiceContextManager.java b/java8/api/src/main/java/org/apache/tamaya/spi/ServiceContextManager.java
index 68e7552..11648a4 100644
--- a/java8/api/src/main/java/org/apache/tamaya/spi/ServiceContextManager.java
+++ b/java8/api/src/main/java/org/apache/tamaya/spi/ServiceContextManager.java
@@ -31,7 +31,7 @@ import org.apache.tamaya.ConfigException;
* behaviour can be adapted, by calling {@link ServiceContextManager#set(ServiceContext)} before accessing any
* services.
*/
-final class ServiceContextManager {
+public final class ServiceContextManager {
/**
* The ServiceProvider used.
*/
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
----------------------------------------------------------------------
diff --git a/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java b/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
index cdcb0e9..459cb9f 100644
--- a/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
+++ b/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
@@ -25,7 +25,7 @@ import java.util.Optional;
/**
* Test Configuration class, that is used to testdata the default methods provided by the API.
*/
-public class TestConfiguration implements Configuration{
+public class TestConfiguration implements Configuration {
private static final Map<String, String> VALUES;
static {
@@ -42,12 +42,12 @@ public class TestConfiguration implements Configuration{
}
@Override
- public Optional<String> get(String key) {
+ public Optional<String> getOptional(String key) {
return Optional.ofNullable(VALUES.get(key));
}
@Override
- public <T> Optional<T> get(String key, Class<T> type) {
+ public <T> Optional<T> getOptional(String key, Class<T> type) {
if(type.equals(Long.class)){
return Optional.class.cast(Optional.ofNullable(Long.MAX_VALUE));
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
index ec23e25..a0bf190 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
@@ -68,13 +68,13 @@ public class DefaultConfiguration implements Configuration {
* @return the optional configuration value, never null.
*/
@Override
- public Optional<String> get(String key) {
+ public Optional<String> getOptional(String key) {
List<PropertySource> propertySources = configurationContext.getPropertySources();
String unfilteredValue = null;
for (PropertySource propertySource : propertySources) {
- Optional<String> value = propertySource.get(key);
- if (value.isPresent()) {
- unfilteredValue = value.get();
+ String value = propertySource.get(key);
+ if (value != null) {
+ unfilteredValue = value.length() > 0 ? value : null;
break;
}
}
@@ -193,7 +193,7 @@ public class DefaultConfiguration implements Configuration {
}
/**
- * Accesses the current String value for the given key (see {@link #get(String)}) and tries to convert it
+ * Accesses the current String value for the given key (see {@link #getOptional(String)}) and tries to convert it
* using the {@link org.apache.tamaya.spi.PropertyConverter} instances provided by the current
* {@link org.apache.tamaya.spi.ConfigurationContext}.
*
@@ -204,8 +204,8 @@ public class DefaultConfiguration implements Configuration {
* @return the converted value, never null.
*/
@Override
- public <T> Optional<T> get(String key, Class<T> type) {
- Optional<String> value = get(key);
+ public <T> Optional<T> getOptional(String key, Class<T> type) {
+ Optional<String> value = getOptional(key);
if (value.isPresent()) {
List<PropertyConverter<T>> converters = configurationContext.getPropertyConverters(type);
for (PropertyConverter<T> converter : converters) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java b/java8/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
index e58be54..7fe3a46 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/propertysource/BasePropertySource.java
@@ -21,7 +21,6 @@ package org.apache.tamaya.core.propertysource;
import org.apache.tamaya.spi.PropertySource;
import java.util.Objects;
-import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -45,9 +44,9 @@ public abstract class BasePropertySource implements PropertySource {
@Override
- public Optional<String> get(String key) {
+ public String get(String key) {
Objects.requireNonNull(key, "key must not be null");
- return Optional.ofNullable(getProperties().get(key));
+ return getProperties().get(key);
}
@@ -62,15 +61,15 @@ public abstract class BasePropertySource implements PropertySource {
protected void initializeOrdinal(final int defaultOrdinal) {
this.ordinal = defaultOrdinal;
- Optional<String> ordinal = get(PropertySource.TAMAYA_ORDINAL);
- if (ordinal.isPresent()) {
+ String ordinal = get(PropertySource.TAMAYA_ORDINAL);
+ if (ordinal != null) {
try {
- this.ordinal = Integer.valueOf(ordinal.get());
+ this.ordinal = Integer.valueOf(ordinal);
} catch (NumberFormatException e) {
LOG.log(Level.WARNING,
"Specified {0} is not a valid Integer value: {1} - using defaultOrdinal {2}",
- new Object[]{PropertySource.TAMAYA_ORDINAL, ordinal.get(), defaultOrdinal});
+ new Object[]{PropertySource.TAMAYA_ORDINAL, ordinal, defaultOrdinal});
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java b/java8/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
index 5a6fc70..c2ddbf8 100644
--- a/java8/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
+++ b/java8/core/src/test/java/org/apache/tamaya/core/ConfigurationTest.java
@@ -37,17 +37,17 @@ public class ConfigurationTest {
@Test
public void testContent(){
- assertEquals("Robin", Configuration.current().get("name").get());
- assertEquals("Sabine", Configuration.current().get("name2").get()); // from default
- assertEquals("Mapped to name: Robin", Configuration.current().get("name3").get()); // oderridden default, mapped by filter to name property
- assertEquals("Sereina(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)", Configuration.current().get("name4").get()); // final only
- assertNull(Configuration.current().get("name5").orElse(null)); // final only, but removed from filter
-
- System.out.println("name : " + Configuration.current().get("name").get());
- System.out.println("name2: " + Configuration.current().get("name2").get());
- System.out.println("name3: " + Configuration.current().get("name3").get());
- System.out.println("name4: " + Configuration.current().get("name4").get());
- System.out.println("name5: " + Configuration.current().get("name5").orElse(null));
+ assertEquals("Robin", Configuration.current().getOptional("name").get());
+ assertEquals("Sabine", Configuration.current().getOptional("name2").get()); // from default
+ assertEquals("Mapped to name: Robin", Configuration.current().getOptional("name3").get()); // oderridden default, mapped by filter to name property
+ assertEquals("Sereina(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)(filtered)", Configuration.current().getOptional("name4").get()); // final only
+ assertNull(Configuration.current().getOptional("name5").orElse(null)); // final only, but removed from filter
+
+ System.out.println("name : " + Configuration.current().getOptional("name").get());
+ System.out.println("name2: " + Configuration.current().getOptional("name2").get());
+ System.out.println("name3: " + Configuration.current().getOptional("name3").get());
+ System.out.println("name4: " + Configuration.current().getOptional("name4").get());
+ System.out.println("name5: " + Configuration.current().getOptional("name5").orElse(null));
System.out.println("ALL :");
Configuration.current().getProperties().entrySet().forEach(e ->
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java b/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java
index d6dc867..1a6a33c 100644
--- a/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java
+++ b/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/BasePropertySourceTest.java
@@ -27,7 +27,6 @@ import org.junit.Test;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import java.util.Optional;
public class BasePropertySourceTest {
@@ -42,8 +41,8 @@ public class BasePropertySourceTest {
}
@Override
- public Optional<String> get(String key) {
- return Optional.ofNullable(null);
+ public String get(String key) {
+ return null;
}
@Override
@@ -61,7 +60,7 @@ public class BasePropertySourceTest {
@Test
public void testGet() {
- Assert.assertEquals("1000", new OverriddenOrdinalPropertySource().get(PropertySource.TAMAYA_ORDINAL).get());
+ Assert.assertEquals("1000", new OverriddenOrdinalPropertySource().get(PropertySource.TAMAYA_ORDINAL));
}
private static class OverriddenOrdinalPropertySource extends BasePropertySource {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java b/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
index 6a1c9e7..6ad7790 100644
--- a/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
+++ b/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/PropertiesFilePropertySourceTest.java
@@ -46,15 +46,15 @@ public class PropertiesFilePropertySourceTest {
@Test
public void testGetOrdinal() {
Assert.assertEquals(DefaultOrdinal.FILE_PROPERTIES, testfilePropertySource.getOrdinal());
- Assert.assertEquals(Integer.parseInt(overrideOrdinalPropertySource.get(PropertySource.TAMAYA_ORDINAL).get()), overrideOrdinalPropertySource.getOrdinal());
+ Assert.assertEquals(Integer.parseInt(overrideOrdinalPropertySource.get(PropertySource.TAMAYA_ORDINAL)), overrideOrdinalPropertySource.getOrdinal());
}
@Test
public void testGet() {
- Assert.assertEquals("val3", testfilePropertySource.get("key3").get());
- Assert.assertEquals("myval5", overrideOrdinalPropertySource.get("mykey5").get());
- Assert.assertFalse(testfilePropertySource.get("nonpresentkey").isPresent());
+ Assert.assertEquals("val3", testfilePropertySource.get("key3"));
+ Assert.assertEquals("myval5", overrideOrdinalPropertySource.get("mykey5"));
+ Assert.assertNull(testfilePropertySource.get("nonpresentkey"));
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java b/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java
index a7712db..5495595 100644
--- a/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java
+++ b/java8/core/src/test/java/org/apache/tamaya/core/test/propertysource/SystemPropertySourceTest.java
@@ -25,7 +25,6 @@ import org.junit.Assert;
import org.junit.Test;
import java.util.Map;
-import java.util.Optional;
import java.util.Properties;
public class SystemPropertySourceTest {
@@ -56,10 +55,10 @@ public class SystemPropertySourceTest {
public void testGet() throws Exception {
String propertyKeyToCheck = System.getProperties().stringPropertyNames().iterator().next();
- Optional<String> property = testPropertySource.get(propertyKeyToCheck);
+ String property = testPropertySource.get(propertyKeyToCheck);
Assert.assertTrue("Property '" + propertyKeyToCheck + "' is not present in " + SystemPropertySource.class.getSimpleName(),
- property.isPresent());
- Assert.assertEquals(System.getProperty(propertyKeyToCheck), property.get());
+ property != null);
+ Assert.assertEquals(System.getProperty(propertyKeyToCheck), property);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java b/java8/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
index 5c5fefc..ae9dccb 100644
--- a/java8/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
+++ b/java8/core/src/test/java/org/apache/tamaya/core/test/provider/JavaConfigurationProviderTest.java
@@ -41,11 +41,11 @@ public class JavaConfigurationProviderTest {
String key = "confkey" + i;
String value = "javaconf-value" + i;
- Assert.assertEquals(value, propertySource.get(key).get());
+ Assert.assertEquals(value, propertySource.get(key));
// check if we had our key in configuration.current
Assert.assertTrue(Configuration.current().getProperties().containsKey(key));
- Assert.assertEquals(value, Configuration.current().get(key).get());
+ Assert.assertEquals(value, Configuration.current().getOptional(key).get());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/java8/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java
----------------------------------------------------------------------
diff --git a/java8/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java b/java8/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java
index 0244d6a..4667ca6 100644
--- a/java8/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java
+++ b/java8/core/src/test/java/org/apache/tamaya/core/testdata/TestPropertyFilterRemoving.java
@@ -22,7 +22,6 @@ import org.apache.tamaya.Configuration;
import org.apache.tamaya.spi.PropertyFilter;
import javax.annotation.Priority;
-import java.util.function.Function;
/**
* Simple PropertyFilter that filters exact one value, registered using ServiceLoader.
@@ -35,7 +34,7 @@ public class TestPropertyFilterRemoving implements PropertyFilter{
return null;
}
else if("name3".equals(key)){
- return "Mapped to name: " + Configuration.current().get("name").orElse("NoName found!");
+ return "Mapped to name: " + Configuration.current().getOptional("name").orElse("NoName found!");
}
return valueToBeFiltered;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesFormat.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesFormat.java b/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesFormat.java
index 6412e77..34c9e21 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesFormat.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesFormat.java
@@ -27,7 +27,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.Optional;
import java.util.Properties;
import java.util.function.Supplier;
import java.util.logging.Level;
@@ -90,8 +89,8 @@ public class PropertiesFormat implements ConfigurationFormat {
}
@Override
- public Optional<String> get(String key) {
- return Optional.ofNullable(p.getProperty(key));
+ public String get(String key) {
+ return p.getProperty(key);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/67855faa/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesXmlFormat.java
----------------------------------------------------------------------
diff --git a/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesXmlFormat.java b/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesXmlFormat.java
index 1de9145..8b3468b 100644
--- a/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesXmlFormat.java
+++ b/modules/formats/src/main/java/org/apache/tamaya/format/PropertiesXmlFormat.java
@@ -27,7 +27,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.Optional;
import java.util.Properties;
import java.util.function.Supplier;
import java.util.logging.Level;
@@ -91,8 +90,8 @@ public class PropertiesXmlFormat implements ConfigurationFormat {
}
@Override
- public Optional<String> get(String key) {
- return Optional.ofNullable(p.getProperty(key));
+ public String get(String key) {
+ return p.getProperty(key);
}
@Override
[4/9] incubator-tamaya git commit: TAMAYA-49 move api and core to
java8 module
Posted by st...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/api/pom.xml
----------------------------------------------------------------------
diff --git a/java8/api/pom.xml b/java8/api/pom.xml
new file mode 100644
index 0000000..6f40b45
--- /dev/null
+++ b/java8/api/pom.xml
@@ -0,0 +1,43 @@
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-java8</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>tamaya-api</artifactId>
+ <description>
+ The API defines a complete SE based API for reading of configuration data.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/api/src/main/java/org/apache/tamaya/ConfigException.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/ConfigException.java b/java8/api/src/main/java/org/apache/tamaya/ConfigException.java
new file mode 100644
index 0000000..bac2ef4
--- /dev/null
+++ b/java8/api/src/main/java/org/apache/tamaya/ConfigException.java
@@ -0,0 +1,44 @@
+/*
+ * 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;
+
+/**
+ * Exception class (runtime exception) for configuration issues.
+ */
+public class ConfigException extends RuntimeException{
+
+ private static final long serialVersionUID = -5886094818057522680L;
+
+ /**
+ * Creates a new configuration exception.
+ * @param message the exception message, not null.
+ */
+ public ConfigException(String message){
+ super(message);
+ }
+
+ /**
+ * Creates a new configuration exception.
+ * @param message the exception message, not null.
+ * @param t the throwable.
+ */
+ public ConfigException(String message, Throwable t){
+ super(message, t);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/api/src/main/java/org/apache/tamaya/Configuration.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/Configuration.java b/java8/api/src/main/java/org/apache/tamaya/Configuration.java
new file mode 100644
index 0000000..2786af7
--- /dev/null
+++ b/java8/api/src/main/java/org/apache/tamaya/Configuration.java
@@ -0,0 +1,204 @@
+/*
+ * 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;
+
+import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.spi.ServiceContext;
+
+import java.util.*;
+import java.util.function.Function;
+import java.util.function.UnaryOperator;
+
+/**
+ * A configuration models a aggregated set current properties, identified by a unique key, but adds higher level access functions to
+ * a {@link org.apache.tamaya.spi.PropertySource}. Hereby in most cases a configuration is a wrapper around a composite
+ * {@link org.apache.tamaya.spi.PropertySource} instance, which may combine multiple child config in well defined tree like structure,
+ * where nodes define logically the rules current priority, filtering, combination and overriding.
+ * <br/>
+ * <h3>Implementation Requirements</h3>
+ * Implementations current this interface must be
+ * <ul>
+ * <li>Thread safe.
+ * <li>Immutable
+ * </ul>
+ * It is not recommended that implementations also are serializable, since the any configuration can be <i>freezed</i>
+ * by reading out its complete configuration map into a serializable and remotable structure. This helps significantly
+ * simplifying the development current this interface, e.g. for being backed up by systems and stores that are not part current
+ * this library at all.
+ */
+public interface Configuration {
+
+ /**
+ * Access a property.
+ *
+ * @param key the property's key, not null.
+ * @return the property's keys.
+ */
+ Optional<String> get(String key);
+
+ /**
+ * Access all current known Configuration properties as a full {@code Map<String,String>}.
+ * Be aware that entries from non scannable parts of the registered {@link org.apache.tamaya.spi.PropertySource}
+ * instances may not be contained in the result, but nevertheless be accessible calling one of the
+ * {@code get(...)} methods.
+ */
+ Map<String,String> getProperties();
+
+ /**
+ * Get the property keys as type T. This will implicitly require a corresponding {@link
+ * org.apache.tamaya.spi.PropertyConverter} to be available that is capable current providing type T
+ * fromMap the given String keys.
+ *
+ * @param key the property's absolute, or relative path, e.g. @code
+ * a/b/c/d.myProperty}.
+ * @param type The target type required, not null.
+ * @return the property value, never null..
+ * @throws ConfigException if the keys could not be converted to the required target
+ * type.
+ */
+ <T> Optional<T> get(String key, Class<T> type);
+
+ /**
+ * Get the property keys as type {@code Class<T>}.
+ * <p>
+ * If {@code Class<T>} is not one current
+ * {@code Boolean, Short, Integer, Long, Float, Double, BigInteger,
+ * BigDecimal, String} , an according converter must be
+ * available to perform the conversion fromMap {@link String} to
+ * {@code Class<T>}.
+ *
+ * @param key the property's absolute, or relative path, e.g. @code
+ * a/b/c/d.myProperty}.
+ * @param converter the PropertyConverter to perform the conversion fromMap
+ * {@link String} to {@code Class<T>}, not {@code null}.
+ * @return the property's keys.
+ * @throws ConfigException if the keys could not be converted to the required target
+ * type, or no such property exists.
+ */
+ default <T> Optional<T> get(String key, PropertyConverter<T> converter) {
+ Optional<String> value = get(key);
+ if (value.isPresent()) {
+ return Optional.ofNullable(converter.convert(value.get()));
+ }
+ return Optional.empty();
+ }
+
+
+ /**
+ * Get the property keys as {@link Boolean}.
+ *
+ * @param key the property's absolute, or relative path, e.g. {@code
+ * a/b/c/d.myProperty}.
+ * @return the property's keys.
+ * @throws ConfigException if the configured value could not be converted to the target type.
+ */
+ default Boolean getBoolean(String key) {
+ Optional<Boolean> val = get(key, Boolean.class);
+ if (val.isPresent()) {
+ return val.get();
+ }
+ return null;
+ }
+
+ /**
+ * Get the property keys as {@link Integer}.
+ *
+ * @param key the property's absolute, or relative path, e.g. @code
+ * a/b/c/d.myProperty}.
+ * @return the property's keys.
+ * @throws ConfigException if the configured value could not be converted to the target type.
+ */
+ default OptionalInt getInteger(String key) {
+ Optional<Integer> val = get(key, Integer.class);
+ if (val.isPresent()){
+ return OptionalInt.of(val.get());
+ }
+ return OptionalInt.empty();
+ }
+
+
+ /**
+ * Get the property keys as {@link Long}.
+ *
+ * @param key the property's absolute, or relative path, e.g. @code
+ * a/b/c/d.myProperty}.
+ * @return the property's keys.
+ * @throws ConfigException if the configured value could not be converted to the target type.
+ */
+ default OptionalLong getLong(String key) {
+ Optional<Long> val = get(key, Long.class);
+ if (val.isPresent()){
+ return OptionalLong.of(val.get());
+ }
+ return OptionalLong.empty();
+ }
+
+
+ /**
+ * Get the property keys as {@link Double}.
+ *
+ * @param key the property's absolute, or relative path, e.g. @code
+ * a/b/c/d.myProperty}.
+ * @return the property's keys.
+ * @throws ConfigException if the configured value could not be converted to the target type.
+ */
+ default OptionalDouble getDouble(String key) {
+
+ Optional<Double> val = get(key, Double.class);
+ if (val.isPresent()){
+ return OptionalDouble.of(val.get());
+ }
+ return OptionalDouble.empty();
+ }
+
+
+ /**
+ * Extension point for adjusting configuration.
+ *
+ * @param operator A configuration operator, e.g. a filter, or an adjuster
+ * combining configurations.
+ * @return the new adjusted configuration, never {@code null}.
+ */
+ default Configuration with(UnaryOperator<Configuration> operator) {
+ return operator.apply(this);
+ }
+
+
+ /**
+ * Query a configuration.
+ *
+ * @param query the query, never {@code null}.
+ * @return the result
+ */
+ default <T> T query(Function<Configuration,T> query) {
+ return query.apply(this);
+ }
+
+
+ /**
+ * Access a configuration.
+ *
+ * @return the corresponding Configuration instance, never null.
+ * @throws ConfigException if no such configuration is defined.
+ */
+ public static Configuration current(){
+ return ServiceContext.getInstance().getService(Configuration.class).get();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java b/java8/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
new file mode 100644
index 0000000..7b51717
--- /dev/null
+++ b/java8/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
@@ -0,0 +1,145 @@
+/*
+ * 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.spi;
+
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Central SPI for programmatically dealing with the setup of the configuration system.
+ * This includes adding and enlisting {@link org.apache.tamaya.spi.PropertySource}s,
+ * managing {@link org.apache.tamaya.spi.PropertyConverter}s, ConfigFilters, etc.
+ */
+public interface ConfigurationContext {
+
+ /**
+ * This method can be used for programmatically adding {@link PropertySource}s.
+ * It is not needed for normal 'usage' by end users, but only for Extension Developers!
+ *
+ * @param propertySourcesToAdd the PropertySources to add
+ */
+ void addPropertySources(PropertySource... propertySourcesToAdd);
+
+ /**
+ * This method returns the current list of registered PropertySources ordered via their ordinal.
+ * PropertySources with a lower ordinal come last. The PropertySource with the
+ * highest ordinal comes first.
+ * If two PropertySources have the same ordinal number they will get sorted
+ * using their class name just to ensure the user at least gets the same ordering
+ * after a JVM restart, hereby names before are added last.
+ * PropertySources are loaded when this method is called the first time, which basically is
+ * when the first time configuration is accessed.
+ *
+ * @return a sorted list of registered PropertySources. The returned list need not be modifiable
+ */
+ List<PropertySource> getPropertySources();
+
+
+ /**
+ * This method can be used for programmatically adding {@link PropertyConverter}s.
+ * It is not needed for normal 'usage' by end users, but only for Extension Developers!
+ *
+ * @param typeToConvert the type which the converter is for
+ * @param propertyConverter the PropertyConverters to add for this type
+ */
+ <T> void addPropertyConverter(Class<T> typeToConvert, PropertyConverter<T> propertyConverter);
+
+ /**
+ * <p>
+ * This method returns the Map of registered PropertyConverters
+ * per type.
+ * The List for each type is ordered via their {@link javax.annotation.Priority} and
+ * cladd name. Refer also to {@link #getPropertyConverters()}.
+ * </p>
+ * <p>
+ * A simplified scenario could be like:
+ * <pre>
+ * {
+ * Date.class -> {StandardDateConverter, TimezoneDateConverter, MyCustomDateConverter }
+ * Boolean.class -> {StandardBooleanConverter, FrenchBooleanConverter}
+ * Integer.class -> {DynamicDefaultConverter}
+ * }
+ * </pre>
+ * </p>
+ *
+ * @return map with sorted list of registered PropertySources per type.
+ */
+ Map<Class<?>, List<PropertyConverter<?>>> getPropertyConverters();
+
+ /**
+ * <p>
+ * This method returns the registered PropertyConverters for a given type.
+ * The List for each type is ordered via their {@link javax.annotation.Priority}.
+ * </p>
+ *
+ * <p>
+ * PropertyConverters with a higher Priority come first. The PropertyConverter with the
+ * lowest Priority comes last.
+ * If two PropertyConverter have the same ordinal number they will get sorted
+ * using their class name just to ensure the user at least gets the same ordering
+ * after a JVM restart.
+ * </p>
+ *
+ * <p>
+ * Additionally if a PropertyProvider is accessed, which is not registered the implementation
+ * should try to figure out, if there could be a default implementation as follows:
+ * <ol>
+ * <le>Look for static factory methods: {@code of(String), valueOf(String), getInstance(String),
+ * instanceOf(String), fomr(String)}</le>
+ * <le>Look for a matching constructor: {@code T(String)}.</le>
+ * </ol>
+ * If a correspoding factory method or constructor could be found, a corresponding
+ * PropertyConverter should be created and registered automatically for the given
+ * type.
+ * </p>
+ *
+ * <p>
+ * The scenario could be like:
+ * <pre>
+ * {
+ * Date.class -> {MyCustomDateConverter,StandardDateConverter, TimezoneDateConverter}
+ * Boolean.class -> {StandardBooleanConverter, FrenchBooleanConverter}
+ * Integer.class -> {DynamicDefaultConverter}
+ * }
+ * </pre>
+ * </p>
+ *
+ * <p>
+ * The converters returned for a type should be used as a chain, whereas the result of the
+ * first converter that is able to convert the configured value, is taken as the chain's result.
+ * No more converters are called after a converter has successfully converted the input into
+ * the required target type.
+ * </p>
+ *
+ * @return a sorted list of registered PropertySources per type.
+ */
+ <T> List<PropertyConverter<T>> getPropertyConverters(Class<T> type);
+
+ /**
+ * Access the current PropertyFilter instances.
+ * @return the list of registered PropertyFilters, never null.
+ */
+ List<PropertyFilter> getPropertyFilters();
+
+ public static ConfigurationContext context(){
+ return ServiceContext.getInstance().getService(ConfigurationContext.class).get();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/api/src/main/java/org/apache/tamaya/spi/PropertyConverter.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/spi/PropertyConverter.java b/java8/api/src/main/java/org/apache/tamaya/spi/PropertyConverter.java
new file mode 100644
index 0000000..9c41983
--- /dev/null
+++ b/java8/api/src/main/java/org/apache/tamaya/spi/PropertyConverter.java
@@ -0,0 +1,42 @@
+/*
+ * 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.spi;
+
+
+/**
+ * Interface for an property that converts a configured String into something else.
+ * This is used for implementing type conversion from a property (String) to a certain target
+ * type. Hereby the target type can be multivalued (eg collections) or complex if needed.
+ */
+@FunctionalInterface
+public interface PropertyConverter<T>{
+
+ /**
+ * Convert the given configuration keys from it' String representation into the required target type.
+ * @param value the configuration keys
+ * @return converted keys
+ */
+ T convert(String value);
+
+ //X TODO probably add some diagnostic info which explains what kind of
+ //X format(s) is supported.
+ //X This could be useful if e.g. no converter in the chain felt responsible
+ //X because a wrongly formatted configuration string had been used.
+ //X This could probably also be handled via an additional Annotation on the converter.
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java b/java8/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java
new file mode 100644
index 0000000..50a03dd
--- /dev/null
+++ b/java8/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java
@@ -0,0 +1,49 @@
+/*
+ * 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.spi;
+
+
+/**
+ * <p>Interface for filtering the current map of properties during the evaluation of the chain of PropertySources.
+ * Filters can be registered using the {@link org.apache.tamaya.spi.ServiceContext}. The ordinal
+ * hereby is defined by the corresponding {@code @Priority} annotation.</p>
+ * <p>Filters </p>
+ */
+public interface PropertyFilter{
+
+ /**
+ * <p>Maps the current {@code valueToBeFiltered} value to a new value. The resulting value will be used as the result
+ * passed to the user.</p>
+ * <p>If a filter is currently not available, it should just pass the input map to the method's
+ * output.</p>
+ * <p>Returning {@code null} will remove the entry and Optional.empty() will be returned to the user.</p>
+ * <h3>Implementation specification</h3>
+ * Implementations of this class must be
+ * <ul>
+ * <li>reentrant</li>
+ * <li>thread-safe</li>
+ * </ul>
+ *
+ * @param key the key accessed, not null.
+ * @param valueToBeFiltered the value to be filtered, not null.
+ * @return the filtered map, never null.
+ */
+ String filterProperty(String key, String valueToBeFiltered);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/spi/PropertySource.java b/java8/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
new file mode 100644
index 0000000..ae80159
--- /dev/null
+++ b/java8/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
@@ -0,0 +1,128 @@
+/*
+* 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.spi;
+
+
+import java.util.Map;
+import java.util.Optional;
+
+
+/**
+ * This interface models a provider that serves configuration properties. The contained
+ * properties may be read fromMap single or several sources (composite).<br/>
+ * PropertySources are the building blocks of the final configuration.
+ * <p/>
+ * <h3>Implementation Requirements</h3>
+ * <p></p>Implementations current this interface must be
+ * <ul>
+ * <li>Thread safe.</li>
+ * </ul>
+ * </p>
+ * <p>
+ * <p>A PropertySourceProvider will get picked up via the
+ * {@link java.util.ServiceLoader} mechanism and can be registered via
+ * META-INF/services/org.apache.tamaya.spi.PropertySource
+ * </p>
+ * <p>
+ * If you like to register multiple PropertySources at the same time
+ * you can use the {@link org.apache.tamaya.spi.PropertySourceProvider}
+ * interface.
+ * </p>
+ */
+public interface PropertySource {
+
+ /**
+ * property name to override default tamaya ordinals
+ */
+ static final String TAMAYA_ORDINAL = "tamaya.ordinal";
+
+
+ /**
+ * Lookup order:
+ * TODO rethink whole default PropertySources and ordering:
+ * TODO introduce default values or constants for ordinals
+ * <ol>
+ * <li>System properties (ordinal 400)</li>
+ * <li>Environment properties (ordinal 300)</li>
+ * <li>JNDI values (ordinal 200)</li>
+ * <li>Properties file values (/META-INF/applicationConfiguration.properties) (ordinal 100)</li>
+ * </ol>
+ * <p/>
+ * <p><b>Important Hints for custom implementations</b>:</p>
+ * <p>
+ * If a custom implementation should be invoked <b>before</b> the default implementations, use a value > 400
+ * </p>
+ * <p>
+ * If a custom implementation should be invoked <b>after</b> the default implementations, use a value < 100
+ * </p>
+ * <p/>
+ * <p>Reordering of the default order of the config-sources:</p>
+ * <p>Example: If the properties file/s should be used <b>before</b> the other implementations,
+ * you have to configure an ordinal > 400. That means, you have to add e.g. deltaspike_ordinal=401 to
+ * /META-INF/apache-deltaspike.properties . Hint: In case of property files every file is handled as independent
+ * config-source, but all of them have ordinal 400 by default (and can be reordered in a fine-grained manner.</p>
+ *
+ * @return the 'importance' aka ordinal of the configured values. The higher, the more important.
+ * //X TODO think about making this a default method which returns default priority
+ */
+ int getOrdinal();
+
+
+ /**
+ * Get the name of the property source. The name should be unique for the type of source, whereas the id is used
+ * to ensure unique identity, either locally or remotely.
+ * @return the configuration's name, never null.
+ */
+ String getName();
+
+ /**
+ * Access a property.
+ *
+ * //X TODO discuss if the key can be null
+ * @param key the property's key, not null.
+ * @return the property's keys.
+ */
+ Optional<String> get(String key);
+
+ /**
+ * Access the current properties as Map. The resulting Map may not return all items accessible, e.g.
+ * when the underlying storage does not support iteration of its entries.
+ *
+ * @return the a corresponding map, never null.
+ * //X TODO or should we just do getPropertyKeys()? Think about security (key) vs easier merging (full map)?
+ */
+ Map<String,String> getProperties();
+
+ /**
+ * Determines if this config source could be scanned for its list of properties.
+ *
+ * <p>
+ * PropertySources which are not scannable might not be able to find all the
+ * configured values to provide via {@link #getProperties()}. This can e.g. happen
+ * if the underlying storage doesn't support listing.
+ * </p>
+ *
+ * @return {@code true} if this PropertySource could be scanned for its list of properties,
+ * {@code false} if it should not be scanned.
+ */
+ default boolean isScannable(){
+ return true;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/api/src/main/java/org/apache/tamaya/spi/PropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/spi/PropertySourceProvider.java b/java8/api/src/main/java/org/apache/tamaya/spi/PropertySourceProvider.java
new file mode 100644
index 0000000..42e3b4d
--- /dev/null
+++ b/java8/api/src/main/java/org/apache/tamaya/spi/PropertySourceProvider.java
@@ -0,0 +1,43 @@
+/*
+ * 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.spi;
+
+import java.util.Collection;
+
+/**
+ * <p>Implement this interfaces to provide a PropertySource provider which
+ * is able to register multiple PropertySources. This is e.g. needed if
+ * there are multiple property files of a given config file name.</p>
+ *
+ * <p>If a PropertySource like JNDI only exists once, then there is no need
+ * to implement it via the PropertySourceProvider but should directly
+ * expose a {@link PropertySource}.</p>
+ *
+ * <p>A PropertySourceProvider will get picked up via the
+ * {@link java.util.ServiceLoader} mechanism and must get registered via
+ * META-INF/services/org.apache.tamaya.spi.PropertySourceProvider</p>
+ */
+public interface PropertySourceProvider {
+
+ /**
+ * @return For each e.g. property file, we return a single PropertySource
+ * or an empty list if no PropertySource exists.
+ */
+ Collection<PropertySource> getPropertySources();
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java b/java8/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java
new file mode 100644
index 0000000..f7817e7
--- /dev/null
+++ b/java8/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java
@@ -0,0 +1,68 @@
+/*
+ * 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.spi;
+
+import java.util.List;
+import java.util.Optional;
+
+
+/**
+ * This class models the component that is managing the lifecycle current the
+ * services used by the Configuration API.
+ */
+public interface ServiceContext {
+
+ /**
+ * @return ordinal of the ServiceContext. The one with the highest ordinal will be taken.
+ */
+ default int ordinal() {
+ return 1;
+ }
+
+ /**
+ * Access a service singleton via its type.
+ * If multiple implementations for the very serviceType exist then
+ * the one with the highest {@link javax.annotation.Priority} will be used.
+ *
+ * @param serviceType the service type.
+ * @return The instance to be used, never {@code null}
+ * @throws org.apache.tamaya.ConfigException if there are multiple service implementations with the maximum priority.
+ */
+ <T> Optional<T> getService(Class<T> serviceType);
+
+ /**
+ * Access a list current services, given its type. The bootstrap mechanism should
+ * order the instance for precedence, hereby the most significant should be
+ * first in order.
+ *
+ * @param serviceType
+ * the service type.
+ * @return The instance to be used, never {@code null}
+ */
+ <T> List<T> getServices(Class<T> serviceType);
+
+ /**
+ * Get the current {@link ServiceContext}. If necessary the {@link ServiceContext} will be laziliy loaded.
+ *
+ * @return the {@link ServiceContext} to be used.
+ */
+ public static ServiceContext getInstance(){
+ return ServiceContextManager.getServiceContext();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/api/src/main/java/org/apache/tamaya/spi/ServiceContextManager.java
----------------------------------------------------------------------
diff --git a/java8/api/src/main/java/org/apache/tamaya/spi/ServiceContextManager.java b/java8/api/src/main/java/org/apache/tamaya/spi/ServiceContextManager.java
new file mode 100644
index 0000000..68e7552
--- /dev/null
+++ b/java8/api/src/main/java/org/apache/tamaya/spi/ServiceContextManager.java
@@ -0,0 +1,109 @@
+/*
+ * 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.spi;
+
+import java.util.Objects;
+import java.util.ServiceLoader;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.tamaya.ConfigException;
+
+
+/**
+ * This singleton provides access to the services available in the current {@link ServiceContext}. The
+ * behaviour can be adapted, by calling {@link ServiceContextManager#set(ServiceContext)} before accessing any
+ * services.
+ */
+final class ServiceContextManager {
+ /**
+ * The ServiceProvider used.
+ */
+ private static volatile ServiceContext serviceContextProviderDelegate;
+
+ /**
+ * Private singletons constructor.
+ */
+ private ServiceContextManager() {
+ }
+
+ /**
+ * Load the {@link ServiceContext} to be used.
+ *
+ * @return {@link ServiceContext} to be used for loading the services.
+ */
+ private static ServiceContext loadDefaultServiceProvider() {
+ ServiceContext highestServiceContext = null;
+ try {
+ int highestOrdinal = 0;
+ for (ServiceContext serviceContext : ServiceLoader.load(ServiceContext.class)) {
+ if (serviceContext.ordinal() > highestOrdinal) {
+ highestServiceContext = serviceContext;
+ }
+ }
+ } catch (Exception e) {
+ throw new ConfigException("ServiceContext not loadable", e);
+ }
+ if(highestServiceContext==null){
+ throw new ConfigException("No ServiceContext found");
+ }
+ return highestServiceContext;
+ }
+
+ /**
+ * Replace the current {@link ServiceContext} in use.
+ *
+ * @param serviceContextProvider the new {@link ServiceContext}, not null.
+ */
+ public static ServiceContext set(ServiceContext serviceContextProvider) {
+ ServiceContext currentContext = ServiceContextManager.serviceContextProviderDelegate;
+ Objects.requireNonNull(serviceContextProvider);
+ synchronized (ServiceContextManager.class) {
+ if (ServiceContextManager.serviceContextProviderDelegate == null) {
+ ServiceContextManager.serviceContextProviderDelegate = serviceContextProvider;
+ Logger.getLogger(ServiceContextManager.class.getName())
+ .log(Level.INFO, "Using ServiceProvider: " + serviceContextProvider.getClass().getName());
+ } else {
+ Logger.getLogger(ServiceContextManager.class.getName())
+ .log(Level.WARNING, "Replacing ServiceProvider " +
+ ServiceContextManager.serviceContextProviderDelegate.getClass().getName() +
+ " with: " + serviceContextProvider.getClass().getName());
+ ServiceContextManager.serviceContextProviderDelegate = serviceContextProvider;
+ }
+ }
+ return currentContext;
+ }
+
+ /**
+ * Ge {@link ServiceContext}. If necessary the {@link ServiceContext} will be laziliy loaded.
+ *
+ * @return the {@link ServiceContext} used.
+ */
+ public static ServiceContext getServiceContext() {
+ if (serviceContextProviderDelegate == null) {
+ synchronized (ServiceContextManager.class) {
+ if (serviceContextProviderDelegate == null) {
+ serviceContextProviderDelegate = loadDefaultServiceProvider();
+ }
+ }
+ }
+ return serviceContextProviderDelegate;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/java8/api/src/test/java/org/apache/tamaya/ConfigurationTest.java b/java8/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
new file mode 100644
index 0000000..0e62205
--- /dev/null
+++ b/java8/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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;
+
+import static org.junit.Assert.*;
+
+/**
+ * Test class that tests the default methods implemented on {@link org.apache.tamaya.Configuration}. The provided
+ * {@link org.apache.tamaya.TestConfiguration} is implemeted with maximal use of the default methods.
+ */
+public class ConfigurationTest {
+
+ @org.junit.Test
+ public void testget() throws Exception {
+ assertEquals(Boolean.TRUE, Configuration.current().get("booleanTrue", (s) -> Boolean.valueOf(s)).get());
+ assertEquals(Boolean.FALSE, Configuration.current().get("booleanFalse", (s) -> Boolean.valueOf(s)).get());
+ assertEquals((int)Byte.MAX_VALUE, (int)Configuration.current().get("byte", (s) -> Byte.valueOf(s)).get());
+ assertEquals((int)Integer.MAX_VALUE, (int)Configuration.current().get("int", (s) -> Integer.valueOf(s)).get());
+ assertEquals((long)Long.MAX_VALUE, (long)Configuration.current().get("long", (s) -> Long.valueOf(s)).get());
+ assertEquals((double)Float.MAX_VALUE, (double)Configuration.current().get("float", (s) -> Float.valueOf(s)).get(), 0.0d);
+ assertEquals((double)Double.MAX_VALUE, (double)Configuration.current().get("double", (s) -> Double.valueOf(s)).get(), 0.0d);
+ }
+
+ @org.junit.Test
+ public void testGetBoolean() throws Exception {
+ assertTrue(Configuration.current().getBoolean("booleanTrue"));
+ assertFalse(Configuration.current().getBoolean("booleanFalse"));
+ assertFalse(Configuration.current().getBoolean("foorBar"));
+ }
+
+ @org.junit.Test
+ public void testGetInteger() throws Exception {
+ assertEquals(Integer.MAX_VALUE,Configuration.current().getInteger("int").getAsInt());
+ }
+
+ @org.junit.Test
+ public void testGetLong() throws Exception {
+ assertEquals(Long.MAX_VALUE,Configuration.current().getLong("long").getAsLong());
+ }
+
+ @org.junit.Test
+ public void testGetDouble() throws Exception {
+ assertEquals(Double.MAX_VALUE,Configuration.current().getDouble("double").getAsDouble(), 0.0d);
+ }
+
+ @org.junit.Test
+ public void testWith() throws Exception {
+ assertEquals(Configuration.current(), Configuration.current().with(c-> c));
+ }
+
+ @org.junit.Test
+ public void testQuery() throws Exception {
+ assertEquals("myFooResult", Configuration.current().query(c -> "myFooResult"));
+ }
+
+ @org.junit.Test
+ public void testGetAdapted() throws Exception {
+ assertEquals("yes", Configuration.current().get("booleanTrue", (v) -> Boolean.parseBoolean(v)?"yes":"no").get());
+ assertEquals("no", Configuration.current().get("booleanFalse", (v) -> Boolean.parseBoolean(v)?"yes":"no").get());
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
----------------------------------------------------------------------
diff --git a/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java b/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
new file mode 100644
index 0000000..cdcb0e9
--- /dev/null
+++ b/java8/api/src/test/java/org/apache/tamaya/TestConfiguration.java
@@ -0,0 +1,87 @@
+/*
+ * 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;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * Test Configuration class, that is used to testdata the default methods provided by the API.
+ */
+public class TestConfiguration implements Configuration{
+
+ private static final Map<String, String> VALUES;
+ static {
+ VALUES = new HashMap<String, String>();
+ VALUES.put("long", String.valueOf(Long.MAX_VALUE));
+ VALUES.put("int", String.valueOf(Integer.MAX_VALUE));
+ VALUES.put("double", String.valueOf(Double.MAX_VALUE));
+ VALUES.put("float", String.valueOf(Float.MAX_VALUE));
+ VALUES.put("short", String.valueOf(Short.MAX_VALUE));
+ VALUES.put("byte", String.valueOf(Byte.MAX_VALUE));
+ VALUES.put("booleanTrue", "true");
+ VALUES.put("booleanFalse", "false");
+ VALUES.put("String", "aStringValue");
+ }
+
+ @Override
+ public Optional<String> get(String key) {
+ return Optional.ofNullable(VALUES.get(key));
+ }
+
+ @Override
+ public <T> Optional<T> get(String key, Class<T> type) {
+ if(type.equals(Long.class)){
+ return Optional.class.cast(Optional.ofNullable(Long.MAX_VALUE));
+ }
+ else if(type.equals(Integer.class)){
+ return Optional.class.cast(Optional.ofNullable(Integer.MAX_VALUE));
+ }
+ else if(type.equals(Double.class)){
+ return Optional.class.cast(Optional.ofNullable(Double.MAX_VALUE));
+ }
+ else if(type.equals(Float.class)){
+ return Optional.class.cast(Optional.ofNullable(Float.MAX_VALUE));
+ }
+ else if(type.equals(Short.class)){
+ return Optional.class.cast(Optional.ofNullable(Short.MAX_VALUE));
+ }
+ else if(type.equals(Byte.class)){
+ return Optional.class.cast(Optional.ofNullable(Byte.MAX_VALUE));
+ }
+ else if(type.equals(Boolean.class)){
+ if("booleanTrue".equals(key)) {
+ return Optional.class.cast(Optional.ofNullable(Boolean.TRUE));
+ }
+ else{
+ return Optional.class.cast(Optional.ofNullable(Boolean.FALSE));
+ }
+ }
+ else if(type.equals(String.class)){
+ return Optional.class.cast(Optional.ofNullable("aStringValue"));
+ }
+ throw new ConfigException("No such property: " + key);
+ }
+
+ @Override
+ public Map<String, String> getProperties() {
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java
----------------------------------------------------------------------
diff --git a/java8/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java b/java8/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java
new file mode 100644
index 0000000..0309c6c
--- /dev/null
+++ b/java8/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java
@@ -0,0 +1,109 @@
+/*
+ * 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.spi;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Optional;
+
+public class ServiceContextManagerTest {
+
+ private static URLClassLoader classLoader;
+ private static Field delegateField;
+
+ @BeforeClass
+ public static void init() throws Exception {
+
+ // setup the environment for our ugly hacks
+
+ // replace classloader with our own
+ classLoader = (URLClassLoader) Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(new UglyHackClassLoader(classLoader));
+
+ // clear the caching field
+ delegateField = ServiceContextManager.class.getDeclaredField("serviceContextProviderDelegate");
+ delegateField.setAccessible(true);
+
+ delegateField.set(null, null);
+ }
+
+ @AfterClass
+ public static void clean() throws Exception {
+
+ // clean our hacks
+
+ delegateField.set(null, null);
+ Thread.currentThread().setContextClassLoader(classLoader);
+ }
+
+ @Test
+ public void testGetServiceContext() {
+
+ ServiceContext context = ServiceContextManager.getServiceContext();
+ Assert.assertEquals(100, context.ordinal());
+
+ }
+
+
+ // has to be public because ServiceLoader won't find it otherwise
+ public static class ServiceContextWithOrdinal implements ServiceContext {
+
+ @Override
+ public int ordinal() {
+ return 100;
+ }
+
+ @Override
+ public <T> Optional<T> getService(Class<T> serviceType) {
+ return null;
+ }
+
+ @Override
+ public <T> List<T> getServices(Class<T> serviceType) {
+ return null;
+ }
+ }
+
+ // to override the getResources method to use our own 'ServiceLoader'-file we have to this ugly hack
+ private static class UglyHackClassLoader extends URLClassLoader {
+
+ private UglyHackClassLoader(URLClassLoader urlClassLoader) {
+ super(urlClassLoader.getURLs());
+ }
+
+
+ @Override
+ public Enumeration<URL> getResources(String name) throws IOException {
+ if ("META-INF/services/org.apache.tamaya.spi.ServiceContext".equals(name)) {
+ return super.getResources("ServiceContextWithOrdinal");
+ }
+
+ return super.getResources(name);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java
----------------------------------------------------------------------
diff --git a/java8/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java b/java8/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java
new file mode 100644
index 0000000..5ebfc19
--- /dev/null
+++ b/java8/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java
@@ -0,0 +1,93 @@
+/*
+ * 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.spi;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Optional;
+
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+
+public class ServiceContextTest {
+
+ private ServiceContext serviceContext = new ServiceContext(){
+
+ @Override
+ public <T> Optional<T> getService(Class<T> serviceType) {
+ if(String.class.equals(serviceType)){
+ return Optional.of(serviceType.cast("ServiceContextTest"));
+ }
+ return Optional.empty();
+ }
+
+ @Override
+ public <T> List<T> getServices(Class<T> serviceType) {
+ if(String.class.equals(serviceType)){
+ List<String> list = new ArrayList<>();
+ list.add("ServiceContextTest");
+ return List.class.cast(list);
+ }
+ return Collections.EMPTY_LIST;
+ }
+ };
+
+ @Test
+ public void testOrdinal() throws Exception {
+ assertEquals(1, serviceContext.ordinal());
+ }
+
+ @Test
+ public void testgetService() throws Exception {
+ assertEquals("ServiceContextTest", serviceContext.getService(String.class).get());
+ assertFalse(serviceContext.getService(Integer.class).isPresent());
+ }
+
+ @Test
+ public void testGetService() throws Exception {
+ Optional<String> service = serviceContext.getService(String.class);
+ assertNotNull(service);
+ assertTrue(service.isPresent());
+ assertEquals("ServiceContextTest", service.get());
+ Optional<Integer> intService = serviceContext.getService(Integer.class);
+ assertNotNull(intService);
+ assertFalse(intService.isPresent());
+ }
+
+ @Test
+ public void testGetServices() throws Exception {
+ Collection<String> services = serviceContext.getServices(String.class);
+ assertNotNull(services);
+ assertFalse(services.isEmpty());
+ assertEquals("ServiceContextTest", services.iterator().next());
+ Collection<Integer> intServices = serviceContext.getServices(Integer.class);
+ assertNotNull(intServices);
+ assertTrue(intServices.isEmpty());
+ }
+
+ @Test
+ public void testGetInstance() throws Exception {
+ assertNotNull(ServiceContext.getInstance());
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java
----------------------------------------------------------------------
diff --git a/java8/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java b/java8/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java
new file mode 100644
index 0000000..665c99f
--- /dev/null
+++ b/java8/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java
@@ -0,0 +1,82 @@
+/*
+ * 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.spi;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.ServiceLoader;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * This class implements the (default) {@link org.apache.tamaya.spi.ServiceContext} interface and hereby uses the JDK
+ * {@link java.util.ServiceLoader} to load the services required.
+ */
+public final class TestServiceContext implements ServiceContext {
+ /** List current services loaded, per class. */
+ private final ConcurrentHashMap<Class, List<Object>> servicesLoaded = new ConcurrentHashMap<>();
+ /** Singletons. */
+ private final Map<Class, Optional<?>> singletons = new ConcurrentHashMap<>();
+
+ @Override
+ public <T> Optional<T> getService(Class<T> serviceType) {
+ Optional<T> cached = Optional.class.cast(singletons.get(serviceType));
+ if(cached==null) {
+ List<? extends T> services = getServices(serviceType);
+ if (services.isEmpty()) {
+ cached = Optional.empty();
+ }
+ else{
+ cached = Optional.of(services.get(0));
+ }
+ singletons.put(serviceType, cached);
+ }
+ return cached;
+ }
+
+ /**
+ * Loads and registers services.
+ *
+ * @param serviceType The service type.
+ * @param <T> the concrete type.
+ *
+ * @return the items found, never {@code null}.
+ */
+ @Override
+ public <T> List<T> getServices(Class<T> serviceType) {
+ try {
+ List<T> services = new ArrayList<>();
+ for (T t : ServiceLoader.load(serviceType)) {
+ services.add(t);
+ }
+ services = Collections.unmodifiableList(services);
+ final List<T> previousServices = List.class.cast(servicesLoaded.putIfAbsent(serviceType, (List<Object>)services));
+ return previousServices != null ? previousServices : services;
+ } catch (Exception e) {
+ Logger.getLogger(TestServiceContext.class.getName()).log(Level.WARNING,
+ "Error loading services current type " + serviceType, e);
+ return Collections.EMPTY_LIST;
+ }
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/api/src/test/resources/META-INF/services/org.apache.tamaya.Configuration
----------------------------------------------------------------------
diff --git a/java8/api/src/test/resources/META-INF/services/org.apache.tamaya.Configuration b/java8/api/src/test/resources/META-INF/services/org.apache.tamaya.Configuration
new file mode 100644
index 0000000..1f42438
--- /dev/null
+++ b/java8/api/src/test/resources/META-INF/services/org.apache.tamaya.Configuration
@@ -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.TestConfiguration
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
----------------------------------------------------------------------
diff --git a/java8/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext b/java8/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
new file mode 100644
index 0000000..0f7abe9
--- /dev/null
+++ b/java8/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
@@ -0,0 +1 @@
+org.apache.tamaya.spi.TestServiceContext
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/api/src/test/resources/ServiceContextWithOrdinal
----------------------------------------------------------------------
diff --git a/java8/api/src/test/resources/ServiceContextWithOrdinal b/java8/api/src/test/resources/ServiceContextWithOrdinal
new file mode 100644
index 0000000..4112c18
--- /dev/null
+++ b/java8/api/src/test/resources/ServiceContextWithOrdinal
@@ -0,0 +1,25 @@
+# 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.
+
+# this is just an ugly hack to test the loading of ServiceContexts
+# if we have more than one
+
+# this one is without overriding ordinal so it shall take the default
+org.apache.tamaya.spi.TestServiceContext
+
+# this one has a higher ordinal (100)
+org.apache.tamaya.spi.ServiceContextManagerTest$ServiceContextWithOrdinal
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/pom.xml
----------------------------------------------------------------------
diff --git a/java8/core/pom.xml b/java8/core/pom.xml
new file mode 100644
index 0000000..7949c3c
--- /dev/null
+++ b/java8/core/pom.xml
@@ -0,0 +1,46 @@
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-java8</artifactId>
+ <version>0.2-incubating-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>tamaya-core</artifactId>
+
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
new file mode 100644
index 0000000..ec23e25
--- /dev/null
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
@@ -0,0 +1,226 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.ServiceContext;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.stream.Collectors;
+
+/**
+ * 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 org.apache.tamaya.spi.PropertyFilter}
+ * instance to evaluate the current Configuration.
+ */
+public class DefaultConfiguration implements Configuration {
+ /**
+ * The logger.
+ */
+ private static final Logger LOG = Logger.getLogger(DefaultConfiguration.class.getName());
+ /**
+ * The maximal number of filter cycles performed before aborting.
+ */
+ private static final int MAX_FILTER_LOOPS = 10;
+
+ /**
+ * The current {@link org.apache.tamaya.spi.ConfigurationContext} of the current instance.
+ */
+ private final ConfigurationContext configurationContext = ServiceContext.getInstance().getService(ConfigurationContext.class).get();
+
+ /**
+ * This method evaluates the given configuration key. Hereby if goes down the chain or PropertySource instances
+ * provided by the current {@link org.apache.tamaya.spi.ConfigurationContext}. The first non-null-value returned
+ * is taken as an intermediate value. Finally the value is filtered through the
+ * {@link org.apache.tamaya.spi.PropertyFilter} instances installed, before it is returned as the final result of
+ * this method.
+ *
+ * @param key the property's key, not null.
+ * @return the optional configuration value, never null.
+ */
+ @Override
+ public Optional<String> get(String key) {
+ List<PropertySource> propertySources = configurationContext.getPropertySources();
+ String unfilteredValue = null;
+ for (PropertySource propertySource : propertySources) {
+ Optional<String> value = propertySource.get(key);
+ if (value.isPresent()) {
+ unfilteredValue = value.get();
+ break;
+ }
+ }
+ return Optional.ofNullable(applyFilter(key, unfilteredValue));
+ }
+
+ /**
+ * Apply filters to a single property value.
+ *
+ * @param key the key, used for logging, not null.
+ * @param unfilteredValue the unfiltered property value.
+ * @return the filtered value, or null.
+ */
+ private String applyFilter(String key, String unfilteredValue) {
+ // 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()) {
+ String newValue = filter.filterProperty(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;
+ }
+
+ /**
+ * Get the current properties, composed by the loaded {@link org.apache.tamaya.spi.PropertySource} and filtered
+ * by registered {@link org.apache.tamaya.spi.PropertyFilter}.
+ *
+ * @return the final properties.
+ */
+ @Override
+ public Map<String, String> getProperties() {
+ 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);
+ }
+ }
+ return applyFilters(result);
+ }
+
+ /**
+ * Filter a full configuration property map.
+ *
+ * @param inputMap the unfiltered map
+ * @return the filtered map.
+ */
+ private Map<String, String> applyFilters(Map<String, String> 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()) {
+ inputMap.replaceAll((k, v) -> {
+ String newValue = filter.filterProperty(k, v);
+ 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);
+ }
+ return newValue;
+ });
+ }
+ 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);
+ }
+ }
+ // Remove null values
+ return inputMap.entrySet().parallelStream().filter((e) -> e.getValue() != null).collect(
+ Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue()));
+ }
+
+ /**
+ * Accesses the current String value for the given key (see {@link #get(String)}) and tries to convert it
+ * using the {@link org.apache.tamaya.spi.PropertyConverter} instances provided by the current
+ * {@link org.apache.tamaya.spi.ConfigurationContext}.
+ *
+ * @param key the property's absolute, or relative path, e.g. @code
+ * a/b/c/d.myProperty}.
+ * @param type The target type required, not null.
+ * @param <T> the value type
+ * @return the converted value, never null.
+ */
+ @Override
+ public <T> Optional<T> get(String key, Class<T> type) {
+ Optional<String> value = get(key);
+ if (value.isPresent()) {
+ List<PropertyConverter<T>> converters = configurationContext.getPropertyConverters(type);
+ for (PropertyConverter<T> converter : converters) {
+ try {
+ T t = converter.convert(value.get());
+ if (t != null) {
+ return Optional.of(t);
+ }
+ } catch (Exception e) {
+ LOG.log(Level.FINEST, e, () -> "PropertyConverter: " + converter +
+ " failed to convert value: " + value.get());
+ }
+ }
+ throw new ConfigException("Unparseable config value for type: " + type.getName() + ": " + key);
+ }
+ return Optional.empty();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
new file mode 100644
index 0000000..b6acae5
--- /dev/null
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfigurationContext.java
@@ -0,0 +1,183 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.PropertyConverter;
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertySource;
+import org.apache.tamaya.spi.PropertySourceProvider;
+import org.apache.tamaya.spi.ServiceContext;
+
+import javax.annotation.Priority;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.StampedLock;
+
+/**
+ * Default Implementation of a simple ConfigurationContext.
+ */
+public class DefaultConfigurationContext implements ConfigurationContext {
+ /**
+ * Cubcomponent handling {@link org.apache.tamaya.spi.PropertyConverter} instances.
+ */
+ private PropertyConverterManager propertyConverterManager = new PropertyConverterManager();
+
+ /**
+ * The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertySource} instances.
+ */
+ private List<PropertySource> immutablePropertySources;
+
+ /**
+ * The current unmodifiable list of loaded {@link org.apache.tamaya.spi.PropertyFilter} instances.
+ */
+ private List<PropertyFilter> immutablePropertyFilters;
+
+ /**
+ * Lock for internal synchronization.
+ */
+ private StampedLock propertySourceLock = new StampedLock();
+
+
+ /**
+ * The first time the Configuration system gets invoked we do initialize
+ * all our {@link org.apache.tamaya.spi.PropertySource}s and
+ * {@link org.apache.tamaya.spi.PropertyFilter}s which are known at startup.
+ */
+ public DefaultConfigurationContext() {
+ List<PropertySource> propertySources = new ArrayList<>();
+
+ // first we load all PropertySources which got registered via java.util.ServiceLoader
+ propertySources.addAll(ServiceContext.getInstance().getServices(PropertySource.class));
+
+ // after that we add all PropertySources which get dynamically registered via their PropertySourceProviders
+ propertySources.addAll(evaluatePropertySourcesFromProviders());
+
+ // now sort them according to their ordinal values
+ Collections.sort(propertySources, this::comparePropertySources);
+
+ immutablePropertySources = Collections.unmodifiableList(propertySources);
+
+ // as next step we pick up the PropertyFilters pretty much the same way
+ List<PropertyFilter> propertyFilters = new ArrayList<>();
+ propertyFilters.addAll(ServiceContext.getInstance().getServices(PropertyFilter.class));
+ Collections.sort(propertyFilters, this::comparePropertyFilters);
+
+ immutablePropertyFilters = Collections.unmodifiableList(propertyFilters);
+ }
+
+ /**
+ * Pick up all {@link org.apache.tamaya.spi.PropertySourceProvider}s and return all the
+ * {@link org.apache.tamaya.spi.PropertySource}s they like to register.
+ */
+ private Collection<? extends PropertySource> evaluatePropertySourcesFromProviders() {
+ List<PropertySource> propertySources = new ArrayList<>();
+ List<PropertySourceProvider> propertySourceProviders = ServiceContext.getInstance().getServices(PropertySourceProvider.class);
+ for (PropertySourceProvider propertySourceProvider : propertySourceProviders) {
+ propertySources.addAll(propertySourceProvider.getPropertySources());
+ }
+
+ return propertySources;
+ }
+
+ @Override
+ public void addPropertySources(PropertySource... propertySourcesToAdd) {
+ Lock writeLock = propertySourceLock.asWriteLock();
+ try {
+ writeLock.lock();
+ List<PropertySource> newPropertySources = new ArrayList<>(this.immutablePropertySources);
+ newPropertySources.addAll(Arrays.asList(propertySourcesToAdd));
+ Collections.sort(newPropertySources, this::comparePropertySources);
+
+ this.immutablePropertySources = Collections.unmodifiableList(newPropertySources);
+ } finally {
+ writeLock.unlock();
+ }
+ }
+
+ /**
+ * Order property source reversely, the most important come first.
+ *
+ * @param source1 the first PropertySource
+ * @param source2 the second PropertySource
+ * @return the comparison result.
+ */
+ private int comparePropertySources(PropertySource source1, PropertySource source2) {
+ if (source1.getOrdinal() < source2.getOrdinal()) {
+ return 1;
+ } else if (source1.getOrdinal() > source2.getOrdinal()) {
+ return -1;
+ } else {
+ return source2.getClass().getName().compareTo(source1.getClass().getName());
+ }
+ }
+
+ /**
+ * Compare 2 filters for ordering the filter chain.
+ *
+ * @param filter1 the first filter
+ * @param filter2 the second filter
+ * @return the comparison result
+ */
+ private int comparePropertyFilters(PropertyFilter filter1, PropertyFilter filter2) {
+ Priority prio1 = filter1.getClass().getAnnotation(Priority.class);
+ Priority prio2 = filter2.getClass().getAnnotation(Priority.class);
+ int ord1 = prio1 != null ? prio1.value() : 0;
+ int ord2 = prio2 != null ? prio2.value() : 0;
+
+ if (ord1 < ord2) {
+ return -1;
+ } else if (ord1 > ord2) {
+ return 1;
+ } else {
+ return filter1.getClass().getName().compareTo(filter2.getClass().getName());
+ }
+ }
+
+ @Override
+ public List<PropertySource> getPropertySources() {
+ return immutablePropertySources;
+ }
+
+ @Override
+ public <T> void addPropertyConverter(Class<T> typeToConvert, PropertyConverter<T> propertyConverter) {
+ propertyConverterManager.register(typeToConvert, propertyConverter);
+ }
+
+ @Override
+ public Map<Class<?>, List<PropertyConverter<?>>> getPropertyConverters() {
+ return propertyConverterManager.getPropertyConverters();
+ }
+
+ @Override
+ public <T> List<PropertyConverter<T>> getPropertyConverters(Class<T> targetType) {
+ return propertyConverterManager.getPropertyConverters(targetType);
+ }
+
+ @Override
+ public List<PropertyFilter> getPropertyFilters() {
+ return immutablePropertyFilters;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java b/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
new file mode 100644
index 0000000..8e27d4a
--- /dev/null
+++ b/java8/core/src/main/java/org/apache/tamaya/core/internal/DefaultServiceContext.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.core.internal;
+
+import org.apache.tamaya.spi.ServiceContext;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.ServiceLoader;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * This class implements the (default) {@link org.apache.tamaya.spi.ServiceContext} interface and hereby uses the JDK
+ * {@link java.util.ServiceLoader} to load the services required.
+ */
+public final class DefaultServiceContext implements ServiceContext {
+ /**
+ * List current services loaded, per class.
+ */
+ private final ConcurrentHashMap<Class, List<Object>> servicesLoaded = new ConcurrentHashMap<>();
+ /**
+ * Singletons.
+ */
+ private final Map<Class, Optional<?>> singletons = new ConcurrentHashMap<>();
+
+ @Override
+ public <T> Optional<T> getService(Class<T> serviceType) {
+ Optional<T> cached = Optional.class.cast(singletons.get(serviceType));
+ if (cached == null) {
+ List<? extends T> services = getServices(serviceType);
+ if (services.isEmpty()) {
+ cached = Optional.empty();
+ } else {
+ cached = Optional.of(services.get(0));
+ }
+ singletons.put(serviceType, cached);
+ }
+ return cached;
+ }
+
+ /**
+ * Loads and registers services.
+ *
+ * @param serviceType The service type.
+ * @param <T> the concrete type.
+ * @return the items found, never {@code null}.
+ */
+ @Override
+ public <T> List<T> getServices(final Class<T> serviceType) {
+ List<T> found = List.class.cast(servicesLoaded.get(serviceType));
+ if (found != null) {
+ return found;
+ }
+ List<T> services = new ArrayList<>();
+ try {
+ for (T t : ServiceLoader.load(serviceType)) {
+ services.add(t);
+ }
+ services = Collections.unmodifiableList(services);
+ } catch (Exception e) {
+ Logger.getLogger(DefaultServiceContext.class.getName()).log(Level.WARNING,
+ "Error loading services current type " + serviceType, e);
+ }
+ final List<T> previousServices = List.class.cast(servicesLoaded.putIfAbsent(serviceType, (List<Object>) services));
+ return previousServices != null ? previousServices : services;
+ }
+
+}
\ No newline at end of file
[2/9] incubator-tamaya git commit: TAMAYA-49 remove Optional from
ConfigSource
Posted by st...@apache.org.
TAMAYA-49 remove Optional from ConfigSource
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/b4bde92b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/b4bde92b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/b4bde92b
Branch: refs/heads/master
Commit: b4bde92b5b6342d4062189a1b7248b05df9fa381
Parents: 67855fa
Author: Mark Struberg <st...@apache.org>
Authored: Tue Jan 6 22:38:50 2015 +0100
Committer: Mark Struberg <st...@apache.org>
Committed: Wed Jan 7 23:17:58 2015 +0100
----------------------------------------------------------------------
.../modules/json/JSONPropertySourceTest.java | 65 ++++++++++----------
1 file changed, 33 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/b4bde92b/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceTest.java b/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceTest.java
index 87a9ff2..8935857 100644
--- a/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceTest.java
+++ b/modules/json/src/test/java/org/apache/tamaya/modules/json/JSONPropertySourceTest.java
@@ -22,15 +22,16 @@ import org.apache.tamaya.ConfigException;
import org.apache.tamaya.core.propertysource.DefaultOrdinal;
import org.apache.tamaya.spi.PropertySource;
import org.hamcrest.CoreMatchers;
+import org.hamcrest.Matchers;
import org.junit.Test;
import java.io.File;
import java.net.URISyntaxException;
import java.net.URL;
-import java.util.Optional;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.fail;
@@ -75,16 +76,16 @@ public class JSONPropertySourceTest {
assertThat(source.getProperties().keySet(), hasSize(3));
- Optional<String> keyA = source.get("a");
- Optional<String> keyB = source.get("b");
- Optional<String> keyC = source.get("c");
+ String keyA = source.get("a");
+ String keyB = source.get("b");
+ String keyC = source.get("c");
- assertThat(keyA.isPresent(), is(true));
- assertThat(keyA.get(), equalTo("A"));
- assertThat(keyB.isPresent(), is(true));
- assertThat(keyB.get(), is("B"));
- assertThat(keyC.isPresent(), is(true));
- assertThat(keyC.get(), is("C"));
+ assertThat(keyA, notNullValue());
+ assertThat(keyA, equalTo("A"));
+ assertThat(keyB, notNullValue());
+ assertThat(keyB, is("B"));
+ assertThat(keyC, notNullValue());
+ assertThat(keyC, is("C"));
}
@Test
@@ -99,16 +100,16 @@ public class JSONPropertySourceTest {
assertThat(source.getProperties().keySet(), hasSize(5));
- Optional<String> keyb = source.get("b");
- Optional<String> keyDO = source.get("d.o");
- Optional<String> keyDP = source.get("d.p");
+ String keyb = source.get("b");
+ String keyDO = source.get("d.o");
+ String keyDP = source.get("d.p");
- assertThat(keyb.isPresent(), is(true));
- assertThat(keyb.get(), equalTo("B"));
- assertThat(keyDO.isPresent(), is(true));
- assertThat(keyDO.get(), equalTo("O"));
- assertThat(keyDP.isPresent(), is(true));
- assertThat(keyDP.get(), is("P"));
+ assertThat(keyb, notNullValue());
+ assertThat(keyb, equalTo("B"));
+ assertThat(keyDO, notNullValue());
+ assertThat(keyDO, equalTo("O"));
+ assertThat(keyDP, Matchers.notNullValue());
+ assertThat(keyDP, is("P"));
}
@Test
@@ -124,19 +125,19 @@ public class JSONPropertySourceTest {
assertThat(source.getProperties().keySet(), hasSize(4));
- Optional<String> keyA = source.get("a");
- Optional<String> keyDO = source.get("b.o");
- Optional<String> keyDP = source.get("b.p");
- Optional<String> keyC = source.get("c");
-
- assertThat(keyA.isPresent(), is(true));
- assertThat(keyA.get(), is("A"));
- assertThat(keyC.isPresent(), is(true));
- assertThat(keyC.get(), equalTo("C"));
- assertThat(keyDO.isPresent(), is(true));
- assertThat(keyDO.get(), equalTo("O"));
- assertThat(keyDP.isPresent(), is(true));
- assertThat(keyDP.get(), is("P"));
+ String keyA = source.get("a");
+ String keyDO = source.get("b.o");
+ String keyDP = source.get("b.p");
+ String keyC = source.get("c");
+
+ assertThat(keyA, notNullValue());
+ assertThat(keyA, is("A"));
+ assertThat(keyC, notNullValue());
+ assertThat(keyC, equalTo("C"));
+ assertThat(keyDO, notNullValue());
+ assertThat(keyDO, equalTo("O"));
+ assertThat(keyDP, notNullValue());
+ assertThat(keyDP, is("P"));
}
@Test
[6/9] incubator-tamaya git commit: TAMAYA-49 move api and core to
java8 module
Posted by st...@apache.org.
TAMAYA-49 move api and core to java8 module
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/328a4ac7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/328a4ac7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/328a4ac7
Branch: refs/heads/master
Commit: 328a4ac73d5bcbc7f9700348e4f2a122966ddca0
Parents: 7985c03
Author: Mark Struberg <st...@apache.org>
Authored: Tue Jan 6 18:10:28 2015 +0100
Committer: Mark Struberg <st...@apache.org>
Committed: Wed Jan 7 23:17:58 2015 +0100
----------------------------------------------------------------------
api/pom.xml | 43 ----
.../java/org/apache/tamaya/ConfigException.java | 44 ----
.../java/org/apache/tamaya/Configuration.java | 204 ---------------
.../apache/tamaya/spi/ConfigurationContext.java | 145 -----------
.../apache/tamaya/spi/PropertyConverter.java | 42 ----
.../org/apache/tamaya/spi/PropertyFilter.java | 49 ----
.../org/apache/tamaya/spi/PropertySource.java | 128 ----------
.../tamaya/spi/PropertySourceProvider.java | 43 ----
.../org/apache/tamaya/spi/ServiceContext.java | 68 -----
.../tamaya/spi/ServiceContextManager.java | 109 --------
.../org/apache/tamaya/ConfigurationTest.java | 78 ------
.../org/apache/tamaya/TestConfiguration.java | 87 -------
.../tamaya/spi/ServiceContextManagerTest.java | 109 --------
.../apache/tamaya/spi/ServiceContextTest.java | 93 -------
.../apache/tamaya/spi/TestServiceContext.java | 82 ------
.../services/org.apache.tamaya.Configuration | 19 --
.../org.apache.tamaya.spi.ServiceContext | 1 -
.../test/resources/ServiceContextWithOrdinal | 25 --
core/pom.xml | 46 ----
.../core/internal/DefaultConfiguration.java | 226 -----------------
.../internal/DefaultConfigurationContext.java | 183 --------------
.../core/internal/DefaultServiceContext.java | 89 -------
.../core/internal/PropertiesFileLoader.java | 102 --------
.../core/internal/PropertyConverterManager.java | 247 -------------------
.../core/propertysource/BasePropertySource.java | 78 ------
.../core/propertysource/DefaultOrdinal.java | 54 ----
.../EnvironmentPropertySource.java | 47 ----
.../PropertiesFilePropertySource.java | 47 ----
.../PropertiesPropertySource.java | 51 ----
.../propertysource/SystemPropertySource.java | 75 ------
.../provider/JavaConfigurationProvider.java | 60 -----
.../services/org.apache.tamaya.Configuration | 19 --
....apache.tamaya.core.resources.ResourceLoader | 19 --
.../org.apache.tamaya.spi.ConfigurationContext | 19 --
.../org.apache.tamaya.spi.ServiceContext | 19 --
.../apache/tamaya/core/ConfigurationTest.java | 58 -----
.../test/internal/PropetiesFileLoaderTest.java | 76 ------
.../propertysource/BasePropertySourceTest.java | 106 --------
.../PropertiesFilePropertySourceTest.java | 71 ------
.../SystemPropertySourceTest.java | 102 --------
.../provider/JavaConfigurationProviderTest.java | 53 ----
.../testdata/TestPropertyDefaultSource.java | 51 ----
.../core/testdata/TestPropertyFilter.java | 38 ---
.../testdata/TestPropertyFilterRemoving.java | 42 ----
.../testdata/TestPropertySourceProvider.java | 73 ------
.../org.apache.tamaya.spi.PropertyFilter | 20 --
.../org.apache.tamaya.spi.PropertySource | 21 --
...org.apache.tamaya.spi.PropertySourceProvider | 20 --
.../test/resources/javaconfiguration.properties | 22 --
.../test/resources/overrideOrdinal.properties | 25 --
core/src/test/resources/testfile.properties | 22 --
java8/api/pom.xml | 43 ++++
.../java/org/apache/tamaya/ConfigException.java | 44 ++++
.../java/org/apache/tamaya/Configuration.java | 204 +++++++++++++++
.../apache/tamaya/spi/ConfigurationContext.java | 145 +++++++++++
.../apache/tamaya/spi/PropertyConverter.java | 42 ++++
.../org/apache/tamaya/spi/PropertyFilter.java | 49 ++++
.../org/apache/tamaya/spi/PropertySource.java | 128 ++++++++++
.../tamaya/spi/PropertySourceProvider.java | 43 ++++
.../org/apache/tamaya/spi/ServiceContext.java | 68 +++++
.../tamaya/spi/ServiceContextManager.java | 109 ++++++++
.../org/apache/tamaya/ConfigurationTest.java | 78 ++++++
.../org/apache/tamaya/TestConfiguration.java | 87 +++++++
.../tamaya/spi/ServiceContextManagerTest.java | 109 ++++++++
.../apache/tamaya/spi/ServiceContextTest.java | 93 +++++++
.../apache/tamaya/spi/TestServiceContext.java | 82 ++++++
.../services/org.apache.tamaya.Configuration | 19 ++
.../org.apache.tamaya.spi.ServiceContext | 1 +
.../test/resources/ServiceContextWithOrdinal | 25 ++
java8/core/pom.xml | 46 ++++
.../core/internal/DefaultConfiguration.java | 226 +++++++++++++++++
.../internal/DefaultConfigurationContext.java | 183 ++++++++++++++
.../core/internal/DefaultServiceContext.java | 89 +++++++
.../core/internal/PropertiesFileLoader.java | 102 ++++++++
.../core/internal/PropertyConverterManager.java | 247 +++++++++++++++++++
.../core/propertysource/BasePropertySource.java | 78 ++++++
.../core/propertysource/DefaultOrdinal.java | 54 ++++
.../EnvironmentPropertySource.java | 47 ++++
.../PropertiesFilePropertySource.java | 47 ++++
.../PropertiesPropertySource.java | 51 ++++
.../propertysource/SystemPropertySource.java | 75 ++++++
.../provider/JavaConfigurationProvider.java | 60 +++++
.../services/org.apache.tamaya.Configuration | 19 ++
....apache.tamaya.core.resources.ResourceLoader | 19 ++
.../org.apache.tamaya.spi.ConfigurationContext | 19 ++
.../org.apache.tamaya.spi.ServiceContext | 19 ++
.../apache/tamaya/core/ConfigurationTest.java | 58 +++++
.../test/internal/PropetiesFileLoaderTest.java | 76 ++++++
.../propertysource/BasePropertySourceTest.java | 106 ++++++++
.../PropertiesFilePropertySourceTest.java | 71 ++++++
.../SystemPropertySourceTest.java | 102 ++++++++
.../provider/JavaConfigurationProviderTest.java | 53 ++++
.../testdata/TestPropertyDefaultSource.java | 51 ++++
.../core/testdata/TestPropertyFilter.java | 38 +++
.../testdata/TestPropertyFilterRemoving.java | 42 ++++
.../testdata/TestPropertySourceProvider.java | 73 ++++++
.../org.apache.tamaya.spi.PropertyFilter | 20 ++
.../org.apache.tamaya.spi.PropertySource | 21 ++
...org.apache.tamaya.spi.PropertySourceProvider | 20 ++
.../test/resources/javaconfiguration.properties | 22 ++
.../test/resources/overrideOrdinal.properties | 25 ++
.../core/src/test/resources/testfile.properties | 22 ++
java8/pom.xml | 37 +++
pom.xml | 3 +-
104 files changed, 3588 insertions(+), 3552 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/api/pom.xml
----------------------------------------------------------------------
diff --git a/api/pom.xml b/api/pom.xml
deleted file mode 100644
index 6cea5b6..0000000
--- a/api/pom.xml
+++ /dev/null
@@ -1,43 +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 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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-all</artifactId>
- <version>0.2-incubating-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
- </parent>
-
- <artifactId>tamaya-api</artifactId>
- <description>
- The API defines a complete SE based API for reading of configuration data.
- </description>
-
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/api/src/main/java/org/apache/tamaya/ConfigException.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/ConfigException.java b/api/src/main/java/org/apache/tamaya/ConfigException.java
deleted file mode 100644
index bac2ef4..0000000
--- a/api/src/main/java/org/apache/tamaya/ConfigException.java
+++ /dev/null
@@ -1,44 +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;
-
-/**
- * Exception class (runtime exception) for configuration issues.
- */
-public class ConfigException extends RuntimeException{
-
- private static final long serialVersionUID = -5886094818057522680L;
-
- /**
- * Creates a new configuration exception.
- * @param message the exception message, not null.
- */
- public ConfigException(String message){
- super(message);
- }
-
- /**
- * Creates a new configuration exception.
- * @param message the exception message, not null.
- * @param t the throwable.
- */
- public ConfigException(String message, Throwable t){
- super(message, t);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/api/src/main/java/org/apache/tamaya/Configuration.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/Configuration.java b/api/src/main/java/org/apache/tamaya/Configuration.java
deleted file mode 100644
index 2786af7..0000000
--- a/api/src/main/java/org/apache/tamaya/Configuration.java
+++ /dev/null
@@ -1,204 +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;
-
-import org.apache.tamaya.spi.PropertyConverter;
-import org.apache.tamaya.spi.ServiceContext;
-
-import java.util.*;
-import java.util.function.Function;
-import java.util.function.UnaryOperator;
-
-/**
- * A configuration models a aggregated set current properties, identified by a unique key, but adds higher level access functions to
- * a {@link org.apache.tamaya.spi.PropertySource}. Hereby in most cases a configuration is a wrapper around a composite
- * {@link org.apache.tamaya.spi.PropertySource} instance, which may combine multiple child config in well defined tree like structure,
- * where nodes define logically the rules current priority, filtering, combination and overriding.
- * <br/>
- * <h3>Implementation Requirements</h3>
- * Implementations current this interface must be
- * <ul>
- * <li>Thread safe.
- * <li>Immutable
- * </ul>
- * It is not recommended that implementations also are serializable, since the any configuration can be <i>freezed</i>
- * by reading out its complete configuration map into a serializable and remotable structure. This helps significantly
- * simplifying the development current this interface, e.g. for being backed up by systems and stores that are not part current
- * this library at all.
- */
-public interface Configuration {
-
- /**
- * Access a property.
- *
- * @param key the property's key, not null.
- * @return the property's keys.
- */
- Optional<String> get(String key);
-
- /**
- * Access all current known Configuration properties as a full {@code Map<String,String>}.
- * Be aware that entries from non scannable parts of the registered {@link org.apache.tamaya.spi.PropertySource}
- * instances may not be contained in the result, but nevertheless be accessible calling one of the
- * {@code get(...)} methods.
- */
- Map<String,String> getProperties();
-
- /**
- * Get the property keys as type T. This will implicitly require a corresponding {@link
- * org.apache.tamaya.spi.PropertyConverter} to be available that is capable current providing type T
- * fromMap the given String keys.
- *
- * @param key the property's absolute, or relative path, e.g. @code
- * a/b/c/d.myProperty}.
- * @param type The target type required, not null.
- * @return the property value, never null..
- * @throws ConfigException if the keys could not be converted to the required target
- * type.
- */
- <T> Optional<T> get(String key, Class<T> type);
-
- /**
- * Get the property keys as type {@code Class<T>}.
- * <p>
- * If {@code Class<T>} is not one current
- * {@code Boolean, Short, Integer, Long, Float, Double, BigInteger,
- * BigDecimal, String} , an according converter must be
- * available to perform the conversion fromMap {@link String} to
- * {@code Class<T>}.
- *
- * @param key the property's absolute, or relative path, e.g. @code
- * a/b/c/d.myProperty}.
- * @param converter the PropertyConverter to perform the conversion fromMap
- * {@link String} to {@code Class<T>}, not {@code null}.
- * @return the property's keys.
- * @throws ConfigException if the keys could not be converted to the required target
- * type, or no such property exists.
- */
- default <T> Optional<T> get(String key, PropertyConverter<T> converter) {
- Optional<String> value = get(key);
- if (value.isPresent()) {
- return Optional.ofNullable(converter.convert(value.get()));
- }
- return Optional.empty();
- }
-
-
- /**
- * Get the property keys as {@link Boolean}.
- *
- * @param key the property's absolute, or relative path, e.g. {@code
- * a/b/c/d.myProperty}.
- * @return the property's keys.
- * @throws ConfigException if the configured value could not be converted to the target type.
- */
- default Boolean getBoolean(String key) {
- Optional<Boolean> val = get(key, Boolean.class);
- if (val.isPresent()) {
- return val.get();
- }
- return null;
- }
-
- /**
- * Get the property keys as {@link Integer}.
- *
- * @param key the property's absolute, or relative path, e.g. @code
- * a/b/c/d.myProperty}.
- * @return the property's keys.
- * @throws ConfigException if the configured value could not be converted to the target type.
- */
- default OptionalInt getInteger(String key) {
- Optional<Integer> val = get(key, Integer.class);
- if (val.isPresent()){
- return OptionalInt.of(val.get());
- }
- return OptionalInt.empty();
- }
-
-
- /**
- * Get the property keys as {@link Long}.
- *
- * @param key the property's absolute, or relative path, e.g. @code
- * a/b/c/d.myProperty}.
- * @return the property's keys.
- * @throws ConfigException if the configured value could not be converted to the target type.
- */
- default OptionalLong getLong(String key) {
- Optional<Long> val = get(key, Long.class);
- if (val.isPresent()){
- return OptionalLong.of(val.get());
- }
- return OptionalLong.empty();
- }
-
-
- /**
- * Get the property keys as {@link Double}.
- *
- * @param key the property's absolute, or relative path, e.g. @code
- * a/b/c/d.myProperty}.
- * @return the property's keys.
- * @throws ConfigException if the configured value could not be converted to the target type.
- */
- default OptionalDouble getDouble(String key) {
-
- Optional<Double> val = get(key, Double.class);
- if (val.isPresent()){
- return OptionalDouble.of(val.get());
- }
- return OptionalDouble.empty();
- }
-
-
- /**
- * Extension point for adjusting configuration.
- *
- * @param operator A configuration operator, e.g. a filter, or an adjuster
- * combining configurations.
- * @return the new adjusted configuration, never {@code null}.
- */
- default Configuration with(UnaryOperator<Configuration> operator) {
- return operator.apply(this);
- }
-
-
- /**
- * Query a configuration.
- *
- * @param query the query, never {@code null}.
- * @return the result
- */
- default <T> T query(Function<Configuration,T> query) {
- return query.apply(this);
- }
-
-
- /**
- * Access a configuration.
- *
- * @return the corresponding Configuration instance, never null.
- * @throws ConfigException if no such configuration is defined.
- */
- public static Configuration current(){
- return ServiceContext.getInstance().getService(Configuration.class).get();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java b/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
deleted file mode 100644
index 7b51717..0000000
--- a/api/src/main/java/org/apache/tamaya/spi/ConfigurationContext.java
+++ /dev/null
@@ -1,145 +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.spi;
-
-
-import java.util.List;
-import java.util.Map;
-
-/**
- * Central SPI for programmatically dealing with the setup of the configuration system.
- * This includes adding and enlisting {@link org.apache.tamaya.spi.PropertySource}s,
- * managing {@link org.apache.tamaya.spi.PropertyConverter}s, ConfigFilters, etc.
- */
-public interface ConfigurationContext {
-
- /**
- * This method can be used for programmatically adding {@link PropertySource}s.
- * It is not needed for normal 'usage' by end users, but only for Extension Developers!
- *
- * @param propertySourcesToAdd the PropertySources to add
- */
- void addPropertySources(PropertySource... propertySourcesToAdd);
-
- /**
- * This method returns the current list of registered PropertySources ordered via their ordinal.
- * PropertySources with a lower ordinal come last. The PropertySource with the
- * highest ordinal comes first.
- * If two PropertySources have the same ordinal number they will get sorted
- * using their class name just to ensure the user at least gets the same ordering
- * after a JVM restart, hereby names before are added last.
- * PropertySources are loaded when this method is called the first time, which basically is
- * when the first time configuration is accessed.
- *
- * @return a sorted list of registered PropertySources. The returned list need not be modifiable
- */
- List<PropertySource> getPropertySources();
-
-
- /**
- * This method can be used for programmatically adding {@link PropertyConverter}s.
- * It is not needed for normal 'usage' by end users, but only for Extension Developers!
- *
- * @param typeToConvert the type which the converter is for
- * @param propertyConverter the PropertyConverters to add for this type
- */
- <T> void addPropertyConverter(Class<T> typeToConvert, PropertyConverter<T> propertyConverter);
-
- /**
- * <p>
- * This method returns the Map of registered PropertyConverters
- * per type.
- * The List for each type is ordered via their {@link javax.annotation.Priority} and
- * cladd name. Refer also to {@link #getPropertyConverters()}.
- * </p>
- * <p>
- * A simplified scenario could be like:
- * <pre>
- * {
- * Date.class -> {StandardDateConverter, TimezoneDateConverter, MyCustomDateConverter }
- * Boolean.class -> {StandardBooleanConverter, FrenchBooleanConverter}
- * Integer.class -> {DynamicDefaultConverter}
- * }
- * </pre>
- * </p>
- *
- * @return map with sorted list of registered PropertySources per type.
- */
- Map<Class<?>, List<PropertyConverter<?>>> getPropertyConverters();
-
- /**
- * <p>
- * This method returns the registered PropertyConverters for a given type.
- * The List for each type is ordered via their {@link javax.annotation.Priority}.
- * </p>
- *
- * <p>
- * PropertyConverters with a higher Priority come first. The PropertyConverter with the
- * lowest Priority comes last.
- * If two PropertyConverter have the same ordinal number they will get sorted
- * using their class name just to ensure the user at least gets the same ordering
- * after a JVM restart.
- * </p>
- *
- * <p>
- * Additionally if a PropertyProvider is accessed, which is not registered the implementation
- * should try to figure out, if there could be a default implementation as follows:
- * <ol>
- * <le>Look for static factory methods: {@code of(String), valueOf(String), getInstance(String),
- * instanceOf(String), fomr(String)}</le>
- * <le>Look for a matching constructor: {@code T(String)}.</le>
- * </ol>
- * If a correspoding factory method or constructor could be found, a corresponding
- * PropertyConverter should be created and registered automatically for the given
- * type.
- * </p>
- *
- * <p>
- * The scenario could be like:
- * <pre>
- * {
- * Date.class -> {MyCustomDateConverter,StandardDateConverter, TimezoneDateConverter}
- * Boolean.class -> {StandardBooleanConverter, FrenchBooleanConverter}
- * Integer.class -> {DynamicDefaultConverter}
- * }
- * </pre>
- * </p>
- *
- * <p>
- * The converters returned for a type should be used as a chain, whereas the result of the
- * first converter that is able to convert the configured value, is taken as the chain's result.
- * No more converters are called after a converter has successfully converted the input into
- * the required target type.
- * </p>
- *
- * @return a sorted list of registered PropertySources per type.
- */
- <T> List<PropertyConverter<T>> getPropertyConverters(Class<T> type);
-
- /**
- * Access the current PropertyFilter instances.
- * @return the list of registered PropertyFilters, never null.
- */
- List<PropertyFilter> getPropertyFilters();
-
- public static ConfigurationContext context(){
- return ServiceContext.getInstance().getService(ConfigurationContext.class).get();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/api/src/main/java/org/apache/tamaya/spi/PropertyConverter.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/PropertyConverter.java b/api/src/main/java/org/apache/tamaya/spi/PropertyConverter.java
deleted file mode 100644
index 9c41983..0000000
--- a/api/src/main/java/org/apache/tamaya/spi/PropertyConverter.java
+++ /dev/null
@@ -1,42 +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.spi;
-
-
-/**
- * Interface for an property that converts a configured String into something else.
- * This is used for implementing type conversion from a property (String) to a certain target
- * type. Hereby the target type can be multivalued (eg collections) or complex if needed.
- */
-@FunctionalInterface
-public interface PropertyConverter<T>{
-
- /**
- * Convert the given configuration keys from it' String representation into the required target type.
- * @param value the configuration keys
- * @return converted keys
- */
- T convert(String value);
-
- //X TODO probably add some diagnostic info which explains what kind of
- //X format(s) is supported.
- //X This could be useful if e.g. no converter in the chain felt responsible
- //X because a wrongly formatted configuration string had been used.
- //X This could probably also be handled via an additional Annotation on the converter.
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java b/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java
deleted file mode 100644
index 50a03dd..0000000
--- a/api/src/main/java/org/apache/tamaya/spi/PropertyFilter.java
+++ /dev/null
@@ -1,49 +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.spi;
-
-
-/**
- * <p>Interface for filtering the current map of properties during the evaluation of the chain of PropertySources.
- * Filters can be registered using the {@link org.apache.tamaya.spi.ServiceContext}. The ordinal
- * hereby is defined by the corresponding {@code @Priority} annotation.</p>
- * <p>Filters </p>
- */
-public interface PropertyFilter{
-
- /**
- * <p>Maps the current {@code valueToBeFiltered} value to a new value. The resulting value will be used as the result
- * passed to the user.</p>
- * <p>If a filter is currently not available, it should just pass the input map to the method's
- * output.</p>
- * <p>Returning {@code null} will remove the entry and Optional.empty() will be returned to the user.</p>
- * <h3>Implementation specification</h3>
- * Implementations of this class must be
- * <ul>
- * <li>reentrant</li>
- * <li>thread-safe</li>
- * </ul>
- *
- * @param key the key accessed, not null.
- * @param valueToBeFiltered the value to be filtered, not null.
- * @return the filtered map, never null.
- */
- String filterProperty(String key, String valueToBeFiltered);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/PropertySource.java b/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
deleted file mode 100644
index ae80159..0000000
--- a/api/src/main/java/org/apache/tamaya/spi/PropertySource.java
+++ /dev/null
@@ -1,128 +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.spi;
-
-
-import java.util.Map;
-import java.util.Optional;
-
-
-/**
- * This interface models a provider that serves configuration properties. The contained
- * properties may be read fromMap single or several sources (composite).<br/>
- * PropertySources are the building blocks of the final configuration.
- * <p/>
- * <h3>Implementation Requirements</h3>
- * <p></p>Implementations current this interface must be
- * <ul>
- * <li>Thread safe.</li>
- * </ul>
- * </p>
- * <p>
- * <p>A PropertySourceProvider will get picked up via the
- * {@link java.util.ServiceLoader} mechanism and can be registered via
- * META-INF/services/org.apache.tamaya.spi.PropertySource
- * </p>
- * <p>
- * If you like to register multiple PropertySources at the same time
- * you can use the {@link org.apache.tamaya.spi.PropertySourceProvider}
- * interface.
- * </p>
- */
-public interface PropertySource {
-
- /**
- * property name to override default tamaya ordinals
- */
- static final String TAMAYA_ORDINAL = "tamaya.ordinal";
-
-
- /**
- * Lookup order:
- * TODO rethink whole default PropertySources and ordering:
- * TODO introduce default values or constants for ordinals
- * <ol>
- * <li>System properties (ordinal 400)</li>
- * <li>Environment properties (ordinal 300)</li>
- * <li>JNDI values (ordinal 200)</li>
- * <li>Properties file values (/META-INF/applicationConfiguration.properties) (ordinal 100)</li>
- * </ol>
- * <p/>
- * <p><b>Important Hints for custom implementations</b>:</p>
- * <p>
- * If a custom implementation should be invoked <b>before</b> the default implementations, use a value > 400
- * </p>
- * <p>
- * If a custom implementation should be invoked <b>after</b> the default implementations, use a value < 100
- * </p>
- * <p/>
- * <p>Reordering of the default order of the config-sources:</p>
- * <p>Example: If the properties file/s should be used <b>before</b> the other implementations,
- * you have to configure an ordinal > 400. That means, you have to add e.g. deltaspike_ordinal=401 to
- * /META-INF/apache-deltaspike.properties . Hint: In case of property files every file is handled as independent
- * config-source, but all of them have ordinal 400 by default (and can be reordered in a fine-grained manner.</p>
- *
- * @return the 'importance' aka ordinal of the configured values. The higher, the more important.
- * //X TODO think about making this a default method which returns default priority
- */
- int getOrdinal();
-
-
- /**
- * Get the name of the property source. The name should be unique for the type of source, whereas the id is used
- * to ensure unique identity, either locally or remotely.
- * @return the configuration's name, never null.
- */
- String getName();
-
- /**
- * Access a property.
- *
- * //X TODO discuss if the key can be null
- * @param key the property's key, not null.
- * @return the property's keys.
- */
- Optional<String> get(String key);
-
- /**
- * Access the current properties as Map. The resulting Map may not return all items accessible, e.g.
- * when the underlying storage does not support iteration of its entries.
- *
- * @return the a corresponding map, never null.
- * //X TODO or should we just do getPropertyKeys()? Think about security (key) vs easier merging (full map)?
- */
- Map<String,String> getProperties();
-
- /**
- * Determines if this config source could be scanned for its list of properties.
- *
- * <p>
- * PropertySources which are not scannable might not be able to find all the
- * configured values to provide via {@link #getProperties()}. This can e.g. happen
- * if the underlying storage doesn't support listing.
- * </p>
- *
- * @return {@code true} if this PropertySource could be scanned for its list of properties,
- * {@code false} if it should not be scanned.
- */
- default boolean isScannable(){
- return true;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/api/src/main/java/org/apache/tamaya/spi/PropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/PropertySourceProvider.java b/api/src/main/java/org/apache/tamaya/spi/PropertySourceProvider.java
deleted file mode 100644
index 42e3b4d..0000000
--- a/api/src/main/java/org/apache/tamaya/spi/PropertySourceProvider.java
+++ /dev/null
@@ -1,43 +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.spi;
-
-import java.util.Collection;
-
-/**
- * <p>Implement this interfaces to provide a PropertySource provider which
- * is able to register multiple PropertySources. This is e.g. needed if
- * there are multiple property files of a given config file name.</p>
- *
- * <p>If a PropertySource like JNDI only exists once, then there is no need
- * to implement it via the PropertySourceProvider but should directly
- * expose a {@link PropertySource}.</p>
- *
- * <p>A PropertySourceProvider will get picked up via the
- * {@link java.util.ServiceLoader} mechanism and must get registered via
- * META-INF/services/org.apache.tamaya.spi.PropertySourceProvider</p>
- */
-public interface PropertySourceProvider {
-
- /**
- * @return For each e.g. property file, we return a single PropertySource
- * or an empty list if no PropertySource exists.
- */
- Collection<PropertySource> getPropertySources();
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java b/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java
deleted file mode 100644
index f7817e7..0000000
--- a/api/src/main/java/org/apache/tamaya/spi/ServiceContext.java
+++ /dev/null
@@ -1,68 +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.spi;
-
-import java.util.List;
-import java.util.Optional;
-
-
-/**
- * This class models the component that is managing the lifecycle current the
- * services used by the Configuration API.
- */
-public interface ServiceContext {
-
- /**
- * @return ordinal of the ServiceContext. The one with the highest ordinal will be taken.
- */
- default int ordinal() {
- return 1;
- }
-
- /**
- * Access a service singleton via its type.
- * If multiple implementations for the very serviceType exist then
- * the one with the highest {@link javax.annotation.Priority} will be used.
- *
- * @param serviceType the service type.
- * @return The instance to be used, never {@code null}
- * @throws org.apache.tamaya.ConfigException if there are multiple service implementations with the maximum priority.
- */
- <T> Optional<T> getService(Class<T> serviceType);
-
- /**
- * Access a list current services, given its type. The bootstrap mechanism should
- * order the instance for precedence, hereby the most significant should be
- * first in order.
- *
- * @param serviceType
- * the service type.
- * @return The instance to be used, never {@code null}
- */
- <T> List<T> getServices(Class<T> serviceType);
-
- /**
- * Get the current {@link ServiceContext}. If necessary the {@link ServiceContext} will be laziliy loaded.
- *
- * @return the {@link ServiceContext} to be used.
- */
- public static ServiceContext getInstance(){
- return ServiceContextManager.getServiceContext();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/api/src/main/java/org/apache/tamaya/spi/ServiceContextManager.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/spi/ServiceContextManager.java b/api/src/main/java/org/apache/tamaya/spi/ServiceContextManager.java
deleted file mode 100644
index 68e7552..0000000
--- a/api/src/main/java/org/apache/tamaya/spi/ServiceContextManager.java
+++ /dev/null
@@ -1,109 +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.spi;
-
-import java.util.Objects;
-import java.util.ServiceLoader;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.apache.tamaya.ConfigException;
-
-
-/**
- * This singleton provides access to the services available in the current {@link ServiceContext}. The
- * behaviour can be adapted, by calling {@link ServiceContextManager#set(ServiceContext)} before accessing any
- * services.
- */
-final class ServiceContextManager {
- /**
- * The ServiceProvider used.
- */
- private static volatile ServiceContext serviceContextProviderDelegate;
-
- /**
- * Private singletons constructor.
- */
- private ServiceContextManager() {
- }
-
- /**
- * Load the {@link ServiceContext} to be used.
- *
- * @return {@link ServiceContext} to be used for loading the services.
- */
- private static ServiceContext loadDefaultServiceProvider() {
- ServiceContext highestServiceContext = null;
- try {
- int highestOrdinal = 0;
- for (ServiceContext serviceContext : ServiceLoader.load(ServiceContext.class)) {
- if (serviceContext.ordinal() > highestOrdinal) {
- highestServiceContext = serviceContext;
- }
- }
- } catch (Exception e) {
- throw new ConfigException("ServiceContext not loadable", e);
- }
- if(highestServiceContext==null){
- throw new ConfigException("No ServiceContext found");
- }
- return highestServiceContext;
- }
-
- /**
- * Replace the current {@link ServiceContext} in use.
- *
- * @param serviceContextProvider the new {@link ServiceContext}, not null.
- */
- public static ServiceContext set(ServiceContext serviceContextProvider) {
- ServiceContext currentContext = ServiceContextManager.serviceContextProviderDelegate;
- Objects.requireNonNull(serviceContextProvider);
- synchronized (ServiceContextManager.class) {
- if (ServiceContextManager.serviceContextProviderDelegate == null) {
- ServiceContextManager.serviceContextProviderDelegate = serviceContextProvider;
- Logger.getLogger(ServiceContextManager.class.getName())
- .log(Level.INFO, "Using ServiceProvider: " + serviceContextProvider.getClass().getName());
- } else {
- Logger.getLogger(ServiceContextManager.class.getName())
- .log(Level.WARNING, "Replacing ServiceProvider " +
- ServiceContextManager.serviceContextProviderDelegate.getClass().getName() +
- " with: " + serviceContextProvider.getClass().getName());
- ServiceContextManager.serviceContextProviderDelegate = serviceContextProvider;
- }
- }
- return currentContext;
- }
-
- /**
- * Ge {@link ServiceContext}. If necessary the {@link ServiceContext} will be laziliy loaded.
- *
- * @return the {@link ServiceContext} used.
- */
- public static ServiceContext getServiceContext() {
- if (serviceContextProviderDelegate == null) {
- synchronized (ServiceContextManager.class) {
- if (serviceContextProviderDelegate == null) {
- serviceContextProviderDelegate = loadDefaultServiceProvider();
- }
- }
- }
- return serviceContextProviderDelegate;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/tamaya/ConfigurationTest.java b/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
deleted file mode 100644
index 0e62205..0000000
--- a/api/src/test/java/org/apache/tamaya/ConfigurationTest.java
+++ /dev/null
@@ -1,78 +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;
-
-import static org.junit.Assert.*;
-
-/**
- * Test class that tests the default methods implemented on {@link org.apache.tamaya.Configuration}. The provided
- * {@link org.apache.tamaya.TestConfiguration} is implemeted with maximal use of the default methods.
- */
-public class ConfigurationTest {
-
- @org.junit.Test
- public void testget() throws Exception {
- assertEquals(Boolean.TRUE, Configuration.current().get("booleanTrue", (s) -> Boolean.valueOf(s)).get());
- assertEquals(Boolean.FALSE, Configuration.current().get("booleanFalse", (s) -> Boolean.valueOf(s)).get());
- assertEquals((int)Byte.MAX_VALUE, (int)Configuration.current().get("byte", (s) -> Byte.valueOf(s)).get());
- assertEquals((int)Integer.MAX_VALUE, (int)Configuration.current().get("int", (s) -> Integer.valueOf(s)).get());
- assertEquals((long)Long.MAX_VALUE, (long)Configuration.current().get("long", (s) -> Long.valueOf(s)).get());
- assertEquals((double)Float.MAX_VALUE, (double)Configuration.current().get("float", (s) -> Float.valueOf(s)).get(), 0.0d);
- assertEquals((double)Double.MAX_VALUE, (double)Configuration.current().get("double", (s) -> Double.valueOf(s)).get(), 0.0d);
- }
-
- @org.junit.Test
- public void testGetBoolean() throws Exception {
- assertTrue(Configuration.current().getBoolean("booleanTrue"));
- assertFalse(Configuration.current().getBoolean("booleanFalse"));
- assertFalse(Configuration.current().getBoolean("foorBar"));
- }
-
- @org.junit.Test
- public void testGetInteger() throws Exception {
- assertEquals(Integer.MAX_VALUE,Configuration.current().getInteger("int").getAsInt());
- }
-
- @org.junit.Test
- public void testGetLong() throws Exception {
- assertEquals(Long.MAX_VALUE,Configuration.current().getLong("long").getAsLong());
- }
-
- @org.junit.Test
- public void testGetDouble() throws Exception {
- assertEquals(Double.MAX_VALUE,Configuration.current().getDouble("double").getAsDouble(), 0.0d);
- }
-
- @org.junit.Test
- public void testWith() throws Exception {
- assertEquals(Configuration.current(), Configuration.current().with(c-> c));
- }
-
- @org.junit.Test
- public void testQuery() throws Exception {
- assertEquals("myFooResult", Configuration.current().query(c -> "myFooResult"));
- }
-
- @org.junit.Test
- public void testGetAdapted() throws Exception {
- assertEquals("yes", Configuration.current().get("booleanTrue", (v) -> Boolean.parseBoolean(v)?"yes":"no").get());
- assertEquals("no", Configuration.current().get("booleanFalse", (v) -> Boolean.parseBoolean(v)?"yes":"no").get());
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/api/src/test/java/org/apache/tamaya/TestConfiguration.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/tamaya/TestConfiguration.java b/api/src/test/java/org/apache/tamaya/TestConfiguration.java
deleted file mode 100644
index cdcb0e9..0000000
--- a/api/src/test/java/org/apache/tamaya/TestConfiguration.java
+++ /dev/null
@@ -1,87 +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;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
-
-/**
- * Test Configuration class, that is used to testdata the default methods provided by the API.
- */
-public class TestConfiguration implements Configuration{
-
- private static final Map<String, String> VALUES;
- static {
- VALUES = new HashMap<String, String>();
- VALUES.put("long", String.valueOf(Long.MAX_VALUE));
- VALUES.put("int", String.valueOf(Integer.MAX_VALUE));
- VALUES.put("double", String.valueOf(Double.MAX_VALUE));
- VALUES.put("float", String.valueOf(Float.MAX_VALUE));
- VALUES.put("short", String.valueOf(Short.MAX_VALUE));
- VALUES.put("byte", String.valueOf(Byte.MAX_VALUE));
- VALUES.put("booleanTrue", "true");
- VALUES.put("booleanFalse", "false");
- VALUES.put("String", "aStringValue");
- }
-
- @Override
- public Optional<String> get(String key) {
- return Optional.ofNullable(VALUES.get(key));
- }
-
- @Override
- public <T> Optional<T> get(String key, Class<T> type) {
- if(type.equals(Long.class)){
- return Optional.class.cast(Optional.ofNullable(Long.MAX_VALUE));
- }
- else if(type.equals(Integer.class)){
- return Optional.class.cast(Optional.ofNullable(Integer.MAX_VALUE));
- }
- else if(type.equals(Double.class)){
- return Optional.class.cast(Optional.ofNullable(Double.MAX_VALUE));
- }
- else if(type.equals(Float.class)){
- return Optional.class.cast(Optional.ofNullable(Float.MAX_VALUE));
- }
- else if(type.equals(Short.class)){
- return Optional.class.cast(Optional.ofNullable(Short.MAX_VALUE));
- }
- else if(type.equals(Byte.class)){
- return Optional.class.cast(Optional.ofNullable(Byte.MAX_VALUE));
- }
- else if(type.equals(Boolean.class)){
- if("booleanTrue".equals(key)) {
- return Optional.class.cast(Optional.ofNullable(Boolean.TRUE));
- }
- else{
- return Optional.class.cast(Optional.ofNullable(Boolean.FALSE));
- }
- }
- else if(type.equals(String.class)){
- return Optional.class.cast(Optional.ofNullable("aStringValue"));
- }
- throw new ConfigException("No such property: " + key);
- }
-
- @Override
- public Map<String, String> getProperties() {
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java b/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java
deleted file mode 100644
index 0309c6c..0000000
--- a/api/src/test/java/org/apache/tamaya/spi/ServiceContextManagerTest.java
+++ /dev/null
@@ -1,109 +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.spi;
-
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Optional;
-
-public class ServiceContextManagerTest {
-
- private static URLClassLoader classLoader;
- private static Field delegateField;
-
- @BeforeClass
- public static void init() throws Exception {
-
- // setup the environment for our ugly hacks
-
- // replace classloader with our own
- classLoader = (URLClassLoader) Thread.currentThread().getContextClassLoader();
- Thread.currentThread().setContextClassLoader(new UglyHackClassLoader(classLoader));
-
- // clear the caching field
- delegateField = ServiceContextManager.class.getDeclaredField("serviceContextProviderDelegate");
- delegateField.setAccessible(true);
-
- delegateField.set(null, null);
- }
-
- @AfterClass
- public static void clean() throws Exception {
-
- // clean our hacks
-
- delegateField.set(null, null);
- Thread.currentThread().setContextClassLoader(classLoader);
- }
-
- @Test
- public void testGetServiceContext() {
-
- ServiceContext context = ServiceContextManager.getServiceContext();
- Assert.assertEquals(100, context.ordinal());
-
- }
-
-
- // has to be public because ServiceLoader won't find it otherwise
- public static class ServiceContextWithOrdinal implements ServiceContext {
-
- @Override
- public int ordinal() {
- return 100;
- }
-
- @Override
- public <T> Optional<T> getService(Class<T> serviceType) {
- return null;
- }
-
- @Override
- public <T> List<T> getServices(Class<T> serviceType) {
- return null;
- }
- }
-
- // to override the getResources method to use our own 'ServiceLoader'-file we have to this ugly hack
- private static class UglyHackClassLoader extends URLClassLoader {
-
- private UglyHackClassLoader(URLClassLoader urlClassLoader) {
- super(urlClassLoader.getURLs());
- }
-
-
- @Override
- public Enumeration<URL> getResources(String name) throws IOException {
- if ("META-INF/services/org.apache.tamaya.spi.ServiceContext".equals(name)) {
- return super.getResources("ServiceContextWithOrdinal");
- }
-
- return super.getResources(name);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java b/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java
deleted file mode 100644
index 5ebfc19..0000000
--- a/api/src/test/java/org/apache/tamaya/spi/ServiceContextTest.java
+++ /dev/null
@@ -1,93 +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.spi;
-
-import org.junit.Test;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
-
-import static org.junit.Assert.*;
-import static org.junit.Assert.assertEquals;
-
-public class ServiceContextTest {
-
- private ServiceContext serviceContext = new ServiceContext(){
-
- @Override
- public <T> Optional<T> getService(Class<T> serviceType) {
- if(String.class.equals(serviceType)){
- return Optional.of(serviceType.cast("ServiceContextTest"));
- }
- return Optional.empty();
- }
-
- @Override
- public <T> List<T> getServices(Class<T> serviceType) {
- if(String.class.equals(serviceType)){
- List<String> list = new ArrayList<>();
- list.add("ServiceContextTest");
- return List.class.cast(list);
- }
- return Collections.EMPTY_LIST;
- }
- };
-
- @Test
- public void testOrdinal() throws Exception {
- assertEquals(1, serviceContext.ordinal());
- }
-
- @Test
- public void testgetService() throws Exception {
- assertEquals("ServiceContextTest", serviceContext.getService(String.class).get());
- assertFalse(serviceContext.getService(Integer.class).isPresent());
- }
-
- @Test
- public void testGetService() throws Exception {
- Optional<String> service = serviceContext.getService(String.class);
- assertNotNull(service);
- assertTrue(service.isPresent());
- assertEquals("ServiceContextTest", service.get());
- Optional<Integer> intService = serviceContext.getService(Integer.class);
- assertNotNull(intService);
- assertFalse(intService.isPresent());
- }
-
- @Test
- public void testGetServices() throws Exception {
- Collection<String> services = serviceContext.getServices(String.class);
- assertNotNull(services);
- assertFalse(services.isEmpty());
- assertEquals("ServiceContextTest", services.iterator().next());
- Collection<Integer> intServices = serviceContext.getServices(Integer.class);
- assertNotNull(intServices);
- assertTrue(intServices.isEmpty());
- }
-
- @Test
- public void testGetInstance() throws Exception {
- assertNotNull(ServiceContext.getInstance());
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java
----------------------------------------------------------------------
diff --git a/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java b/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java
deleted file mode 100644
index 665c99f..0000000
--- a/api/src/test/java/org/apache/tamaya/spi/TestServiceContext.java
+++ /dev/null
@@ -1,82 +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.spi;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.ServiceLoader;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * This class implements the (default) {@link org.apache.tamaya.spi.ServiceContext} interface and hereby uses the JDK
- * {@link java.util.ServiceLoader} to load the services required.
- */
-public final class TestServiceContext implements ServiceContext {
- /** List current services loaded, per class. */
- private final ConcurrentHashMap<Class, List<Object>> servicesLoaded = new ConcurrentHashMap<>();
- /** Singletons. */
- private final Map<Class, Optional<?>> singletons = new ConcurrentHashMap<>();
-
- @Override
- public <T> Optional<T> getService(Class<T> serviceType) {
- Optional<T> cached = Optional.class.cast(singletons.get(serviceType));
- if(cached==null) {
- List<? extends T> services = getServices(serviceType);
- if (services.isEmpty()) {
- cached = Optional.empty();
- }
- else{
- cached = Optional.of(services.get(0));
- }
- singletons.put(serviceType, cached);
- }
- return cached;
- }
-
- /**
- * Loads and registers services.
- *
- * @param serviceType The service type.
- * @param <T> the concrete type.
- *
- * @return the items found, never {@code null}.
- */
- @Override
- public <T> List<T> getServices(Class<T> serviceType) {
- try {
- List<T> services = new ArrayList<>();
- for (T t : ServiceLoader.load(serviceType)) {
- services.add(t);
- }
- services = Collections.unmodifiableList(services);
- final List<T> previousServices = List.class.cast(servicesLoaded.putIfAbsent(serviceType, (List<Object>)services));
- return previousServices != null ? previousServices : services;
- } catch (Exception e) {
- Logger.getLogger(TestServiceContext.class.getName()).log(Level.WARNING,
- "Error loading services current type " + serviceType, e);
- return Collections.EMPTY_LIST;
- }
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/api/src/test/resources/META-INF/services/org.apache.tamaya.Configuration
----------------------------------------------------------------------
diff --git a/api/src/test/resources/META-INF/services/org.apache.tamaya.Configuration b/api/src/test/resources/META-INF/services/org.apache.tamaya.Configuration
deleted file mode 100644
index 1f42438..0000000
--- a/api/src/test/resources/META-INF/services/org.apache.tamaya.Configuration
+++ /dev/null
@@ -1,19 +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 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.TestConfiguration
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
----------------------------------------------------------------------
diff --git a/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext b/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
deleted file mode 100644
index 0f7abe9..0000000
--- a/api/src/test/resources/META-INF/services/org.apache.tamaya.spi.ServiceContext
+++ /dev/null
@@ -1 +0,0 @@
-org.apache.tamaya.spi.TestServiceContext
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/api/src/test/resources/ServiceContextWithOrdinal
----------------------------------------------------------------------
diff --git a/api/src/test/resources/ServiceContextWithOrdinal b/api/src/test/resources/ServiceContextWithOrdinal
deleted file mode 100644
index 4112c18..0000000
--- a/api/src/test/resources/ServiceContextWithOrdinal
+++ /dev/null
@@ -1,25 +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.
-
-# this is just an ugly hack to test the loading of ServiceContexts
-# if we have more than one
-
-# this one is without overriding ordinal so it shall take the default
-org.apache.tamaya.spi.TestServiceContext
-
-# this one has a higher ordinal (100)
-org.apache.tamaya.spi.ServiceContextManagerTest$ServiceContextWithOrdinal
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/pom.xml
----------------------------------------------------------------------
diff --git a/core/pom.xml b/core/pom.xml
deleted file mode 100644
index 8f53980..0000000
--- a/core/pom.xml
+++ /dev/null
@@ -1,46 +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 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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-all</artifactId>
- <version>0.2-incubating-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
- </parent>
-
- <artifactId>tamaya-core</artifactId>
-
-
- <dependencies>
- <dependency>
- <groupId>org.apache.tamaya</groupId>
- <artifactId>tamaya-api</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
- </dependencies>
-
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/328a4ac7/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java b/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
deleted file mode 100644
index ec23e25..0000000
--- a/core/src/main/java/org/apache/tamaya/core/internal/DefaultConfiguration.java
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.core.internal;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.PropertyConverter;
-import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.ServiceContext;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.util.stream.Collectors;
-
-/**
- * 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 org.apache.tamaya.spi.PropertyFilter}
- * instance to evaluate the current Configuration.
- */
-public class DefaultConfiguration implements Configuration {
- /**
- * The logger.
- */
- private static final Logger LOG = Logger.getLogger(DefaultConfiguration.class.getName());
- /**
- * The maximal number of filter cycles performed before aborting.
- */
- private static final int MAX_FILTER_LOOPS = 10;
-
- /**
- * The current {@link org.apache.tamaya.spi.ConfigurationContext} of the current instance.
- */
- private final ConfigurationContext configurationContext = ServiceContext.getInstance().getService(ConfigurationContext.class).get();
-
- /**
- * This method evaluates the given configuration key. Hereby if goes down the chain or PropertySource instances
- * provided by the current {@link org.apache.tamaya.spi.ConfigurationContext}. The first non-null-value returned
- * is taken as an intermediate value. Finally the value is filtered through the
- * {@link org.apache.tamaya.spi.PropertyFilter} instances installed, before it is returned as the final result of
- * this method.
- *
- * @param key the property's key, not null.
- * @return the optional configuration value, never null.
- */
- @Override
- public Optional<String> get(String key) {
- List<PropertySource> propertySources = configurationContext.getPropertySources();
- String unfilteredValue = null;
- for (PropertySource propertySource : propertySources) {
- Optional<String> value = propertySource.get(key);
- if (value.isPresent()) {
- unfilteredValue = value.get();
- break;
- }
- }
- return Optional.ofNullable(applyFilter(key, unfilteredValue));
- }
-
- /**
- * Apply filters to a single property value.
- *
- * @param key the key, used for logging, not null.
- * @param unfilteredValue the unfiltered property value.
- * @return the filtered value, or null.
- */
- private String applyFilter(String key, String unfilteredValue) {
- // 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()) {
- String newValue = filter.filterProperty(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;
- }
-
- /**
- * Get the current properties, composed by the loaded {@link org.apache.tamaya.spi.PropertySource} and filtered
- * by registered {@link org.apache.tamaya.spi.PropertyFilter}.
- *
- * @return the final properties.
- */
- @Override
- public Map<String, String> getProperties() {
- 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);
- }
- }
- return applyFilters(result);
- }
-
- /**
- * Filter a full configuration property map.
- *
- * @param inputMap the unfiltered map
- * @return the filtered map.
- */
- private Map<String, String> applyFilters(Map<String, String> 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()) {
- inputMap.replaceAll((k, v) -> {
- String newValue = filter.filterProperty(k, v);
- 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);
- }
- return newValue;
- });
- }
- 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);
- }
- }
- // Remove null values
- return inputMap.entrySet().parallelStream().filter((e) -> e.getValue() != null).collect(
- Collectors.toMap((e) -> e.getKey(), (e) -> e.getValue()));
- }
-
- /**
- * Accesses the current String value for the given key (see {@link #get(String)}) and tries to convert it
- * using the {@link org.apache.tamaya.spi.PropertyConverter} instances provided by the current
- * {@link org.apache.tamaya.spi.ConfigurationContext}.
- *
- * @param key the property's absolute, or relative path, e.g. @code
- * a/b/c/d.myProperty}.
- * @param type The target type required, not null.
- * @param <T> the value type
- * @return the converted value, never null.
- */
- @Override
- public <T> Optional<T> get(String key, Class<T> type) {
- Optional<String> value = get(key);
- if (value.isPresent()) {
- List<PropertyConverter<T>> converters = configurationContext.getPropertyConverters(type);
- for (PropertyConverter<T> converter : converters) {
- try {
- T t = converter.convert(value.get());
- if (t != null) {
- return Optional.of(t);
- }
- } catch (Exception e) {
- LOG.log(Level.FINEST, e, () -> "PropertyConverter: " + converter +
- " failed to convert value: " + value.get());
- }
- }
- throw new ConfigException("Unparseable config value for type: " + type.getName() + ": " + key);
- }
- return Optional.empty();
- }
-}