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 2014/12/08 00:54:37 UTC
[1/2] incubator-tamaya git commit: TAMAYA-3: -Fixed tests,
by implementing a mutable config instance. - Added some Javadocs.
Repository: incubator-tamaya
Updated Branches:
refs/heads/master 67f27e1a2 -> 1c11c0f09
TAMAYA-3:
-Fixed tests, by implementing a mutable config instance.
- Added some Javadocs.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/889bf37b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/889bf37b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/889bf37b
Branch: refs/heads/master
Commit: 889bf37b81bbcd180a9ba480f1f59c40a61bcc04
Parents: 5c36d32
Author: anatole <an...@apache.org>
Authored: Mon Dec 8 00:52:33 2014 +0100
Committer: anatole <an...@apache.org>
Committed: Mon Dec 8 00:52:33 2014 +0100
----------------------------------------------------------------------
.../java/org/apache/tamaya/ConfigFunctions.java | 113 -------------------
.../tamaya/annotation/WithLoadPolicy.java | 4 +
.../tamaya/core/config/MappedConfiguration.java | 58 ++++++++++
.../internal/MutableTestConfigProvider.java | 64 +++++++++--
.../apache/tamaya/ucs/UC1ReadProperties.java | 1 +
5 files changed, 118 insertions(+), 122 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/889bf37b/api/src/main/java/org/apache/tamaya/ConfigFunctions.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/ConfigFunctions.java b/api/src/main/java/org/apache/tamaya/ConfigFunctions.java
deleted file mode 100644
index c732120..0000000
--- a/api/src/main/java/org/apache/tamaya/ConfigFunctions.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.tamaya;
-
-import java.util.*;
-import java.util.stream.Collectors;
-
-/**
- * Accessor that provides useful functions along with configuration.
- */
-public final class ConfigFunctions {
- /**
- * Private singleton constructor.
- */
- private ConfigFunctions() {
- }
-
- /**
- * Creates a ConfigOperator that creates a Configuration containing only keys
- * that are contained in the given area (non recursive). Hereby
- * the area key is stripped away fromMap the resulting key.
- *
- * @param areaKey the area key, not null
- * @return the area configuration, with the areaKey stripped away.
- */
- public static ConfigOperator selectArea(String areaKey) {
- return selectArea(areaKey, true);
- }
-
- /**
- * Creates a ConfigOperator that creates a Configuration containing only keys
- * that are contained in the given area (non recursive).
- *
- * @param areaKey the area key, not null
- * @param stripKeys if set to true, the area key is stripped away fromMap the resulting key.
- * @return the area configuration, with the areaKey stripped away.
- */
- public static ConfigOperator selectArea(String areaKey, boolean stripKeys) {
- return config -> {
- Map<String, String> area = new HashMap<>();
- area.putAll(
- config.toMap().entrySet().stream()
- .filter(e -> isKeyInArea(e.getKey(), areaKey))
- .collect(Collectors.toMap(
- e -> stripKeys ? e.getKey().substring(areaKey.length() + 1) : e.getKey(),
- e -> e.getValue())));
- return PropertyProviderBuilder.create("area: " + areaKey).addMap(area).build().toConfiguration();
- };
- }
-
- /**
- * Calculates the current area key and compares it with the given key.
- *
- * @param key the fully qualified entry key, not null
- * @param areaKey the area key, not null
- * @return true, if the entry is exact in this area
- */
- public static boolean isKeyInArea(String key, String areaKey) {
- int lastIndex = key.lastIndexOf('.');
- String curAreaKey = lastIndex > 0 ? key.substring(0, lastIndex) : "";
- return curAreaKey.equals(areaKey);
- }
-
- /**
- * Creates a ConfigOperator that creates a Configuration containing only keys
- * that are contained in the given area (recursive). Hereby
- * the area key is stripped away fromMap the resulting key.
- *
- * @param areaKey the area key, not null
- * @return the area configuration, with the areaKey stripped away.
- */
- public static ConfigOperator selectAreaRecursive(String areaKey) {
- return selectAreaRecursive(areaKey, true);
- }
-
- /**
- * Creates a ConfigOperator that creates a Configuration containing only keys
- * that are contained in the given area (recursive).
- *
- * @param areaKey the area key, not null
- * @param stripKeys if set to true, the area key is stripped away fromMap the resulting key.
- * @return the area configuration, with the areaKey stripped away.
- */
- public static ConfigOperator selectAreaRecursive(String areaKey, boolean stripKeys) {
- return config -> {
- Map<String, String> area = new HashMap<>();
- String lookupKey = areaKey + '.';
- area.putAll(
- config.toMap().entrySet().stream()
- .filter(e -> e.getKey().startsWith(lookupKey))
- .collect(Collectors.toMap(
- e -> stripKeys ? e.getKey().substring(areaKey.length() + 1) : e.getKey(),
- e -> e.getValue())));
- return PropertyProviderBuilder.create("area (recursive): " + areaKey).addMap(area).build().toConfiguration();
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/889bf37b/api/src/main/java/org/apache/tamaya/annotation/WithLoadPolicy.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/tamaya/annotation/WithLoadPolicy.java b/api/src/main/java/org/apache/tamaya/annotation/WithLoadPolicy.java
index 572a36e..e469f5a 100644
--- a/api/src/main/java/org/apache/tamaya/annotation/WithLoadPolicy.java
+++ b/api/src/main/java/org/apache/tamaya/annotation/WithLoadPolicy.java
@@ -31,6 +31,10 @@ import java.lang.annotation.Target;
@Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.TYPE })
public @interface WithLoadPolicy {
+ /**
+ * The load policy to be used. If this annotation is present a load policy must be defined.
+ * @return The load policy to be used, not null.
+ */
LoadPolicy value();
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/889bf37b/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java b/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java
new file mode 100644
index 0000000..d61b99c
--- /dev/null
+++ b/core/src/main/java/org/apache/tamaya/core/config/MappedConfiguration.java
@@ -0,0 +1,58 @@
+package org.apache.tamaya.core.config;
+
+import com.sun.javafx.scene.control.behavior.OptionalBoolean;
+import org.apache.tamaya.*;
+
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Predicate;
+import java.util.function.UnaryOperator;
+
+/**
+ * Created by Anatole on 07.12.2014.
+ */
+class MappedConfiguration extends AbstractConfiguration implements Configuration {
+
+ private UnaryOperator<String> keyMapper;
+ private Configuration config;
+
+ public MappedConfiguration(Configuration config, UnaryOperator<String> keyMapper) {
+ super(MetaInfoBuilder.of(config.getMetaInfo()).setInfo("Mapped configuration, mapper=" + keyMapper).build());
+ this.config = Objects.requireNonNull(config);
+ this.keyMapper = Objects.requireNonNull(keyMapper);
+ }
+
+ @Override
+ public Map<String, String> toMap() {
+ Map<String, String> result = new HashMap<>();
+ Map<String, String> map = this.config.toMap();
+ map.forEach((k,v) -> {
+ String targetKey = keyMapper.apply(k);
+ if(targetKey!=null){
+ result.put(targetKey, v);
+ }
+ });
+ return result;
+ }
+
+ @Override
+ public boolean isMutable() {
+ return this.config.isMutable();
+ }
+
+ @Override
+ public void apply(ConfigChangeSet change) {
+ this.config.apply(change);
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return this.config.isEmpty();
+ }
+
+ @Override
+ public Configuration toConfiguration() {
+ return this;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/889bf37b/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java b/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java
index d035e1d..34ab3a9 100644
--- a/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java
+++ b/core/src/test/java/org/apache/tamaya/internal/MutableTestConfigProvider.java
@@ -18,32 +18,37 @@
*/
package org.apache.tamaya.internal;
-import org.apache.tamaya.Configuration;
-import org.apache.tamaya.MetaInfoBuilder;
-import org.apache.tamaya.PropertyProvider;
-import org.apache.tamaya.PropertyProviderBuilder;
+import org.apache.tamaya.*;
+import org.apache.tamaya.core.config.AbstractConfiguration;
import org.apache.tamaya.core.spi.ConfigurationProviderSpi;
+import java.beans.PropertyChangeEvent;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
- * Created by Anatole on 29.09.2014.
+ * Simple test provider that creates a mutable instance of a configuration, just using a simple map instance.
*/
public class MutableTestConfigProvider implements ConfigurationProviderSpi{
-
+ /** The config name. */
private static final String CONFIG_NAME = "mutableTestConfig";
- private Configuration testConfig;
- private final Map<String, String> dataMap = new ConcurrentHashMap<>();
+ /** The config provided. */
+ private MutableConfiguration testConfig;
+ /**
+ * COnsatructor.
+ */
public MutableTestConfigProvider(){
+ Map<String, String> dataMap = new HashMap<>();
dataMap.put("dad", "Anatole");
dataMap.put("mom", "Sabine");
dataMap.put("sons.1", "Robin");
dataMap.put("sons.2", "Luke");
dataMap.put("sons.3", "Benjamin");
PropertyProvider provider = PropertyProviderBuilder.create(CONFIG_NAME).addMap(dataMap).build();
- testConfig = provider.toConfiguration();
+ testConfig = new MutableConfiguration(dataMap, MetaInfo.of(CONFIG_NAME));
}
@Override
@@ -55,4 +60,45 @@ public class MutableTestConfigProvider implements ConfigurationProviderSpi{
public Configuration getConfiguration(){
return testConfig;
}
+
+ /**
+ * Implements a simple mutable config based on a Mao instance.
+ */
+ private final class MutableConfiguration extends AbstractConfiguration{
+
+ private final Map<String,String> data = new ConcurrentHashMap<>();
+
+ MutableConfiguration(Map<String,String> data, MetaInfo metaInfo){
+ super(metaInfo);
+ this.data.putAll(data);
+ }
+
+ @Override
+ public Map<String, String> toMap() {
+ return Collections.unmodifiableMap(data);
+ }
+
+ @Override
+ public boolean isMutable() {
+ return true;
+ }
+
+ @Override
+ public void apply(ConfigChangeSet changeSet) {
+ for(PropertyChangeEvent change: changeSet.getEvents()){
+ if(change.getNewValue()==null){
+ this.data.remove(change.getPropertyName());
+ }
+ else{
+ this.data.put(change.getPropertyName(), (String) change.getNewValue());
+ }
+ }
+ publishPropertyChangeEvents(changeSet.getEvents());
+ }
+
+ @Override
+ public Configuration toConfiguration(){
+ return this;
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/889bf37b/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java b/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
index 6c2ae19..61ef70d 100644
--- a/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
+++ b/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.ucs;
import org.apache.tamaya.*;
+import org.apache.tamaya.core.config.ConfigFunctions;
import org.junit.Test;
import java.math.BigDecimal;
[2/2] incubator-tamaya git commit: Merge remote-tracking branch
'origin/master'
Posted by an...@apache.org.
Merge remote-tracking branch 'origin/master'
Conflicts:
api/src/main/java/org/apache/tamaya/ConfigFunctions.java
Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/1c11c0f0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/1c11c0f0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/1c11c0f0
Branch: refs/heads/master
Commit: 1c11c0f0954e9e00f434e437aeb1d2b426de529f
Parents: 889bf37 67f27e1
Author: anatole <an...@apache.org>
Authored: Mon Dec 8 00:53:38 2014 +0100
Committer: anatole <an...@apache.org>
Committed: Mon Dec 8 00:53:38 2014 +0100
----------------------------------------------------------------------
.../apache/tamaya/PropertyProviderBuilder.java | 83 ++++++++++++--------
api/src/test/resources/META-INF/beans.xml | 25 ++++++
....tamaya.spi.ConfigurationManagerSingletonSpi | 18 +++++
...he.tamaya.spi.EnvironmentManagerSingletonSpi | 18 +++++
...ache.tamaya.spi.PropertyAdaptersSingletonSpi | 18 +++++
...DependentApplicationEnvironmentProvider.java | 2 +-
...ssLoaderDependentEarEnvironmentProvider.java | 2 +-
.../DefaultConfigFormatsSingletonSpi.java | 6 +-
.../internal/inject/ConfigurationInjector.java | 2 +-
.../core/internal/inject/ConfiguredField.java | 2 +-
.../logging/AbstractDelegatingLogger.java | 4 +-
.../core/internal/logging/Log4jLogger.java | 4 +-
.../properties/AggregatedPropertyProvider.java | 2 +-
.../properties/BuildablePropertyProvider.java | 20 ++++-
.../DefaultPropertyAdaptersSingletonSpi.java | 2 +-
.../IntersectingPropertyProvider.java | 2 +-
.../properties/ReplacingPropertyProvider.java | 8 +-
.../properties/SubtractingPropertyProvider.java | 4 +-
.../resources/AntPathClasspathResolver.java | 2 +-
.../internal/resources/AntPathFileResolver.java | 2 +-
.../resources/DefaultPathResourceLoader.java | 8 +-
.../internal/resources/io/AntPathMatcher.java | 16 ++--
.../core/internal/resources/io/ClassUtils.java | 8 +-
.../io/PathMatchingResourcePatternResolver.java | 19 +++--
.../core/internal/resources/io/StringUtils.java | 6 +-
.../tamaya/core/config/MutableConfigTest.java | 4 +-
.../java/org/apache/tamaya/package-info.java | 20 ++++-
.../samples/annotations/ConfiguredTest.java | 6 +-
.../apache/tamaya/ucs/UC1ReadProperties.java | 2 +-
.../UC1ReadProperties/UC1ReadPropertiesTest.ini | 20 ++++-
.../UC1ReadPropertiesTest.properties | 20 ++++-
.../ucs/UC2CombineProperties/props1.properties | 20 ++++-
.../ucs/UC2CombineProperties/props2.properties | 18 +++++
.../java/metamodel/ext/cdi/ConfiguredClass.java | 20 +++++
.../java/metamodel/ext/cdi/ConfiguredTest.java | 27 ++++---
.../metamodel/ext/cdi/TestConfigProvider.java | 21 ++++-
36 files changed, 354 insertions(+), 107 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/1c11c0f0/core/src/test/java/org/apache/tamaya/ucs/UC1ReadProperties.java
----------------------------------------------------------------------