You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by an...@apache.org on 2017/11/14 09:33:23 UTC
[1/9] incubator-tamaya-extensions git commit: TAMAYA-260 Added MP
styled configuration builder.
Repository: incubator-tamaya-extensions
Updated Branches:
refs/heads/master 05b1faadc -> 13e43a49e
TAMAYA-260 Added MP styled configuration builder.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/commit/bad5feae
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/bad5feae
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/bad5feae
Branch: refs/heads/master
Commit: bad5feae202184003c014cdf88fbe5393cb1932b
Parents: 572e1ab
Author: Anatole Tresch <an...@apache.org>
Authored: Sun Nov 12 21:28:55 2017 +0100
Committer: Anatole Tresch <an...@apache.org>
Committed: Tue Nov 14 10:26:04 2017 +0100
----------------------------------------------------------------------
.../tamaya/spisupport/ConfigurationBuilder.java | 334 +++++++++++++++++++
.../spisupport/DefaultConfigurationBuilder.java | 229 +++++++++++++
2 files changed, 563 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/bad5feae/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/ConfigurationBuilder.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/ConfigurationBuilder.java
new file mode 100644
index 0000000..be2978b
--- /dev/null
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/ConfigurationBuilder.java
@@ -0,0 +1,334 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spisupport;
+
+
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.*;
+
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A builder for creating new or adapting instances of {@link Configuration}.
+ * Builders can be obtained in exactly two ways:
+ * <ol>
+ * <li>By accessing a preinitialized builder from an existing {@link Configuration},
+ * by calling {@link org.apache.tamaya.Configuration#toBuilder()}.</li>
+ * <li>By accessing an empty builder instance from
+ * {@link org.apache.tamaya.ConfigurationProvider#getConfigurationBuilder()}.</li>
+ * </ol>
+ */
+public interface ConfigurationBuilder {
+
+ /**
+ * Init this builder instance with the given {@link ConfigurationContext} instance. This
+ * method will use any existing property sources, filters, converters and the combination
+ * policy of the given {@link ConfigurationContext} and initialize the current builder
+ * with them.
+ *
+ * @param context the {@link ConfigurationContext} instance to be used, not {@code null}.
+ * @return this builder, for chaining, never null.
+ */
+ ConfigurationBuilder setContext(ConfigurationContext context);
+
+ /**
+ * This method can be used for adding {@link PropertySource}s.
+ * Hereby the property source is added to the tail of property sources with
+ * lowest priority regardless of its current ordinal value. To sort the property
+ * sources based on their ordinals call {@link #sortPropertySources}.
+ *
+ * @param propertySources the PropertySources to add
+ * @return this builder, for chaining, never null.
+ * @throws IllegalArgumentException If a property source with a given name already
+ * exists.
+ */
+ ConfigurationBuilder addPropertySources(PropertySource... propertySources);
+
+ /**
+ * This method can be used for programmatically adding {@link PropertySource}s.
+ * Hereby the property source is added to the tail of property sources with
+ * lowest priority regardless of its current ordinal value. To sort the property
+ * sources based on their ordinals call {@link #sortPropertySources}.
+ *
+ * @param propertySources the PropertySources to add
+ * @return this builder, for chaining, never null.
+ * @throws IllegalArgumentException If a property source with a given name already
+ * exists.
+ */
+ ConfigurationBuilder addPropertySources(Collection<PropertySource> propertySources);
+
+ /**
+ * Add all registered (default) property sources to the context built. The sources are ordered
+ * based on their ordinal values and added to the chain of property sources with
+ * higher priority.
+ * @return this builder, for chaining, never null.
+ */
+ ConfigurationBuilder addDefaultPropertySources();
+
+ /**
+ * Removes the given property sources, if existing. The existing order of property
+ * sources is preserved.
+ *
+ * @param propertySources the property sources to remove, not {@code null}.
+ * @return the builder for chaining.
+ */
+ ConfigurationBuilder removePropertySources(PropertySource... propertySources);
+
+ /**
+ * Removes the given property sources, if existing. The existing order of property
+ * sources is preserved.
+ *
+ * @param propertySources the property sources to remove, not {@code null}.
+ * @return the builder for chaining.
+ */
+ ConfigurationBuilder removePropertySources(Collection<PropertySource> propertySources);
+
+ /**
+ * Access the current chain of property sources. Items at the end of the list have
+ * precedence/more significance.
+ *
+ * @return the property source chain, never {@code null}.
+ */
+ List<PropertySource> getPropertySources();
+
+ /**
+ * Access the current chain of property filters. Items at the end of the list have
+ * precedence/more significance.
+ *
+ * @return the property source chain, never {@code null}.
+ */
+ List<PropertyFilter> getPropertyFilters();
+
+ /**
+ * Access the current registered property converters.
+ *
+ * @return the current registered property converters.
+ */
+ Map<TypeLiteral<?>, Collection<PropertyConverter<?>>> getPropertyConverter();
+
+ /**
+ * Increases the priority of the given property source, by moving it towards the end
+ * of the chain of property sources. If the property source given is already at the end
+ * this method has no effect. This operation does not change any ordinal values.
+ *
+ * @param propertySource the property source to be incresed regarding its significance.
+ * @return the builder for chaining.
+ * @throws IllegalArgumentException If no such property source exists in the current
+ * chain.
+ */
+ ConfigurationBuilder increasePriority(PropertySource propertySource);
+
+ /**
+ * Decreases the priority of the given property source, by moving it towards the start
+ * of the chain of property sources. If the property source given is already the first
+ * this method has no effect. This operation does not change any ordinal values.
+ *
+ * @param propertySource the property source to be decresed regarding its significance.
+ * @return the builder for chaining.
+ * @throws IllegalArgumentException If no such property source exists in the current
+ * chain.
+ */
+ ConfigurationBuilder decreasePriority(PropertySource propertySource);
+
+ /**
+ * Increases the priority of the given property source to be maximal, by moving it to
+ * the tail of the of property source chain. If the property source given is
+ * already the last item this method has no effect. This operation does not change
+ * any ordinal values.
+ *
+ * @param propertySource the property source to be maximized regarding its significance.
+ * @return the builder for chaining.
+ * @throws IllegalArgumentException If no such property source exists in the current
+ * chain.
+ */
+ ConfigurationBuilder highestPriority(PropertySource propertySource);
+
+ /**
+ * Decreases the priority of the given property source to be minimal, by moving it to
+ * the start of the chain of property source chain. If the property source given is
+ * already the first item this method has no effect. This operation does not change
+ * any ordinal values.
+ *
+ * @param propertySource the property source to be minimized regarding its significance.
+ * @return the builder for chaining.
+ * @throws IllegalArgumentException If no such property source exists in the current
+ * chain.
+ */
+ ConfigurationBuilder lowestPriority(PropertySource propertySource);
+
+ /**
+ * Adds the given PropertyFilter instances, hereby the instances are added
+ * to the end of the list with highest priority. The ordering of existing
+ * property filters remains unchanged. To sort the property
+ * filters call {@link #sortPropertyFilter}.
+ *
+ * @param filters the filters to add
+ * @return this builder, for chaining, never null.
+ */
+ ConfigurationBuilder addPropertyFilters(PropertyFilter... filters);
+
+ /**
+ * Adds the given PropertyFilter instances, hereby the instances are added
+ * to the end of the list with highest priority. The ordering of existing
+ * property filters remains unchanged. To sort the property
+ * filters call {@link #sortPropertyFilter}.
+ *
+ * @param filters the filters to add
+ * @return this builder, for chaining, never null.
+ */
+ ConfigurationBuilder addPropertyFilters(Collection<PropertyFilter> filters);
+
+ /**
+ * Add all registered (default) property filters to the context built.
+ * @return this builder, for chaining, never null.
+ */
+ ConfigurationBuilder addDefaultPropertyFilters();
+
+
+ /**
+ * Removes the given PropertyFilter instances, if existing. The order of the remaining
+ * filters is preserved.
+ *
+ * @param filters the filter to remove
+ * @return this builder, for chaining, never null.
+ */
+ ConfigurationBuilder removePropertyFilters(PropertyFilter... filters);
+
+ /**
+ * Removes the given PropertyFilter instances, if existing. The order of the remaining
+ * filters is preserved.
+ *
+ * @param filters the filter to remove
+ * @return this builder, for chaining, never null.
+ */
+ ConfigurationBuilder removePropertyFilters(Collection<PropertyFilter> filters);
+
+ /**
+ * This method can be used for adding {@link PropertyConverter}s.
+ * Converters are added at the end after any existing converters.
+ * For converters already registered for the current target type the
+ * method has no effect.
+ *
+ * @param typeToConvert the type for which the converter is for
+ * @param propertyConverters the PropertyConverters to add for this type
+ * @param <T> the target type.
+ * @return this builder, for chaining, never null.
+ */
+ <T> ConfigurationBuilder addPropertyConverters(TypeLiteral<T> typeToConvert,
+ PropertyConverter<T>... propertyConverters);
+
+ /**
+ * This method can be used for adding {@link PropertyConverter}s.
+ * Converters are added at the end after any existing converters.
+ * For converters already registered for the current target type the
+ * method has no effect.
+ *
+ * @param typeToConvert the type for which the converter is for
+ * @param propertyConverters the PropertyConverters to add for this type
+ * @param <T> the target type.
+ * @return this builder, for chaining, never null.
+ */
+ <T> ConfigurationBuilder addPropertyConverters(TypeLiteral<T> typeToConvert,
+ Collection<PropertyConverter<T>> propertyConverters);
+
+ /**
+ * Add all registered (default) property converters to the context built.
+ * @return this builder, for chaining, never null.
+ */
+ ConfigurationBuilder addDefaultPropertyConverters();
+
+ /**
+ * Removes the given PropertyConverter instances for the given type,
+ * if existing.
+ *
+ * @param typeToConvert the type which the converter is for
+ * @param propertyConverters the converter to remove
+ * @param <T> the target type.
+ * @return this builder, for chaining, never null.
+ */
+ <T> ConfigurationBuilder removePropertyConverters(TypeLiteral<T> typeToConvert,
+ PropertyConverter<T>... propertyConverters);
+
+ /**
+ * Removes the given PropertyConverter instances for the given type,
+ * if existing.
+ *
+ * @param typeToConvert the type which the converter is for
+ * @param propertyConverters the converter to remove
+ * @param <T> the target type.
+ * @return this builder, for chaining, never null.
+ */
+ <T> ConfigurationBuilder removePropertyConverters(TypeLiteral<T> typeToConvert,
+ Collection<PropertyConverter<T>> propertyConverters);
+
+ /**
+ * Removes all converters for the given type, which actually renders a given type
+ * unsupported for type conversion.
+ *
+ * @param typeToConvert the type which the converter is for
+ * @return this builder, for chaining, never null.
+ */
+ ConfigurationBuilder removePropertyConverters(TypeLiteral<?> typeToConvert);
+
+ /**
+ * Sorts the current registered property sources using the given comparator.
+ *
+ * NOTE: property sources at the beginning have minimal significance.
+ *
+ * @param comparator the comparator to be used, not {@code null}.
+ * @return this instance for chaining.
+ */
+ ConfigurationBuilder sortPropertySources(Comparator<PropertySource> comparator);
+
+ /**
+ * Sorts the current registered property filters using the given comparator.
+ *
+ * NOTE: property filters at the beginning have minimal significance.
+ *
+ * @param comparator the comparator to be used, not {@code null}.
+ * @return this instance for chaining.
+ */
+ ConfigurationBuilder sortPropertyFilter(Comparator<PropertyFilter> comparator);
+
+ /**
+ * Sets the {@link PropertyValueCombinationPolicy} used to evaluate the final
+ * property values.
+ *
+ * @param policy the {@link PropertyValueCombinationPolicy} used, not {@code null}.
+ * @return this builder, for chaining, never null.
+ */
+ ConfigurationBuilder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy policy);
+
+ /**
+ * Builds a new {@link Configuration} based on the data in this builder. The ordering of property
+ * sources and property filters is not changed, regardless of their ordinals. For ensure a certain
+ * ordering/significance call {@link #sortPropertyFilter(Comparator)} and/or {@link #sortPropertySources(Comparator)}
+ * before building the context.
+ *
+ * @return the final configuration.
+ */
+ Configuration build();
+
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/bad5feae/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java
new file mode 100644
index 0000000..b26d0af
--- /dev/null
+++ b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java
@@ -0,0 +1,229 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tamaya.spisupport;
+
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.TypeLiteral;
+import org.apache.tamaya.spi.*;
+
+import java.util.*;
+
+/**
+ * Default implementation of {@link ConfigurationContextBuilder}.
+ */
+public class DefaultConfigurationBuilder implements ConfigurationBuilder {
+
+ private final ConfigurationContextBuilder contextBuilder;
+
+ /**
+ * Creates a new builder instance.
+ */
+ public DefaultConfigurationBuilder() {
+ this.contextBuilder = new DefaultConfigurationContextBuilder();
+ }
+
+ /**
+ * Creates a new builder instance initializing it with the given context.
+ * @param configuration the configuration to be used, not null.
+ */
+ public DefaultConfigurationBuilder(Configuration configuration) {
+ this.contextBuilder = new DefaultConfigurationContextBuilder(configuration.getContext());
+ }
+
+ /**
+ * Allows to set configuration context during unit tests.
+ */
+ ConfigurationBuilder setConfiguration(Configuration configuration) {
+ this.contextBuilder.setContext(configuration.getContext());
+ return this;
+ }
+
+
+ @Override
+ public ConfigurationBuilder setContext(ConfigurationContext context) {
+ this.contextBuilder.setContext(context);
+ return this;
+ }
+
+ @Override
+ public ConfigurationBuilder addPropertySources(PropertySource... sources){
+ this.contextBuilder.addPropertySources(sources);
+ return this;
+ }
+
+ @Override
+ public ConfigurationBuilder addPropertySources(Collection<PropertySource> sources){
+ this.contextBuilder.addPropertySources(sources);
+ return this;
+ }
+
+ public ConfigurationBuilder addDefaultPropertyFilters() {
+ this.contextBuilder.addDefaultPropertyFilters();
+ return this;
+ }
+
+ public ConfigurationBuilder addDefaultPropertySources() {
+ this.contextBuilder.addDefaultPropertySources();
+ return this;
+ }
+
+ public ConfigurationBuilder addDefaultPropertyConverters() {
+ this.contextBuilder.addDefaultPropertyConverters();
+ return this;
+ }
+
+ @Override
+ public ConfigurationBuilder removePropertySources(PropertySource... propertySources) {
+ this.contextBuilder.removePropertySources(propertySources);
+ return this;
+ }
+
+ @Override
+ public ConfigurationBuilder removePropertySources(Collection<PropertySource> propertySources) {
+ this.contextBuilder.removePropertySources(propertySources);
+ return this;
+ }
+
+ @Override
+ public List<PropertySource> getPropertySources() {
+ return this.contextBuilder.getPropertySources();
+ }
+
+ @Override
+ public ConfigurationBuilder increasePriority(PropertySource propertySource) {
+ this.contextBuilder.increasePriority(propertySource);
+ return this;
+ }
+
+ @Override
+ public ConfigurationBuilder decreasePriority(PropertySource propertySource) {
+ this.contextBuilder.decreasePriority(propertySource);
+ return this;
+ }
+
+ @Override
+ public ConfigurationBuilder highestPriority(PropertySource propertySource) {
+ this.contextBuilder.highestPriority(propertySource);
+ return this;
+ }
+
+ @Override
+ public ConfigurationBuilder lowestPriority(PropertySource propertySource) {
+ this.contextBuilder.lowestPriority(propertySource);
+ return this;
+ }
+
+ @Override
+ public ConfigurationBuilder addPropertyFilters(PropertyFilter... filters){
+ this.contextBuilder.addPropertyFilters(filters);
+ return this;
+ }
+
+ @Override
+ public ConfigurationBuilder addPropertyFilters(Collection<PropertyFilter> filters){
+ this.contextBuilder.addPropertyFilters(filters);
+ return this;
+ }
+
+ @Override
+ public ConfigurationBuilder removePropertyFilters(PropertyFilter... filters) {
+ this.contextBuilder.removePropertyFilters(filters);
+ return this;
+ }
+
+ @Override
+ public ConfigurationBuilder removePropertyFilters(Collection<PropertyFilter> filters) {
+ this.contextBuilder.removePropertyFilters(filters);
+ return this;
+ }
+
+
+ @Override
+ public <T> ConfigurationBuilder removePropertyConverters(TypeLiteral<T> typeToConvert,
+ PropertyConverter<T>... converters) {
+ this.contextBuilder.removePropertyConverters(typeToConvert, converters);
+ return this;
+ }
+
+ @Override
+ public <T> ConfigurationBuilder removePropertyConverters(TypeLiteral<T> typeToConvert,
+ Collection<PropertyConverter<T>> converters) {
+ this.contextBuilder.removePropertyConverters(typeToConvert, converters);
+ return this;
+ }
+
+ @Override
+ public ConfigurationBuilder removePropertyConverters(TypeLiteral<?> typeToConvert) {
+ this.contextBuilder.removePropertyConverters(typeToConvert);
+ return this;
+ }
+
+
+ @Override
+ public ConfigurationBuilder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy combinationPolicy){
+ this.contextBuilder.setPropertyValueCombinationPolicy(combinationPolicy);
+ return this;
+ }
+
+
+ @Override
+ public <T> ConfigurationBuilder addPropertyConverters(TypeLiteral<T> type, PropertyConverter<T>... propertyConverters){
+ this.contextBuilder.addPropertyConverters(type, propertyConverters);
+ return this;
+ }
+
+ @Override
+ public <T> ConfigurationBuilder addPropertyConverters(TypeLiteral<T> type, Collection<PropertyConverter<T>> propertyConverters){
+ this.contextBuilder.addPropertyConverters(type, propertyConverters);
+ return this;
+ }
+
+ /**
+ * Builds a new configuration based on the configuration of this builder instance.
+ *
+ * @return a new {@link org.apache.tamaya.Configuration configuration instance},
+ * never {@code null}.
+ */
+ @Override
+ public Configuration build() {
+ return new DefaultConfiguration(this.contextBuilder.build());
+ }
+
+ @Override
+ public ConfigurationBuilder sortPropertyFilter(Comparator<PropertyFilter> comparator) {
+ this.contextBuilder.sortPropertyFilter(comparator);
+ return this;
+ }
+
+ @Override
+ public ConfigurationBuilder sortPropertySources(Comparator<PropertySource> comparator) {
+ this.contextBuilder.sortPropertySources(comparator);
+ return this;
+ }
+
+ @Override
+ public List<PropertyFilter> getPropertyFilters() {
+ return this.contextBuilder.getPropertyFilters();
+ }
+
+ @Override
+ public Map<TypeLiteral<?>, Collection<PropertyConverter<?>>> getPropertyConverter() {
+ return this.contextBuilder.getPropertyConverter();
+ }
+}
[5/9] incubator-tamaya-extensions git commit: TAMAYA-318 Moved
spi-support as API base implementation package to remove code duplicates.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyConverterManager.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyConverterManager.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyConverterManager.java
deleted file mode 100644
index 1f1a2a9..0000000
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyConverterManager.java
+++ /dev/null
@@ -1,469 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-import org.apache.tamaya.spi.ServiceContextManager;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.Type;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Manager that deals with {@link 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 final Map<TypeLiteral<?>, List<PropertyConverter<?>>> converters = new ConcurrentHashMap<>();
- /**
- * The transitive converters.
- */
- private final Map<TypeLiteral<?>, List<PropertyConverter<?>>> transitiveConverters = new ConcurrentHashMap<>();
- /**
- * The lock used.
- */
- private final ReadWriteLock lock = new ReentrantReadWriteLock();
-
- private static final Comparator<Object> PRIORITY_COMPARATOR = new Comparator<Object>() {
-
- @Override
- public int compare(Object o1, Object o2) {
- int prio = PriorityServiceComparator.getPriority(o1) - PriorityServiceComparator.getPriority(o2);
- if (prio < 0) {
- return 1;
- } else if (prio > 0) {
- return -1;
- } else {
- return o1.getClass().getSimpleName().compareTo(o2.getClass().getSimpleName());
- }
- }
- };
-
- /**
- * Constructor.
- */
- public PropertyConverterManager() {
- this(true);
- }
-
- public PropertyConverterManager(boolean init) {
- if (init) {
- initConverters();
- }
- }
-
- /**
- * Registers the default converters provided out of the box.
- */
- protected void initConverters() {
- for (PropertyConverter conv : ServiceContextManager.getServiceContext().getServices(PropertyConverter.class)) {
- Type type = TypeLiteral.getGenericInterfaceTypeParameters(conv.getClass(), PropertyConverter.class)[0];
- register(TypeLiteral.of(type), conv);
- }
- }
-
- /**
- * 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(TypeLiteral<T> targetType, PropertyConverter<T> converter) {
- Objects.requireNonNull(converter);
- Lock writeLock = lock.writeLock();
- try {
- writeLock.lock();
- List converters = List.class.cast(this.converters.get(targetType));
- if(converters!=null && converters.contains(converter)){
- return;
- }
- List<PropertyConverter<?>> newConverters = new ArrayList<>();
- if (converters != null) {
- newConverters.addAll(converters);
- }
- if(!newConverters.contains(converter)) {
- newConverters.add(converter);
- }
- Collections.sort(newConverters, PRIORITY_COMPARATOR);
- this.converters.put(targetType, Collections.unmodifiableList(newConverters));
- // evaluate transitive closure for all inherited supertypes and implemented interfaces
- // direct implemented interfaces
- for (Class<?> ifaceType : targetType.getRawType().getInterfaces()) {
- converters = List.class.cast(this.transitiveConverters.get(TypeLiteral.of(ifaceType)));
- newConverters = new ArrayList<>();
- if (converters != null) {
- newConverters.addAll(converters);
- }
- newConverters.add(converter);
- Collections.sort(newConverters, PRIORITY_COMPARATOR);
- this.transitiveConverters.put(TypeLiteral.of(ifaceType), Collections.unmodifiableList(newConverters));
- }
- Class<?> superClass = targetType.getRawType().getSuperclass();
- while (superClass != null && !superClass.equals(Object.class)) {
- converters = List.class.cast(this.transitiveConverters.get(TypeLiteral.of(superClass)));
- newConverters = new ArrayList<>();
- if (converters != null) {
- newConverters.addAll(converters);
- }
- newConverters.add(converter);
- Collections.sort(newConverters, PRIORITY_COMPARATOR);
- this.transitiveConverters.put(TypeLiteral.of(superClass), Collections.unmodifiableList(newConverters));
- for (Class<?> ifaceType : superClass.getInterfaces()) {
- converters = List.class.cast(this.transitiveConverters.get(TypeLiteral.of(ifaceType)));
- newConverters = new ArrayList<>();
- if (converters != null) {
- newConverters.addAll(converters);
- }
- newConverters.add(converter);
- Collections.sort(newConverters, PRIORITY_COMPARATOR);
- this.transitiveConverters.put(TypeLiteral.of(ifaceType), Collections.unmodifiableList(newConverters));
- }
- superClass = superClass.getSuperclass();
- }
- } 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(TypeLiteral<?> targetType) {
- return converters.containsKey(targetType) || transitiveConverters.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(TypeLiteral)
- */
- public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() {
- Lock readLock = lock.readLock();
- 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.
- * The converters provided are of the following type and returned in the following order:
- * <ul>
- * <li>Converters mapped explicitly to the required target type are returned first, ordered
- * by decreasing priority. This means, if explicit converters are registered these are used
- * primarly for converting a value.</li>
- * <li>The target type of each explicitly registered converter also can be transitively mapped to
- * 1) all directly implemented interfaces, 2) all its superclasses (except Object), 3) all the interfaces
- * implemented by its superclasses. These groups of transitive converters is returned similarly in the
- * order as mentioned, whereas also here a priority based decreasing ordering is applied.</li>
- * <li>java.lang wrapper classes and native types are automatically mapped.</li>
- * <li>If no explicit converters are registered, for Enum types a default implementation is provided that
- * compares the configuration values with the different enum members defined (cases sensitive mapping).</li>
- * </ul>
- * <p>
- * So given that list above directly registered mappings always are tried first, before any transitive mapping
- * should be used. Also in all cases @Priority annotations are honored for ordering of the converters in place.
- * Transitive conversion is supported for all directly implemented interfaces (including inherited ones) and
- * the inheritance hierarchy (exception Object). Superinterfaces of implemented interfaces are ignored.
- *
- * @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(TypeLiteral)
- */
- public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> targetType) {
- Lock readLock = lock.readLock();
- List<PropertyConverter<T>> converterList = new ArrayList<>();
- List<PropertyConverter<T>> converters;
- // direct mapped converters
- try {
- readLock.lock();
- addConvertersToList(List.class.cast(this.converters.get(targetType)), converterList);
- addConvertersToList(List.class.cast(this.transitiveConverters.get(targetType)), converterList);
- } finally {
- readLock.unlock();
- }
- // handling of java.lang wrapper classes
- TypeLiteral<T> boxedType = mapBoxedType(targetType);
- if (boxedType != null) {
- try {
- readLock.lock();
- addConvertersToList(List.class.cast(this.converters.get(boxedType)), converterList);
- } finally {
- readLock.unlock();
- }
- }
- if (converterList.isEmpty() && !TypeLiteral.of(String.class).equals(targetType)) {
- // adding any converters created on the fly, e.g. for enum types.
- PropertyConverter<T> defaultConverter = createDefaultPropertyConverter(targetType);
- if (defaultConverter != null) {
- register(targetType, defaultConverter);
- try {
- readLock.lock();
- addConvertersToList(List.class.cast(this.converters.get(targetType)), converterList);
- } finally {
- readLock.unlock();
- }
- }
- }
- // check for parametrized types, ignoring param type
- // direct mapped converters
- if(targetType.getType()!=null) {
- try {
- readLock.lock();
- addConvertersToList(List.class.cast(this.converters.get(
- TypeLiteral.of(targetType.getRawType()))), converterList);
- } finally {
- readLock.unlock();
- }
- }
- return converterList;
- }
-
- private <T> void addConvertersToList(Collection<PropertyConverter<T>> converters, List<PropertyConverter<T>> converterList) {
- if (converters != null) {
- for(PropertyConverter<T> conv:converters) {
- if(!converterList.contains(conv)) {
- converterList.add(conv);
- }
- }
- }
- }
-
- /**
- * Maps native types to the corresponding boxed types.
- *
- * @param targetType the native type.
- * @param <T> the type
- * @return the boxed type, or null.
- */
- private <T> TypeLiteral<T> mapBoxedType(TypeLiteral<T> targetType) {
- Type parameterType = targetType.getType();
- if (parameterType == int.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Integer.class));
- }
- if (parameterType == short.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Short.class));
- }
- if (parameterType == byte.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Byte.class));
- }
- if (parameterType == long.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Long.class));
- }
- if (parameterType == boolean.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Boolean.class));
- }
- if (parameterType == char.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Character.class));
- }
- if (parameterType == float.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Float.class));
- }
- if (parameterType == double.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Double.class));
- }
- if (parameterType == int[].class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Integer[].class));
- }
- if (parameterType == short[].class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Short[].class));
- }
- if (parameterType == byte[].class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Byte[].class));
- }
- if (parameterType == long[].class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Long[].class));
- }
- if (parameterType == boolean.class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Boolean.class));
- }
- if (parameterType == char[].class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Character[].class));
- }
- if (parameterType == float[].class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Float[].class));
- }
- if (parameterType == double[].class) {
- return TypeLiteral.class.cast(TypeLiteral.of(Double[].class));
- }
- return null;
- }
-
- /**
- * 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(final TypeLiteral<T> targetType) {
- if (Enum.class.isAssignableFrom(targetType.getRawType())) {
- return new EnumConverter<>(targetType.getRawType());
- }
- PropertyConverter<T> converter = null;
- final Method factoryMethod = getFactoryMethod(targetType.getRawType(), "of", "valueOf", "instanceOf", "getInstance", "from", "fromString", "parse");
- if (factoryMethod != null) {
- converter = new DefaultPropertyConverter<>(factoryMethod, targetType.getRawType());
- }
- if (converter == null) {
- final Constructor<T> constr;
- try {
- constr = targetType.getRawType().getDeclaredConstructor(String.class);
- } catch (NoSuchMethodException e) {
- LOG.log(Level.FINEST, "No matching constrctor for " + targetType, e);
- return null;
- }
- converter = new PropertyConverter<T>() {
- @Override
- public T convert(String value, ConversionContext context) {
- AccessController.doPrivileged(new PrivilegedAction<Object>() {
- @Override
- public Object run() {
- AccessController.doPrivileged(new PrivilegedAction<Object>() {
- @Override
- public Object run() {
- constr.setAccessible(true);
- return null;
- }
- });
- return null;
- }
- });
- try {
- return constr.newInstance(value);
- } catch (Exception e) {
- LOG.log(Level.SEVERE, "Error creating new PropertyConverter instance " + targetType, e);
- }
- return null;
- }
- };
- }
- 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 (NoSuchMethodException | RuntimeException e) {
- LOG.finest("No such factory method found on type: " + type.getName() + ", methodName: " + name);
- }
- }
- return null;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof PropertyConverterManager)) {
- return false;
- }
- PropertyConverterManager that = (PropertyConverterManager) o;
- return converters.equals(that.converters);
-
- }
-
- @Override
- public int hashCode() {
- return converters.hashCode();
- }
-
- /**
- * Default converter imüöementation perfoming several lookups for String converion
- * option.
- * @param <T>
- */
- private static class DefaultPropertyConverter<T> implements PropertyConverter<T> {
-
- private final Method factoryMethod;
- private final Class<T> targetType;
-
- DefaultPropertyConverter(Method factoryMethod, Class<T> targetType){
- this.factoryMethod = Objects.requireNonNull(factoryMethod);
- this.targetType = Objects.requireNonNull(targetType);
- }
-
- @Override
- public T convert(String value, ConversionContext context) {
- context.addSupportedFormats(getClass(), "<String -> "+factoryMethod.toGenericString());
-
- if (!Modifier.isStatic(factoryMethod.getModifiers())) {
- throw new ConfigException(factoryMethod.toGenericString() +
- " is not a static method. Only static " +
- "methods can be used as factory methods.");
- }
- try {
- AccessController.doPrivileged(new PrivilegedAction<Object>() {
- @Override
- public Object run() {
- factoryMethod.setAccessible(true);
- return null;
- }
- });
- Object invoke = factoryMethod.invoke(null, value);
- return targetType.cast(invoke);
- } catch (Exception e) {
- throw new ConfigException("Failed to decode '" + value + "'", e);
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFilterComparator.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFilterComparator.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFilterComparator.java
deleted file mode 100644
index 20eef63..0000000
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFilterComparator.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import org.apache.tamaya.spi.PropertyFilter;
-
-import javax.annotation.Priority;
-import java.io.Serializable;
-import java.util.Comparator;
-
-/**
- * Comparator for PropertyFilters based on their priority annotations.
- */
-public final class PropertyFilterComparator implements Comparator<PropertyFilter>, Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private static final PropertyFilterComparator INSTANCE = new PropertyFilterComparator();
-
- /**
- * Get the shared instance of the comparator.
- * @return the shared instance, never null.
- */
- public static PropertyFilterComparator getInstance(){
- return INSTANCE;
- }
-
- private PropertyFilterComparator(){}
-
- /**
- * 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 int compare(PropertyFilter filter1, PropertyFilter filter2) {
- return comparePropertyFilters(filter1, filter2);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFiltering.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFiltering.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFiltering.java
deleted file mode 100644
index ee76623..0000000
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertyFiltering.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.FilterContext;
-import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.PropertyValue;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Implementation of the Configuration API. This class uses the current {@link ConfigurationContext} to evaluate the
- * chain of {@link org.apache.tamaya.spi.PropertySource} and {@link PropertyFilter}
- * instance to evaluate the current Configuration.
- */
-public final class PropertyFiltering{
- /**
- * The logger.
- */
- private static final Logger LOG = Logger.getLogger(PropertyFiltering.class.getName());
- /**
- * The maximal number of filter cycles performed before aborting.
- */
- private static final int MAX_FILTER_LOOPS = 10;
-
- /**
- * Private singleton constructor.
- */
- private PropertyFiltering(){}
-
- /**
- * Filters a single value.
- * @param value the raw value, not null.
- * @param context the context
- * @return the filtered value, inclusing null.
- */
- public static PropertyValue applyFilter(PropertyValue value, ConfigurationContext context) {
- FilterContext filterContext = new FilterContext(value, context);
- return filterValue(filterContext);
- }
-
- /**
- * Filters all properties.
- * @param rawProperties the unfiltered properties, not null.
- * @param context the context
- * @return the filtered value, inclusing null.
- */
- public static Map<String, PropertyValue> applyFilters(Map<String, PropertyValue> rawProperties, ConfigurationContext context) {
- Map<String, PropertyValue> result = new HashMap<>();
- // Apply filters to values, prevent values filtered to null!
- for (Map.Entry<String, PropertyValue> entry : rawProperties.entrySet()) {
- FilterContext filterContext = new FilterContext(entry.getValue(), rawProperties, context);
- PropertyValue filtered = filterValue(filterContext);
- if(filtered!=null){
- result.put(filtered.getKey(), filtered);
- }
- }
- return result;
- }
-
- /**
- * Basic filter logic.
- * @param context the filter context, not null.
- * @return the filtered value.
- */
- private static PropertyValue filterValue(FilterContext context) {
- PropertyValue inputValue = context.getProperty();
- PropertyValue filteredValue = inputValue;
-
- for (int i = 0; i < MAX_FILTER_LOOPS; i++) {
- int changes = 0;
- for (PropertyFilter filter : context.getContext().getPropertyFilters()) {
- filteredValue = filter.filterProperty(inputValue, context);
- if (filteredValue != null && !filteredValue.equals(inputValue)) {
- changes++;
- LOG.finest("Filter - " + inputValue + " -> " + filteredValue + " by " + filter);
- }
- if(filteredValue==null){
- LOG.finest("Filter removed entry - " + inputValue + ": " + filter);
- break;
- }else{
- inputValue = filteredValue;
- }
- }
- if (changes == 0) {
- LOG.finest("Finishing filter loop, no changes detected.");
- break;
- } else if (filteredValue == null) {
- break;
- } else {
- if (i == (MAX_FILTER_LOOPS - 1)) {
- if (LOG.isLoggable(Level.WARNING)) {
- LOG.warning("Maximal filter loop count reached, aborting filter evaluation after cycles: " + i);
- }
- } else {
- LOG.finest("Repeating filter loop, changes detected: " + changes);
- }
- }
- }
- return filteredValue;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceComparator.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceComparator.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceComparator.java
deleted file mode 100644
index 6799e4e..0000000
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertySourceComparator.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-
-import javax.annotation.Priority;
-import java.io.Serializable;
-import java.lang.reflect.Method;
-import java.util.Comparator;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Comparator for ordering of PropertySources based on their ordinal method and class name.
- */
-public class PropertySourceComparator implements Comparator<PropertySource>, Serializable {
- /** serial version UID. */
- private static final long serialVersionUID = 1L;
-
- private static final Logger LOG = Logger.getLogger(PropertySourceComparator.class.getName());
-
- private static final PropertySourceComparator INSTANCE = new PropertySourceComparator();
-
- private String alternativeOrdinalKey;
-
- private PropertySourceComparator(){}
-
- /**
- * Get the shared instance of the comparator.
- * @return the shared instance, never null.
- */
- public static PropertySourceComparator getInstance(){
- return INSTANCE;
- }
-
-
- /**
- * 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 (getOrdinal(source1, alternativeOrdinalKey) < getOrdinal(source2, alternativeOrdinalKey)) {
- return -1;
- } else if (getOrdinal(source1, alternativeOrdinalKey) > getOrdinal(source2, alternativeOrdinalKey)) {
- return 1;
- } else {
- return source1.getClass().getName().compareTo(source2.getClass().getName());
- }
- }
-
- public static int getOrdinal(PropertySource propertySource) {
- return getOrdinal(propertySource, null);
- }
-
- public static int getOrdinal(PropertySource propertySource, String alternativeOrdinalKey) {
- if(alternativeOrdinalKey!=null) {
- PropertyValue ordinalValue = propertySource.get(alternativeOrdinalKey);
- if (ordinalValue != null) {
- try {
- return Integer.parseInt(ordinalValue.getValue().trim());
- } catch (Exception e) {
- LOG.finest("Failed to parse ordinal from " + alternativeOrdinalKey +
- " in " + propertySource.getName() + ": " + ordinalValue.getValue());
- }
- }
- }
- return propertySource.getOrdinal();
- }
-
- /**
- * Overrides/adds the key to evaluate/override a property sources ordinal.
- * @param ordinalKey sets the alternative ordinal key, if null default
- * behaviour will be active.
- * @return the instance for chaining.
- */
- public PropertySourceComparator setOrdinalKey(String ordinalKey) {
- this.alternativeOrdinalKey = ordinalKey;
- return this;
- }
-
- @Override
- public int compare(PropertySource source1, PropertySource source2) {
- return comparePropertySources(source1, source2);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/RegexPropertyFilter.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/RegexPropertyFilter.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/RegexPropertyFilter.java
deleted file mode 100644
index 1f8cce9..0000000
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/RegexPropertyFilter.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import org.apache.tamaya.spi.FilterContext;
-import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.PropertyValue;
-
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * Predicate filtering using a regex expression operating on the key. It allows either
- * to define the target keys to be selected (includes), or to be excluded (excludes).
- */
-public final class RegexPropertyFilter implements PropertyFilter{
- /** The expression used to include entries that match. */
- private List<String> includes;
- /** The expression used to exclude entries that match. */
- private List<String> excludes;
-
- /**
- * Sets the regex expression to be applied on the key to filter the corresponding entry
- * if matching.
- * @param expressions the regular expression for inclusion, not null.
- */
- public void setIncludes(String... expressions){
- this.includes = Arrays.asList(expressions);
- }
-
- /**
- * Sets the regex expression to be applied on the key to remove the corresponding entries
- * if matching.
- * @param expressions the regular expressions for exclusion, not null.
- */
- public void setExcludes(String... expressions){
- this.excludes= Arrays.asList(expressions);
- }
-
- @Override
- public PropertyValue filterProperty(PropertyValue valueToBeFiltered, FilterContext context) {
- if(includes!=null){
- for(String expression:includes){
- if(context.getProperty().getKey().matches(expression)){
- return valueToBeFiltered;
- }
- }
- return null;
- }
- if(excludes!=null){
- for(String expression:excludes){
- if(context.getProperty().getKey().matches(expression)){
- return null;
- }
- }
- }
- return valueToBeFiltered;
- }
-
- @Override
- public String toString() {
- return "RegexPropertyFilter{" +
- "includes='" + includes + '\'' +
- "excludes='" + excludes + '\'' +
- '}';
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SimplePropertySource.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SimplePropertySource.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SimplePropertySource.java
deleted file mode 100644
index f1a5a57..0000000
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SimplePropertySource.java
+++ /dev/null
@@ -1,284 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.spi.PropertyValue;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Properties;
-import java.util.UUID;
-import java.util.logging.Logger;
-
-/**
- * Simple implementation of a {@link org.apache.tamaya.spi.PropertySource} for
- * simple property files and XML property files.
- */
-public class SimplePropertySource extends BasePropertySource {
-
- private static final Logger LOG = Logger.getLogger(SimplePropertySource.class.getName());
-
- /**
- * The current properties.
- */
- private Map<String, PropertyValue> properties = new HashMap<>();
-
- /**
- * Creates a new Properties based PropertySource based on the given URL.
- *
- * @param propertiesLocation the URL encoded location, not null.
- */
- public SimplePropertySource(File propertiesLocation) {
- super(propertiesLocation.toString(), 0);
- try {
- this.properties = load(propertiesLocation.toURI().toURL());
- } catch (IOException e) {
- throw new ConfigException("Failed to load properties from " + propertiesLocation, e);
- }
- }
-
- /**
- * Creates a new Properties based PropertySource based on the given URL.
- *
- * @param propertiesLocation the URL encoded location, not null.
- */
- public SimplePropertySource(URL propertiesLocation) {
- super(propertiesLocation.toString(), 0);
- this.properties = load(Objects.requireNonNull(propertiesLocation));
- }
-
- /**
- * Creates a new Properties based PropertySource.
- *
- * @param name the property source name, not null.
- * @param properties the properties, not null
- * @param defaultOrdinal the default ordinal
- */
- public SimplePropertySource(String name, Map<String, String> properties, int defaultOrdinal){
- super(name, defaultOrdinal);
- for(Map.Entry<String,String> en: properties.entrySet()) {
- this.properties.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), name));
- }
- }
-
- /**
- * Creates a new Properties based PropertySource based on the given properties map.
- *
- * @param name the name, not null.
- * @param properties the properties, not null.
- */
- public SimplePropertySource(String name, Map<String, String> properties) {
- this(name, properties, 0);
- }
-
- /**
- * Creates a new Properties based PropertySource based on the given URL.
- *
- * @param name The property source name
- * @param propertiesLocation the URL encoded location, not null.
- */
- public SimplePropertySource(String name, URL propertiesLocation) {
- super(name, 0);
- this.properties = load(propertiesLocation);
- }
-
- private SimplePropertySource(Builder builder) {
- properties = builder.properties;
- if(builder.defaultOrdinal!=null){
- setDefaultOrdinal(builder.defaultOrdinal);
- }
- if(builder.ordinal!=null){
- setOrdinal(builder.ordinal);
- }
- setName(builder.name);
- }
-
- public static Builder newBuilder() {
- return new Builder();
- }
-
- @Override
- public Map<String, PropertyValue> getProperties() {
- return this.properties;
- }
-
- /**
- * 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
- */
- private static Map<String, PropertyValue> load(URL propertiesFile) {
- boolean isXML = isXMLPropertieFiles(propertiesFile);
-
- Map<String, PropertyValue> properties = new HashMap<>();
- try (InputStream stream = propertiesFile.openStream()) {
- Properties props = new Properties();
- if (stream != null) {
- if (isXML) {
- props.loadFromXML(stream);
- } else {
- props.load(stream);
- }
- }
- String source = propertiesFile.toString();
- for (String key : props.stringPropertyNames()) {
- properties.put(key, PropertyValue.of(key, props.getProperty(key), source));
- }
- } catch (IOException e) {
- throw new ConfigException("Error loading properties from " + propertiesFile, e);
- }
-
- return properties;
- }
-
- private static boolean isXMLPropertieFiles(URL url) {
- return url.getFile().endsWith(".xml");
- }
-
-
- /**
- * {@code SimplePropertySource} builder static inner class.
- */
- public static final class Builder {
- private String name;
- private Integer defaultOrdinal;
- private Integer ordinal;
- private Map<String, PropertyValue> properties = new HashMap<>();
-
- private Builder() {
- }
-
- /**
- * Sets the {@code name} to a new UUID and returns a reference to this Builder so that the methods
- * can be chained together.
- *
- * @return a reference to this Builder
- */
- public Builder withUuidName() {
- this.name = UUID.randomUUID().toString();
- return this;
- }
-
- /**
- * Sets the {@code name} and returns a reference to this Builder so that the methods
- * can be chained together.
- *
- * @param val the {@code name} to set, not null.
- * @return a reference to this Builder
- */
- public Builder withName(String val) {
- this.name = Objects.requireNonNull(name);
- return this;
- }
-
- /**
- * Sets the {@code ordinal} and returns a reference to this Builder so that the methods
- * can be chained together.
- *
- * @param val the {@code ordinal} to set
- * @return a reference to this Builder
- */
- public Builder withOrdinal(int val) {
- this.ordinal = val;
- return this;
- }
-
- /**
- * Sets the {@code defaultOrdinal} and returns a reference to this Builder so that the methods
- * can be chained together.
- *
- * @param val the {@code defaultOrdinal} to set
- * @return a reference to this Builder
- */
- public Builder withDefaultOrdinal(int val) {
- this.defaultOrdinal = val;
- return this;
- }
-
- /**
- * Reads the {@code properties} from the given resource and returns a reference
- * to this Builder so that the methods can be chained together.
- *
- * @param resource the {@code resource} to read
- * @return a reference to this Builder
- */
- public Builder withProperties(URL resource) {
- this.properties.putAll(load(resource));
- return this;
- }
-
- /**
- * Reads the {@code properties} from the given resource and returns a reference
- * to this Builder so that the methods can be chained together.
- *
- * @param file the {@code file} to read from (xml or properties format).
- * @return a reference to this Builder
- */
- public Builder withProperties(File file) {
- try {
- this.properties.putAll(load(file.toURI().toURL()));
- } catch (MalformedURLException e) {
- throw new IllegalArgumentException("Failed to read file: " + file, e);
- }
- return this;
- }
-
- /**
- * Sets the {@code properties} and returns a reference to this Builder so that the methods can be chained together.
- *
- * @param val the {@code properties} to set
- * @return a reference to this Builder
- */
- public Builder withProperties(Map<String, String> val) {
- for(Map.Entry<String,String> en: val.entrySet()) {
- this.properties.put(en.getKey(), PropertyValue.of(en.getKey(), en.getValue(), name));
- }
- return this;
- }
-
- /**
- * Sets the {@code properties} and returns a reference to this Builder so that the methods can be chained together.
- *
- * @param val the {@code properties} to set
- * @return a reference to this Builder
- */
- public Builder withProperty(String key, String val) {
- this.properties.put(key, PropertyValue.of(key, val, name));
- return this;
- }
-
- /**
- * Returns a {@code SimplePropertySource} built from the parameters previously set.
- *
- * @return a {@code SimplePropertySource} built with parameters of this {@code SimplePropertySource.Builder}
- */
- public SimplePropertySource build() {
- return new SimplePropertySource(this);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SystemPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SystemPropertySource.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SystemPropertySource.java
deleted file mode 100644
index bc5f99e..0000000
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/SystemPropertySource.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import org.apache.tamaya.spi.PropertyValue;
-
-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. You can disable this feature by
- * setting {@code tamaya.envprops.disable} or {@code tamaya.defaults.disable}.
- */
-public class SystemPropertySource extends BasePropertySource {
-
- /**
- * default ordinal used.
- */
- public static final int DEFAULT_ORDINAL = 1000;
-
- private volatile Map<String,PropertyValue> cachedProperties;
-
- /**
- * previous System.getProperties().hashCode()
- * so we can check if we need to reload
- */
- private volatile int previousHash;
-
- /**
- * Prefix that allows system properties to virtually be mapped on specified sub section.
- */
- private String prefix;
-
- /**
- * If true, this property source does not return any properties. This is useful since this
- * property source is applied by default, but can be switched off by setting the
- * {@code tamaya.envprops.disable} system/environment property to {@code true}.
- */
- private boolean disabled = false;
-
- /**
- * Creates a new instance. Also initializes the {@code prefix} and {@code disabled} properties
- * from the system-/ environment properties:
- * <pre>
- * tamaya.envprops.prefix
- * tamaya.envprops.disable
- * </pre>
- */
- public SystemPropertySource(){
- super("system-properties", DEFAULT_ORDINAL);
- initFromSystemProperties();
- if(!disabled){
- cachedProperties = Collections.unmodifiableMap(loadProperties());
- }
- }
-
- /**
- * Initializes the {@code prefix} and {@code disabled} properties from the system-/
- * environment properties:
- * <pre>
- * tamaya.envprops.prefix
- * tamaya.envprops.disable
- * </pre>
- */
- private void initFromSystemProperties() {
- String value = System.getProperty("tamaya.sysprops.prefix");
- if(value==null){
- prefix = System.getenv("tamaya.sysprops.prefix");
- }
- value = System.getProperty("tamaya.sysprops.disable");
- if(value==null){
- value = System.getenv("tamaya.sysprops.disable");
- }
- if(value==null){
- value = System.getProperty("tamaya.defaults.disable");
- }
- if(value==null){
- value = System.getenv("tamaya.defaults.disable");
- }
- if(value!=null && !value.isEmpty()) {
- this.disabled = Boolean.parseBoolean(value);
- }
- }
-
- /**
- * Creates a new instance using a fixed ordinal value.
- * @param ordinal the ordinal number.
- */
- public SystemPropertySource(int ordinal){
- this(null, ordinal);
- }
-
- /**
- * Creates a new instance.
- * @param prefix the prefix to be used, or null.
- * @param ordinal the ordinal to be used.
- */
- public SystemPropertySource(String prefix, int ordinal){
- this.prefix = prefix;
- setOrdinal(ordinal);
- }
-
- /**
- * Creates a new instance.
- * @param prefix the prefix to be used, or null.
- */
- public SystemPropertySource(String prefix){
- this.prefix = prefix;
- }
-
-
- private Map<String, PropertyValue> loadProperties() {
- Properties sysProps = System.getProperties();
- previousHash = System.getProperties().hashCode();
- final String prefix = this.prefix;
- Map<String, PropertyValue> entries = new HashMap<>();
- for (Map.Entry<Object,Object> entry : sysProps.entrySet()) {
- if(entry.getKey() instanceof String && entry.getValue() instanceof String) {
- if (prefix == null) {
- entries.put((String) entry.getKey(),
- PropertyValue.of((String) entry.getKey(),
- (String) entry.getValue(),
- getName()));
- } else {
- entries.put(prefix + entry.getKey(),
- PropertyValue.of(prefix + entry.getKey(),
- (String) entry.getValue(),
- getName()));
- }
- }
- }
- return entries;
- }
-
- @Override
- public String getName() {
- if(disabled){
- return super.getName() + "(disabled)";
- }
- return super.getName();
- }
-
- @Override
- public PropertyValue get(String key) {
- if(disabled){
- return null;
- }
- String prefix = this.prefix;
- if(prefix==null) {
- return PropertyValue.of(key, System.getProperty(key), getName());
- }
- return PropertyValue.of(key, System.getProperty(key.substring(prefix.length())), getName());
- }
-
- @Override
- public Map<String, PropertyValue> getProperties() {
- if(disabled){
- return Collections.emptyMap();
- }
- // only need to reload and fill our map if something has changed
- // synchronization was removed, Instance was marked as volatile. In the worst case it
- // is reloaded twice, but the values will be the same.
- if (previousHash != System.getProperties().hashCode()) {
- Map<String, PropertyValue> properties = loadProperties();
- this.cachedProperties = Collections.unmodifiableMap(properties);
- }
- return this.cachedProperties;
- }
-
- @Override
- public boolean isScannable() {
- return true;
- }
-
- @Override
- protected String toStringValues() {
- return super.toStringValues() +
- " prefix=" + prefix + '\n' +
- " disabled=" + disabled + '\n';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/A.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/A.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/A.java
deleted file mode 100644
index 4101f1e..0000000
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/A.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-/**
- * Test class for testing transitively evaluated property converters.
- */
-class A implements AutoCloseable{
- @Override
- public void close() throws Exception {
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/B.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/B.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/B.java
deleted file mode 100644
index 584b923..0000000
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/B.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-/**
- * Test class for testing transitively evaluated property converters.
- */
-public class B extends A implements Runnable{
- @Override
- public void run() {
-
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BasePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BasePropertySourceTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BasePropertySourceTest.java
deleted file mode 100644
index a986b7b..0000000
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BasePropertySourceTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.*;
-
-public class BasePropertySourceTest {
-
- @Test
- public void testGetOrdinal() {
-
- PropertySource defaultPropertySource = new BasePropertySource("testWithDefault", 56) {
-
- @Override
- public PropertyValue get(String key) {
- return null;
- }
-
- @Override
- public Map<String, PropertyValue> getProperties() {
- return Collections.emptyMap();
- }
- };
-
- Assert.assertEquals(56, PropertySourceComparator.getOrdinal(defaultPropertySource));
- 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().getOrdinal());
- }
-
- private static class OverriddenOrdinalPropertySource extends BasePropertySource {
-
- private OverriddenOrdinalPropertySource() {
- super("overriddenOrdinal", 250);
- }
-
- @Override
- public Map<String, PropertyValue> getProperties() {
- Map<String,PropertyValue> props = new HashMap<>(1);
- props.put(PropertySource.TAMAYA_ORDINAL, PropertyValue.of(PropertySource.TAMAYA_ORDINAL, "1000", getName()));
- return props;
- }
- }
-
- private static class OverriddenInvalidOrdinalPropertySource extends BasePropertySource {
-
- private OverriddenInvalidOrdinalPropertySource() {
- super("overriddenInvalidOrdinal", 1);
- }
-
- @Override
- public Map<String, PropertyValue> getProperties() {
- Map<String,PropertyValue> props = new HashMap<>(1);
- props.put(PropertySource.TAMAYA_ORDINAL, PropertyValue.of(PropertySource.TAMAYA_ORDINAL, "invalid", getName()));
- return props;
- }
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceProviderTest.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceProviderTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceProviderTest.java
deleted file mode 100644
index cab05d2..0000000
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceProviderTest.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.spisupport;
-
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-public class BuildablePropertySourceProviderTest {
-
- @Test
- public void getPropertySources() throws Exception {
- BuildablePropertySource ps = BuildablePropertySource.builder()
- .withName("test1").build();
- BuildablePropertySourceProvider prov = BuildablePropertySourceProvider.builder()
- .withPropertySourcs(ps).build();
- assertNotNull(prov);
- assertEquals(prov.getPropertySources().iterator().next(), ps);
- }
-
- @Test
- public void equals() throws Exception {
- BuildablePropertySource ps = BuildablePropertySource.builder()
- .withName("test1").build();
- BuildablePropertySourceProvider prov1 = BuildablePropertySourceProvider.builder()
- .withPropertySourcs(ps).build();
- BuildablePropertySourceProvider prov2 = BuildablePropertySourceProvider.builder()
- .withPropertySourcs(ps).build();
- assertEquals(prov1, prov2);
- BuildablePropertySource ps2 = BuildablePropertySource.builder()
- .withName("test12").build();
- prov2 = BuildablePropertySourceProvider.builder()
- .withPropertySourcs(ps2).build();
- assertNotEquals(prov1, prov2);
- }
-
- @Test
- public void testHashCode() throws Exception {
- BuildablePropertySource ps = BuildablePropertySource.builder()
- .withName("test1").build();
- BuildablePropertySourceProvider prov1 = BuildablePropertySourceProvider.builder()
- .withPropertySourcs(ps).build();
- BuildablePropertySourceProvider prov2 = BuildablePropertySourceProvider.builder()
- .withPropertySourcs(ps).build();
- assertEquals(prov1.hashCode(), prov2.hashCode());
- BuildablePropertySource ps2 = BuildablePropertySource.builder()
- .withName("test12").build();
- prov2 = BuildablePropertySourceProvider.builder()
- .withPropertySourcs(ps2).build();
- assertNotEquals(prov1.hashCode(), prov2.hashCode());
- }
-
-
- @Test
- public void builder() throws Exception {
- assertNotNull(BuildablePropertySource.builder());
- assertNotEquals(BuildablePropertySource.builder(), BuildablePropertySource.builder());
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceTest.java
deleted file mode 100644
index 721216d..0000000
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/BuildablePropertySourceTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-public class BuildablePropertySourceTest {
- @Test
- public void getOrdinal() throws Exception {
- BuildablePropertySource ps1 = BuildablePropertySource.builder()
- .withOrdinal(55).build();
- assertEquals(55, ps1.getOrdinal());
- }
-
- @Test
- public void getName() throws Exception {
- BuildablePropertySource ps1 = BuildablePropertySource.builder()
- .withName("test1").build();
- assertEquals("test1", ps1.getName());
- ps1 = BuildablePropertySource.builder().build();
- assertNotNull(ps1.getName());
- }
-
- @Test
- public void get() throws Exception {
- BuildablePropertySource ps1 = BuildablePropertySource.builder()
- .withSimpleProperty("a", "b").build();
- assertEquals("b", ps1.get("a").getValue());
- }
-
- @Test
- public void getProperties() throws Exception {
- BuildablePropertySource ps1 = BuildablePropertySource.builder()
- .withSimpleProperty("a", "b").build();
- assertNotNull(ps1.getProperties());
- assertEquals(1, ps1.getProperties().size());
- assertEquals("b", ps1.getProperties().get("a").getValue());
- }
-
- @Test
- public void equals() throws Exception {
- BuildablePropertySource ps1 = BuildablePropertySource.builder()
- .withName("test1").build();
- BuildablePropertySource ps2 = BuildablePropertySource.builder()
- .withName("test1").build();
- assertEquals(ps1, ps2);
- ps2 = BuildablePropertySource.builder()
- .withName("test2").build();
- assertNotEquals(ps1, ps2);
- }
-
- @Test
- public void testHashCode() throws Exception {
- BuildablePropertySource ps1 = BuildablePropertySource.builder()
- .withName("test1").build();
- BuildablePropertySource ps2 = BuildablePropertySource.builder()
- .withName("test1").build();
- assertEquals(ps1.hashCode(), ps2.hashCode());
- ps2 = BuildablePropertySource.builder()
- .withName("test2").build();
- assertNotEquals(ps1.hashCode(), ps2.hashCode());
- }
-
- @Test
- public void builder() throws Exception {
- assertNotNull(BuildablePropertySource.builder());
- assertNotEquals(BuildablePropertySource.builder(), BuildablePropertySource.builder());
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/C.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/C.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/C.java
deleted file mode 100644
index da581e6..0000000
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/C.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import java.io.IOException;
-import java.nio.CharBuffer;
-
-/**
- * Test class for testing transitively evaluated property converters.
- */
-public class C extends B implements Readable{
-
- private final String inValue;
-
- public C(String inValue){
- this.inValue = inValue;
- }
-
- @Override
- public int read(CharBuffer cb) throws IOException {
- return 0;
- }
-
- /**
- * Returns the input value, set on creation. Used for test assertion.
- * @return the in value.
- */
- public String getInValue() {
- return inValue;
- }
-
- @Override
- public String toString() {
- return "C{" +
- "inValue='" + inValue + '\'' +
- '}';
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/CLIPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/CLIPropertySourceTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/CLIPropertySourceTest.java
deleted file mode 100644
index e08bf80..0000000
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/CLIPropertySourceTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import org.apache.tamaya.core.propertysource.CLIPropertySource;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * Tests for PropertySource for reading main arguments as configuration.
- */
-public class CLIPropertySourceTest {
-
- @Test
- public void setCLIProps() throws Exception {
- System.clearProperty("main.args");
- CLIPropertySource ps = new CLIPropertySource();
- assertTrue(ps.getProperties().isEmpty());
- CLIPropertySource.initMainArgs("-a", "b");
- assertFalse(ps.getProperties().isEmpty());
- assertEquals(ps.getProperties().get("a").getValue(), "b");
- CLIPropertySource.initMainArgs("--c");
- assertFalse(ps.getProperties().isEmpty());
- assertEquals(ps.getProperties().get("c").getValue(), "c");
- CLIPropertySource.initMainArgs("sss");
- assertFalse(ps.getProperties().isEmpty());
- assertEquals(ps.getProperties().get("sss").getValue(), "sss");
- CLIPropertySource.initMainArgs("-a", "b", "--c", "sss", "--val=vvv");
- assertFalse(ps.getProperties().isEmpty());
- assertEquals(ps.getProperties().get("a").getValue(), "b");
- assertEquals(ps.getProperties().get("c").getValue(), "c");
- assertEquals(ps.getProperties().get("sss").getValue(), "sss");
- // getProperties() throws Exception {
- System.setProperty("main.args", "-a b\t--c sss ");
- ps = new CLIPropertySource();
- assertFalse(ps.getProperties().isEmpty());
- System.clearProperty("main.args");
- assertEquals(ps.getProperties().get("a").getValue(), "b");
- assertEquals(ps.getProperties().get("c").getValue(), "c");
- assertEquals(ps.getProperties().get("sss").getValue(), "sss");
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/CTestConverter.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/CTestConverter.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/CTestConverter.java
deleted file mode 100644
index dce8121..0000000
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/CTestConverter.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-
-/**
- * Created by Anatole on 13.06.2015.
- */
-public class CTestConverter implements PropertyConverter<C>{
- @Override
- public C convert(String value, ConversionContext context) {
- return new C(value);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationContextTest.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationContextTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationContextTest.java
deleted file mode 100644
index 5e748ce..0000000
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/DefaultConfigurationContextTest.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.*;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- * Simple tests for {@link DefaultConfigurationContext} by atsticks on 16.08.16.
- */
-public class DefaultConfigurationContextTest {
-
- @Test
- public void addPropertySources() throws Exception {
- ConfigurationContext ctx = new DefaultConfigurationContextBuilder().build();
- PropertySource def = new TestPropertyDefaultSource();
- assertFalse(ctx.getPropertySources().contains(def));
- ctx.addPropertySources(def);
- assertTrue(ctx.getPropertySources().contains(def));
- }
-
- @Test
- public void testToString() throws Exception {
- String toString = ConfigurationProvider.getConfiguration().getContext().toString();
- System.out.println(toString);
- }
-
- @Test
- public void getPropertySources() throws Exception {
- ConfigurationContext ctx = new DefaultConfigurationContextBuilder().build();
- assertNotNull(ctx.getPropertySources());
- assertEquals(ctx.getPropertySources().size(), 0);
- ctx = new DefaultConfigurationContextBuilder().addDefaultPropertySources().build();
- assertNotNull(ctx.getPropertySources());
- assertEquals(4, ctx.getPropertySources().size());
- }
-
- @Test
- public void getPropertySource() throws Exception {
- PropertySource ps = new TestPropertyDefaultSource();
- ConfigurationContext ctx = new DefaultConfigurationContextBuilder()
- .addPropertySources(ps).build();
- assertNotNull(ctx.getPropertySources());
- assertEquals(ctx.getPropertySources().size(), 1);
- assertNotNull(((DefaultConfigurationContext)ctx).getPropertySource(ps.getName()));
- assertEquals(ps.getName(), ((DefaultConfigurationContext)ctx).getPropertySource(ps.getName()).getName());
- assertNull(((DefaultConfigurationContext)ctx).getPropertySource("huhu"));
-
- }
-
- @Test
- public void testHashCode() throws Exception {
- PropertySource ps = new TestPropertyDefaultSource();
- ConfigurationContext ctx1 = new DefaultConfigurationContextBuilder()
- .addPropertySources(ps).build();
- ConfigurationContext ctx2 = new DefaultConfigurationContextBuilder()
- .addPropertySources(ps).build();
- assertEquals(ctx1.hashCode(), ctx2.hashCode());
- ctx2 = new DefaultConfigurationContextBuilder()
- .build();
- assertNotEquals(ctx1.hashCode(), ctx2.hashCode());
-
- }
-
- @Test
- public void addPropertyConverter() throws Exception {
- ConfigurationContext ctx = new DefaultConfigurationContextBuilder().build();
- PropertyConverter testConverter = new PropertyConverter() {
- @Override
- public Object convert(String value, ConversionContext context) {
- return "";
- }
- };
- assertFalse(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(testConverter));
- ctx.addPropertyConverter(TypeLiteral.of(String.class), testConverter);
- assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(testConverter));
- }
-
- @Test
- public void getPropertyConverters() throws Exception {
- ConfigurationContext ctx = new DefaultConfigurationContextBuilder().build();
- PropertyConverter testConverter = new PropertyConverter() {
- @Override
- public Object convert(String value, ConversionContext context) {
- return "";
- }
- };
- ctx.addPropertyConverter(TypeLiteral.of(String.class), testConverter);
- assertNotNull(ctx.getPropertyConverters());
- assertTrue(ctx.getPropertyConverters().containsKey(TypeLiteral.of(String.class)));
- assertTrue(ctx.getPropertyConverters().get(TypeLiteral.of(String.class)).contains(testConverter));
- testConverter = new PropertyConverter() {
- @Override
- public Object convert(String value, ConversionContext context) {
- return Integer.valueOf(5);
- }
- };
- ctx.addPropertyConverter(TypeLiteral.of(Integer.class), testConverter);
- assertTrue(ctx.getPropertyConverters().containsKey(TypeLiteral.of(Integer.class)));
- assertTrue(ctx.getPropertyConverters().get(TypeLiteral.of(Integer.class)).contains(testConverter));
- }
-
- @Test
- public void getPropertyConverters1() throws Exception {
- ConfigurationContext ctx = new DefaultConfigurationContextBuilder().build();
- PropertyConverter testConverter = new PropertyConverter() {
- @Override
- public Object convert(String value, ConversionContext context) {
- return "";
- }
- };
- assertNotNull(ctx.getPropertyConverters(TypeLiteral.of(String.class)));
- assertEquals(ctx.getPropertyConverters(TypeLiteral.of(String.class)).size(),0);
- ctx.addPropertyConverter(TypeLiteral.of(String.class), testConverter);
- assertNotNull(ctx.getPropertyConverters(TypeLiteral.of(String.class)));
- assertEquals(ctx.getPropertyConverters(TypeLiteral.of(String.class)).size(),1);
- assertTrue(ctx.getPropertyConverters(TypeLiteral.of(String.class)).contains(testConverter));
-
- }
-
- @Test
- public void getPropertyFilters() throws Exception {
- ConfigurationContext ctx = new DefaultConfigurationContextBuilder().build();
- PropertyFilter testFilter = new PropertyFilter() {
-
- @Override
- public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- return value;
- }
- };
- assertNotNull(ctx.getPropertyFilters());
- assertFalse(ctx.getPropertyFilters().contains(testFilter));
- ctx = ctx.toBuilder().addPropertyFilters(testFilter).build();
- assertTrue(ctx.getPropertyFilters().contains(testFilter));
- }
-
- @Test
- public void getPropertyValueCombinationPolicy() throws Exception {
- ConfigurationContext ctx = new DefaultConfigurationContextBuilder().build();
- assertNotNull(ctx.getPropertyValueCombinationPolicy());
- assertEquals(ctx.getPropertyValueCombinationPolicy(),
- PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR);
- }
-
- @Test
- public void toBuilder() throws Exception {
- assertNotNull(new DefaultConfigurationContextBuilder().build().toBuilder());
- }
-
- @Test
- public void testRoundTrip() throws Exception {
- ConfigurationContext ctx = new DefaultConfigurationContextBuilder().build();
- assertEquals(ctx.toBuilder().build(), ctx);
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/EnumConverterTest.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/EnumConverterTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/EnumConverterTest.java
deleted file mode 100644
index c846e81..0000000
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/EnumConverterTest.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.spisupport;
-
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.ConversionContext;
-import org.junit.Test;
-
-import java.math.RoundingMode;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-/**
- * Test class testing the {@link EnumConverter} class.
- */
-public class EnumConverterTest {
-
- private final EnumConverter testConverter = new EnumConverter(RoundingMode.class);
-
- private final ConversionContext DUMMY_CONTEXT = new ConversionContext.Builder("someKey", TypeLiteral.of(Enum.class)).build();
-
- @Test
- public void testConvert() {
- assertEquals(testConverter.convert(RoundingMode.CEILING.toString(),
- DUMMY_CONTEXT), RoundingMode.CEILING);
- }
-
- @Test
- public void testConvert_LowerCase() {
- assertEquals(testConverter.convert("ceiling", DUMMY_CONTEXT), RoundingMode.CEILING);
- }
-
- @Test
- public void testConvert_MixedCase() {
- assertEquals(testConverter.convert("CeiLinG", DUMMY_CONTEXT), RoundingMode.CEILING);
- }
-
- @Test
- public void testConvert_OtherValue() {
- assertNull(testConverter.convert("fooBars", DUMMY_CONTEXT));
- }
-}
\ No newline at end of file
[9/9] incubator-tamaya-extensions git commit: TAMAYA-318 Merged
changes.
Posted by an...@apache.org.
TAMAYA-318 Merged changes.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/commit/13e43a49
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/13e43a49
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/13e43a49
Branch: refs/heads/master
Commit: 13e43a49eef761e07afddf5a5271be4883b6daaf
Parents: c074073
Author: Anatole Tresch <an...@apache.org>
Authored: Tue Nov 14 10:33:10 2017 +0100
Committer: Anatole Tresch <an...@apache.org>
Committed: Tue Nov 14 10:33:10 2017 +0100
----------------------------------------------------------------------
.../microprofile/MicroprofileAdapterTest.java | 20 +++-----------------
1 file changed, 3 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/13e43a49/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileAdapterTest.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileAdapterTest.java b/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileAdapterTest.java
index 8fea044..a8e8488 100644
--- a/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileAdapterTest.java
+++ b/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileAdapterTest.java
@@ -18,13 +18,12 @@
*/
package org.apache.tamaya.microprofile;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.*;
+import org.apache.tamaya.spi.ConfigurationContext;
import org.apache.tamaya.spi.PropertyConverter;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertyValue;
import org.apache.tamaya.spisupport.propertysource.BuildablePropertySource;
-import org.apache.tamaya.spisupport.BuildablePropertySource;
import org.assertj.core.api.Assertions;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
@@ -33,10 +32,7 @@ import org.eclipse.microprofile.config.spi.ConfigSource;
import org.eclipse.microprofile.config.spi.Converter;
import org.junit.Test;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import static org.junit.Assert.*;
@@ -242,16 +238,6 @@ public class MicroprofileAdapterTest {
}
@Override
- public Configuration with(ConfigOperator operator) {
- throw new RuntimeException("Not implemented yet!");
- }
-
- @Override
- public <T> T query(ConfigQuery<T> query) {
- throw new RuntimeException("Not implemented yet!");
- }
-
- @Override
public ConfigurationContext getContext() {
throw new RuntimeException("Not implemented yet!");
}
[4/9] incubator-tamaya-extensions git commit: TAMAYA-318 Moved
spi-support as API base implementation package to remove code duplicates.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/EnvironmentPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/EnvironmentPropertySourceTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/EnvironmentPropertySourceTest.java
deleted file mode 100644
index 877d30d..0000000
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/EnvironmentPropertySourceTest.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.spisupport;
-
-import org.apache.tamaya.core.propertysource.EnvironmentPropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-import org.junit.Test;
-
-import java.util.Map;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Tests for {@link EnvironmentPropertySource}.
- */
-public class EnvironmentPropertySourceTest {
-
- private final EnvironmentPropertySource envPropertySource = new EnvironmentPropertySource();
-
- @Test
- public void testGetOrdinal() throws Exception {
- assertEquals(EnvironmentPropertySource.DEFAULT_ORDINAL, envPropertySource.getOrdinal());
- }
-
- @Test
- public void testGetName() throws Exception {
- assertEquals("environment-properties", envPropertySource.getName());
- }
-
- @Test
- public void testGet() throws Exception {
- for (Map.Entry<String, String> envEntry : System.getenv().entrySet()) {
- assertEquals(envPropertySource.get(envEntry.getKey()).getValue(), envEntry.getValue());
- }
- }
-
- @Test
- public void testGetProperties() throws Exception {
- Map<String, PropertyValue> props = envPropertySource.getProperties();
- for(Map.Entry<String,PropertyValue> en: props.entrySet()){
- if(!en.getKey().startsWith("_")){
- assertEquals(System.getenv(en.getKey()), en.getValue().getValue());
- }
- }
- }
-
- @Test
- public void testIsScannable() throws Exception {
- assertTrue(envPropertySource.isScannable());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/MapPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/MapPropertySourceTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/MapPropertySourceTest.java
deleted file mode 100644
index 8a2e369..0000000
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/MapPropertySourceTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import org.apache.tamaya.spi.PropertyValue;
-import org.assertj.core.api.Condition;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class MapPropertySourceTest {
-
- private Map<String,String> sourceMap;
- private Properties sourceProperties;
-
- @Before
- public void createMapAndProperties() throws Exception {
- sourceMap = new HashMap<>();
- sourceMap.put("a", "AAA");
- sourceMap.put("b", "BBB");
-
- sourceProperties = new Properties();
- sourceProperties.setProperty("a", "AAA");
- sourceProperties.setProperty("b", "BBB");
- }
-
- @Test
- public void sourceWillProperlyInitializedWithMapWithoutPrefix() throws Exception {
- MapPropertySource propertySource = new MapPropertySource("UT", sourceMap);
-
- assertThat(propertySource.getProperties()).describedAs("Should contain exactly 2 properties.")
- .hasSize(2);
- assertThat(propertySource.get("a")).isNotNull();
- assertThat(propertySource.get("b")).isNotNull();
- }
-
- @Test
- public void sourceWillProperlyInitializedWithMapWithPrefix() throws Exception {
- MapPropertySource propertySource = new MapPropertySource("UT", sourceMap, "pre-");
-
- assertThat(propertySource.getProperties()).describedAs("Should contain exactly 2 properties.")
- .hasSize(2);
- assertThat(propertySource.get("pre-a")).isNotNull();
- assertThat(propertySource.get("pre-b")).isNotNull();
- }
-
- @Test
- public void sourceWillProperlyInitializedWithPropertiesWithPrefix() throws Exception {
- MapPropertySource propertySource = new MapPropertySource("UT", sourceProperties, "pre-");
-
- assertThat(propertySource.getProperties()).describedAs("Should contain exactly 2 properties.")
- .hasSize(2);
- assertThat(propertySource.get("pre-a")).isNotNull();
- assertThat(propertySource.get("pre-b")).isNotNull();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PriorityServiceComparatorTest.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PriorityServiceComparatorTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PriorityServiceComparatorTest.java
deleted file mode 100644
index dc15a16..0000000
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PriorityServiceComparatorTest.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.spisupport;
-
-import org.junit.Test;
-
-import javax.annotation.Priority;
-
-import static org.junit.Assert.*;
-
-/**
- * Created by atsticks on 12.09.16.
- */
-public class PriorityServiceComparatorTest {
-
- @Test
- public void compare() throws Exception {
- assertTrue(PriorityServiceComparator.getInstance().compare("a", "b")==0);
- assertTrue(PriorityServiceComparator.getInstance().compare(getClass(), getClass())==0);
- assertTrue(PriorityServiceComparator.getInstance().compare(new A(), new SystemPropertySource())==-1);
- assertTrue(PriorityServiceComparator.getInstance().compare(new SystemPropertySource(), new A())==1);
- }
-
- @Priority(100)
- private static final class A{}
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertiesFilePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertiesFilePropertySourceTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertiesFilePropertySourceTest.java
deleted file mode 100644
index 984be08..0000000
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertiesFilePropertySourceTest.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.spisupport;
-
-import org.apache.tamaya.core.propertysource.SimplePropertySource;
-import org.apache.tamaya.spi.PropertySource;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class PropertiesFilePropertySourceTest {
-
- private final SimplePropertySource testfilePropertySource = new SimplePropertySource(Thread.currentThread()
- .getContextClassLoader().getResource("testfile.properties"));
- private final SimplePropertySource overrideOrdinalPropertySource = new SimplePropertySource(
- Thread.currentThread().getContextClassLoader().getResource("overrideOrdinal.properties"));
-
-
- @Test
- public void testGetOrdinal() {
- Assert.assertEquals(0, testfilePropertySource.getOrdinal());
- Assert.assertEquals(Integer.parseInt(overrideOrdinalPropertySource.get(PropertySource.TAMAYA_ORDINAL)
- .getValue()),
- overrideOrdinalPropertySource.getOrdinal());
- }
-
-
- @Test
- public void testGet() {
- Assert.assertEquals("val3", testfilePropertySource.get("key3").getValue());
- Assert.assertEquals("myval5", overrideOrdinalPropertySource.get("mykey5").getValue());
- Assert.assertNull(testfilePropertySource.get("nonpresentkey"));
- }
-
-
- @Test
- public void testGetProperties() throws Exception {
- Assert.assertEquals(5, testfilePropertySource.getProperties().size());
- Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key1"));
- Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key2"));
- Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key3"));
- Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key4"));
- Assert.assertTrue(testfilePropertySource.getProperties().containsKey("key5"));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyConverterManagerTest.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyConverterManagerTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyConverterManagerTest.java
deleted file mode 100644
index 45ecc9d..0000000
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/PropertyConverterManagerTest.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-
-
-import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-import org.apache.tamaya.TypeLiteral;
-import org.junit.Test;
-
-import java.util.List;
-
-import static org.hamcrest.CoreMatchers.*;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
-
-public class PropertyConverterManagerTest {
-
- private final ConversionContext DUMMY_CONTEXT = new ConversionContext.Builder(
- "someKey", TypeLiteral.of(Object.class)).build();
-
- @Test
- public void customTypeWithFactoryMethodOfIsRecognizedAsSupported() {
- PropertyConverterManager manager = new PropertyConverterManager();
-
- assertThat(manager.isTargetTypeSupported(TypeLiteral.of(MyType.class)),
- is(true));
- }
-
- @Test
- public void factoryMethodOfIsUsedAsConverter() {
- PropertyConverterManager manager = new PropertyConverterManager();
-
- List<PropertyConverter<MyType>> converters = manager.getPropertyConverters(
- (TypeLiteral)TypeLiteral.of(MyType.class));
-
- assertThat(converters, hasSize(1));
-
- PropertyConverter<MyType> converter = converters.get(0);
-
- Object result = converter.convert("IN", DUMMY_CONTEXT);
-
- assertThat(result, notNullValue());
- assertThat(result, instanceOf(MyType.class));
- assertThat(((MyType)result).getValue(), equalTo("IN"));
- }
-
- @Test
- public void testDirectConverterMapping(){
- PropertyConverterManager manager = new PropertyConverterManager();
- List<PropertyConverter<C>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(C.class)));
- assertThat(converters, hasSize(1));
-
- PropertyConverter<C> converter = converters.get(0);
- C result = converter.convert("testDirectConverterMapping", DUMMY_CONTEXT);
-
- assertThat(result, notNullValue());
- assertThat(result, instanceOf(C.class));
- assertThat((result).getInValue(), equalTo("testDirectConverterMapping"));
- }
-
- @Test
- public void testDirectSuperclassConverterMapping(){
- PropertyConverterManager manager = new PropertyConverterManager();
- List<PropertyConverter<B>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class)));
- assertThat(converters, hasSize(1));
- converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class)));
- assertThat(converters, hasSize(1));
-
- PropertyConverter<B> converter = converters.get(0);
- B result = converter.convert("testDirectSuperclassConverterMapping", DUMMY_CONTEXT);
-
- assertThat(result, notNullValue());
- assertThat(result, instanceOf(C.class));
- assertThat(((C)result).getInValue(), equalTo("testDirectSuperclassConverterMapping"));
- }
-
- @Test
- public void testMultipleConverterLoad(){
- PropertyConverterManager manager = new PropertyConverterManager();
- List<PropertyConverter<B>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class)));
- assertThat(converters, hasSize(1));
- manager = new PropertyConverterManager();
- converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(B.class)));
- assertThat(converters, hasSize(1));
- }
-
- @Test
- public void testTransitiveSuperclassConverterMapping(){
- PropertyConverterManager manager = new PropertyConverterManager();
- List<PropertyConverter<A>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(A.class)));
- assertThat(converters, hasSize(1));
-
- PropertyConverter<A> converter = converters.get(0);
- A result = converter.convert("testTransitiveSuperclassConverterMapping", DUMMY_CONTEXT);
-
- assertThat(result, notNullValue());
- assertThat(result, instanceOf(C.class));
- assertThat(((C)result).getInValue(), equalTo("testTransitiveSuperclassConverterMapping"));
- }
-
- @Test
- public void testDirectInterfaceMapping(){
- PropertyConverterManager manager = new PropertyConverterManager();
- List<PropertyConverter<Readable>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(Readable.class)));
- assertThat(converters, hasSize(1));
-
- PropertyConverter<Readable> converter = converters.get(0);
- Readable result = converter.convert("testDirectInterfaceMapping", DUMMY_CONTEXT);
-
- assertThat(result, notNullValue());
- assertThat(result, instanceOf(C.class));
- assertThat(((C)result).getInValue(), equalTo("testDirectInterfaceMapping"));
- }
-
- @Test
- public void testTransitiveInterfaceMapping1(){
- PropertyConverterManager manager = new PropertyConverterManager();
- List<PropertyConverter<Runnable>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(Runnable.class)));
- assertThat(converters, hasSize(1));
-
- PropertyConverter<Runnable> converter = converters.get(0);
- Runnable result = converter.convert("testTransitiveInterfaceMapping1", DUMMY_CONTEXT);
-
- assertThat(result, notNullValue());
- assertThat(result, instanceOf(C.class));
- assertThat(((C)result).getInValue(), equalTo("testTransitiveInterfaceMapping1"));
- }
-
- @Test
- public void testTransitiveInterfaceMapping2(){
- PropertyConverterManager manager = new PropertyConverterManager();
- List<PropertyConverter<AutoCloseable>> converters = List.class.cast(manager.getPropertyConverters(TypeLiteral.of(AutoCloseable.class)));
- assertThat(converters, hasSize(1));
-
- PropertyConverter<AutoCloseable> converter = converters.get(0);
- AutoCloseable result = converter.convert("testTransitiveInterfaceMapping2", DUMMY_CONTEXT);
-
- assertThat(result, notNullValue());
- assertThat(result, instanceOf(C.class));
- assertThat(((C)result).getInValue(), equalTo("testTransitiveInterfaceMapping2"));
- }
-
- public static class MyType {
- private final String typeValue;
-
- private MyType(String value) {
- typeValue = value;
- }
-
- public static MyType of(String source) {
- return new MyType(source);
- }
-
- public String getValue() {
- return typeValue;
- }
-
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java
deleted file mode 100644
index 0b616cd..0000000
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/RegexPropertyFilterTest.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.FilterContext;
-import org.apache.tamaya.spi.PropertyValue;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import static org.junit.Assert.*;
-
-/**
- * Tests for {@link RegexPropertyFilter}. Created by anatole on 11.02.16.
- */
-public class RegexPropertyFilterTest {
-
- private static PropertyValue prop1 = PropertyValue.of("test1", "test1", "test");
- private static PropertyValue prop2 = PropertyValue.of("test2", "test2", "test");
- private static PropertyValue prop3 = PropertyValue.of("test1.test3", "test.test3", "test");
- private static ConfigurationContext configContext = new DefaultConfigurationContext();
-
- @org.junit.Test
- public void testFilterProperty() throws Exception {
- RegexPropertyFilter filter = new RegexPropertyFilter();
- filter.setIncludes("test1.*");
- Map<String,PropertyValue> map = new HashMap<>();
- map.put(prop1.getKey(), prop1);
- map.put(prop2.getKey(), prop2);
- map.put(prop3.getKey(), prop3);
- assertEquals(filter.filterProperty(prop1, new FilterContext(prop1, configContext)), prop1);
- assertNull(filter.filterProperty(prop2, new FilterContext(prop2, configContext)));
- assertEquals(filter.filterProperty(
- prop3,
- new FilterContext(prop3, map, configContext)), prop3);
- assertEquals(filter.filterProperty(
- prop3,
- new FilterContext(prop3, map, configContext)), prop3);
- filter = new RegexPropertyFilter();
- filter.setIncludes("test1.*");
- assertNotNull(filter.filterProperty(prop1, new FilterContext(prop1, map, configContext)));
- assertNull(filter.filterProperty(prop2, new FilterContext(prop2, map, configContext)));
- assertNotNull(filter.filterProperty(prop3, new FilterContext(prop3, map, configContext)));
- }
-
- @org.junit.Test
- public void testToString() throws Exception {
- RegexPropertyFilter filter = new RegexPropertyFilter();
- filter.setIncludes("test\\..*");
- assertTrue(filter.toString().contains("test\\..*"));
- assertTrue(filter.toString().contains("RegexPropertyFilter"));
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/SimplePropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/SimplePropertySourceTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/SimplePropertySourceTest.java
deleted file mode 100644
index 7ef56c7..0000000
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/SimplePropertySourceTest.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.spi.PropertyValue;
-import org.junit.Test;
-
-import java.net.URL;
-
-import static org.hamcrest.CoreMatchers.*;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.aMapWithSize;
-import static org.hamcrest.Matchers.hasEntry;
-
-public class SimplePropertySourceTest {
- @Test
- public void successfulCreationWithPropertiesFromXMLPropertiesFile() {
- URL resource = getClass().getResource("/valid-properties.xml");
-
- SimplePropertySource source = new SimplePropertySource(resource);
-
- assertThat(source, notNullValue());
- assertThat(source.getProperties(), aMapWithSize(2));
- assertThat(source.getProperties(), hasEntry("a", PropertyValue.of("a","b", source.getName())));
- assertThat(source.getProperties(), hasEntry("b", PropertyValue.of("b", "1", source.getName())));
-
- }
-
- @Test
- public void failsToCreateFromNonXMLPropertiesXMLFile() {
- URL resource = getClass().getResource("/non-xml-properties.xml");
- ConfigException catchedException = null;
-
- try {
- new SimplePropertySource(resource);
- } catch (ConfigException ce) {
- catchedException = ce;
- }
-
- assertThat(catchedException.getMessage(), allOf(startsWith("Error loading properties from"),
- endsWith("non-xml-properties.xml")));
- }
-
- @Test
- public void failsToCreateFromInvalidPropertiesXMLFile() {
- URL resource = getClass().getResource("/invalid-properties.xml");
- ConfigException catchedException = null;
-
- try {
- new SimplePropertySource(resource);
- } catch (ConfigException ce) {
- catchedException = ce;
- }
-
- assertThat(catchedException.getMessage(), allOf(startsWith("Error loading properties from"),
- endsWith("invalid-properties.xml")));
- }
-
-
- @Test
- public void successfulCreationWithPropertiesFromSimplePropertiesFile() {
- URL resource = getClass().getResource("/testfile.properties");
-
- SimplePropertySource source = new SimplePropertySource(resource);
-
- assertThat(source, notNullValue());
- assertThat(source.getProperties(), aMapWithSize(5)); // 5 * 2 meta entries.
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/SystemPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/SystemPropertySourceTest.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/SystemPropertySourceTest.java
deleted file mode 100644
index 2e1625a..0000000
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/SystemPropertySourceTest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import org.apache.tamaya.core.propertysource.SystemPropertySource;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.Map;
-import java.util.Properties;
-
-public class SystemPropertySourceTest {
-
- private final SystemPropertySource testPropertySource = new SystemPropertySource();
-
-
- @Test
- public void testGetOrdinal() throws Exception {
-
- // test the default ordinal
- Assert.assertEquals(SystemPropertySource.DEFAULT_ORDINAL, testPropertySource.getOrdinal());
-
- // set the ordinal to 1000
- System.setProperty(PropertySource.TAMAYA_ORDINAL, "1001");
- Assert.assertEquals(1001, new SystemPropertySource().getOrdinal());
- // currently its not possible to change ordinal at runtime
-
- // reset it to not destroy other tests!!
- System.clearProperty(PropertySource.TAMAYA_ORDINAL);
- }
-
- @Test
- public void testGetName() throws Exception {
- Assert.assertEquals("system-properties", testPropertySource.getName());
- }
-
- @Test
- public void testGet() throws Exception {
- String propertyKeyToCheck = System.getProperties().stringPropertyNames().iterator().next();
-
- PropertyValue property = testPropertySource.get(propertyKeyToCheck);
- Assert.assertNotNull("Property '" + propertyKeyToCheck + "' is not present in " +
- SystemPropertySource.class.getSimpleName(), property);
- Assert.assertEquals(System.getProperty(propertyKeyToCheck), property.getValue());
- }
-
- @Test
- public void testGetProperties() throws Exception {
- checkWithSystemProperties(testPropertySource.getProperties());
-
- // modify system properties
- System.setProperty("test", "myTestVal");
-
- checkWithSystemProperties(testPropertySource.getProperties());
-
- // cleanup
- System.clearProperty("test");
- }
-
- private void checkWithSystemProperties(Map<String,PropertyValue> toCheck) {
- Properties systemEntries = System.getProperties();
-
- int num = 0;
-
- for (PropertyValue propertySourceEntry : toCheck.values()) {
- if(propertySourceEntry.getKey().startsWith("_")){
- continue; // meta entry
- }
- num++;
- Assert.assertEquals("Entry values for key '" + propertySourceEntry.getKey() + "' do not match",
- systemEntries.getProperty(propertySourceEntry.getKey()), propertySourceEntry.getValue());
- }
-
- Assert.assertEquals("size of System.getProperties().entrySet() must be the same as SystemPropertySrouce.getProperties().entrySet()",
- systemEntries.size(), num);
-
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/TestPropertyDefaultSource.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/TestPropertyDefaultSource.java b/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/TestPropertyDefaultSource.java
deleted file mode 100644
index 33b2462..0000000
--- a/modules/spi-support/src/test/java/org/apache/tamaya/spisupport/TestPropertyDefaultSource.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import org.apache.tamaya.core.propertysource.BasePropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-
-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,PropertyValue> properties = new HashMap<>();
-
- public TestPropertyDefaultSource() {
- super(100);
- properties.put("name",PropertyValue.of("name", "Anatole", "Test"));
- properties.put("name2",PropertyValue.of("name2", "Sabine", "Test"));
- properties = Collections.unmodifiableMap(properties);
- }
-
- @Override
- public String getName() {
- return "default-testdata-properties";
- }
-
- @Override
- public Map<String, PropertyValue> getProperties() {
- return properties;
- }
-
- @Override
- public boolean isScannable() {
- return true;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter b/modules/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
deleted file mode 100644
index ff5d32c..0000000
--- a/modules/spi-support/src/test/resources/META-INF/services/org.apache.tamaya.spi.PropertyConverter
+++ /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.
-#
-
-#
-# 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.spisupport.CTestConverter
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/resources/invalid-properties.xml
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/resources/invalid-properties.xml b/modules/spi-support/src/test/resources/invalid-properties.xml
deleted file mode 100644
index d8b10b7..0000000
--- a/modules/spi-support/src/test/resources/invalid-properties.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-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.
--->
-
-<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
-<properties>
- <entry key="a">
- <entry key="b">1</entry>
-</properties>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/resources/non-xml-properties.xml
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/resources/non-xml-properties.xml b/modules/spi-support/src/test/resources/non-xml-properties.xml
deleted file mode 100644
index 8de819a..0000000
--- a/modules/spi-support/src/test/resources/non-xml-properties.xml
+++ /dev/null
@@ -1,18 +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.
--->
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/resources/overrideOrdinal.properties
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/resources/overrideOrdinal.properties b/modules/spi-support/src/test/resources/overrideOrdinal.properties
deleted file mode 100644
index c68208a..0000000
--- a/modules/spi-support/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.
-
-#overrideValue 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-extensions/blob/2d0ef4b9/modules/spi-support/src/test/resources/testfile.properties
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/resources/testfile.properties b/modules/spi-support/src/test/resources/testfile.properties
deleted file mode 100644
index abd7ee8..0000000
--- a/modules/spi-support/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
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/test/resources/valid-properties.xml
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/test/resources/valid-properties.xml b/modules/spi-support/src/test/resources/valid-properties.xml
deleted file mode 100644
index 7eb51d9..0000000
--- a/modules/spi-support/src/test/resources/valid-properties.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-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.
--->
-
-<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
-<properties>
- <entry key="a">b</entry>
- <entry key="b">1</entry>
-</properties>
[7/9] incubator-tamaya-extensions git commit: TAMAYA-318 Moved
spi-support as API base implementation package to remove code duplicates.
Posted by an...@apache.org.
TAMAYA-318 Moved spi-support as API base implementation package to remove code duplicates.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/commit/2d0ef4b9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/2d0ef4b9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/2d0ef4b9
Branch: refs/heads/master
Commit: 2d0ef4b92643989af0efa220944b9428f2c1cbf9
Parents: bad5fea
Author: Anatole Tresch <an...@apache.org>
Authored: Tue Nov 14 00:13:20 2017 +0100
Committer: Anatole Tresch <an...@apache.org>
Committed: Tue Nov 14 10:27:18 2017 +0100
----------------------------------------------------------------------
.../resources/MyPathPropertySourceProvider.java | 2 +-
.../events/FilePropertySourceProvider.java | 2 +-
modules/events/pom.xml | 2 +-
.../events/ChangeableGlobalPropertySource.java | 2 +-
.../ChangeableThreadLocalPropertySource.java | 2 +-
.../tamaya/events/FrozenPropertySourceTest.java | 2 +-
.../tamaya/events/PropertySourceChangeTest.java | 6 +-
.../ObservingPropertySourceProvider.java | 2 +-
modules/features/pom.xml | 2 +-
modules/filter/pom.xml | 2 +-
.../tamaya/filter/ProgrammableFilterTest.java | 3 +-
modules/formats/base/pom.xml | 2 +-
.../MappedConfigurationDataPropertySource.java | 2 +-
modules/functions/pom.xml | 2 +-
.../functions/CombinedConfigurationTest.java | 11 +-
.../functions/ConfigurationFunctionsTest.java | 4 +-
.../functions/MappedConfigurationTest.java | 7 -
modules/injection/cdi/pom.xml | 2 +-
.../tamaya/cdi/ConfigurationProducer.java | 13 +-
modules/jndi/pom.xml | 2 +-
.../apache/tamaya/jndi/JNDIPropertySource.java | 2 +-
.../microprofile/MicroprofileConfigBuilder.java | 4 +-
.../MicroprofileDefaultProperties.java | 2 +-
.../microprofile/MicroprofileAdapterTest.java | 10 +-
.../MicroprofileConfigSourceProviderTest.java | 4 +-
modules/mutable-config/pom.xml | 2 +-
.../MutablePropertiesPropertySource.java | 4 +-
.../MutableXmlPropertiesPropertySource.java | 4 +-
modules/osgi/common/pom.xml | 2 +-
.../OSGIConfigAdminPropertySource.java | 2 +-
.../src/main/features/features.xml | 2 +-
modules/osgi/updater/pom.xml | 2 +-
modules/pom.xml | 1 -
modules/spi-support/bnd.bnd | 26 -
.../tamaya/spisupport/BasePropertySource.java | 163 -------
.../spisupport/BuildablePropertySource.java | 231 ---------
.../BuildablePropertySourceProvider.java | 114 -----
.../tamaya/spisupport/CLIPropertySource.java | 137 ------
.../tamaya/spisupport/ConfigValueEvaluator.java | 48 --
.../tamaya/spisupport/ConfigurationBuilder.java | 334 -------------
.../spisupport/DefaultConfigValueEvaluator.java | 70 ---
.../tamaya/spisupport/DefaultConfiguration.java | 251 ----------
.../spisupport/DefaultConfigurationBuilder.java | 229 ---------
.../spisupport/DefaultConfigurationContext.java | 300 ------------
.../DefaultConfigurationContextBuilder.java | 408 ----------------
.../apache/tamaya/spisupport/EnumConverter.java | 68 ---
.../spisupport/EnvironmentPropertySource.java | 182 -------
.../tamaya/spisupport/MapPropertySource.java | 102 ----
.../spisupport/PriorityServiceComparator.java | 71 ---
.../PropertiesResourcePropertySource.java | 109 -----
.../spisupport/PropertyConverterManager.java | 469 -------------------
.../spisupport/PropertyFilterComparator.java | 72 ---
.../tamaya/spisupport/PropertyFiltering.java | 124 -----
.../spisupport/PropertySourceComparator.java | 107 -----
.../tamaya/spisupport/RegexPropertyFilter.java | 84 ----
.../tamaya/spisupport/SimplePropertySource.java | 284 -----------
.../tamaya/spisupport/SystemPropertySource.java | 199 --------
.../java/org/apache/tamaya/spisupport/A.java | 29 --
.../java/org/apache/tamaya/spisupport/B.java | 29 --
.../spisupport/BasePropertySourceTest.java | 88 ----
.../BuildablePropertySourceProviderTest.java | 76 ---
.../spisupport/BuildablePropertySourceTest.java | 88 ----
.../java/org/apache/tamaya/spisupport/C.java | 56 ---
.../spisupport/CLIPropertySourceTest.java | 59 ---
.../tamaya/spisupport/CTestConverter.java | 32 --
.../DefaultConfigurationContextTest.java | 177 -------
.../tamaya/spisupport/EnumConverterTest.java | 60 ---
.../EnvironmentPropertySourceTest.java | 68 ---
.../spisupport/MapPropertySourceTest.java | 77 ---
.../PriorityServiceComparatorTest.java | 43 --
.../PropertiesFilePropertySourceTest.java | 60 ---
.../PropertyConverterManagerTest.java | 180 -------
.../spisupport/RegexPropertyFilterTest.java | 70 ---
.../spisupport/SimplePropertySourceTest.java | 86 ----
.../spisupport/SystemPropertySourceTest.java | 96 ----
.../spisupport/TestPropertyDefaultSource.java | 57 ---
.../org.apache.tamaya.spi.PropertyConverter | 38 --
.../src/test/resources/invalid-properties.xml | 25 -
.../src/test/resources/non-xml-properties.xml | 18 -
.../test/resources/overrideOrdinal.properties | 25 -
.../src/test/resources/testfile.properties | 22 -
.../src/test/resources/valid-properties.xml | 25 -
82 files changed, 53 insertions(+), 5826 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/examples/01-resources-example/src/main/java/org/apache/tamaya/ext/examples/resources/MyPathPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/examples/01-resources-example/src/main/java/org/apache/tamaya/ext/examples/resources/MyPathPropertySourceProvider.java b/examples/01-resources-example/src/main/java/org/apache/tamaya/ext/examples/resources/MyPathPropertySourceProvider.java
index b961121..0348157 100644
--- a/examples/01-resources-example/src/main/java/org/apache/tamaya/ext/examples/resources/MyPathPropertySourceProvider.java
+++ b/examples/01-resources-example/src/main/java/org/apache/tamaya/ext/examples/resources/MyPathPropertySourceProvider.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.ext.examples.resources;
-import org.apache.tamaya.core.propertysource.SimplePropertySource;
+import org.apache.tamaya.spisupport.propertysource.SimplePropertySource;
import org.apache.tamaya.resource.AbstractPathPropertySourceProvider;
import org.apache.tamaya.spi.PropertySource;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FilePropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FilePropertySourceProvider.java b/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FilePropertySourceProvider.java
index 088ffe2..a15ad6e 100644
--- a/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FilePropertySourceProvider.java
+++ b/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FilePropertySourceProvider.java
@@ -20,7 +20,7 @@ package org.apache.tamaya.ext.examples.events;
import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.core.propertysource.BasePropertySource;
+import org.apache.tamaya.spisupport.propertysource.BasePropertySource;
import org.apache.tamaya.resource.AbstractPathPropertySourceProvider;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertyValue;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/events/pom.xml
----------------------------------------------------------------------
diff --git a/modules/events/pom.xml b/modules/events/pom.xml
index dd8bb41..aaa650f 100644
--- a/modules/events/pom.xml
+++ b/modules/events/pom.xml
@@ -44,7 +44,7 @@ under the License.
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.apache.tamaya.ext</groupId>
+ <groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-spisupport</artifactId>
<version>${project.version}</version>
</dependency>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/events/src/test/java/org/apache/tamaya/events/ChangeableGlobalPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/ChangeableGlobalPropertySource.java b/modules/events/src/test/java/org/apache/tamaya/events/ChangeableGlobalPropertySource.java
index 180b36e..94a0a9d 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/ChangeableGlobalPropertySource.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/ChangeableGlobalPropertySource.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.events;
-import org.apache.tamaya.core.propertysource.BasePropertySource;
+import org.apache.tamaya.spisupport.propertysource.BasePropertySource;
import org.apache.tamaya.spi.PropertyValue;
import java.util.Map;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/events/src/test/java/org/apache/tamaya/events/ChangeableThreadLocalPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/ChangeableThreadLocalPropertySource.java b/modules/events/src/test/java/org/apache/tamaya/events/ChangeableThreadLocalPropertySource.java
index fe6f973..f8fd413 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/ChangeableThreadLocalPropertySource.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/ChangeableThreadLocalPropertySource.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.events;
-import org.apache.tamaya.core.propertysource.BasePropertySource;
+import org.apache.tamaya.spisupport.propertysource.BasePropertySource;
import org.apache.tamaya.spi.PropertyValue;
import java.util.HashMap;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/events/src/test/java/org/apache/tamaya/events/FrozenPropertySourceTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/FrozenPropertySourceTest.java b/modules/events/src/test/java/org/apache/tamaya/events/FrozenPropertySourceTest.java
index 88cee48..cdc70b8 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/FrozenPropertySourceTest.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/FrozenPropertySourceTest.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.events;
-import org.apache.tamaya.core.propertysource.SystemPropertySource;
+import org.apache.tamaya.spisupport.propertysource.SystemPropertySource;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertyValue;
import org.apache.tamaya.spisupport.PropertySourceComparator;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/events/src/test/java/org/apache/tamaya/events/PropertySourceChangeTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/PropertySourceChangeTest.java b/modules/events/src/test/java/org/apache/tamaya/events/PropertySourceChangeTest.java
index a8b230e..a1a9200 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/PropertySourceChangeTest.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/PropertySourceChangeTest.java
@@ -18,9 +18,9 @@
*/
package org.apache.tamaya.events;
-import org.apache.tamaya.core.propertysource.EnvironmentPropertySource;
-import org.apache.tamaya.core.propertysource.SimplePropertySource;
-import org.apache.tamaya.core.propertysource.SystemPropertySource;
+import org.apache.tamaya.spisupport.propertysource.EnvironmentPropertySource;
+import org.apache.tamaya.spisupport.propertysource.SimplePropertySource;
+import org.apache.tamaya.spisupport.propertysource.SystemPropertySource;
import org.apache.tamaya.spi.PropertySource;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/events/src/test/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java b/modules/events/src/test/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
index 7a60ea8..c821d43 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
@@ -43,7 +43,7 @@ import org.apache.tamaya.ConfigException;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertySourceProvider;
import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.spisupport.BasePropertySource;
+import org.apache.tamaya.spisupport.propertysource.BasePropertySource;
/**
* This implementation runs in a folder taking up all files compatible with the given
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/features/pom.xml
----------------------------------------------------------------------
diff --git a/modules/features/pom.xml b/modules/features/pom.xml
index 6f15c0f..db616aa 100644
--- a/modules/features/pom.xml
+++ b/modules/features/pom.xml
@@ -108,7 +108,7 @@ under the License.
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.apache.tamaya.ext</groupId>
+ <groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-spisupport</artifactId>
<version>${project.version}</version>
<scope>test</scope>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/filter/pom.xml
----------------------------------------------------------------------
diff --git a/modules/filter/pom.xml b/modules/filter/pom.xml
index c19d4a2..88ebfa6 100644
--- a/modules/filter/pom.xml
+++ b/modules/filter/pom.xml
@@ -54,7 +54,7 @@ under the License.
<artifactId>junit</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.tamaya.ext</groupId>
+ <groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-spisupport</artifactId>
<version>${project.version}</version>
<scope>test</scope>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java
----------------------------------------------------------------------
diff --git a/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java b/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java
index f886ba0..9b25bb6 100644
--- a/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java
+++ b/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java
@@ -21,8 +21,7 @@ package org.apache.tamaya.filter;
import org.apache.tamaya.spi.ConfigurationContext;
import org.apache.tamaya.spi.PropertyFilter;
import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.spisupport.DefaultConfigurationContext;
-import org.apache.tamaya.spisupport.DefaultConfigurationContextBuilder;
+import org.apache.tamaya.core.internal.DefaultConfigurationContextBuilder;
import org.apache.tamaya.spisupport.RegexPropertyFilter;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/formats/base/pom.xml
----------------------------------------------------------------------
diff --git a/modules/formats/base/pom.xml b/modules/formats/base/pom.xml
index aa2c660..a2007ce 100644
--- a/modules/formats/base/pom.xml
+++ b/modules/formats/base/pom.xml
@@ -45,7 +45,7 @@ under the License.
<version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.apache.tamaya.ext</groupId>
+ <groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-spisupport</artifactId>
<version>${project.version}</version>
</dependency>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/formats/base/src/main/java/org/apache/tamaya/format/MappedConfigurationDataPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/formats/base/src/main/java/org/apache/tamaya/format/MappedConfigurationDataPropertySource.java b/modules/formats/base/src/main/java/org/apache/tamaya/format/MappedConfigurationDataPropertySource.java
index 743f8cd..5bd6444 100644
--- a/modules/formats/base/src/main/java/org/apache/tamaya/format/MappedConfigurationDataPropertySource.java
+++ b/modules/formats/base/src/main/java/org/apache/tamaya/format/MappedConfigurationDataPropertySource.java
@@ -20,7 +20,7 @@ package org.apache.tamaya.format;
import org.apache.tamaya.functions.Supplier;
import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.spisupport.BasePropertySource;
+import org.apache.tamaya.spisupport.propertysource.BasePropertySource;
import java.util.HashMap;
import java.util.Map;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/functions/pom.xml
----------------------------------------------------------------------
diff --git a/modules/functions/pom.xml b/modules/functions/pom.xml
index 957f3a3..05b38a5 100644
--- a/modules/functions/pom.xml
+++ b/modules/functions/pom.xml
@@ -46,7 +46,7 @@ under the License.
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.apache.tamaya.ext</groupId>
+ <groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-spisupport</artifactId>
<version>${project.version}</version>
</dependency>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/functions/src/test/java/org/apache/tamaya/functions/CombinedConfigurationTest.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/test/java/org/apache/tamaya/functions/CombinedConfigurationTest.java b/modules/functions/src/test/java/org/apache/tamaya/functions/CombinedConfigurationTest.java
index 04c6573..bb65d69 100644
--- a/modules/functions/src/test/java/org/apache/tamaya/functions/CombinedConfigurationTest.java
+++ b/modules/functions/src/test/java/org/apache/tamaya/functions/CombinedConfigurationTest.java
@@ -23,23 +23,16 @@ import org.apache.tamaya.ConfigQuery;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.ConfigurationContextBuilder;
import org.apache.tamaya.spisupport.DefaultConfiguration;
-import org.apache.tamaya.spisupport.DefaultConfigurationContext;
-import org.apache.tamaya.spisupport.DefaultConfigurationContextBuilder;
-import org.apache.tamaya.spisupport.SimplePropertySource;
+import org.apache.tamaya.core.internal.DefaultConfigurationContextBuilder;
+import org.apache.tamaya.spisupport.propertysource.SimplePropertySource;
import org.assertj.core.api.ThrowableAssert;
import org.junit.Test;
import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import java.lang.reflect.Method;
-import java.lang.reflect.Type;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import java.util.TreeMap;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonMap;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/functions/src/test/java/org/apache/tamaya/functions/ConfigurationFunctionsTest.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/test/java/org/apache/tamaya/functions/ConfigurationFunctionsTest.java b/modules/functions/src/test/java/org/apache/tamaya/functions/ConfigurationFunctionsTest.java
index 5850eb4..99cb944 100644
--- a/modules/functions/src/test/java/org/apache/tamaya/functions/ConfigurationFunctionsTest.java
+++ b/modules/functions/src/test/java/org/apache/tamaya/functions/ConfigurationFunctionsTest.java
@@ -20,8 +20,8 @@ package org.apache.tamaya.functions;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.core.propertysource.EnvironmentPropertySource;
-import org.apache.tamaya.core.propertysource.SystemPropertySource;
+import org.apache.tamaya.spisupport.propertysource.EnvironmentPropertySource;
+import org.apache.tamaya.spisupport.propertysource.SystemPropertySource;
import org.apache.tamaya.spi.ConfigurationContextBuilder;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/functions/src/test/java/org/apache/tamaya/functions/MappedConfigurationTest.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/test/java/org/apache/tamaya/functions/MappedConfigurationTest.java b/modules/functions/src/test/java/org/apache/tamaya/functions/MappedConfigurationTest.java
index c31077a..2a470a2 100644
--- a/modules/functions/src/test/java/org/apache/tamaya/functions/MappedConfigurationTest.java
+++ b/modules/functions/src/test/java/org/apache/tamaya/functions/MappedConfigurationTest.java
@@ -18,15 +18,8 @@
*/
package org.apache.tamaya.functions;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spisupport.DefaultConfigurationContext;
import org.junit.Test;
-import org.mockito.Matchers;
-import org.mockito.Mockito;
-import org.mockito.internal.matchers.Null;
-import static org.junit.Assert.*;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doCallRealMethod;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/injection/cdi/pom.xml
----------------------------------------------------------------------
diff --git a/modules/injection/cdi/pom.xml b/modules/injection/cdi/pom.xml
index de1e318..e1e59a5 100644
--- a/modules/injection/cdi/pom.xml
+++ b/modules/injection/cdi/pom.xml
@@ -105,7 +105,7 @@ under the License.
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.apache.tamaya.ext</groupId>
+ <groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-spisupport</artifactId>
<version>${project.version}</version>
</dependency>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/ConfigurationProducer.java
----------------------------------------------------------------------
diff --git a/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/ConfigurationProducer.java b/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/ConfigurationProducer.java
index ea6a81c..279f04b 100644
--- a/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/ConfigurationProducer.java
+++ b/modules/injection/cdi/src/main/java/org/apache/tamaya/cdi/ConfigurationProducer.java
@@ -30,6 +30,7 @@ import javax.enterprise.inject.spi.InjectionPoint;
import javax.inject.Provider;
import java.lang.reflect.*;
import java.util.List;
+import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -147,12 +148,17 @@ public class ConfigurationProducer {
return textValue;
}
Object value = null;
+ ParameterizedType pt = null;
Type toType = injectionPoint.getAnnotated().getBaseType();
if(toType instanceof ParameterizedType){
- ParameterizedType pt = (ParameterizedType)toType;
- if(Provider.class.equals(pt.getRawType()) || Instance.class.equals(pt.getRawType())){
+ pt = (ParameterizedType)toType;
+ if(Provider.class.equals(pt.getRawType()) || Instance.class.equals(pt.getRawType())
+ || Optional.class.equals(pt.getRawType())){
toType = pt.getActualTypeArguments()[0];
}
+ if(toType.equals(String.class)){
+ value = textValue;
+ }
}
List<PropertyConverter<Object>> converters = ConfigurationProvider.getConfiguration().getContext()
.getPropertyConverters(TypeLiteral.of(toType));
@@ -169,6 +175,9 @@ public class ConfigurationProducer {
injectionPoint, e);
}
}
+ if(pt != null && Optional.class.equals(pt.getRawType())){
+ return Optional.ofNullable(value);
+ }
return value;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/jndi/pom.xml
----------------------------------------------------------------------
diff --git a/modules/jndi/pom.xml b/modules/jndi/pom.xml
index 3e6c46a..805729b 100644
--- a/modules/jndi/pom.xml
+++ b/modules/jndi/pom.xml
@@ -54,7 +54,7 @@ under the License.
<artifactId>junit</artifactId>
</dependency>
<dependency>
- <groupId>org.apache.tamaya.ext</groupId>
+ <groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-spisupport</artifactId>
<version>${project.version}</version>
</dependency>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/jndi/src/main/java/org/apache/tamaya/jndi/JNDIPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/jndi/src/main/java/org/apache/tamaya/jndi/JNDIPropertySource.java b/modules/jndi/src/main/java/org/apache/tamaya/jndi/JNDIPropertySource.java
index 00ad746..d2b549b 100644
--- a/modules/jndi/src/main/java/org/apache/tamaya/jndi/JNDIPropertySource.java
+++ b/modules/jndi/src/main/java/org/apache/tamaya/jndi/JNDIPropertySource.java
@@ -33,7 +33,7 @@ import javax.naming.NamingException;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.spisupport.BasePropertySource;
+import org.apache.tamaya.spisupport.propertysource.BasePropertySource;
import org.osgi.service.component.annotations.Component;
/**
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigBuilder.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigBuilder.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigBuilder.java
index 896311c..82209c3 100644
--- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigBuilder.java
+++ b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileConfigBuilder.java
@@ -22,9 +22,9 @@ import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.spi.ConfigurationContextBuilder;
import org.apache.tamaya.spi.ServiceContextManager;
-import org.apache.tamaya.spisupport.EnvironmentPropertySource;
+import org.apache.tamaya.spisupport.propertysource.EnvironmentPropertySource;
import org.apache.tamaya.spisupport.PropertySourceComparator;
-import org.apache.tamaya.spisupport.SystemPropertySource;
+import org.apache.tamaya.spisupport.propertysource.SystemPropertySource;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.spi.ConfigBuilder;
import org.eclipse.microprofile.config.spi.ConfigSource;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileDefaultProperties.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileDefaultProperties.java b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileDefaultProperties.java
index cfe06bd..b20dc8f 100644
--- a/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileDefaultProperties.java
+++ b/modules/microprofile/src/main/java/org/apache/tamaya/microprofile/MicroprofileDefaultProperties.java
@@ -18,7 +18,7 @@
*/
package org.apache.tamaya.microprofile;
-import org.apache.tamaya.spisupport.PropertiesResourcePropertySource;
+import org.apache.tamaya.spisupport.propertysource.PropertiesResourcePropertySource;
/**
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileAdapterTest.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileAdapterTest.java b/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileAdapterTest.java
index d227b42..8fea044 100644
--- a/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileAdapterTest.java
+++ b/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileAdapterTest.java
@@ -18,11 +18,12 @@
*/
package org.apache.tamaya.microprofile;
-import org.apache.tamaya.*;
-import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.Configuration;
+import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.spi.PropertyConverter;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertyValue;
+import org.apache.tamaya.spisupport.propertysource.BuildablePropertySource;
import org.apache.tamaya.spisupport.BuildablePropertySource;
import org.assertj.core.api.Assertions;
import org.eclipse.microprofile.config.Config;
@@ -32,7 +33,10 @@ import org.eclipse.microprofile.config.spi.ConfigSource;
import org.eclipse.microprofile.config.spi.Converter;
import org.junit.Test;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import static org.junit.Assert.*;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileConfigSourceProviderTest.java
----------------------------------------------------------------------
diff --git a/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileConfigSourceProviderTest.java b/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileConfigSourceProviderTest.java
index c62b390..ab792aa 100644
--- a/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileConfigSourceProviderTest.java
+++ b/modules/microprofile/src/test/java/org/apache/tamaya/microprofile/MicroprofileConfigSourceProviderTest.java
@@ -18,8 +18,8 @@
*/
package org.apache.tamaya.microprofile;
-import org.apache.tamaya.spisupport.BuildablePropertySource;
-import org.apache.tamaya.spisupport.BuildablePropertySourceProvider;
+import org.apache.tamaya.spisupport.propertysource.BuildablePropertySource;
+import org.apache.tamaya.spisupport.propertysource.BuildablePropertySourceProvider;
import org.eclipse.microprofile.config.spi.ConfigSource;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/mutable-config/pom.xml
----------------------------------------------------------------------
diff --git a/modules/mutable-config/pom.xml b/modules/mutable-config/pom.xml
index ab467cf..ef74d57 100644
--- a/modules/mutable-config/pom.xml
+++ b/modules/mutable-config/pom.xml
@@ -39,7 +39,7 @@ under the License.
<version>${tamaya-apicore.version}</version>
</dependency>
<dependency>
- <groupId>org.apache.tamaya.ext</groupId>
+ <groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-spisupport</artifactId>
<version>${project.version}</version>
</dependency>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java
index 39b840c..659dab2 100644
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutablePropertiesPropertySource.java
@@ -22,8 +22,7 @@ import org.apache.tamaya.ConfigException;
import org.apache.tamaya.mutableconfig.ConfigChangeRequest;
import org.apache.tamaya.mutableconfig.spi.MutablePropertySource;
import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.spi.PropertyValueBuilder;
-import org.apache.tamaya.spisupport.BasePropertySource;
+import org.apache.tamaya.spisupport.propertysource.BasePropertySource;
import java.io.BufferedOutputStream;
import java.io.File;
@@ -31,7 +30,6 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java
index 96ac691..bcba53a 100644
--- a/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java
+++ b/modules/mutable-config/src/main/java/org/apache/tamaya/mutableconfig/propertysources/MutableXmlPropertiesPropertySource.java
@@ -22,8 +22,7 @@ import org.apache.tamaya.ConfigException;
import org.apache.tamaya.mutableconfig.ConfigChangeRequest;
import org.apache.tamaya.mutableconfig.spi.MutablePropertySource;
import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.spi.PropertyValueBuilder;
-import org.apache.tamaya.spisupport.BasePropertySource;
+import org.apache.tamaya.spisupport.propertysource.BasePropertySource;
import java.io.BufferedOutputStream;
import java.io.File;
@@ -31,7 +30,6 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/osgi/common/pom.xml
----------------------------------------------------------------------
diff --git a/modules/osgi/common/pom.xml b/modules/osgi/common/pom.xml
index 622907b..57c56c3 100644
--- a/modules/osgi/common/pom.xml
+++ b/modules/osgi/common/pom.xml
@@ -67,7 +67,7 @@
<version>${project.parent.version}</version>
</dependency>
<dependency>
- <groupId>org.apache.tamaya.ext</groupId>
+ <groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-spisupport</artifactId>
<version>${project.parent.version}</version>
</dependency>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySource.java b/modules/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySource.java
index 529468e..6c5b00a 100644
--- a/modules/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySource.java
+++ b/modules/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySource.java
@@ -19,7 +19,7 @@
package org.apache.tamaya.osgi.injection;
import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.spisupport.BasePropertySource;
+import org.apache.tamaya.spisupport.propertysource.BasePropertySource;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/osgi/karaf-features/src/main/features/features.xml
----------------------------------------------------------------------
diff --git a/modules/osgi/karaf-features/src/main/features/features.xml b/modules/osgi/karaf-features/src/main/features/features.xml
index 20c5ee3..34949b7 100644
--- a/modules/osgi/karaf-features/src/main/features/features.xml
+++ b/modules/osgi/karaf-features/src/main/features/features.xml
@@ -20,7 +20,7 @@ limitations under the License.
<features name="org-apache-tamaya-configadmin" version="0.4-incubating">
<bundle>mvn:org.apache.tamaya.ext/tamaya-osgi_alpha/0.4-incubating/jar</bundle>
<bundle>mvn:org.apache.tamaya.ext/tamaya-functions/0.4-incubating/jar</bundle>
- <bundle>mvn:org.apache.tamaya.ext/tamaya-spisupport/0.4-incubating/jar</bundle>
+ <bundle>mvn:org.apache.tamaya/tamaya-spisupport/0.4-incubating/jar</bundle>
<bundle>mvn:org.apache.tamaya.ext/tamaya-osgi-karaf_alpha/0.4-incubating/jar</bundle>
<features name="org-apache-tamaya-minimal" version="0.4-incubating">
<feature name="org-apache-tamaya-api" version="0.4-incubating">
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/osgi/updater/pom.xml
----------------------------------------------------------------------
diff --git a/modules/osgi/updater/pom.xml b/modules/osgi/updater/pom.xml
index 18d5370..2819239 100644
--- a/modules/osgi/updater/pom.xml
+++ b/modules/osgi/updater/pom.xml
@@ -58,7 +58,7 @@
<version>${project.parent.version}</version>
</dependency>
<dependency>
- <groupId>org.apache.tamaya.ext</groupId>
+ <groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-spisupport</artifactId>
<version>${project.parent.version}</version>
</dependency>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/pom.xml
----------------------------------------------------------------------
diff --git a/modules/pom.xml b/modules/pom.xml
index f5d9ffc..25a4541 100644
--- a/modules/pom.xml
+++ b/modules/pom.xml
@@ -34,7 +34,6 @@ under the License.
<modules>
<module>features</module>
<module>functions</module>
- <module>spi-support</module>
<module>optional</module>
<module>events</module>
<module>filter</module>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/bnd.bnd
----------------------------------------------------------------------
diff --git a/modules/spi-support/bnd.bnd b/modules/spi-support/bnd.bnd
deleted file mode 100644
index 1ce81a3..0000000
--- a/modules/spi-support/bnd.bnd
+++ /dev/null
@@ -1,26 +0,0 @@
--buildpath: \
- osgi.annotation; version=6.0.0,\
- osgi.core; version=6.0,\
- osgi.cmpn; version=6.0
-
--testpath: \
- ${junit}
-
-javac.source: 1.8
-javac.target: 1.8
-
-Bundle-Version: ${version}.${tstamp}
-Bundle-Name: Apache Tamaya - SPI Support
-Bundle-SymbolicName: org.apache.tamaya.spisupport
-Bundle-Description: Apacha Tamaya Config - SPI Support
-Bundle-Category: Implementation
-Bundle-Copyright: (C) Apache Foundation
-Bundle-License: Apache Licence version 2
-Bundle-Vendor: Apache Software Foundation
-Bundle-ContactAddress: dev-tamaya@incubator.apache.org
-Bundle-DocURL: http://tamaya.apache.org
-Export-Package: \
- org.apache.tamaya.spisupport
-Import-Package: \
- org.apache.tamaya,\
- org.apache.tamaya.spi
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/BasePropertySource.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/BasePropertySource.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/BasePropertySource.java
deleted file mode 100644
index 14c3764..0000000
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/BasePropertySource.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.spi.PropertyValueBuilder;
-
-import java.util.Map;
-import java.util.Objects;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Abstract {@link org.apache.tamaya.spi.PropertySource} that allows to set a default ordinal that will be used, if no
- * ordinal is provided with the config.
- */
-public abstract class BasePropertySource implements PropertySource{
- /** default ordinal that will be used, if no ordinal is provided with the config. */
- private int defaultOrdinal;
- /** Used if the ordinal has been set explicitly. */
- private volatile Integer ordinal;
- /** The name of the property source. */
- private String name;
-
- /**
- * Constructor.
- * @param name the (unique) property source name, not null.
- */
- protected BasePropertySource(String name){
- this.name = Objects.requireNonNull(name);
- this.defaultOrdinal = 0;
- }
-
- /**
- * Constructor.
- * @param defaultOrdinal default ordinal that will be used, if no ordinal is provided with the config.
- */
- protected BasePropertySource(int defaultOrdinal){
- this.name = getClass().getSimpleName();
- this.defaultOrdinal = defaultOrdinal;
- }
-
- /**
- * Constructor.
- * @param name the (unique) property source name, not null.
- * @param defaultOrdinal default ordinal that will be used, if no ordinal is provided with the config.
- */
- protected BasePropertySource(String name, int defaultOrdinal){
- this.name = Objects.requireNonNull(name);
- this.defaultOrdinal = defaultOrdinal;
- }
-
-
- /**
- * Constructor, using a default ordinal of 0.
- */
- protected BasePropertySource(){
- this(0);
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- /**
- * Sets the property source's (unique) name.
- * @param name the name, not null.
- */
- public void setName(String name){
- this.name = Objects.requireNonNull(name);
- }
-
- /**
- * Allows to set the ordinal of this property source explcitly. This will override any evaluated
- * ordinal, or default ordinal. To reset an explcit ordinal call {@code setOrdinal(null);}.
- * @param ordinal the explicit ordinal, or null.
- */
- public void setOrdinal(Integer ordinal){
- this.ordinal = ordinal;
- }
-
- /**
- * Allows to set the ordinal of this property source explcitly. This will override any evaluated
- * ordinal, or default ordinal. To reset an explcit ordinal call {@code setOrdinal(null);}.
- * @param defaultOrdinal the default ordinal, or null.
- */
- public void setDefaultOrdinal(Integer defaultOrdinal){
- this.defaultOrdinal = defaultOrdinal;
- }
-
- public int getOrdinal() {
- Integer ordinal = this.ordinal;
- if(ordinal!=null){
- Logger.getLogger(getClass().getName()).finest(
- "Using explicit ordinal '"+ordinal+"' for property source: " + getName());
- return ordinal;
- }
- PropertyValue configuredOrdinal = get(TAMAYA_ORDINAL);
- if(configuredOrdinal!=null){
- try {
- return Integer.parseInt(configuredOrdinal.getValue());
- } catch (Exception e) {
- Logger.getLogger(getClass().getName()).log(Level.WARNING,
- "Configured Ordinal is not an int number: " + configuredOrdinal, e);
- }
- }
- return getDefaultOrdinal();
- }
-
- /**
- * Returns the default ordinal used, when no ordinal is set, or the ordinal was not parseable to an int value.
- * @return the default ordinal used, by default 0.
- */
- public int getDefaultOrdinal(){
- return defaultOrdinal;
- }
-
- @Override
- public PropertyValue get(String key) {
- Map<String,PropertyValue> properties = getProperties();
- PropertyValue val = properties.get(key);
- if(val==null){
- return null;
- }
- return val;
- }
-
- @Override
- public boolean isScannable(){
- return true;
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName() + "{" +
- toStringValues() +
- '}';
- }
-
- protected String toStringValues() {
- return " defaultOrdinal=" + defaultOrdinal + '\n' +
- " ordinal=" + ordinal + '\n' +
- " name='" + name + '\'' + '\n';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/BuildablePropertySource.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/BuildablePropertySource.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/BuildablePropertySource.java
deleted file mode 100644
index b7b4129..0000000
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/BuildablePropertySource.java
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-
-import java.util.*;
-
-/**
- * A Buildable property source.
- */
-public class BuildablePropertySource implements PropertySource{
-
- private int ordinal;
- private String name = "PropertySource-"+UUID.randomUUID().toString();
- private Map<String,PropertyValue> properties = new HashMap<>();
-
- @Override
- public int getOrdinal() {
- return ordinal;
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- @Override
- public PropertyValue get(String key) {
- return properties.get(key);
- }
-
- @Override
- public Map<String, PropertyValue> getProperties() {
- return Collections.unmodifiableMap(properties);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- BuildablePropertySource that = (BuildablePropertySource) o;
-
- return name.equals(that.name);
- }
-
- @Override
- public boolean isScannable() {
- return true;
- }
-
- @Override
- public int hashCode() {
- return name.hashCode();
- }
-
- @Override
- public String toString() {
- return "BuildablePropertySource{" +
- "ordinal=" + ordinal +
- ", name='" + name + '\'' +
- ", properties=" + properties +
- '}';
- }
-
- /**
- * Builder builder.
- *
- * @return the builder
- */
- public static Builder builder() {
- return new Builder();
- }
-
-
- /**
- * The type Builder.
- */
- public static final class Builder {
- private int ordinal;
- private String source = "<on-the-fly-build>";
- private String name = "PropertySource-"+ UUID.randomUUID().toString();
- private Map<String,PropertyValue> properties = new HashMap<>();
-
- private Builder() {
- }
-
- /**
- * With ordinal builder.
- *
- * @param ordinal the ordinal
- * @return the builder
- */
- public Builder withOrdinal(int ordinal) {
- this.ordinal = ordinal;
- return this;
- }
-
- /**
- * With source builder.
- *
- * @param source the source
- * @return the builder
- */
- public Builder withSource(String source) {
- this.source = Objects.requireNonNull(source);
- return this;
- }
-
- /**
- * With name builder.
- *
- * @param name the name
- * @return the builder
- */
- public Builder withName(String name) {
- this.name = Objects.requireNonNull(name);
- return this;
- }
-
- /**
- * With simple property builder.
- *
- * @param key the key
- * @param value the value
- * @return the builder
- */
- public Builder withSimpleProperty(String key, String value) {
- return withProperties(PropertyValue.of(key, value, this.source));
- }
-
- /**
- * With simple property builder.
- *
- * @param key the key
- * @param value the value
- * @param source the source
- * @return the builder
- */
- public Builder withSimpleProperty(String key, String value, String source) {
- return withProperties(PropertyValue.of(key, value, source));
- }
-
- /**
- * With properties builder.
- *
- * @param values the values
- * @return the builder
- */
- public Builder withProperties(PropertyValue... values) {
- for(PropertyValue val:values){
- this.properties.put(val.getKey(), val);
- }
- return this;
- }
-
- /**
- * With properties builder.
- *
- * @param properties the properties
- * @return the builder
- */
- public Builder withProperties(Map<String, PropertyValue> properties) {
- this.properties = Objects.requireNonNull(properties);
- return this;
- }
-
- /**
- * With properties builder.
- *
- * @param properties the properties
- * @param source the source
- * @return the builder
- */
- public Builder withProperties(Map<String, String> properties, String source) {
- this.properties.putAll(PropertyValue.map(properties, source));
- return this;
- }
-
- /**
- * With simple properties builder.
- *
- * @param properties the properties
- * @return the builder
- */
- public Builder withSimpleProperties(Map<String, String> properties) {
- this.properties.putAll(PropertyValue.map(properties, this.source));
- return this;
- }
-
- /**
- * But builder.
- *
- * @return the builder
- */
- public Builder but() {
- return builder().withOrdinal(ordinal).withName(name).withProperties(properties);
- }
-
- /**
- * Build buildable property source.
- *
- * @return the buildable property source
- */
- public BuildablePropertySource build() {
- BuildablePropertySource buildablePropertySource = new BuildablePropertySource();
- buildablePropertySource.name = this.name;
- buildablePropertySource.properties = this.properties;
- buildablePropertySource.ordinal = this.ordinal;
- return buildablePropertySource;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/BuildablePropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/BuildablePropertySourceProvider.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/BuildablePropertySourceProvider.java
deleted file mode 100644
index 8341a44..0000000
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/BuildablePropertySourceProvider.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
-
-import java.util.*;
-
-/**
- * A Buildable property source.
- */
-public class BuildablePropertySourceProvider implements PropertySourceProvider{
-
- private List<PropertySource> sources = new ArrayList<>();
-
- @Override
- public Collection<PropertySource> getPropertySources() {
- return Collections.unmodifiableCollection(sources);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- BuildablePropertySourceProvider that = (BuildablePropertySourceProvider) o;
-
- return sources.equals(that.sources);
- }
-
- @Override
- public int hashCode() {
- return sources.hashCode();
- }
-
- @Override
- public String toString() {
- return "BuildablePropertySourceProvider{" +
- "sources=" + sources +
- '}';
- }
-
- /**
- * Builder builder.
- *
- * @return the builder
- */
- public static Builder builder() {
- return new Builder();
- }
-
-
-
-
- /**
- * The type Builder.
- */
- public static final class Builder {
- private List<PropertySource> sources = new ArrayList<>();
-
- private Builder() {
- }
-
- /**
- * With propertySources.
- *
- * @param propertySources the propertySources
- * @return the builder
- */
- public Builder withPropertySourcs(PropertySource... propertySources) {
- this.sources.addAll(Arrays.asList(propertySources));
- return this;
- }
-
- /**
- * With property sources builder.
- *
- * @param sources the property sources
- * @return the builder
- */
- public Builder withPropertySourcs(Collection<PropertySource> sources) {
- this.sources.addAll(sources);
- return this;
- }
-
- /**
- * Build buildable property source.
- *
- * @return the buildable property source
- */
- public BuildablePropertySourceProvider build() {
- BuildablePropertySourceProvider buildablePropertySource = new BuildablePropertySourceProvider();
- buildablePropertySource.sources.addAll(this.sources);
- return buildablePropertySource;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/CLIPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/CLIPropertySource.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/CLIPropertySource.java
deleted file mode 100644
index c74a8f3..0000000
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/CLIPropertySource.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import org.apache.tamaya.spi.PropertyValue;
-
-import java.util.*;
-
-/**
- * PropertySource that allows to add the programs main arguments as configuration entries. Unix syntax using '--' and
- * '-' params is supported.
- */
-public class CLIPropertySource extends BasePropertySource{
-
- /** The original main arguments. */
- private static String[] args = new String[0];
-
- /** The map of parsed main arguments. */
- private static Map<String,PropertyValue> mainArgs;
-
- /** Initializes the initial state. */
- static{
- initMainArgs(args);
- }
-
- /**
- * Creates a new instance.
- */
- public CLIPropertySource(){
- this((String[])null);
- }
-
- /**
- * Creates a new instance, allows optionally to pass the main arguments.
- * @param args the args, or null.
- */
- public CLIPropertySource(String... args){
- super("CLI");
- if(args!=null){
- initMainArgs(args);
- }
- }
-
- /**
- * Creates a new instance, allows optionally to pass the main arguments.
- * @param args the args, or null.
- * @param ordinal the ordinal to be applied.
- */
- public CLIPropertySource(int ordinal, String... args){
- if(args!=null){
- initMainArgs(args);
- }
- setOrdinal(ordinal);
- }
-
-
-
- /**
- * Configure the main arguments, hereby parsing and mapping the main arguments into
- * configuration propertiesi as key-value pairs.
- * @param args the main arguments, not null.
- */
- public static void initMainArgs(String... args){
- CLIPropertySource.args = Objects.requireNonNull(args);
- // TODO is there a way to figure out the args?
- String argsProp = System.getProperty("main.args");
- if(argsProp!=null){
- CLIPropertySource.args = argsProp.split("\\s");
- }
- Map<String,String> result = null;
- if(CLIPropertySource.args==null){
- result = Collections.emptyMap();
- }else{
- result = new HashMap<>();
- String prefix = System.getProperty("main.args.prefix");
- if(prefix==null){
- prefix="";
- }
- String key = null;
- for(String arg:CLIPropertySource.args){
- if(arg.startsWith("--")){
- arg = arg.substring(2);
- int index = arg.indexOf("=");
- if(index>0){
- key = arg.substring(0,index).trim();
- result.put(prefix+key, arg.substring(index+1).trim());
- key = null;
- }else{
- result.put(prefix+arg, arg);
- }
- }else if(arg.startsWith("-")){
- key = arg.substring(1);
- }else{
- if(key!=null){
- result.put(prefix+key, arg);
- key = null;
- }else{
- result.put(prefix+arg, arg);
- }
- }
- }
- }
- Map<String,PropertyValue> finalProps = new HashMap<>();
- for(Map.Entry<String,String> en:result.entrySet()) {
- finalProps.put(en.getKey(),
- PropertyValue.of(en.getKey(), en.getValue(), "main-args"));
- }
- CLIPropertySource.mainArgs = Collections.unmodifiableMap(finalProps);
- }
-
- @Override
- public Map<String, PropertyValue> getProperties() {
- return Collections.unmodifiableMap(mainArgs);
- }
-
- @Override
- protected String toStringValues() {
- return super.toStringValues() +
- " args=" + Arrays.toString(args) + '\n';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/ConfigValueEvaluator.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/ConfigValueEvaluator.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/ConfigValueEvaluator.java
deleted file mode 100644
index 92fd614..0000000
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/ConfigValueEvaluator.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.PropertyValue;
-
-import java.util.Map;
-
-
-/**
- * Component SPI which encapsulates the evaluation of a single or full <b>raw</b>value
- * for a {@link ConfigurationContext}.
- */
-public interface ConfigValueEvaluator {
-
- /**
- * Evaluates single value using a {@link ConfigurationContext}.
- * @param key the config key, not null.
- * @param context the context, not null.
- * @return the value, or null.
- */
- PropertyValue evaluteRawValue(String key, ConfigurationContext context);
-
- /**
- * Evaluates all property values from a {@link ConfigurationContext}.
- * @param context the context, not null.
- * @return the value, or null.
- */
- Map<String, PropertyValue> evaluateRawValues(ConfigurationContext context);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/ConfigurationBuilder.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/ConfigurationBuilder.java
deleted file mode 100644
index be2978b..0000000
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/ConfigurationBuilder.java
+++ /dev/null
@@ -1,334 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.*;
-
-import java.util.Collection;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
-
-/**
- * A builder for creating new or adapting instances of {@link Configuration}.
- * Builders can be obtained in exactly two ways:
- * <ol>
- * <li>By accessing a preinitialized builder from an existing {@link Configuration},
- * by calling {@link org.apache.tamaya.Configuration#toBuilder()}.</li>
- * <li>By accessing an empty builder instance from
- * {@link org.apache.tamaya.ConfigurationProvider#getConfigurationBuilder()}.</li>
- * </ol>
- */
-public interface ConfigurationBuilder {
-
- /**
- * Init this builder instance with the given {@link ConfigurationContext} instance. This
- * method will use any existing property sources, filters, converters and the combination
- * policy of the given {@link ConfigurationContext} and initialize the current builder
- * with them.
- *
- * @param context the {@link ConfigurationContext} instance to be used, not {@code null}.
- * @return this builder, for chaining, never null.
- */
- ConfigurationBuilder setContext(ConfigurationContext context);
-
- /**
- * This method can be used for adding {@link PropertySource}s.
- * Hereby the property source is added to the tail of property sources with
- * lowest priority regardless of its current ordinal value. To sort the property
- * sources based on their ordinals call {@link #sortPropertySources}.
- *
- * @param propertySources the PropertySources to add
- * @return this builder, for chaining, never null.
- * @throws IllegalArgumentException If a property source with a given name already
- * exists.
- */
- ConfigurationBuilder addPropertySources(PropertySource... propertySources);
-
- /**
- * This method can be used for programmatically adding {@link PropertySource}s.
- * Hereby the property source is added to the tail of property sources with
- * lowest priority regardless of its current ordinal value. To sort the property
- * sources based on their ordinals call {@link #sortPropertySources}.
- *
- * @param propertySources the PropertySources to add
- * @return this builder, for chaining, never null.
- * @throws IllegalArgumentException If a property source with a given name already
- * exists.
- */
- ConfigurationBuilder addPropertySources(Collection<PropertySource> propertySources);
-
- /**
- * Add all registered (default) property sources to the context built. The sources are ordered
- * based on their ordinal values and added to the chain of property sources with
- * higher priority.
- * @return this builder, for chaining, never null.
- */
- ConfigurationBuilder addDefaultPropertySources();
-
- /**
- * Removes the given property sources, if existing. The existing order of property
- * sources is preserved.
- *
- * @param propertySources the property sources to remove, not {@code null}.
- * @return the builder for chaining.
- */
- ConfigurationBuilder removePropertySources(PropertySource... propertySources);
-
- /**
- * Removes the given property sources, if existing. The existing order of property
- * sources is preserved.
- *
- * @param propertySources the property sources to remove, not {@code null}.
- * @return the builder for chaining.
- */
- ConfigurationBuilder removePropertySources(Collection<PropertySource> propertySources);
-
- /**
- * Access the current chain of property sources. Items at the end of the list have
- * precedence/more significance.
- *
- * @return the property source chain, never {@code null}.
- */
- List<PropertySource> getPropertySources();
-
- /**
- * Access the current chain of property filters. Items at the end of the list have
- * precedence/more significance.
- *
- * @return the property source chain, never {@code null}.
- */
- List<PropertyFilter> getPropertyFilters();
-
- /**
- * Access the current registered property converters.
- *
- * @return the current registered property converters.
- */
- Map<TypeLiteral<?>, Collection<PropertyConverter<?>>> getPropertyConverter();
-
- /**
- * Increases the priority of the given property source, by moving it towards the end
- * of the chain of property sources. If the property source given is already at the end
- * this method has no effect. This operation does not change any ordinal values.
- *
- * @param propertySource the property source to be incresed regarding its significance.
- * @return the builder for chaining.
- * @throws IllegalArgumentException If no such property source exists in the current
- * chain.
- */
- ConfigurationBuilder increasePriority(PropertySource propertySource);
-
- /**
- * Decreases the priority of the given property source, by moving it towards the start
- * of the chain of property sources. If the property source given is already the first
- * this method has no effect. This operation does not change any ordinal values.
- *
- * @param propertySource the property source to be decresed regarding its significance.
- * @return the builder for chaining.
- * @throws IllegalArgumentException If no such property source exists in the current
- * chain.
- */
- ConfigurationBuilder decreasePriority(PropertySource propertySource);
-
- /**
- * Increases the priority of the given property source to be maximal, by moving it to
- * the tail of the of property source chain. If the property source given is
- * already the last item this method has no effect. This operation does not change
- * any ordinal values.
- *
- * @param propertySource the property source to be maximized regarding its significance.
- * @return the builder for chaining.
- * @throws IllegalArgumentException If no such property source exists in the current
- * chain.
- */
- ConfigurationBuilder highestPriority(PropertySource propertySource);
-
- /**
- * Decreases the priority of the given property source to be minimal, by moving it to
- * the start of the chain of property source chain. If the property source given is
- * already the first item this method has no effect. This operation does not change
- * any ordinal values.
- *
- * @param propertySource the property source to be minimized regarding its significance.
- * @return the builder for chaining.
- * @throws IllegalArgumentException If no such property source exists in the current
- * chain.
- */
- ConfigurationBuilder lowestPriority(PropertySource propertySource);
-
- /**
- * Adds the given PropertyFilter instances, hereby the instances are added
- * to the end of the list with highest priority. The ordering of existing
- * property filters remains unchanged. To sort the property
- * filters call {@link #sortPropertyFilter}.
- *
- * @param filters the filters to add
- * @return this builder, for chaining, never null.
- */
- ConfigurationBuilder addPropertyFilters(PropertyFilter... filters);
-
- /**
- * Adds the given PropertyFilter instances, hereby the instances are added
- * to the end of the list with highest priority. The ordering of existing
- * property filters remains unchanged. To sort the property
- * filters call {@link #sortPropertyFilter}.
- *
- * @param filters the filters to add
- * @return this builder, for chaining, never null.
- */
- ConfigurationBuilder addPropertyFilters(Collection<PropertyFilter> filters);
-
- /**
- * Add all registered (default) property filters to the context built.
- * @return this builder, for chaining, never null.
- */
- ConfigurationBuilder addDefaultPropertyFilters();
-
-
- /**
- * Removes the given PropertyFilter instances, if existing. The order of the remaining
- * filters is preserved.
- *
- * @param filters the filter to remove
- * @return this builder, for chaining, never null.
- */
- ConfigurationBuilder removePropertyFilters(PropertyFilter... filters);
-
- /**
- * Removes the given PropertyFilter instances, if existing. The order of the remaining
- * filters is preserved.
- *
- * @param filters the filter to remove
- * @return this builder, for chaining, never null.
- */
- ConfigurationBuilder removePropertyFilters(Collection<PropertyFilter> filters);
-
- /**
- * This method can be used for adding {@link PropertyConverter}s.
- * Converters are added at the end after any existing converters.
- * For converters already registered for the current target type the
- * method has no effect.
- *
- * @param typeToConvert the type for which the converter is for
- * @param propertyConverters the PropertyConverters to add for this type
- * @param <T> the target type.
- * @return this builder, for chaining, never null.
- */
- <T> ConfigurationBuilder addPropertyConverters(TypeLiteral<T> typeToConvert,
- PropertyConverter<T>... propertyConverters);
-
- /**
- * This method can be used for adding {@link PropertyConverter}s.
- * Converters are added at the end after any existing converters.
- * For converters already registered for the current target type the
- * method has no effect.
- *
- * @param typeToConvert the type for which the converter is for
- * @param propertyConverters the PropertyConverters to add for this type
- * @param <T> the target type.
- * @return this builder, for chaining, never null.
- */
- <T> ConfigurationBuilder addPropertyConverters(TypeLiteral<T> typeToConvert,
- Collection<PropertyConverter<T>> propertyConverters);
-
- /**
- * Add all registered (default) property converters to the context built.
- * @return this builder, for chaining, never null.
- */
- ConfigurationBuilder addDefaultPropertyConverters();
-
- /**
- * Removes the given PropertyConverter instances for the given type,
- * if existing.
- *
- * @param typeToConvert the type which the converter is for
- * @param propertyConverters the converter to remove
- * @param <T> the target type.
- * @return this builder, for chaining, never null.
- */
- <T> ConfigurationBuilder removePropertyConverters(TypeLiteral<T> typeToConvert,
- PropertyConverter<T>... propertyConverters);
-
- /**
- * Removes the given PropertyConverter instances for the given type,
- * if existing.
- *
- * @param typeToConvert the type which the converter is for
- * @param propertyConverters the converter to remove
- * @param <T> the target type.
- * @return this builder, for chaining, never null.
- */
- <T> ConfigurationBuilder removePropertyConverters(TypeLiteral<T> typeToConvert,
- Collection<PropertyConverter<T>> propertyConverters);
-
- /**
- * Removes all converters for the given type, which actually renders a given type
- * unsupported for type conversion.
- *
- * @param typeToConvert the type which the converter is for
- * @return this builder, for chaining, never null.
- */
- ConfigurationBuilder removePropertyConverters(TypeLiteral<?> typeToConvert);
-
- /**
- * Sorts the current registered property sources using the given comparator.
- *
- * NOTE: property sources at the beginning have minimal significance.
- *
- * @param comparator the comparator to be used, not {@code null}.
- * @return this instance for chaining.
- */
- ConfigurationBuilder sortPropertySources(Comparator<PropertySource> comparator);
-
- /**
- * Sorts the current registered property filters using the given comparator.
- *
- * NOTE: property filters at the beginning have minimal significance.
- *
- * @param comparator the comparator to be used, not {@code null}.
- * @return this instance for chaining.
- */
- ConfigurationBuilder sortPropertyFilter(Comparator<PropertyFilter> comparator);
-
- /**
- * Sets the {@link PropertyValueCombinationPolicy} used to evaluate the final
- * property values.
- *
- * @param policy the {@link PropertyValueCombinationPolicy} used, not {@code null}.
- * @return this builder, for chaining, never null.
- */
- ConfigurationBuilder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy policy);
-
- /**
- * Builds a new {@link Configuration} based on the data in this builder. The ordering of property
- * sources and property filters is not changed, regardless of their ordinals. For ensure a certain
- * ordering/significance call {@link #sortPropertyFilter(Comparator)} and/or {@link #sortPropertySources(Comparator)}
- * before building the context.
- *
- * @return the final configuration.
- */
- Configuration build();
-
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigValueEvaluator.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigValueEvaluator.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigValueEvaluator.java
deleted file mode 100644
index cdfcfdc..0000000
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigValueEvaluator.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-
-import java.util.HashMap;
-import java.util.Map;
-
-
-/**
- * Implementation of the Configuration API. This class uses the current {@link ConfigurationContext} to evaluate the
- * chain of {@link PropertySource} and {@link PropertyFilter}
- * instance to evaluate the current Configuration.
- */
-public class DefaultConfigValueEvaluator implements ConfigValueEvaluator{
-
- @Override
- public PropertyValue evaluteRawValue(String key, ConfigurationContext context) {
- PropertyValue unfilteredValue = null;
- for (PropertySource propertySource : context.getPropertySources()) {
- unfilteredValue = context.getPropertyValueCombinationPolicy().
- collect(unfilteredValue, key, propertySource);
- }
- if(unfilteredValue==null || unfilteredValue.getValue()==null){
- return unfilteredValue;
- }
- return unfilteredValue;
- }
-
- @Override
- public Map<String, PropertyValue> evaluateRawValues(ConfigurationContext context) {
- Map<String, PropertyValue> result = new HashMap<>();
- for (PropertySource propertySource : context.getPropertySources()) {
- for (Map.Entry<String,PropertyValue> propEntry: propertySource.getProperties().entrySet()) {
- PropertyValue unfilteredValue = result.get(propEntry.getKey());
- unfilteredValue = context.getPropertyValueCombinationPolicy().
- collect(unfilteredValue, propEntry.getKey(), propertySource);
- if(unfilteredValue!=null){
- result.put(unfilteredValue.getKey(), unfilteredValue);
- }
- }
- }
- return result;
- }
-
- @Override
- public String toString() {
- return "DefaultConfigEvaluator{}";
- }
-}
[8/9] incubator-tamaya-extensions git commit: TAMAYA-318 Moved
spi-support as API base implementation package to remove code duplicates.
Posted by an...@apache.org.
TAMAYA-318 Moved spi-support as API base implementation package to remove code duplicates.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/commit/c0740730
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/c0740730
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/c0740730
Branch: refs/heads/master
Commit: c07407308eb41b5ea5513de9043e591a04f04ebb
Parents: 2d0ef4b
Author: Anatole Tresch <an...@apache.org>
Authored: Tue Nov 14 10:25:15 2017 +0100
Committer: Anatole Tresch <an...@apache.org>
Committed: Tue Nov 14 10:27:18 2017 +0100
----------------------------------------------------------------------
.../apache/tamaya/filter/ProgrammableFilterTest.java | 4 ++--
.../tamaya/functions/CombinedConfigurationTest.java | 12 ++++++------
2 files changed, 8 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/c0740730/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java
----------------------------------------------------------------------
diff --git a/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java b/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java
index 9b25bb6..57d5efb 100644
--- a/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java
+++ b/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java
@@ -21,7 +21,7 @@ package org.apache.tamaya.filter;
import org.apache.tamaya.spi.ConfigurationContext;
import org.apache.tamaya.spi.PropertyFilter;
import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.core.internal.DefaultConfigurationContextBuilder;
+import org.apache.tamaya.core.internal.CoreConfigurationContextBuilder;
import org.apache.tamaya.spisupport.RegexPropertyFilter;
import org.junit.Test;
@@ -36,7 +36,7 @@ import static org.junit.Assert.*;
*/
public class ProgrammableFilterTest {
- private static ConfigurationContext context = new DefaultConfigurationContextBuilder().build();
+ private static ConfigurationContext context = new CoreConfigurationContextBuilder().build();
private static PropertyValue test1Property = PropertyValue.of("test1","test1","test");
private static PropertyValue test2Property = PropertyValue.of("test2","test2","test");
private static PropertyValue test3Property = PropertyValue.of("test.test3","test.test3","test");
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/c0740730/modules/functions/src/test/java/org/apache/tamaya/functions/CombinedConfigurationTest.java
----------------------------------------------------------------------
diff --git a/modules/functions/src/test/java/org/apache/tamaya/functions/CombinedConfigurationTest.java b/modules/functions/src/test/java/org/apache/tamaya/functions/CombinedConfigurationTest.java
index bb65d69..cb56e9b 100644
--- a/modules/functions/src/test/java/org/apache/tamaya/functions/CombinedConfigurationTest.java
+++ b/modules/functions/src/test/java/org/apache/tamaya/functions/CombinedConfigurationTest.java
@@ -24,7 +24,7 @@ import org.apache.tamaya.Configuration;
import org.apache.tamaya.TypeLiteral;
import org.apache.tamaya.spi.ConfigurationContext;
import org.apache.tamaya.spisupport.DefaultConfiguration;
-import org.apache.tamaya.core.internal.DefaultConfigurationContextBuilder;
+import org.apache.tamaya.core.internal.CoreConfigurationContextBuilder;
import org.apache.tamaya.spisupport.propertysource.SimplePropertySource;
import org.assertj.core.api.ThrowableAssert;
import org.junit.Test;
@@ -57,15 +57,15 @@ public class CombinedConfigurationTest {
SimplePropertySource sourceWithKeyC = new SimplePropertySource("C", singletonMap("c", "c"));
SimplePropertySource sourceWithoutKeys = new SimplePropertySource("NONE", Collections.<String, String>emptyMap());
- ConfigurationContext ccWithA1 = new DefaultConfigurationContextBuilder().addPropertySources(sourceWithKeyA1)
+ ConfigurationContext ccWithA1 = new CoreConfigurationContextBuilder().addPropertySources(sourceWithKeyA1)
.build();
- ConfigurationContext ccWithA2 = new DefaultConfigurationContextBuilder().addPropertySources(sourceWithKeyA2)
+ ConfigurationContext ccWithA2 = new CoreConfigurationContextBuilder().addPropertySources(sourceWithKeyA2)
.build();
- ConfigurationContext ccWithB = new DefaultConfigurationContextBuilder().addPropertySources(sourceWithKeyB)
+ ConfigurationContext ccWithB = new CoreConfigurationContextBuilder().addPropertySources(sourceWithKeyB)
.build();
- ConfigurationContext ccWithC = new DefaultConfigurationContextBuilder().addPropertySources(sourceWithKeyC)
+ ConfigurationContext ccWithC = new CoreConfigurationContextBuilder().addPropertySources(sourceWithKeyC)
.build();
- ConfigurationContext ccWithoutEntries = new DefaultConfigurationContextBuilder().addPropertySources(sourceWithoutKeys)
+ ConfigurationContext ccWithoutEntries = new CoreConfigurationContextBuilder().addPropertySources(sourceWithoutKeys)
.build();
configWithA1 = new DefaultConfiguration(ccWithA1);
[2/9] incubator-tamaya-extensions git commit: TAMAYA-274 Added Java 8
supplier based methods.
Posted by an...@apache.org.
TAMAYA-274 Added Java 8 supplier based methods.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/commit/48f3f7b3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/48f3f7b3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/48f3f7b3
Branch: refs/heads/master
Commit: 48f3f7b36b0f2a0d6e25484a02db0c700d807cb6
Parents: 05b1faa
Author: Anatole Tresch <an...@apache.org>
Authored: Sun Nov 12 21:24:28 2017 +0100
Committer: Anatole Tresch <an...@apache.org>
Committed: Tue Nov 14 10:26:04 2017 +0100
----------------------------------------------------------------------
.../apache/tamaya/inject/api/DynamicValue.java | 60 +++++++-------
.../tamaya/inject/spi/BaseDynamicValue.java | 84 ++++++++++----------
.../inject/internal/DefaultDynamicValue.java | 19 +++++
3 files changed, 91 insertions(+), 72 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/48f3f7b3/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java
----------------------------------------------------------------------
diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java
index d56e29c..54ab10a 100644
--- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java
+++ b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/DynamicValue.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.inject.api;
import java.beans.PropertyChangeListener;
+import java.util.function.Supplier;
/**
@@ -128,35 +129,34 @@ public interface DynamicValue<T> {
*/
T orElse(T other);
- // TODO enable with Java 8
-// /**
-// * Return the value if present, otherwise invoke {@code other} and return
-// * the result of that invocation.
-// *
-// * @param other a {@code ConfiguredItemSupplier} whose result is returned if no value
-// * is present
-// * @return the value if present otherwise the result of {@code other.get()}
-// * @throws NullPointerException if value is not present and {@code other} is
-// * null
-// */
-// T orElseGet(ConfiguredItemSupplier<? extends T> other);
-//
-// /**
-// * Return the contained value, if present, otherwise throw an exception
-// * to be created by the provided supplier.
-// *
-// * NOTE A method reference to the exception constructor with an empty
-// * argument list can be used as the supplier. For example,
-// * {@code IllegalStateException::new}
-// *
-// * @param <X> Type of the exception to be thrown
-// * @param exceptionSupplier The supplier which will return the exception to
-// * be thrown
-// * @return the present value
-// * @throws X if there is no value present
-// * @throws NullPointerException if no value is present and
-// * {@code exceptionSupplier} is null
-// */
-// <X extends Throwable> T orElseThrow(ConfiguredItemSupplier<? extends X> exceptionSupplier) throws X;
+ /**
+ * Return the value if present, otherwise invoke {@code other} and return
+ * the result of that invocation.
+ *
+ * @param other a {@code ConfiguredItemSupplier} whose result is returned if no value
+ * is present
+ * @return the value if present otherwise the result of {@code other.get()}
+ * @throws NullPointerException if value is not present and {@code other} is
+ * null
+ */
+ T orElseGet(Supplier<? extends T> other);
+
+ /**
+ * Return the contained value, if present, otherwise throw an exception
+ * to be created by the provided supplier.
+ *
+ * NOTE A method reference to the exception constructor with an empty
+ * argument list can be used as the supplier. For example,
+ * {@code IllegalStateException::new}
+ *
+ * @param <X> Type of the exception to be thrown
+ * @param exceptionSupplier The supplier which will return the exception to
+ * be thrown
+ * @return the present value
+ * @throws X if there is no value present
+ * @throws NullPointerException if no value is present and
+ * {@code exceptionSupplier} is null
+ */
+ <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/48f3f7b3/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/BaseDynamicValue.java
----------------------------------------------------------------------
diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/BaseDynamicValue.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/BaseDynamicValue.java
index a23a85c..1d0e75e 100644
--- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/BaseDynamicValue.java
+++ b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/spi/BaseDynamicValue.java
@@ -21,6 +21,7 @@ package org.apache.tamaya.inject.spi;
import org.apache.tamaya.inject.api.DynamicValue;
import java.io.Serializable;
+import java.util.function.Supplier;
/**
* Basic abstract implementation skeleton for a {@link DynamicValue}. This can be used to support values that may
@@ -80,47 +81,46 @@ public abstract class BaseDynamicValue<T> implements DynamicValue<T>, Serializab
return value;
}
- // TODO: Enable with Java 8 support.
-// /**
-// * Return the value if present, otherwise invoke {@code other} and return
-// * the result of that invocation.
-// *
-// * @param other a {@code ConfiguredItemSupplier} whose result is returned if no value
-// * is present
-// * @return the value if present otherwise the result of {@code other.get()}
-// * @throws NullPointerException if value is not present and {@code other} is
-// * null
-// */
-// public T orElseGet(Supplier<? extends T> other) {
-// T value = get();
-// if (value == null) {
-// return other.get();
-// }
-// return value;
-// }
-//
-// /**
-// * Return the contained value, if present, otherwise throw an exception
-// * to be created by the provided supplier.
-// * <p>
-// * NOTE A method reference to the exception constructor with an empty
-// * argument list can be used as the supplier. For example,
-// * {@code IllegalStateException::new}
-// *
-// * @param <X> Type of the exception to be thrown
-// * @param exceptionSupplier The supplier which will return the exception to
-// * be thrown
-// * @return the present value
-// * @throws X if there is no value present
-// * @throws NullPointerException if no value is present and
-// * {@code exceptionSupplier} is null
-// */
-// public <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X {
-// T value = get();
-// if (value == null) {
-// throw exceptionSupplier.get();
-// }
-// return value;
-// }
+ /**
+ * Return the value if present, otherwise invoke {@code other} and return
+ * the result of that invocation.
+ *
+ * @param other a {@code ConfiguredItemSupplier} whose result is returned if no value
+ * is present
+ * @return the value if present otherwise the result of {@code other.get()}
+ * @throws NullPointerException if value is not present and {@code other} is
+ * null
+ */
+ public T orElseGet(Supplier<? extends T> other) {
+ T value = get();
+ if (value == null) {
+ return other.get();
+ }
+ return value;
+ }
+
+ /**
+ * Return the contained value, if present, otherwise throw an exception
+ * to be created by the provided supplier.
+ * <p>
+ * NOTE A method reference to the exception constructor with an empty
+ * argument list can be used as the supplier. For example,
+ * {@code IllegalStateException::new}
+ *
+ * @param <X> Type of the exception to be thrown
+ * @param exceptionSupplier The supplier which will return the exception to
+ * be thrown
+ * @return the present value
+ * @throws X if there is no value present
+ * @throws NullPointerException if no value is present and
+ * {@code exceptionSupplier} is null
+ */
+ public <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X {
+ T value = get();
+ if (value == null) {
+ throw exceptionSupplier.get();
+ }
+ return value;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/48f3f7b3/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java
----------------------------------------------------------------------
diff --git a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java
index a6b8c06..621399d 100644
--- a/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java
+++ b/modules/injection/standalone/src/main/java/org/apache/tamaya/inject/internal/DefaultDynamicValue.java
@@ -45,6 +45,7 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
+import java.util.function.Supplier;
import java.util.logging.Logger;
/**
@@ -409,6 +410,24 @@ final class DefaultDynamicValue<T> extends BaseDynamicValue<T> {
return nv;
}
+ @Override
+ public T orElseGet(Supplier<? extends T> other) {
+ T t = evaluateValue();
+ if(t==null){
+ return other.get();
+ }
+ return t;
+ }
+
+ @Override
+ public <X extends Throwable> T orElseThrow(Supplier<? extends X> exceptionSupplier) throws X {
+ T t = evaluateValue();
+ if(t==null){
+ throw exceptionSupplier.get();
+ }
+ return t;
+ }
+
/**
* Serialization implementation that strips away the non serializable Optional part.
[6/9] incubator-tamaya-extensions git commit: TAMAYA-318 Moved
spi-support as API base implementation package to remove code duplicates.
Posted by an...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java
deleted file mode 100644
index 55399de..0000000
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfiguration.java
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.ConfigOperator;
-import org.apache.tamaya.ConfigQuery;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
-import org.apache.tamaya.spi.ServiceContextManager;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Implementation of the Configuration API. This class uses the current {@link ConfigurationContext} to evaluate the
- * chain of {@link 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 current {@link ConfigurationContext} of the current instance.
- */
- private final ConfigurationContext configurationContext;
-
- /**
- * EvaluationStrategy
- */
- private ConfigValueEvaluator configEvaluator = loadConfigValueEvaluator();
-
- private ConfigValueEvaluator loadConfigValueEvaluator() {
- ConfigValueEvaluator eval = null;
- try{
- eval = ServiceContextManager.getServiceContext()
- .getService(ConfigValueEvaluator.class);
- }catch(Exception e){
- LOG.log(Level.WARNING, "Failed to load ConfigValueEvaluator from ServiceContext, using default.", e);
- }
- if(eval==null){
- eval = new DefaultConfigValueEvaluator();
- }
- return eval;
- }
-
-
- /**
- * Constructor.
- * @param configurationContext The configuration Context to be used.
- */
- public DefaultConfiguration(ConfigurationContext configurationContext){
- this.configurationContext = Objects.requireNonNull(configurationContext);
- }
-
- /**
- * Get a given value, filtered with the context's filters as needed.
- * @param key the property's key, not null.
- * @return the filtered value, or null.
- */
- @Override
- public String get(String key) {
- PropertyValue value = configEvaluator.evaluteRawValue(key, configurationContext);
- if(value==null || value.getValue()==null){
- return null;
- }
- value = PropertyFiltering.applyFilter(value, configurationContext);
- if(value!=null){
- return value.getValue();
- }
- return null;
- }
-
- /**
- * Evaluates the raw value using the context's PropertyValueCombinationPolicy.
- * @param key the key, not null.
- * @return the value, before filtering is applied.
- */
- protected PropertyValue evaluteRawValue(String key) {
- List<PropertySource> propertySources = configurationContext.getPropertySources();
- PropertyValue filteredValue = null;
- PropertyValueCombinationPolicy combinationPolicy = this.configurationContext
- .getPropertyValueCombinationPolicy();
- for (PropertySource propertySource : propertySources) {
- filteredValue = combinationPolicy.collect(filteredValue, key, propertySource);
- }
- return filteredValue;
- }
-
-
- @Override
- public String getOrDefault(String key, String defaultValue) {
- String val = get(key);
- if(val==null){
- return defaultValue;
- }
- return val;
- }
-
- @Override
- public <T> T getOrDefault(String key, Class<T> type, T defaultValue) {
- T val = get(key, type);
- if(val==null){
- return defaultValue;
- }
- return val;
- }
-
- /**
- * Get the current properties, composed by the loaded {@link PropertySource} and filtered
- * by registered {@link org.apache.tamaya.spi.PropertyFilter}.
- *
- * @return the final properties.
- */
- @Override
- public Map<String, String> getProperties() {
- Map<String, PropertyValue> filtered = PropertyFiltering.applyFilters(
- configEvaluator.evaluateRawValues(configurationContext),
- configurationContext);
- Map<String,String> result = new HashMap<>();
- for(PropertyValue val:filtered.values()){
- if(val.getValue()!=null) {
- result.put(val.getKey(), val.getValue());
- // TODO: Discuss metadata handling...
- result.putAll(val.getMetaEntries());
- }
- }
- return result;
- }
-
-
- /**
- * Accesses the current String value for the given key and tries to convert it
- * using the {@link PropertyConverter} instances provided by the current
- * {@link 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> T get(String key, Class<T> type) {
- return get(key, (TypeLiteral<T>)TypeLiteral.of(type));
- }
-
- /**
- * Accesses the current String value for the given key and tries to convert it
- * using the {@link PropertyConverter} instances provided by the current
- * {@link 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> T get(String key, TypeLiteral<T> type) {
- return convertValue(key, get(key), type);
- }
-
- protected <T> T convertValue(String key, String value, TypeLiteral<T> type) {
- if (value != null) {
- List<PropertyConverter<T>> converters = configurationContext.getPropertyConverters(type);
- ConversionContext context = new ConversionContext.Builder(this, this.configurationContext, key, type)
- .build();
- for (PropertyConverter<T> converter : converters) {
- try {
- T t = converter.convert(value, context);
- if (t != null) {
- return t;
- }
- } catch (Exception e) {
- LOG.log(Level.FINEST, "PropertyConverter: " + converter + " failed to convert value: " + value, e);
- }
- }
- // if the target type is a String, we can return the value, no conversion required.
- if(type.equals(TypeLiteral.of(String.class))){
- return (T)value;
- }
- // unsupported type, throw an exception
- throw new ConfigException("Unparseable config value for type: " + type.getRawType().getName() + ": " + key +
- ", supported formats: " + context.getSupportedFormats());
- }
- return null;
- }
-
- @Override
- public <T> T getOrDefault(String key, TypeLiteral<T> type, T defaultValue) {
- T val = get(key, type);
- if(val==null){
- return defaultValue;
- }
- return val;
- }
-
- @Override
- public Configuration with(ConfigOperator operator) {
- return operator.operate(this);
- }
-
- @Override
- public <T> T query(ConfigQuery<T> query) {
- return query.query(this);
- }
-
- @Override
- public ConfigurationContext getContext() {
- return configurationContext;
- }
-
- @Override
- public String toString() {
- return "Configuration{\n " +
- configurationContext +
- '}';
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java
deleted file mode 100644
index b26d0af..0000000
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationBuilder.java
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.*;
-
-import java.util.*;
-
-/**
- * Default implementation of {@link ConfigurationContextBuilder}.
- */
-public class DefaultConfigurationBuilder implements ConfigurationBuilder {
-
- private final ConfigurationContextBuilder contextBuilder;
-
- /**
- * Creates a new builder instance.
- */
- public DefaultConfigurationBuilder() {
- this.contextBuilder = new DefaultConfigurationContextBuilder();
- }
-
- /**
- * Creates a new builder instance initializing it with the given context.
- * @param configuration the configuration to be used, not null.
- */
- public DefaultConfigurationBuilder(Configuration configuration) {
- this.contextBuilder = new DefaultConfigurationContextBuilder(configuration.getContext());
- }
-
- /**
- * Allows to set configuration context during unit tests.
- */
- ConfigurationBuilder setConfiguration(Configuration configuration) {
- this.contextBuilder.setContext(configuration.getContext());
- return this;
- }
-
-
- @Override
- public ConfigurationBuilder setContext(ConfigurationContext context) {
- this.contextBuilder.setContext(context);
- return this;
- }
-
- @Override
- public ConfigurationBuilder addPropertySources(PropertySource... sources){
- this.contextBuilder.addPropertySources(sources);
- return this;
- }
-
- @Override
- public ConfigurationBuilder addPropertySources(Collection<PropertySource> sources){
- this.contextBuilder.addPropertySources(sources);
- return this;
- }
-
- public ConfigurationBuilder addDefaultPropertyFilters() {
- this.contextBuilder.addDefaultPropertyFilters();
- return this;
- }
-
- public ConfigurationBuilder addDefaultPropertySources() {
- this.contextBuilder.addDefaultPropertySources();
- return this;
- }
-
- public ConfigurationBuilder addDefaultPropertyConverters() {
- this.contextBuilder.addDefaultPropertyConverters();
- return this;
- }
-
- @Override
- public ConfigurationBuilder removePropertySources(PropertySource... propertySources) {
- this.contextBuilder.removePropertySources(propertySources);
- return this;
- }
-
- @Override
- public ConfigurationBuilder removePropertySources(Collection<PropertySource> propertySources) {
- this.contextBuilder.removePropertySources(propertySources);
- return this;
- }
-
- @Override
- public List<PropertySource> getPropertySources() {
- return this.contextBuilder.getPropertySources();
- }
-
- @Override
- public ConfigurationBuilder increasePriority(PropertySource propertySource) {
- this.contextBuilder.increasePriority(propertySource);
- return this;
- }
-
- @Override
- public ConfigurationBuilder decreasePriority(PropertySource propertySource) {
- this.contextBuilder.decreasePriority(propertySource);
- return this;
- }
-
- @Override
- public ConfigurationBuilder highestPriority(PropertySource propertySource) {
- this.contextBuilder.highestPriority(propertySource);
- return this;
- }
-
- @Override
- public ConfigurationBuilder lowestPriority(PropertySource propertySource) {
- this.contextBuilder.lowestPriority(propertySource);
- return this;
- }
-
- @Override
- public ConfigurationBuilder addPropertyFilters(PropertyFilter... filters){
- this.contextBuilder.addPropertyFilters(filters);
- return this;
- }
-
- @Override
- public ConfigurationBuilder addPropertyFilters(Collection<PropertyFilter> filters){
- this.contextBuilder.addPropertyFilters(filters);
- return this;
- }
-
- @Override
- public ConfigurationBuilder removePropertyFilters(PropertyFilter... filters) {
- this.contextBuilder.removePropertyFilters(filters);
- return this;
- }
-
- @Override
- public ConfigurationBuilder removePropertyFilters(Collection<PropertyFilter> filters) {
- this.contextBuilder.removePropertyFilters(filters);
- return this;
- }
-
-
- @Override
- public <T> ConfigurationBuilder removePropertyConverters(TypeLiteral<T> typeToConvert,
- PropertyConverter<T>... converters) {
- this.contextBuilder.removePropertyConverters(typeToConvert, converters);
- return this;
- }
-
- @Override
- public <T> ConfigurationBuilder removePropertyConverters(TypeLiteral<T> typeToConvert,
- Collection<PropertyConverter<T>> converters) {
- this.contextBuilder.removePropertyConverters(typeToConvert, converters);
- return this;
- }
-
- @Override
- public ConfigurationBuilder removePropertyConverters(TypeLiteral<?> typeToConvert) {
- this.contextBuilder.removePropertyConverters(typeToConvert);
- return this;
- }
-
-
- @Override
- public ConfigurationBuilder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy combinationPolicy){
- this.contextBuilder.setPropertyValueCombinationPolicy(combinationPolicy);
- return this;
- }
-
-
- @Override
- public <T> ConfigurationBuilder addPropertyConverters(TypeLiteral<T> type, PropertyConverter<T>... propertyConverters){
- this.contextBuilder.addPropertyConverters(type, propertyConverters);
- return this;
- }
-
- @Override
- public <T> ConfigurationBuilder addPropertyConverters(TypeLiteral<T> type, Collection<PropertyConverter<T>> propertyConverters){
- this.contextBuilder.addPropertyConverters(type, propertyConverters);
- return this;
- }
-
- /**
- * Builds a new configuration based on the configuration of this builder instance.
- *
- * @return a new {@link org.apache.tamaya.Configuration configuration instance},
- * never {@code null}.
- */
- @Override
- public Configuration build() {
- return new DefaultConfiguration(this.contextBuilder.build());
- }
-
- @Override
- public ConfigurationBuilder sortPropertyFilter(Comparator<PropertyFilter> comparator) {
- this.contextBuilder.sortPropertyFilter(comparator);
- return this;
- }
-
- @Override
- public ConfigurationBuilder sortPropertySources(Comparator<PropertySource> comparator) {
- this.contextBuilder.sortPropertySources(comparator);
- return this;
- }
-
- @Override
- public List<PropertyFilter> getPropertyFilters() {
- return this.contextBuilder.getPropertyFilters();
- }
-
- @Override
- public Map<TypeLiteral<?>, Collection<PropertyConverter<?>>> getPropertyConverter() {
- return this.contextBuilder.getPropertyConverter();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContext.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContext.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContext.java
deleted file mode 100644
index f5c97d6..0000000
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContext.java
+++ /dev/null
@@ -1,300 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.ConfigurationContextBuilder;
-import org.apache.tamaya.spi.PropertyConverter;
-import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-import org.apache.tamaya.spi.PropertyValueCombinationPolicy;
-import org.apache.tamaya.spi.ServiceContextManager;
-
-import java.util.ArrayList;
-import java.util.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.ReentrantReadWriteLock;
-import java.util.logging.Logger;
-
-/**
- * Default Implementation of a simple ConfigurationContext.
- */
-public class DefaultConfigurationContext implements ConfigurationContext {
- /** The logger used. */
- private final static Logger LOG = Logger.getLogger(DefaultConfigurationContext.class.getName());
- /**
- * Cubcomponent handling {@link PropertyConverter} instances.
- */
- private final PropertyConverterManager propertyConverterManager = new PropertyConverterManager();
-
- /**
- * The current unmodifiable list of loaded {@link PropertySource} instances.
- */
- private List<PropertySource> immutablePropertySources;
-
- /**
- * The current unmodifiable list of loaded {@link PropertyFilter} instances.
- */
- private List<PropertyFilter> immutablePropertyFilters;
-
- /**
- * The overriding policy used when combining PropertySources registered to evalute the final configuration
- * values.
- */
- private PropertyValueCombinationPolicy propertyValueCombinationPolicy;
-
- /**
- * Lock for internal synchronization.
- */
- private final ReentrantReadWriteLock propertySourceLock = new ReentrantReadWriteLock();
- /**
- * Lock for internal synchronization.
- */
- private final ReentrantReadWriteLock propertyFilterLock = new ReentrantReadWriteLock();
-
- /**
- * Creates an empty Configuration context.
- */
- protected DefaultConfigurationContext() {
- this(new DefaultConfigurationContextBuilder());
- }
-
- DefaultConfigurationContext(DefaultConfigurationContextBuilder builder) {
- List<PropertySource> propertySources = new ArrayList<>();
- // first we load all PropertySources which got registered via java.util.ServiceLoader
- propertySources.addAll(builder.propertySources);
- // now sort them according to their ordinal values
- immutablePropertySources = Collections.unmodifiableList(propertySources);
- LOG.info("Registered " + immutablePropertySources.size() + " property sources: " +
- immutablePropertySources);
-
- // as next step we pick up the PropertyFilters pretty much the same way
- List<PropertyFilter> propertyFilters = new ArrayList<>(builder.getPropertyFilters());
- immutablePropertyFilters = Collections.unmodifiableList(propertyFilters);
- LOG.info("Registered " + immutablePropertyFilters.size() + " property filters: " +
- immutablePropertyFilters);
-
- // Finally add the converters
- for(Map.Entry<TypeLiteral<?>, Collection<PropertyConverter<?>>> en:builder.getPropertyConverter().entrySet()) {
- for (PropertyConverter converter : en.getValue()) {
- this.propertyConverterManager.register(en.getKey(), converter);
- }
- }
- LOG.info("Registered " + propertyConverterManager.getPropertyConverters().size() + " property converters: " +
- propertyConverterManager.getPropertyConverters());
-
- propertyValueCombinationPolicy = builder.combinationPolicy;
- if(propertyValueCombinationPolicy==null){
- propertyValueCombinationPolicy = ServiceContextManager.getServiceContext().getService(PropertyValueCombinationPolicy.class);
- }
- if(propertyValueCombinationPolicy==null){
- propertyValueCombinationPolicy = PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR;
- }
- LOG.info("Using PropertyValueCombinationPolicy: " + propertyValueCombinationPolicy);
- }
-
-
- @Deprecated
- @Override
- public void addPropertySources(PropertySource... propertySourcesToAdd) {
- Lock writeLock = propertySourceLock.writeLock();
- try {
- writeLock.lock();
- List<PropertySource> newPropertySources = new ArrayList<>(this.immutablePropertySources);
- newPropertySources.addAll(Arrays.asList(propertySourcesToAdd));
- Collections.sort(newPropertySources, PropertySourceComparator.getInstance());
-
- this.immutablePropertySources = Collections.unmodifiableList(newPropertySources);
- } finally {
- writeLock.unlock();
- }
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (!(o instanceof DefaultConfigurationContext)){
- return false;
- }
-
- DefaultConfigurationContext that = (DefaultConfigurationContext) o;
-
- if (!propertyConverterManager.equals(that.propertyConverterManager)) {
- return false;
- }
- if (!immutablePropertySources.equals(that.immutablePropertySources)) {
- return false;
- }
- if (!immutablePropertyFilters.equals(that.immutablePropertyFilters)) {
- return false;
- }
- return getPropertyValueCombinationPolicy().equals(that.getPropertyValueCombinationPolicy());
-
- }
-
- @Override
- public int hashCode() {
- int result = propertyConverterManager.hashCode();
- result = 31 * result + immutablePropertySources.hashCode();
- result = 31 * result + immutablePropertyFilters.hashCode();
- result = 31 * result + getPropertyValueCombinationPolicy().hashCode();
- return result;
- }
-
- @Override
- public String toString() {
- StringBuilder b = new StringBuilder("ConfigurationContext{\n");
- b.append(" Property Sources\n");
- b.append(" ----------------\n");
- if(immutablePropertySources.isEmpty()){
- b.append(" No property sources loaded.\n\n");
- }else {
- b.append(" CLASS NAME ORDINAL SCANNABLE SIZE STATE ERROR\n\n");
- for (PropertySource ps : immutablePropertySources) {
- b.append(" ");
- appendFormatted(b, ps.getClass().getSimpleName(), 30);
- appendFormatted(b, ps.getName(), 70);
- appendFormatted(b, String.valueOf(PropertySourceComparator.getOrdinal(ps)), 8);
- appendFormatted(b, String.valueOf(ps.isScannable()), 10);
- if (ps.isScannable()) {
- appendFormatted(b, String.valueOf(ps.getProperties().size()), 8);
- } else {
- appendFormatted(b, "-", 8);
- }
- PropertyValue state = ps.get("_state");
- if(state==null){
- appendFormatted(b, "OK", 10);
- }else {
- appendFormatted(b, state.getValue(), 10);
- if("ERROR".equals(state.getValue())){
- PropertyValue val = ps.get("_exception");
- if(val!=null) {
- appendFormatted(b, val.getValue(), 30);
- }
- }
- }
- b.append('\n');
- }
- b.append("\n");
- }
- b.append(" Property Filters\n");
- b.append(" ----------------\n");
- if(immutablePropertyFilters.isEmpty()){
- b.append(" No property filters loaded.\n\n");
- }else {
- b.append(" CLASS INFO\n\n");
- for (PropertyFilter filter : getPropertyFilters()) {
- b.append(" ");
- appendFormatted(b, filter.getClass().getSimpleName(), 30);
- b.append(removeNewLines(filter.toString()));
- b.append('\n');
- }
- b.append("\n\n");
- }
- b.append(" Property Converters\n");
- b.append(" -------------------\n");
- b.append(" CLASS TYPE INFO\n\n");
- for(Map.Entry<TypeLiteral<?>, List<PropertyConverter<?>>> converterEntry:getPropertyConverters().entrySet()){
- for(PropertyConverter converter: converterEntry.getValue()){
- b.append(" ");
- appendFormatted(b, converter.getClass().getSimpleName(), 30);
- appendFormatted(b, converterEntry.getKey().getRawType().getSimpleName(), 30);
- b.append(removeNewLines(converter.toString()));
- b.append('\n');
- }
- }
- b.append("\n\n");
- b.append(" PropertyValueCombinationPolicy: " + getPropertyValueCombinationPolicy().getClass().getName()).append('\n');
- b.append('}');
- return b.toString();
- }
-
- private void appendFormatted(StringBuilder b, String text, int length) {
- int padding;
- if(text.length() <= (length)){
- b.append(text);
- padding = length - text.length();
- }else{
- b.append(text.substring(0, length-1));
- padding = 1;
- }
- for(int i=0;i<padding;i++){
- b.append(' ');
- }
- }
-
- private String removeNewLines(String s) {
- return s.replace('\n', ' ').replace('\r', ' ');
- }
-
- @Override
- public List<PropertySource> getPropertySources() {
- return immutablePropertySources;
- }
-
- @Override
- public PropertySource getPropertySource(String name) {
- for(PropertySource ps:getPropertySources()){
- if(name.equals(ps.getName())){
- return ps;
- }
- }
- return null;
- }
-
- @Override
- public <T> void addPropertyConverter(TypeLiteral<T> typeToConvert, PropertyConverter<T> propertyConverter) {
- propertyConverterManager.register(typeToConvert, propertyConverter);
- LOG.info("Added PropertyConverter: " + propertyConverter.getClass().getName());
- }
-
- @Override
- public Map<TypeLiteral<?>, List<PropertyConverter<?>>> getPropertyConverters() {
- return propertyConverterManager.getPropertyConverters();
- }
-
- @Override
- public <T> List<PropertyConverter<T>> getPropertyConverters(TypeLiteral<T> targetType) {
- return propertyConverterManager.getPropertyConverters(targetType);
- }
-
- @Override
- public List<PropertyFilter> getPropertyFilters() {
- return immutablePropertyFilters;
- }
-
- @Override
- public PropertyValueCombinationPolicy getPropertyValueCombinationPolicy(){
- return propertyValueCombinationPolicy;
- }
-
- @Override
- public ConfigurationContextBuilder toBuilder() {
- return new DefaultConfigurationContextBuilder(this);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContextBuilder.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContextBuilder.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContextBuilder.java
deleted file mode 100644
index 023faf3..0000000
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/DefaultConfigurationContextBuilder.java
+++ /dev/null
@@ -1,408 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import org.apache.tamaya.TypeLiteral;
-import org.apache.tamaya.spi.ConfigurationContext;
-import org.apache.tamaya.spi.ConfigurationContextBuilder;
-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.PropertyValueCombinationPolicy;
-import org.apache.tamaya.spi.ServiceContextManager;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.logging.Logger;
-
-/**
- * Default implementation of {@link ConfigurationContextBuilder}.
- */
-public class DefaultConfigurationContextBuilder implements ConfigurationContextBuilder {
-
- private static final Logger LOG = Logger.getLogger(DefaultConfigurationContextBuilder.class.getName());
-
- List<PropertyFilter> propertyFilters = new ArrayList<>();
- List<PropertySource> propertySources = new ArrayList<>();
- PropertyValueCombinationPolicy combinationPolicy =
- PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR;
- Map<TypeLiteral<?>, Collection<PropertyConverter<?>>> propertyConverters = new HashMap<>();
-
- /**
- * Flag if the config has already been built.
- * Configuration can be built only once
- */
- private boolean built;
-
-
-
- /**
- * Creates a new builder instance.
- */
- public DefaultConfigurationContextBuilder() {
- }
-
- /**
- * Creates a new builder instance initializing it with the given context.
- * @param context the context to be used, not null.
- */
- public DefaultConfigurationContextBuilder(ConfigurationContext context) {
- this.propertyConverters.putAll(context.getPropertyConverters());
- this.propertyFilters.addAll(context.getPropertyFilters());
- for(PropertySource ps:context.getPropertySources()) {
- addPropertySources(ps);
- }
- this.combinationPolicy = context.getPropertyValueCombinationPolicy();
- }
-
- /**
- * Allows to set configuration context during unit tests.
- */
- ConfigurationContextBuilder setConfigurationContext(ConfigurationContext configurationContext) {
- checkBuilderState();
- //noinspection deprecation
- this.propertyFilters.clear();
- this.propertyFilters.addAll(configurationContext.getPropertyFilters());
- this.propertySources.clear();
- for(PropertySource ps:configurationContext.getPropertySources()) {
- addPropertySources(ps);
- }
- this.propertyConverters.clear();
- this.propertyConverters.putAll(configurationContext.getPropertyConverters());
- this.combinationPolicy = configurationContext.getPropertyValueCombinationPolicy();
- return this;
- }
-
-
- @Override
- public ConfigurationContextBuilder setContext(ConfigurationContext context) {
- checkBuilderState();
- this.propertyConverters.putAll(context.getPropertyConverters());
- for(PropertySource ps:context.getPropertySources()){
- this.propertySources.add(ps);
- }
- this.propertyFilters.addAll(context.getPropertyFilters());
- this.combinationPolicy = context.getPropertyValueCombinationPolicy();
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder addPropertySources(PropertySource... sources){
- return addPropertySources(Arrays.asList(sources));
- }
-
- @Override
- public ConfigurationContextBuilder addPropertySources(Collection<PropertySource> sources){
- checkBuilderState();
- for(PropertySource source:sources) {
- if (!this.propertySources.contains(source)) {
- this.propertySources.add(source);
- }
- }
- return this;
- }
-
- public DefaultConfigurationContextBuilder addDefaultPropertyFilters() {
- checkBuilderState();
- for(PropertyFilter pf:ServiceContextManager.getServiceContext().getServices(PropertyFilter.class)){
- addPropertyFilters(pf);
- }
- return this;
- }
-
- public DefaultConfigurationContextBuilder addDefaultPropertySources() {
- checkBuilderState();
- for(PropertySource ps:ServiceContextManager.getServiceContext().getServices(PropertySource.class)){
- addPropertySources(ps);
- }
- for(PropertySourceProvider pv:ServiceContextManager.getServiceContext().getServices(PropertySourceProvider.class)){
- for(PropertySource ps:pv.getPropertySources()){
- addPropertySources(ps);
- }
- }
- return this;
- }
-
- public DefaultConfigurationContextBuilder addDefaultPropertyConverters() {
- checkBuilderState();
- for(Map.Entry<TypeLiteral, Collection<PropertyConverter>> en:getDefaultPropertyConverters().entrySet()){
- for(PropertyConverter pc: en.getValue()) {
- addPropertyConverters(en.getKey(), pc);
- }
- }
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder removePropertySources(PropertySource... propertySources) {
- return removePropertySources(Arrays.asList(propertySources));
- }
-
- @Override
- public ConfigurationContextBuilder removePropertySources(Collection<PropertySource> propertySources) {
- checkBuilderState();
- this.propertySources.removeAll(propertySources);
- return this;
- }
-
- private PropertySource getPropertySource(String name) {
- for(PropertySource ps:propertySources){
- if(ps.getName().equals(name)){
- return ps;
- }
- }
- throw new IllegalArgumentException("No such PropertySource: "+name);
- }
-
- @Override
- public List<PropertySource> getPropertySources() {
- return this.propertySources;
- }
-
- @Override
- public ConfigurationContextBuilder increasePriority(PropertySource propertySource) {
- checkBuilderState();
- int index = propertySources.indexOf(propertySource);
- if(index<0){
- throw new IllegalArgumentException("No such PropertySource: " + propertySource);
- }
- if(index<(propertySources.size()-1)){
- propertySources.remove(propertySource);
- propertySources.add(index+1, propertySource);
- }
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder decreasePriority(PropertySource propertySource) {
- checkBuilderState();
- int index = propertySources.indexOf(propertySource);
- if(index<0){
- throw new IllegalArgumentException("No such PropertySource: " + propertySource);
- }
- if(index>0){
- propertySources.remove(propertySource);
- propertySources.add(index-1, propertySource);
- }
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder highestPriority(PropertySource propertySource) {
- checkBuilderState();
- int index = propertySources.indexOf(propertySource);
- if(index<0){
- throw new IllegalArgumentException("No such PropertySource: " + propertySource);
- }
- if(index<(propertySources.size()-1)){
- propertySources.remove(propertySource);
- propertySources.add(propertySource);
- }
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder lowestPriority(PropertySource propertySource) {
- checkBuilderState();
- int index = propertySources.indexOf(propertySource);
- if(index<0){
- throw new IllegalArgumentException("No such PropertySource: " + propertySource);
- }
- if(index>0){
- propertySources.remove(propertySource);
- propertySources.add(0, propertySource);
- }
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder addPropertyFilters(PropertyFilter... filters){
- return addPropertyFilters(Arrays.asList(filters));
- }
-
- @Override
- public ConfigurationContextBuilder addPropertyFilters(Collection<PropertyFilter> filters){
- checkBuilderState();
- for(PropertyFilter f:filters) {
- if (!this.propertyFilters.contains(f)) {
- this.propertyFilters.add(f);
- }
- }
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder removePropertyFilters(PropertyFilter... filters) {
- return removePropertyFilters(Arrays.asList(filters));
- }
-
- @Override
- public ConfigurationContextBuilder removePropertyFilters(Collection<PropertyFilter> filters) {
- checkBuilderState();
- this.propertyFilters.removeAll(filters);
- return this;
- }
-
-
- @Override
- public <T> ConfigurationContextBuilder removePropertyConverters(TypeLiteral<T> typeToConvert,
- PropertyConverter<T>... converters) {
- return removePropertyConverters(typeToConvert, Arrays.asList(converters));
- }
-
- @Override
- public <T> ConfigurationContextBuilder removePropertyConverters(TypeLiteral<T> typeToConvert,
- Collection<PropertyConverter<T>> converters) {
- Collection<PropertyConverter<?>> subConverters = this.propertyConverters.get(typeToConvert);
- if(subConverters!=null) {
- subConverters.removeAll(converters);
- }
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder removePropertyConverters(TypeLiteral<?> typeToConvert) {
- this.propertyConverters.remove(typeToConvert);
- return this;
- }
-
-
- @Override
- public ConfigurationContextBuilder setPropertyValueCombinationPolicy(PropertyValueCombinationPolicy combinationPolicy){
- checkBuilderState();
- this.combinationPolicy = Objects.requireNonNull(combinationPolicy);
- return this;
- }
-
-
- @Override
- public <T> ConfigurationContextBuilder addPropertyConverters(TypeLiteral<T> type, PropertyConverter<T>... propertyConverters){
- checkBuilderState();
- Objects.requireNonNull(type);
- Objects.requireNonNull(propertyConverters);
- Collection<PropertyConverter<?>> converters = this.propertyConverters.get(type);
- if(converters==null){
- converters = new ArrayList<>();
- this.propertyConverters.put(type, converters);
- }
- for(PropertyConverter<T> propertyConverter:propertyConverters) {
- if (!converters.contains(propertyConverter)) {
- converters.add(propertyConverter);
- } else {
- LOG.warning("Converter ignored, already registered: " + propertyConverter);
- }
- }
- return this;
- }
-
- @Override
- public <T> ConfigurationContextBuilder addPropertyConverters(TypeLiteral<T> type, Collection<PropertyConverter<T>> propertyConverters){
- checkBuilderState();
- Objects.requireNonNull(type);
- Objects.requireNonNull(propertyConverters);
- Collection<PropertyConverter<?>> converters = this.propertyConverters.get(type);
- if(converters==null){
- converters = new ArrayList<>();
- this.propertyConverters.put(type, converters);
- }
- for(PropertyConverter<T> propertyConverter:propertyConverters) {
- if (!converters.contains(propertyConverter)) {
- converters.add(propertyConverter);
- } else {
- LOG.warning("Converter ignored, already registered: " + propertyConverter);
- }
- }
- return this;
- }
-
- protected ConfigurationContextBuilder loadDefaults() {
- checkBuilderState();
- this.combinationPolicy = PropertyValueCombinationPolicy.DEFAULT_OVERRIDING_COLLECTOR;
- addDefaultPropertySources();
- addDefaultPropertyFilters();
- addDefaultPropertyConverters();
- return this;
- }
-
-
- private Map<TypeLiteral, Collection<PropertyConverter>> getDefaultPropertyConverters() {
- Map<TypeLiteral, Collection<PropertyConverter>> result = new HashMap<>();
- for (PropertyConverter conv : ServiceContextManager.getServiceContext().getServices(
- PropertyConverter.class)) {
- TypeLiteral target = TypeLiteral.of(TypeLiteral.of(conv.getClass()).getType());
- Collection<PropertyConverter> convList = result.get(target);
- if (convList == null) {
- convList = new ArrayList<>();
- result.put(target, convList);
- }
- convList.add(conv);
- }
- return result;
- }
-
-
- /**
- * Builds a new configuration based on the configuration of this builder instance.
- *
- * @return a new {@link org.apache.tamaya.Configuration configuration instance},
- * never {@code null}.
- */
- @Override
- public ConfigurationContext build() {
- checkBuilderState();
- built = true;
- return new DefaultConfigurationContext(this);
- }
-
- @Override
- public ConfigurationContextBuilder sortPropertyFilter(Comparator<PropertyFilter> comparator) {
- Collections.sort(propertyFilters, comparator);
- return this;
- }
-
- @Override
- public ConfigurationContextBuilder sortPropertySources(Comparator<PropertySource> comparator) {
- Collections.sort(propertySources, comparator);
- return this;
- }
-
- private void checkBuilderState() {
- if (built) {
- throw new IllegalStateException("Configuration has already been build.");
- }
- }
-
- @Override
- public List<PropertyFilter> getPropertyFilters() {
- return propertyFilters;
- }
-
- @Override
- public Map<TypeLiteral<?>, Collection<PropertyConverter<?>>> getPropertyConverter() {
- return Collections.unmodifiableMap(this.propertyConverters);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/EnumConverter.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/EnumConverter.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/EnumConverter.java
deleted file mode 100644
index d003ccb..0000000
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/EnumConverter.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.spisupport;
-
-import org.apache.tamaya.ConfigException;
-import org.apache.tamaya.spi.ConversionContext;
-import org.apache.tamaya.spi.PropertyConverter;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Locale;
-import java.util.Objects;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Converter, converting from String to tge given enum type.
- * @param <T> the enum type.
- */
-public class EnumConverter<T> implements PropertyConverter<T> {
- private final Logger LOG = Logger.getLogger(EnumConverter.class.getName());
- private Class<T> enumType;
- private Method factory;
-
- public EnumConverter(Class<T> enumType) {
- if (!Enum.class.isAssignableFrom(enumType)) {
- throw new IllegalArgumentException("Not an Enum: " + enumType.getName());
- }
- this.enumType = Objects.requireNonNull(enumType);
- try {
- this.factory = enumType.getMethod("valueOf", String.class);
- } catch (NoSuchMethodException e) {
- throw new ConfigException("Uncovertible enum type without valueOf method found, please provide a custom " +
- "PropertyConverter for: " + enumType.getName());
- }
- }
-
- @Override
- public T convert(String value, ConversionContext context) {
- try {
- return (T) factory.invoke(null, value);
- } catch (InvocationTargetException | IllegalAccessException e) {
- LOG.log(Level.FINEST, "Invalid enum value '" + value + "' for " + enumType.getName(), e);
- }
- try {
- return (T) factory.invoke(null, value.toUpperCase(Locale.ENGLISH));
- } catch (InvocationTargetException | IllegalAccessException e) {
- LOG.log(Level.FINEST, "Invalid enum value '" + value + "' for " + enumType.getName(), e);
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/EnvironmentPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/EnvironmentPropertySource.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/EnvironmentPropertySource.java
deleted file mode 100644
index 200c567..0000000
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/EnvironmentPropertySource.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya.spisupport;
-
-import org.apache.tamaya.spi.PropertyValue;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.logging.Logger;
-
-/**
- * This {@link org.apache.tamaya.spi.PropertySource} provides all Properties which are set
- * via
- * {@code export myprop=myval} on UNIX Systems or
- * {@code set myprop=myval} on Windows. You can disable this feature by setting {@code tamaya.envprops.disable}
- * or {@code tamaya.defaults.disable}.
- */
-public class EnvironmentPropertySource extends BasePropertySource {
-
- private static final Logger LOG = Logger.getLogger(EnvironmentPropertySource.class.getName());
-
- /**
- * Default ordinal used.
- */
- public static final int DEFAULT_ORDINAL = 300;
-
- /**
- * Prefix that allows environment properties to virtually be mapped on specified sub section.
- */
- private String prefix;
-
- /**
- * If true, this property source does not return any properties. This is useful since this
- * property source is applied by default, but can be switched off by setting the
- * {@code tamaya.envprops.disable} system/environment property to {@code true}.
- */
- private boolean disabled = false;
-
-
- /**
- * Creates a new instance. Also initializes the {@code prefix} and {@code disabled} properties
- * from the system-/ environment properties:
- * <pre>
- * tamaya.envprops.prefix
- * tamaya.envprops.disable
- * </pre>
- */
- public EnvironmentPropertySource(){
- initFromSystemProperties();
- }
-
- /**
- * Initializes the {@code prefix} and {@code disabled} properties from the system-/
- * environment properties:
- * <pre>
- * tamaya.envprops.prefix
- * tamaya.envprops.disable
- * </pre>
- */
- private void initFromSystemProperties() {
- String value = System.getProperty("tamaya.envprops.prefix");
- if(value==null){
- prefix = System.getenv("tamaya.envprops.prefix");
- }
- value = System.getProperty("tamaya.envprops.disable");
- if(value==null){
- value = System.getenv("tamaya.envprops.disable");
- }
- if(value==null){
- value = System.getProperty("tamaya.defaults.disable");
- }
- if(value==null){
- value = System.getenv("tamaya.defaults.disable");
- }
- if(value!=null && !value.isEmpty()) {
- this.disabled = Boolean.parseBoolean(value);
- }
- }
-
- /**
- * Creates a new instance using a fixed ordinal value.
- * @param ordinal the ordinal number.
- */
- public EnvironmentPropertySource(int ordinal){
- this(null, ordinal);
- }
-
- /**
- * Creates a new instance.
- * @param prefix the prefix to be used, or null.
- * @param ordinal the ordinal to be used.
- */
- public EnvironmentPropertySource(String prefix, int ordinal){
- super("environment-properties");
- this.prefix = prefix;
- setOrdinal(ordinal);
- }
-
- /**
- * Creates a new instance.
- * @param prefix the prefix to be used, or null.
- */
- public EnvironmentPropertySource(String prefix){
- this.prefix = prefix;
- }
-
- @Override
- public int getDefaultOrdinal() {
- return DEFAULT_ORDINAL;
- }
-
- @Override
- public String getName() {
- if(disabled){
- return super.getName() + "(disabled)";
- }
- return super.getName();
- }
-
- @Override
- public PropertyValue get(String key) {
- if(disabled){
- return null;
- }
- String prefix = this.prefix;
- if(prefix==null) {
- return PropertyValue.of(key, System.getenv(key), getName());
- }
- return PropertyValue.of(key, System.getenv(key.substring(prefix.length())), getName());
- }
-
- @Override
- public Map<String, PropertyValue> getProperties() {
- if(disabled){
- return Collections.emptyMap();
- }
- String prefix = this.prefix;
- if(prefix==null) {
- Map<String, PropertyValue> entries = new HashMap<>(System.getenv().size());
- for (Map.Entry<String, String> entry : System.getenv().entrySet()) {
- entries.put(entry.getKey(), PropertyValue.of(entry.getKey(), entry.getValue(), getName()));
- }
- return entries;
- }else{
- Map<String, PropertyValue> entries = new HashMap<>(System.getenv().size());
- for (Map.Entry<String, String> entry : System.getenv().entrySet()) {
- entries.put(prefix + entry.getKey(), PropertyValue.of(prefix + entry.getKey(), entry.getValue(), getName()));
- }
- return entries;
- }
- }
-
- @Override
- public boolean isScannable() {
- return true;
- }
-
- @Override
- protected String toStringValues() {
- return super.toStringValues() +
- " prefix=" + prefix + '\n' +
- " disabled=" + disabled + '\n';
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/MapPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/MapPropertySource.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/MapPropertySource.java
deleted file mode 100644
index b07231e..0000000
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/MapPropertySource.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.spisupport;
-
-import org.apache.tamaya.spi.PropertyValue;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- * Simple PropertySource implementation that just takes a Map and an (optional) priority.
- * Optionally the entries passed can be mapped to a different rootContext.
- */
-public class MapPropertySource extends BasePropertySource {
-
- /**
- * The current properties.
- */
- private final Map<String, PropertyValue> props = new HashMap<>();
-
- /**
- * Creates a new instance, hereby using the default mechanism for evaluating the property source's
- * priority.
- *
- * @param name unique name of this source.
- * @param props the properties
- */
- public MapPropertySource(String name, Map<String, String> props) {
- this(name, props, null);
- }
-
- /**
- * Creates a new instance, hereby using the default mechanism for evaluating the property source's
- * priority, but applying a custom mapping {@code prefix} to the entries provided.
- *
- * @param name unique name of this source.
- * @param props the properties
- * @param prefix the prefix context mapping, or null (for no mapping).
- */
- public MapPropertySource(String name, Map<String, String> props, String prefix) {
- super(name);
- if (prefix == null) {
- for (Map.Entry<String, String> en : props.entrySet()) {
- this.props.put(en.getKey(),
- PropertyValue.of(en.getKey(), en.getValue(), name));
- }
- } else {
- for (Map.Entry<String, String> en : props.entrySet()) {
- this.props.put(prefix + en.getKey(),
- PropertyValue.of(prefix + en.getKey(), en.getValue(), name));
- }
- }
- }
-
- /**
- * Creates a new instance, hereby using the default mechanism for evaluating the property source's
- * priority, but applying a custom mapping {@code rootContext} to the entries provided.
- *
- * @param name unique name of this source.
- * @param props the properties
- * @param prefix the prefix context mapping, or null (for no mapping).
- */
- public MapPropertySource(String name, Properties props, String prefix) {
- this(name, getMap(props), prefix);
- }
-
- /**
- * Simple method to convert Properties into a Map instance.
- * @param props the properties, not null.
- * @return the corresponding Map instance.
- */
- public static Map<String, String> getMap(Properties props) {
- Map<String, String> result = new HashMap<>();
- for (Map.Entry en : props.entrySet()) {
- result.put(en.getKey().toString(), en.getValue().toString());
- }
- return result;
- }
-
-
- @Override
- public Map<String, PropertyValue> getProperties() {
- return Collections.unmodifiableMap(this.props);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PriorityServiceComparator.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PriorityServiceComparator.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PriorityServiceComparator.java
deleted file mode 100644
index 90a8387..0000000
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PriorityServiceComparator.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.spisupport;
-
-import javax.annotation.Priority;
-import java.io.Serializable;
-import java.util.Comparator;
-
-/**
- * Comparator implementation for odering services loaded based on their increasing priority values.
- */
-public class PriorityServiceComparator implements Comparator<Object>, Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private static final PriorityServiceComparator INSTANCE = new PriorityServiceComparator();
-
- private PriorityServiceComparator(){}
-
- /**
- * Get the shared instance of the comparator.
- * @return the shared instance, never null.
- */
- public static PriorityServiceComparator getInstance(){
- return INSTANCE;
- }
-
- @Override
- public int compare(Object o1, Object o2) {
- int prio = getPriority(o1) - getPriority(o2);
- if (prio < 0) {
- return 1;
- } else if (prio > 0) {
- return -1;
- } else {
- return o1.getClass().getSimpleName().compareTo(o2.getClass().getSimpleName());
- }
- }
-
- /**
- * Checks the given instance for a @Priority annotation. If present the annotation's value s evaluated. If no such
- * annotation is present, a default priority is returned (1);
- *
- * @param o the instance, not null.
- * @return a priority, by default 1.
- */
- public static int getPriority(Object o) {
- int prio = 1;
- Priority priority = o.getClass().getAnnotation(Priority.class);
- if (priority != null) {
- prio = priority.value();
- }
- return prio;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/2d0ef4b9/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertiesResourcePropertySource.java
----------------------------------------------------------------------
diff --git a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertiesResourcePropertySource.java b/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertiesResourcePropertySource.java
deleted file mode 100644
index 1dc7586..0000000
--- a/modules/spi-support/src/main/java/org/apache/tamaya/spisupport/PropertiesResourcePropertySource.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.spisupport;
-
-import org.apache.tamaya.spi.ServiceContextManager;
-
-import java.io.InputStream;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * Simple PropertySource, with a fixed ordinal that reads a .properties file from a given URL.
- */
-public class PropertiesResourcePropertySource extends MapPropertySource {
- /** The logger used. */
- private static final Logger LOGGER = Logger.getLogger(PropertiesResourcePropertySource.class.getName());
-
- /**
- * Creates a new instance.
- * @param url the resource URL, not null.
- */
- public PropertiesResourcePropertySource(URL url){
- this(url, null);
- }
-
- /**
- * Creates a new instance.
- * @param prefix the (optional) prefix context for mapping (prefixing) the properties loaded.
- * @param url the resource URL, not null.
- */
- public PropertiesResourcePropertySource(URL url, String prefix){
- super(url.toExternalForm(), loadProps(url), prefix);
- }
-
- /**
- * Creates a new instance.
- * @param prefix the (optional) prefix context for mapping (prefixing) the properties loaded.
- * @param path the resource path, not null.
- */
- public PropertiesResourcePropertySource(String path, String prefix){
- super(path, loadProps(path, null), prefix);
- }
-
- /**
- * Creates a new instance.
- * @param prefix the (optional) prefix context for mapping (prefixing) the properties loaded.
- * @param path the resource path, not null.
- */
- public PropertiesResourcePropertySource(String path, String prefix, ClassLoader cl){
- super(path, loadProps(path, cl), prefix);
- }
-
- /**
- * Loads the properties using the JDK's Property loading mechanism.
- * @param path the resource classpath, not null.
- * @return the loaded properties.
- */
- private static Map<String, String> loadProps(String path, ClassLoader cl) {
- if(cl==null){
- cl = PropertiesResourcePropertySource.class.getClassLoader();
- }
- URL url = ServiceContextManager.getServiceContext().getResource(path, cl);
- return loadProps(url);
- }
-
- /**
- * Loads the properties using the JDK's Property loading mechanism.
- * @param url the resource URL, not null.
- * @return the loaded properties.
- */
- private static Map<String, String> loadProps(URL url) {
- Map<String,String> result = new HashMap<>();
- if(url!=null) {
- try (InputStream is = url.openStream()) {
- Properties props = new Properties();
- props.load(is);
- for (Map.Entry en : props.entrySet()) {
- result.put(en.getKey().toString(), en.getValue().toString());
- }
- } catch (Exception e) {
- LOGGER.log(Level.WARNING, "Failed to read properties from " + url, e);
- }
- }else{
- LOGGER.log(Level.WARNING, "No properties found at " + url);
- }
- return result;
- }
-
-}
[3/9] incubator-tamaya-extensions git commit: TAMAYA-274 Fixed
javadocs.
Posted by an...@apache.org.
TAMAYA-274 Fixed javadocs.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/commit/572e1abd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/572e1abd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/572e1abd
Branch: refs/heads/master
Commit: 572e1abd8dcb3e917accb4f39f83d768420661cd
Parents: 48f3f7b
Author: Anatole Tresch <an...@apache.org>
Authored: Sun Nov 12 21:28:12 2017 +0100
Committer: Anatole Tresch <an...@apache.org>
Committed: Tue Nov 14 10:26:04 2017 +0100
----------------------------------------------------------------------
.../src/main/java/org/apache/tamaya/inject/api/NoConfig.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/572e1abd/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/NoConfig.java
----------------------------------------------------------------------
diff --git a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/NoConfig.java b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/NoConfig.java
index c5234d3..0a00409 100644
--- a/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/NoConfig.java
+++ b/modules/injection/injection-api/src/main/java/org/apache/tamaya/inject/api/NoConfig.java
@@ -26,7 +26,7 @@ import java.lang.annotation.Target;
/**
* This is a small marker annotations to inform Tamaya that the annotated element should never be injected with
- * configured data. This is useful because by default Tamaya tries to lookup and inject configuration also by
+ * configured data. This is useful because Tamaya can also try to lookup and inject configuration also by
* using property or method names without annotations. With that annotation none of these will be happen.
*/
@Retention(RetentionPolicy.RUNTIME)