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 2018/11/18 21:20:23 UTC
[05/20] incubator-tamaya-extensions git commit: TAMAYA-274 Reduced
API footprint by using Java 8 features. Added some lambdas. TAMAYA-355 Enable
mapping of lists and arrays into internal datastructures. TAMAYA-353 Adding
support for different classloa
TAMAYA-274 Reduced API footprint by using Java 8 features. Added some lambdas.
TAMAYA-355 Enable mapping of lists and arrays into internal datastructures.
TAMAYA-353 Adding support for different classloaders.
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/ade6eb8b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/ade6eb8b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/ade6eb8b
Branch: refs/heads/master
Commit: ade6eb8ba722a3f19ecccadd739d12247d3f1aa7
Parents: ac45f10
Author: Anatole Tresch <at...@gmail.com>
Authored: Tue Oct 23 18:39:21 2018 +0200
Committer: Anatole Tresch <at...@gmail.com>
Committed: Tue Oct 23 18:39:23 2018 +0200
----------------------------------------------------------------------
.../tamaya/ext/examples/resources/Main.java | 2 +-
.../tamay/ext/examples/resolver/Main.java | 2 +-
.../ext/examples/injection/MinimalTest.java | 2 +-
.../apache/tamaya/ext/examples/events/Main.java | 2 +-
.../tamaya/springexample/ColorConverter.java | 3 +-
.../tamaya/springexample/WelcomeController.java | 11 +-
.../src/main/resources/templates/welcome.ftl | 2 +-
.../org/apache/tamaya/events/ConfigEvent.java | 2 +-
.../tamaya/events/ConfigEventManager.java | 3 +-
.../tamaya/events/ConfigurationChange.java | 10 +-
.../events/ConfigurationChangeBuilder.java | 24 +-
.../tamaya/events/FrozenConfiguration.java | 30 +-
.../tamaya/events/PropertySourceChange.java | 8 +-
.../events/PropertySourceChangeBuilder.java | 22 +-
.../internal/DefaultConfigChangeObserver.java | 3 +-
.../internal/DefaultConfigEventManagerSpi.java | 4 +-
.../tamaya/events/ConfigurationChangeTest.java | 35 +--
.../tamaya/events/RandomPropertySource.java | 4 +-
.../apache/tamaya/events/TestConfigView.java | 27 +-
.../ObservingPropertySourceProvider.java | 2 +-
.../DefaultConfigChangeObserverTest.java | 4 +-
modules/filter/pom.xml | 6 +-
.../apache/tamaya/filter/CompositeFilter.java | 119 ++++++++
.../tamaya/filter/ConfigurationFilter.java | 27 +-
.../org/apache/tamaya/filter/FilterContext.java | 119 --------
.../filter/internal/DefaultMetadataFilter.java | 7 +-
.../tamaya/filter/ConfigurationFilterTest.java | 31 +-
.../tamaya/filter/ProgrammableFilterTest.java | 164 ++++++----
.../BaseFormatPropertySourceProvider.java | 7 +-
.../apache/tamaya/format/ConfigurationData.java | 121 ++------
.../tamaya/format/ConfigurationDataBuilder.java | 198 ------------
.../tamaya/format/ConfigurationFormat.java | 35 +--
.../tamaya/format/ConfigurationFormats.java | 4 +-
.../MappedConfigurationDataPropertySource.java | 81 ++---
.../format/formats/IniConfigurationFormat.java | 23 +-
.../tamaya/format/formats/PropertiesFormat.java | 13 +-
.../format/formats/PropertiesXmlFormat.java | 13 +-
...ppedConfigurationDataPropertySourceTest.java | 128 ++++----
.../org/apache/tamaya/json/JSONDataBuilder.java | 116 +++++++
.../java/org/apache/tamaya/json/JSONFormat.java | 8 +-
.../apache/tamaya/json/JSONPropertySource.java | 10 +-
.../org/apache/tamaya/json/JSONVisitor.java | 122 --------
.../org/apache/tamaya/json/JSONVisitorTest.java | 59 ++--
.../yaml/CommonJSONTestCaseCollection.java | 7 +-
.../tamaya/yaml/JSONPropertySourceTest.java | 4 +-
.../java/org/apache/tamaya/yaml/YAMLFormat.java | 111 +++----
.../apache/tamaya/yaml/YAMLPropertySource.java | 14 +-
.../org/apache/tamaya/yaml/YAMLFormatTest.java | 2 +-
.../test/resources/configs/valid/contact.yaml | 3 +
.../tamaya/functions/CombinedConfiguration.java | 2 +-
.../functions/ConfigurationFunctions.java | 300 +++++--------------
.../functions/EnrichedPropertySource.java | 4 +-
.../tamaya/functions/MappedPropertySource.java | 6 +-
.../functions/PropertySourceFunctions.java | 26 +-
.../functions/ValueMappedPropertySource.java | 4 +-
.../functions/CombinedConfigurationTest.java | 2 +-
.../functions/ConfigurationFunctionsTest.java | 7 +-
.../functions/EnrichedConfigurationTest.java | 8 +-
.../functions/EnrichedPropertySourceTest.java | 2 +-
.../functions/FilteredPropertySourceTest.java | 2 +-
.../functions/MappedPropertySourceTest.java | 2 +-
.../functions/PropertySourceFunctionsTest.java | 17 +-
.../ValueMappedPropertySourceTest.java | 30 +-
.../tamaya/cdi/CDIAwareServiceContext.java | 59 ++--
.../tamaya/cdi/ConfigurationProducer.java | 90 +++---
.../apache/tamaya/cdi/DefaultDynamicValue.java | 2 +-
.../tamaya/cdi/ServiceLoaderServiceContext.java | 30 +-
.../apache/tamaya/cdi/TamayaCDIAccessor.java | 2 +-
.../tamaya/cdi/TamayaCDIInjectionExtension.java | 7 +-
.../cdi/extra/ConfiguredVetoExtension.java | 4 +-
.../org/apache/tamaya/cdi/ConfiguredTest.java | 8 -
.../tamaya/cdi/ConfiguredVetoExtensionTest.java | 122 ++++++++
.../tamaya/cdi/cfg/TestPropertySource.java | 2 +-
.../cdi/extra/ConfiguredVetoExtensionTest.java | 148 ---------
modules/injection/injection-api/pom.xml | 5 +
.../org/apache/tamaya/inject/api/Config.java | 8 +-
.../apache/tamaya/inject/api/DynamicValue.java | 4 +-
.../tamaya/inject/spi/BaseDynamicValue.java | 26 +-
.../tamaya/inject/spi/ConfiguredMethod.java | 2 +-
.../tamaya/inject/spi/InjectionUtils.java | 2 +-
.../tamaya/inject/spi/BaseDynamicValueTest.java | 2 +-
.../ConfigTemplateInvocationHandler.java | 2 +-
.../inject/internal/ConfiguredFieldImpl.java | 4 +-
.../inject/internal/ConfiguredSetterMethod.java | 2 +-
.../inject/internal/ConfiguredTypeImpl.java | 2 +-
.../internal/DefaultConfigurationInjector.java | 8 +-
.../inject/internal/DefaultDynamicValue.java | 10 +-
.../tamaya/inject/internal/InjectionHelper.java | 27 +-
.../java/annottext/NonAnnotatedConfigBean.java | 2 +-
.../tamaya/inject/TamayaInjectionTest.java | 4 +-
.../internal/DefaultDynamicValueTest.java | 15 +-
.../apache/tamaya/jndi/JNDIPropertySource.java | 6 +-
.../microprofile/MicroprofileAdapter.java | 4 +-
.../microprofile/MicroprofileConfigBuilder.java | 6 +-
.../MicroprofileConfigProviderResolver.java | 6 +-
.../microprofile/MicroprofileConverter.java | 10 +-
.../microprofile/TamayaConfiguration.java | 12 +-
.../microprofile/TamayaPropertyConverter.java | 3 +-
.../microprofile/TamayaPropertySource.java | 8 +-
.../cdi/MicroprofileConfigurationProducer.java | 12 +-
.../converter/BooleanAsIntegerConverterFix.java | 5 +-
.../converter/ProviderConverter.java | 43 +--
.../microprofile/MicroprofileAdapterTest.java | 8 +-
.../MicroprofileConfigProviderTest.java | 5 +-
.../microprofile/MicroprofileConfigTest.java | 3 +
.../UppercasePropertyConverter.java | 4 +-
.../mutableconfig/ConfigChangeRequest.java | 6 +-
.../mutableconfig/MutableConfiguration.java | 2 +-
.../MutableConfigurationProvider.java | 4 +-
.../MutableConfigurationProviderTest.java | 5 +-
.../mutableconfig/MutableConfigurationTest.java | 16 +-
.../tamaya/optional/OptionalConfiguration.java | 4 +-
.../org/apache/tamaya/osgi/ConfigChanger.java | 5 +-
.../org/apache/tamaya/osgi/ConfigHistory.java | 8 +-
.../tamaya/osgi/commands/ConfigCommands.java | 18 +-
.../tamaya/osgi/commands/HistoryCommands.java | 2 +-
.../osgi/commands/TamayaConfigService.java | 18 +-
.../org/apache/tamaya/osgi/BackupsTest.java | 6 +-
.../osgi/commands/HistoryCommandsTest.java | 2 +-
.../tamaya/gogo/shell/BackupCommands.java | 2 +-
.../tamaya/gogo/shell/ConfigCommands.java | 4 +-
.../tamaya/gogo/shell/HistoryCommands.java | 8 +-
.../karaf/shell/ApplyTamayaConfigCommand.java | 4 +-
.../karaf/shell/HistoryMaxsizeCommand.java | 2 +-
.../karaf/shell/HistoryMaxsizeSetCommand.java | 4 +-
.../org/apache/tamaya/resolver/Resolver.java | 60 +++-
.../resolver/internal/ConfigResolver.java | 19 +-
.../internal/DefaultExpressionEvaluator.java | 2 +-
.../internal/ExpressionResolutionFilter.java | 29 +-
.../resolver/internal/ResourceResolver.java | 39 +--
.../tamaya/resolver/ConfigResolutionTest.java | 37 +--
.../apache/tamaya/resolver/ResolverTest.java | 30 +-
modules/resources/README.md | 2 +-
.../AbstractPathPropertySourceProvider.java | 18 +-
.../tamaya/resource/BaseResourceResolver.java | 52 +---
.../apache/tamaya/resource/ConfigResources.java | 16 +-
.../tamaya/resource/ResourceResolver.java | 17 +-
.../internal/ClassPathResourceLocator.java | 5 +-
.../resource/internal/ClasspathCollector.java | 10 +-
.../internal/DefaultResourceResolver.java | 4 +-
.../tamaya/resource/internal/FileCollector.java | 6 +-
.../tamaya/resource/internal/VfsSupport.java | 6 +-
.../AbstractPathPropertySourceProviderTest.java | 2 +-
.../internal/ClasspathCollectorTest.java | 14 +-
.../spring/TamayaSpringPropertySource.java | 3 +-
145 files changed, 1564 insertions(+), 1827 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/examples/01-resources-example/src/main/java/org/apache/tamaya/ext/examples/resources/Main.java
----------------------------------------------------------------------
diff --git a/examples/01-resources-example/src/main/java/org/apache/tamaya/ext/examples/resources/Main.java b/examples/01-resources-example/src/main/java/org/apache/tamaya/ext/examples/resources/Main.java
index db5cc3e..92abbe4 100644
--- a/examples/01-resources-example/src/main/java/org/apache/tamaya/ext/examples/resources/Main.java
+++ b/examples/01-resources-example/src/main/java/org/apache/tamaya/ext/examples/resources/Main.java
@@ -43,7 +43,7 @@ public class Main {
}
public static void main(String[] args){
- Configuration cfg = ConfigurationProvider.getConfiguration();
+ Configuration cfg = Configuration.current();
System.out.println("****************************************************");
System.out.println("Example for an property sources using a ");
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/examples/02-resolver-example/src/main/java/org/apache/tamay/ext/examples/resolver/Main.java
----------------------------------------------------------------------
diff --git a/examples/02-resolver-example/src/main/java/org/apache/tamay/ext/examples/resolver/Main.java b/examples/02-resolver-example/src/main/java/org/apache/tamay/ext/examples/resolver/Main.java
index 6b99c57..b9bba45 100644
--- a/examples/02-resolver-example/src/main/java/org/apache/tamay/ext/examples/resolver/Main.java
+++ b/examples/02-resolver-example/src/main/java/org/apache/tamay/ext/examples/resolver/Main.java
@@ -47,7 +47,7 @@ public class Main {
}
public static void main(String[] args){
- Configuration cfg = ConfigurationProvider.getConfiguration();
+ Configuration cfg = Configuration.current();
System.out.println("****************************************************");
System.out.println("Resolver Example");
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/examples/03-injection-example/src/test/java/org/apache/tamaya/ext/examples/injection/MinimalTest.java
----------------------------------------------------------------------
diff --git a/examples/03-injection-example/src/test/java/org/apache/tamaya/ext/examples/injection/MinimalTest.java b/examples/03-injection-example/src/test/java/org/apache/tamaya/ext/examples/injection/MinimalTest.java
index 022b5b8..d0d7b1c 100644
--- a/examples/03-injection-example/src/test/java/org/apache/tamaya/ext/examples/injection/MinimalTest.java
+++ b/examples/03-injection-example/src/test/java/org/apache/tamaya/ext/examples/injection/MinimalTest.java
@@ -32,7 +32,7 @@ public class MinimalTest {
@BeforeClass
public static void before() throws InterruptedException {
- config = ConfigurationProvider.getConfiguration();
+ config = Configuration.current();
Thread.sleep(100L);
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/Main.java
----------------------------------------------------------------------
diff --git a/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/Main.java b/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/Main.java
index 67d680c..2cf3fa0 100644
--- a/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/Main.java
+++ b/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/Main.java
@@ -64,7 +64,7 @@ public class Main {
ConfigEventManager.addListener(new ConfigurationChangeListener());
ConfigEventManager.setChangeMonitoringPeriod(1_000L);
ConfigEventManager.enableChangeMonitoring(true);
- Configuration configuration = ConfigurationProvider.getConfiguration();
+ Configuration configuration = Configuration.current();
for (Map.Entry<String, String> e : configuration.getProperties().entrySet()) {
System.out.println(e.getKey() + ": " + e.getValue());
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/examples/05-spring-example/src/main/java/org/apache/tamaya/springexample/ColorConverter.java
----------------------------------------------------------------------
diff --git a/examples/05-spring-example/src/main/java/org/apache/tamaya/springexample/ColorConverter.java b/examples/05-spring-example/src/main/java/org/apache/tamaya/springexample/ColorConverter.java
index 3ec3977..d625949 100644
--- a/examples/05-spring-example/src/main/java/org/apache/tamaya/springexample/ColorConverter.java
+++ b/examples/05-spring-example/src/main/java/org/apache/tamaya/springexample/ColorConverter.java
@@ -15,7 +15,6 @@
*/
package org.apache.tamaya.springexample;
-import org.apache.tamaya.spi.ConversionContext;
import org.apache.tamaya.spi.PropertyConverter;
import java.awt.*;
@@ -26,7 +25,7 @@ import java.awt.*;
public class ColorConverter implements PropertyConverter<Color>{
@Override
- public Color convert(String value, ConversionContext context) {
+ public Color convert(String value) {
if(value.length()<7){
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/examples/05-spring-example/src/main/java/org/apache/tamaya/springexample/WelcomeController.java
----------------------------------------------------------------------
diff --git a/examples/05-spring-example/src/main/java/org/apache/tamaya/springexample/WelcomeController.java b/examples/05-spring-example/src/main/java/org/apache/tamaya/springexample/WelcomeController.java
index affafef..352822b 100644
--- a/examples/05-spring-example/src/main/java/org/apache/tamaya/springexample/WelcomeController.java
+++ b/examples/05-spring-example/src/main/java/org/apache/tamaya/springexample/WelcomeController.java
@@ -20,7 +20,6 @@ import java.util.Date;
import java.util.Map;
import org.apache.tamaya.Configuration;
-import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.functions.ConfigurationFunctions;
import org.apache.tamaya.inject.api.Config;
import org.apache.tamaya.inject.api.DynamicValue;
@@ -72,19 +71,19 @@ public class WelcomeController {
@GetMapping("/config")
public String config(Map<String, Object> model) {
- Configuration config = ConfigurationProvider.getConfiguration();
+ Configuration config = Configuration.current();
model.put("filter", "NO FILTER");
model.put("config", config
- .query(ConfigurationFunctions.textInfo()));
+ .adapt(ConfigurationFunctions.textInfo()));
return "config";
}
@GetMapping(value="/config/{path}")
public String config(@PathVariable("path") String path, Map<String, Object> model) {
- Configuration config = ConfigurationProvider.getConfiguration();
+ Configuration config = Configuration.current();
model.put("filter", path);
- model.put("config", config.with(ConfigurationFunctions.section(path))
- .query(ConfigurationFunctions.textInfo()));
+ model.put("config", config.map(ConfigurationFunctions.section(path))
+ .adapt(ConfigurationFunctions.textInfo()));
return "config";
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/examples/05-spring-example/src/main/resources/templates/welcome.ftl
----------------------------------------------------------------------
diff --git a/examples/05-spring-example/src/main/resources/templates/welcome.ftl b/examples/05-spring-example/src/main/resources/templates/welcome.ftl
index 183d3de..d70ef9a 100644
--- a/examples/05-spring-example/src/main/resources/templates/welcome.ftl
+++ b/examples/05-spring-example/src/main/resources/templates/welcome.ftl
@@ -26,7 +26,7 @@
<h2>Accessing properties programmatically</h2>
Configuration properties can be easily accessed with Tamaya's Java API:<br/>
<pre>
-Configuration config = ConfigurationProvider.getConfiguration();
+Configuration config = Configuration.current();
String value = config.get("foreground.color");
</pre>
Hereby Tamaya also offers type safe access:<br/>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/modules/events/src/main/java/org/apache/tamaya/events/ConfigEvent.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/ConfigEvent.java b/modules/events/src/main/java/org/apache/tamaya/events/ConfigEvent.java
index 5a713d7..262786c 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/ConfigEvent.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/ConfigEvent.java
@@ -20,7 +20,7 @@ package org.apache.tamaya.events;
/**
- * Event that contains a set current changes that were applied or could be applied.
+ * Event that contains a setCurrent current changes that were applied or could be applied.
* @param <T> the resource type.
*/
public interface ConfigEvent<T>{
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/modules/events/src/main/java/org/apache/tamaya/events/ConfigEventManager.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/ConfigEventManager.java b/modules/events/src/main/java/org/apache/tamaya/events/ConfigEventManager.java
index 96dc9a5..1830dfb 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/ConfigEventManager.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/ConfigEventManager.java
@@ -34,7 +34,8 @@ public final class ConfigEventManager {
* The backing SPI.
*/
private static final ConfigEventManagerSpi spi(){
- ConfigEventManagerSpi spi = ServiceContextManager.getServiceContext()
+ ConfigEventManagerSpi spi = ServiceContextManager.getServiceContext(
+ Thread.currentThread().getContextClassLoader())
.getService(ConfigEventManagerSpi.class);
if(spi==null){
throw new ConfigException("No SPI registered for " +
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationChange.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationChange.java b/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationChange.java
index 9cdd4fc..5b75b61 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationChange.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationChange.java
@@ -29,7 +29,7 @@ import java.util.Map;
import java.util.UUID;
/**
- * Event that contains a set current changes that were applied or could be applied.
+ * Event that contains a setCurrent current changes that were applied or could be applied.
* This class is immutable and thread-safe. To create instances use
* {@link PropertySourceChangeBuilder}.
*
@@ -42,13 +42,13 @@ public final class ConfigurationChange implements ConfigEvent<Configuration>, Se
private final FrozenConfiguration configuration;
/** The base version, usable for optimistic locking. */
private String version = UUID.randomUUID().toString();
- /** The timestamp of the change set in millis from the epoch. */
+ /** The timestamp of the change setCurrent in millis from the epoch. */
private long timestamp = System.currentTimeMillis();
/** The recorded changes. */
private final Map<String,PropertyChangeEvent> changes = new HashMap<>();
/**
- * Get an empty change set for the given provider.
+ * Get an empty change setCurrent for the given provider.
* @param configuration The configuration changed, not null.
* @return an empty ConfigurationChangeSet instance.
*/
@@ -208,8 +208,8 @@ public final class ConfigurationChange implements ConfigEvent<Configuration>, Se
}
/**
- * CHecks if the current change set does not contain any changes.
- * @return tru, if the change set is empty.
+ * CHecks if the current change setCurrent does not contain any changes.
+ * @return tru, if the change setCurrent is empty.
*/
public boolean isEmpty(){
return this.changes.isEmpty();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationChangeBuilder.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationChangeBuilder.java b/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationChangeBuilder.java
index 8becb11..79061ba 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationChangeBuilder.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/ConfigurationChangeBuilder.java
@@ -29,7 +29,7 @@ import java.util.SortedMap;
import java.util.TreeMap;
/**
- * Models a set current changes applied to a {@link org.apache.tamaya.spi.PropertySource}. Consumers of these events
+ * Models a setCurrent current changes applied to a {@link org.apache.tamaya.spi.PropertySource}. Consumers of these events
* can observe changes to property sources and
* <ol>
* <li>Check if their current configuration instance ({@link org.apache.tamaya.spi.ConfigurationContext}
@@ -73,7 +73,7 @@ public final class ConfigurationChangeBuilder {
* @return the builder for chaining.
*/
public static ConfigurationChangeBuilder of() {
- return new ConfigurationChangeBuilder(ConfigurationProvider.getConfiguration());
+ return new ConfigurationChangeBuilder(Configuration.current());
}
/**
@@ -127,7 +127,7 @@ public final class ConfigurationChangeBuilder {
}
/*
- * Apply a version/UUID to the set being built.
+ * Apply a version/UUID to the setCurrent being built.
* @param version the version to apply, or null, to let the system generate a version for you.
* @return the builder for chaining.
*/
@@ -137,7 +137,7 @@ public final class ConfigurationChangeBuilder {
}
/*
- * Apply given timestamp to the set being built.
+ * Apply given timestamp to the setCurrent being built.
* @param version the version to apply, or null, to let the system generate a version for you.
* @return the builder for chaining.
*/
@@ -173,7 +173,7 @@ public final class ConfigurationChangeBuilder {
}
/**
- * Get the current values, also considering any changes recorded within this change set.
+ * Get the current values, also considering any changes recorded within this change setCurrent.
*
* @param key the key current the entry, not null.
* @return the keys, or null.
@@ -229,7 +229,7 @@ public final class ConfigurationChangeBuilder {
}
/**
- * This method will create a change set that clears all entries fromMap the given base configuration/properties.
+ * This method will create a change setCurrent that clears all entries fromMap the given base configuration/properties.
*
* @return the builder for chaining.
*/
@@ -244,26 +244,26 @@ public final class ConfigurationChangeBuilder {
}
/**
- * Checks if the change set is empty, i.e. does not contain any changes.
+ * Checks if the change setCurrent is empty, i.e. does not contain any changes.
*
- * @return true, if the set is empty.
+ * @return true, if the setCurrent is empty.
*/
public boolean isEmpty() {
return this.delta.isEmpty();
}
/**
- * Resets this change set instance. This will clear all changes done to this builder, so the
- * set will be empty.
+ * Resets this change setCurrent instance. This will clear all changes done to this builder, so the
+ * setCurrent will be empty.
*/
public void reset() {
this.delta.clear();
}
/**
- * Builds the corresponding change set.
+ * Builds the corresponding change setCurrent.
*
- * @return the new change set, never null.
+ * @return the new change setCurrent, never null.
*/
public ConfigurationChange build() {
return new ConfigurationChange(this);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/modules/events/src/main/java/org/apache/tamaya/events/FrozenConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/FrozenConfiguration.java b/modules/events/src/main/java/org/apache/tamaya/events/FrozenConfiguration.java
index 21ef873..2707200 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/FrozenConfiguration.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/FrozenConfiguration.java
@@ -117,22 +117,26 @@ public final class FrozenConfiguration implements Configuration, Serializable {
if (value != null) {
List<PropertyConverter<T>> converters = getContext()
.getPropertyConverters(type);
- ConversionContext context = new ConversionContext.Builder(this,
- getContext(), key,type).build();
- for (PropertyConverter<T> converter : converters) {
- try {
- T t = converter.convert(value, context);
- if (t != null) {
- return t;
+ ConversionContext context = new ConversionContext.Builder(this, key,type).build();
+ try {
+ ConversionContext.set(context);
+ for (PropertyConverter<T> converter : converters) {
+ try {
+ T t = converter.convert(value);
+ if (t != null) {
+ return t;
+ }
+ } catch (Exception e) {
+ Logger.getLogger(getClass().getName())
+ .log(Level.FINEST, "PropertyConverter: " + converter + " failed to convert value: " + value,
+ e);
}
- } catch (Exception e) {
- Logger.getLogger(getClass().getName())
- .log(Level.FINEST, "PropertyConverter: " + converter + " failed to convert value: " + value,
- e);
}
+ throw new ConfigException("Unparseable config value for type: " + type.getRawType().getName() + ": " + key
+ + ", supported formats: " + context.getSupportedFormats());
+ }finally{
+ ConversionContext.reset();
}
- throw new ConfigException("Unparseable config value for type: " + type.getRawType().getName() + ": " + key
- + ", supported formats: " + context.getSupportedFormats());
}
return null;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChange.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChange.java b/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChange.java
index e7782a0..d7e73b8 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChange.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChange.java
@@ -29,7 +29,7 @@ import java.util.Map;
import java.util.UUID;
/**
- * Event that contains a set current changes that were applied or could be applied.
+ * Event that contains a setCurrent current changes that were applied or could be applied.
* This class is immutable and thread-safe. To create instances use
* {@link PropertySourceChangeBuilder}.
*
@@ -42,7 +42,7 @@ public final class PropertySourceChange implements ConfigEvent<PropertySource>,
private final FrozenPropertySource propertySource;
/** The base version, usable for optimistic locking. */
private String version = UUID.randomUUID().toString();
- /** The timestamp of the change set in millis from the epoch. */
+ /** The timestamp of the change setCurrent in millis from the epoch. */
private long timestamp = System.currentTimeMillis();
/** The recorded changes. */
private final Map<String,PropertyChangeEvent> changes = new HashMap<>();
@@ -193,8 +193,8 @@ public final class PropertySourceChange implements ConfigEvent<PropertySource>,
}
/**
- * CHecks if the current change set does not contain any changes.
- * @return tru, if the change set is empty.
+ * CHecks if the current change setCurrent does not contain any changes.
+ * @return tru, if the change setCurrent is empty.
*/
public boolean isEmpty(){
return this.changes.isEmpty();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChangeBuilder.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChangeBuilder.java b/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChangeBuilder.java
index 1e58855..51da86d 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChangeBuilder.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/PropertySourceChangeBuilder.java
@@ -31,7 +31,7 @@ import java.util.SortedMap;
import java.util.TreeMap;
/**
- * Models a set current changes applied to a {@link org.apache.tamaya.spi.PropertySource}. Consumers of these events
+ * Models a setCurrent current changes applied to a {@link org.apache.tamaya.spi.PropertySource}. Consumers of these events
* can observing changes to property sources and
* <ol>
* <li>Check if their current configuration instance ({@link org.apache.tamaya.spi.ConfigurationContext}
@@ -109,7 +109,7 @@ public final class PropertySourceChangeBuilder {
}
/*
- * Apply a version/UUID to the set being built.
+ * Apply a version/UUID to the setCurrent being built.
* @param version the version to apply, or null, to let the system generate a version for you.
* @return the builder for chaining.
*/
@@ -119,7 +119,7 @@ public final class PropertySourceChangeBuilder {
}
/*
- * Apply given timestamp to the set being built.
+ * Apply given timestamp to the setCurrent being built.
* @param version the version to apply, or null, to let the system generate a version for you.
* @return the builder for chaining.
*/
@@ -144,7 +144,7 @@ public final class PropertySourceChangeBuilder {
}
/**
- * Get the current values, also considering any changes recorded within this change set.
+ * Get the current values, also considering any changes recorded within this change setCurrent.
*
* @param key the key current the entry, not null.
* @return the keys, or null.
@@ -200,7 +200,7 @@ public final class PropertySourceChangeBuilder {
}
/**
- * This method will create a change set that clears all entries fromMap the given base configuration/properties.
+ * This method will create a change setCurrent that clears all entries fromMap the given base configuration/properties.
*
* @return the builder for chaining.
*/
@@ -213,17 +213,17 @@ public final class PropertySourceChangeBuilder {
}
/**
- * Checks if the change set is empty, i.e. does not contain any changes.
+ * Checks if the change setCurrent is empty, i.e. does not contain any changes.
*
- * @return true, if the set is empty.
+ * @return true, if the setCurrent is empty.
*/
public boolean isEmpty() {
return this.delta.isEmpty();
}
/**
- * Resets this change set instance. This will clear all changes done to this builder, so the
- * set will be empty.
+ * Resets this change setCurrent instance. This will clear all changes done to this builder, so the
+ * setCurrent will be empty.
*/
public void reset() {
this.delta.clear();
@@ -231,9 +231,9 @@ public final class PropertySourceChangeBuilder {
/**
- * Builds the corresponding change set.
+ * Builds the corresponding change setCurrent.
*
- * @return the new change set, never null.
+ * @return the new change setCurrent, never null.
*/
public PropertySourceChange build() {
return new PropertySourceChange(this);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserver.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserver.java b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserver.java
index 51951de..c806446 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserver.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserver.java
@@ -18,6 +18,7 @@
*/
package org.apache.tamaya.events.internal;
+import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
import org.apache.tamaya.events.ConfigEventManager;
import org.apache.tamaya.events.ConfigurationChange;
@@ -61,7 +62,7 @@ public class DefaultConfigChangeObserver {
public void checkConfigurationUpdate() {
LOG.finest("Checking configuration for changes...");
- FrozenConfiguration frozenConfig = FrozenConfiguration.of(ConfigurationProvider.getConfiguration());
+ FrozenConfiguration frozenConfig = FrozenConfiguration.of(Configuration.current());
ConfigurationChange changes;
if (getLastConfig() != null) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpi.java
----------------------------------------------------------------------
diff --git a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpi.java b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpi.java
index bc5fdcf..a0d58bd 100644
--- a/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpi.java
+++ b/modules/events/src/main/java/org/apache/tamaya/events/internal/DefaultConfigEventManagerSpi.java
@@ -52,7 +52,9 @@ public class DefaultConfigEventManagerSpi implements ConfigEventManagerSpi {
*/
public DefaultConfigEventManagerSpi() {
try {
- for (ConfigEventListener l : ServiceContextManager.getServiceContext().getServices(ConfigEventListener.class)) {
+ for (ConfigEventListener l : ServiceContextManager.getServiceContext(
+ Thread.currentThread().getContextClassLoader()
+ ).getServices(ConfigEventListener.class)) {
try {
addListener(l);
} catch (Exception e) {
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/modules/events/src/test/java/org/apache/tamaya/events/ConfigurationChangeTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/ConfigurationChangeTest.java b/modules/events/src/test/java/org/apache/tamaya/events/ConfigurationChangeTest.java
index 60f40c2..b90b0a9 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/ConfigurationChangeTest.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/ConfigurationChangeTest.java
@@ -33,14 +33,14 @@ public class ConfigurationChangeTest {
@Test
public void testEmptyChangeSet() throws Exception {
- ConfigurationChange change = ConfigurationChange.emptyChangeSet(ConfigurationProvider.getConfiguration());
+ ConfigurationChange change = ConfigurationChange.emptyChangeSet(Configuration.current());
assertThat(change).isNotNull();
assertThat(change.getChanges()).isEmpty();
}
@Test
public void testGetConfiguration() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
+ Configuration config = Configuration.current();
ConfigurationChange change = ConfigurationChangeBuilder.of(config).build();
assertNotNull(change);
assertTrue(change.getUpdatedSize()==0);
@@ -48,7 +48,7 @@ public class ConfigurationChangeTest {
assertTrue(change.getRemovedSize()==0);
assertTrue(change.getChanges().size()==0);
for (Map.Entry<String, String> en : config.getProperties().entrySet()) {
- if (!"[meta]frozenAt".equals(en.getKey())) {
+ if (!"[getMeta]frozenAt".equals(en.getKey())) {
if(en.getKey().contains("random.new")){ // dynamic generated value!
continue;
}
@@ -59,7 +59,7 @@ public class ConfigurationChangeTest {
@Test
public void testGetVersion() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
+ Configuration config = Configuration.current();
ConfigurationChange change = ConfigurationChangeBuilder.of(config).build();
assertNotNull(change.getVersion());
change = ConfigurationChangeBuilder.of(config).setVersion("version2").build();
@@ -68,17 +68,18 @@ public class ConfigurationChangeTest {
@Test
public void testGetTimestamp() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
- Thread.sleep(10L);
+ long startTS = System.currentTimeMillis();
+ Configuration config = Configuration.current();
+ Thread.sleep(20L);
ConfigurationChange change = ConfigurationChangeBuilder.of(config).build();
- assertTrue((System.currentTimeMillis() - change.getTimestamp()) > 0L);
+ assertTrue((change.getTimestamp() - startTS) > 0L);
change = ConfigurationChangeBuilder.of(config).setTimestamp(10L).build();
assertEquals(10L, change.getTimestamp());
}
@Test
public void testGetEvents() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
+ Configuration config = Configuration.current();
ConfigurationChange change = ConfigurationChangeBuilder.of(config).removeKey("key1", "key2").build();
assertTrue(change.getChanges().size() == 2);
change = ConfigurationChangeBuilder.of(config).addChange("key1Added", "value1Added").build();
@@ -87,7 +88,7 @@ public class ConfigurationChangeTest {
@Test
public void testGetRemovedSize() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
+ Configuration config = Configuration.current();
ConfigurationChange change = ConfigurationChangeBuilder.of(config).removeKey("java.version", "key2").build();
assertTrue(change.getRemovedSize() == 2);
assertTrue(change.getAddedSize() == 0);
@@ -95,7 +96,7 @@ public class ConfigurationChangeTest {
@Test
public void testGetAddedSize() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
+ Configuration config = Configuration.current();
ConfigurationChange change = ConfigurationChangeBuilder.of(config).addChange("key1", "key2").build();
assertTrue(change.getAddedSize() == 1);
assertTrue(change.getRemovedSize() == 0);
@@ -103,35 +104,35 @@ public class ConfigurationChangeTest {
@Test
public void testGetUpdatedSize() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
+ Configuration config = Configuration.current();
ConfigurationChange change = ConfigurationChangeBuilder.of(config).addChange("java.version", "1.8").build();
assertTrue(change.getUpdatedSize() == 1);
}
@Test
public void testIsRemoved() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
+ Configuration config = Configuration.current();
ConfigurationChange change = ConfigurationChangeBuilder.of(config).removeKey("java.version").build();
assertTrue(change.isRemoved("java.version"));
}
@Test
public void testIsAdded() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
+ Configuration config = Configuration.current();
ConfigurationChange change = ConfigurationChangeBuilder.of(config).addChange("key1", "key2").build();
assertTrue(change.isAdded("key1"));
}
@Test
public void testIsUpdated() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
+ Configuration config = Configuration.current();
ConfigurationChange change = ConfigurationChangeBuilder.of(config).addChange("java.version", "1.8").build();
assertTrue(change.isUpdated("java.version"));
}
@Test
public void testContainsKey() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
+ Configuration config = Configuration.current();
ConfigurationChange change = ConfigurationChangeBuilder.of(config).addChange("key1", "key2").build();
assertTrue(change.isKeyAffected("key1"));
assertFalse(change.isKeyAffected("key2"));
@@ -142,14 +143,14 @@ public class ConfigurationChangeTest {
@Test
public void testIsEmpty() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
+ Configuration config = Configuration.current();
ConfigurationChange change = ConfigurationChangeBuilder.of(config).build();
assertTrue(change.isEmpty());
}
@Test
public void testToString() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
+ Configuration config = Configuration.current();
ConfigurationChange change = ConfigurationChangeBuilder.of(config).removeKey("java.version").build();
String toString =
change.toString();
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/modules/events/src/test/java/org/apache/tamaya/events/RandomPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/RandomPropertySource.java b/modules/events/src/test/java/org/apache/tamaya/events/RandomPropertySource.java
index 4faa1b5..36bcaaa 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/RandomPropertySource.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/RandomPropertySource.java
@@ -52,8 +52,8 @@ public class RandomPropertySource implements PropertySource{
@Override
public Map<String, PropertyValue> getProperties() {
synchronized(data) {
- data.put("random.new", PropertyValue.builder("random.new", String.valueOf(Math.random()), getName())
- .addMetaEntry("_random.new.timestamp", String.valueOf(System.currentTimeMillis())).build());
+ data.put("random.new", PropertyValue.of("random.new", String.valueOf(Math.random()), getName())
+ .setMeta("_random.new.timestamp", String.valueOf(System.currentTimeMillis())));
return new HashMap<>(data);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/modules/events/src/test/java/org/apache/tamaya/events/TestConfigView.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/TestConfigView.java b/modules/events/src/test/java/org/apache/tamaya/events/TestConfigView.java
index b15d966..2ec7c1b 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/TestConfigView.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/TestConfigView.java
@@ -125,20 +125,25 @@ public class TestConfigView implements ConfigOperator{
.getPropertyConverters(type);
ConversionContext context = new ConversionContext.Builder(
key,type).build();
- for (PropertyConverter<T> converter : converters) {
- try {
- T t = converter.convert(value, context);
- if (t != null) {
- return t;
+ try {
+ ConversionContext.set(context);
+ for (PropertyConverter<T> converter : converters) {
+ try {
+ T t = converter.convert(value);
+ if (t != null) {
+ return t;
+ }
+ } catch (Exception e) {
+ Logger.getLogger(getClass().getName())
+ .log(Level.FINEST, "PropertyConverter: " + converter + " failed to convert value: "
+ + value, e);
}
- } catch (Exception e) {
- Logger.getLogger(getClass().getName())
- .log(Level.FINEST, "PropertyConverter: " + converter + " failed to convert value: "
- + value, e);
}
+ throw new ConfigException("Unparseable config value for type: " + type.getRawType().getName() + ": "
+ + key + ", supportedFormats: " + context.getSupportedFormats());
+ }finally{
+ ConversionContext.reset();
}
- throw new ConfigException("Unparseable config value for type: " + type.getRawType().getName() + ": "
- + key + ", supportedFormats: " + context.getSupportedFormats());
}
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/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 c821d43..8cb4d8d 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
@@ -68,7 +68,7 @@ public class ObservingPropertySourceProvider implements PropertySourceProvider,
private final ExecutorService executor = Executors.newSingleThreadExecutor();
/**
- * Constructor using an explicit directory, ignoring all kind of configuration, if set.
+ * Constructor using an explicit directory, ignoring all kind of configuration, if setCurrent.
*
* @param directory the target directory. If null, the default configuration and system property are used.
*/
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/modules/events/src/test/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserverTest.java
----------------------------------------------------------------------
diff --git a/modules/events/src/test/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserverTest.java b/modules/events/src/test/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserverTest.java
index e0fa52b..4bceacc 100644
--- a/modules/events/src/test/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserverTest.java
+++ b/modules/events/src/test/java/org/apache/tamaya/events/internal/DefaultConfigChangeObserverTest.java
@@ -57,7 +57,7 @@ public class DefaultConfigChangeObserverTest {
observer.checkConfigurationUpdate();
- assertThat(observer.getLastConfig()).describedAs("After the firt check last configuration must be set.")
+ assertThat(observer.getLastConfig()).describedAs("After the firt check last configuration must be setCurrent.")
.isNotNull();
}
@@ -71,7 +71,7 @@ public class DefaultConfigChangeObserverTest {
observer.checkConfigurationUpdate();
FrozenConfiguration config2 = observer.getLastConfig();
- assertThat(config1).describedAs("After the firt check last configuration must be set.")
+ assertThat(config1).describedAs("After the firt check last configuration must be setCurrent.")
.isNotEqualTo(config2);
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/modules/filter/pom.xml
----------------------------------------------------------------------
diff --git a/modules/filter/pom.xml b/modules/filter/pom.xml
index 88ebfa6..272f139 100644
--- a/modules/filter/pom.xml
+++ b/modules/filter/pom.xml
@@ -41,6 +41,11 @@ under the License.
</dependency>
<dependency>
<groupId>org.apache.tamaya</groupId>
+ <artifactId>tamaya-spisupport</artifactId>
+ <version>${tamaya-apicore.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-core</artifactId>
<version>${tamaya-apicore.version}</version>
<scope>provided</scope>
@@ -57,7 +62,6 @@ under the License.
<groupId>org.apache.tamaya</groupId>
<artifactId>tamaya-spisupport</artifactId>
<version>${project.version}</version>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/modules/filter/src/main/java/org/apache/tamaya/filter/CompositeFilter.java
----------------------------------------------------------------------
diff --git a/modules/filter/src/main/java/org/apache/tamaya/filter/CompositeFilter.java b/modules/filter/src/main/java/org/apache/tamaya/filter/CompositeFilter.java
new file mode 100644
index 0000000..0189648
--- /dev/null
+++ b/modules/filter/src/main/java/org/apache/tamaya/filter/CompositeFilter.java
@@ -0,0 +1,119 @@
+/*
+ * 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.filter;
+
+import org.apache.tamaya.spi.PropertyFilter;
+import org.apache.tamaya.spi.PropertyValue;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * A setCurrent of property filter and accessor methods. This class is built for
+ * usage within a single threaded context, so it is NOT thread-safe.
+ */
+public final class CompositeFilter implements PropertyFilter{
+ /** The filters. */
+ private List<PropertyFilter> filters = new ArrayList<>();
+
+ /**
+ * Add a filter.
+ * @param filter the filter.
+ */
+ public void addFilter(PropertyFilter filter){
+ filters.add(filter);
+ }
+
+ /**
+ * Adds a filter at given position.
+ * @param pos the position.
+ * @param filter the filter.
+ */
+ public void addFilter(int pos, PropertyFilter filter){
+ filters.add(pos, filter);
+ }
+
+ /**
+ * Removes a filter at a given position.
+ * @param pos the position.
+ * @return the filter removed, or null.
+ */
+ public PropertyFilter removeFilter(int pos){
+ return filters.remove(pos);
+ }
+
+ /**
+ * Removes a filter.
+ * @param filter the filter to be removed, not null.
+ */
+ public void removeFilter(PropertyFilter filter) {
+ filters.remove(filter);
+ }
+
+ /**
+ * Clears all filters.
+ */
+ public void clearFilters(){
+ filters.clear();
+ }
+
+ /**
+ * Set the filters.
+ * @param filters the filters to be applied.
+ */
+ public void setFilters(PropertyFilter... filters){
+ setFilters(Arrays.asList(filters));
+ }
+
+ /**
+ * Set the filters.
+ * @param filters the filters to be applied.
+ */
+ public void setFilters(Collection<PropertyFilter> filters) {
+ this.filters.clear();
+ this.filters.addAll(filters);
+ }
+
+ /**
+ * Get all filters.
+ * @return all filters.
+ */
+ public List<PropertyFilter> getFilters(){
+ return Collections.unmodifiableList(filters);
+ }
+
+ @Override
+ public PropertyValue filterProperty(PropertyValue valueToBeFiltered) {
+ for(PropertyFilter filter:filters){
+ valueToBeFiltered = filter.filterProperty(valueToBeFiltered);
+ }
+ return valueToBeFiltered;
+ }
+
+ @Override
+ public String toString() {
+ return "ProgrammableFilter{" +
+ "filters=" + filters +
+ '}';
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/modules/filter/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java
----------------------------------------------------------------------
diff --git a/modules/filter/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java b/modules/filter/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java
index 7f81dcb..54b0af0 100644
--- a/modules/filter/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java
+++ b/modules/filter/src/main/java/org/apache/tamaya/filter/ConfigurationFilter.java
@@ -21,7 +21,7 @@ package org.apache.tamaya.filter;
import org.apache.tamaya.spi.PropertyFilter;
import org.apache.tamaya.spi.PropertyValue;
import org.osgi.service.component.annotations.Component;
-
+import org.apache.tamaya.spi.FilterContext;
/**
* Hereby
@@ -49,17 +49,17 @@ public final class ConfigurationFilter implements PropertyFilter{
}
};
- private static final ThreadLocal<FilterContext> THREADED_MAP_FILTERS = new ThreadLocal<FilterContext>(){
+ private static final ThreadLocal<CompositeFilter> THREADED_MAP_FILTERS = new ThreadLocal<CompositeFilter>(){
@Override
- protected FilterContext initialValue() {
- return new FilterContext();
+ protected CompositeFilter initialValue() {
+ return new CompositeFilter();
}
};
- private static final ThreadLocal<FilterContext> THREADED_VALUE_FILTERS = new ThreadLocal<FilterContext>(){
+ private static final ThreadLocal<CompositeFilter> THREADED_VALUE_FILTERS = new ThreadLocal<CompositeFilter>(){
@Override
- protected FilterContext initialValue() {
- return new FilterContext();
+ protected CompositeFilter initialValue() {
+ return new CompositeFilter();
}
};
@@ -87,7 +87,7 @@ public final class ConfigurationFilter implements PropertyFilter{
*
* @return the filtering config, never null.
*/
- public static FilterContext getSingleValueFilterContext(){
+ public static CompositeFilter getSingleValueFilterContext(){
return THREADED_VALUE_FILTERS.get();
}
@@ -97,7 +97,7 @@ public final class ConfigurationFilter implements PropertyFilter{
* map.
* @return the filtering config, never null.
*/
- public static FilterContext getMapFilterContext(){
+ public static CompositeFilter getMapFilterContext(){
return THREADED_MAP_FILTERS.get();
}
@@ -111,14 +111,15 @@ public final class ConfigurationFilter implements PropertyFilter{
}
@Override
- public PropertyValue filterProperty(PropertyValue valueToBeFiltered, org.apache.tamaya.spi.FilterContext context) {
- if(context.isSinglePropertyScoped()){
+ public PropertyValue filterProperty(PropertyValue valueToBeFiltered) {
+ FilterContext context = FilterContext.get();
+ if(context==null || context.isSinglePropertyScoped()){
for(PropertyFilter pred: THREADED_VALUE_FILTERS.get().getFilters()){
- valueToBeFiltered = pred.filterProperty(valueToBeFiltered, context);
+ valueToBeFiltered = pred.filterProperty(valueToBeFiltered);
}
}else{
for(PropertyFilter pred: THREADED_MAP_FILTERS.get().getFilters()){
- valueToBeFiltered = pred.filterProperty(valueToBeFiltered, context);
+ valueToBeFiltered = pred.filterProperty(valueToBeFiltered);
}
}
return valueToBeFiltered;
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/modules/filter/src/main/java/org/apache/tamaya/filter/FilterContext.java
----------------------------------------------------------------------
diff --git a/modules/filter/src/main/java/org/apache/tamaya/filter/FilterContext.java b/modules/filter/src/main/java/org/apache/tamaya/filter/FilterContext.java
deleted file mode 100644
index 35eb987..0000000
--- a/modules/filter/src/main/java/org/apache/tamaya/filter/FilterContext.java
+++ /dev/null
@@ -1,119 +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.filter;
-
-import org.apache.tamaya.spi.PropertyFilter;
-import org.apache.tamaya.spi.PropertyValue;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * A set of property filter and accessor methods. This class is built for
- * usage within a single threaded context, so it is NOT thread-safe.
- */
-public final class FilterContext implements PropertyFilter{
- /** The filters. */
- private List<PropertyFilter> filters = new ArrayList<>();
-
- /**
- * Add a filter.
- * @param filter the filter.
- */
- public void addFilter(PropertyFilter filter){
- filters.add(filter);
- }
-
- /**
- * Adds a filter at given position.
- * @param pos the position.
- * @param filter the filter.
- */
- public void addFilter(int pos, PropertyFilter filter){
- filters.add(pos, filter);
- }
-
- /**
- * Removes a filter at a given position.
- * @param pos the position.
- * @return the filter removed, or null.
- */
- public PropertyFilter removeFilter(int pos){
- return filters.remove(pos);
- }
-
- /**
- * Removes a filter.
- * @param filter the filter to be removed, not null.
- */
- public void removeFilter(PropertyFilter filter) {
- filters.remove(filter);
- }
-
- /**
- * Clears all filters.
- */
- public void clearFilters(){
- filters.clear();
- }
-
- /**
- * Set the filters.
- * @param filters the filters to be applied.
- */
- public void setFilters(PropertyFilter... filters){
- setFilters(Arrays.asList(filters));
- }
-
- /**
- * Set the filters.
- * @param filters the filters to be applied.
- */
- public void setFilters(Collection<PropertyFilter> filters) {
- this.filters.clear();
- this.filters.addAll(filters);
- }
-
- /**
- * Get all filters.
- * @return all filters.
- */
- public List<PropertyFilter> getFilters(){
- return Collections.unmodifiableList(filters);
- }
-
- @Override
- public PropertyValue filterProperty(PropertyValue valueToBeFiltered, org.apache.tamaya.spi.FilterContext context) {
- for(PropertyFilter filter:filters){
- valueToBeFiltered = filter.filterProperty(valueToBeFiltered, context);
- }
- return valueToBeFiltered;
- }
-
- @Override
- public String toString() {
- return "ProgrammableFilter{" +
- "filters=" + filters +
- '}';
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/modules/filter/src/main/java/org/apache/tamaya/filter/internal/DefaultMetadataFilter.java
----------------------------------------------------------------------
diff --git a/modules/filter/src/main/java/org/apache/tamaya/filter/internal/DefaultMetadataFilter.java b/modules/filter/src/main/java/org/apache/tamaya/filter/internal/DefaultMetadataFilter.java
index e9554a2..fbfcb36 100644
--- a/modules/filter/src/main/java/org/apache/tamaya/filter/internal/DefaultMetadataFilter.java
+++ b/modules/filter/src/main/java/org/apache/tamaya/filter/internal/DefaultMetadataFilter.java
@@ -19,17 +19,18 @@
package org.apache.tamaya.filter.internal;
import org.apache.tamaya.filter.ConfigurationFilter;
-import org.apache.tamaya.spi.FilterContext;
import org.apache.tamaya.spi.PropertyFilter;
import org.apache.tamaya.spi.PropertyValue;
+import org.apache.tamaya.spi.FilterContext;
/**
* Default property filter that hides metadta entries starting with an '_', similar ti {@code etcd}.
*/
public final class DefaultMetadataFilter implements PropertyFilter{
@Override
- public PropertyValue filterProperty(PropertyValue valueToBeFiltered, FilterContext context) {
- if(context.isSinglePropertyScoped()){
+ public PropertyValue filterProperty(PropertyValue valueToBeFiltered) {
+ FilterContext context = FilterContext.get();
+ if(context==null || context.isSinglePropertyScoped()){
// When accessing keys explicitly, do not hide anything.
return valueToBeFiltered;
}
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/modules/filter/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java
----------------------------------------------------------------------
diff --git a/modules/filter/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java b/modules/filter/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java
index a3a75a3..1b812ea 100644
--- a/modules/filter/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java
+++ b/modules/filter/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java
@@ -20,7 +20,6 @@ package org.apache.tamaya.filter;
import org.apache.tamaya.Configuration;
import org.apache.tamaya.ConfigurationProvider;
-import org.apache.tamaya.spi.FilterContext;
import org.apache.tamaya.spi.PropertyFilter;
import org.apache.tamaya.spi.PropertyValue;
import org.junit.Test;
@@ -42,12 +41,12 @@ public class ConfigurationFilterTest {
@Test
public void testGetSingleFilters() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
+ Configuration config = Configuration.current();
assertNotNull(ConfigurationFilter.getSingleValueFilterContext());
PropertyFilter testFilter = new PropertyFilter() {
@Override
- public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- return value.toBuilder().setValue(value.getKey() + ":testGetSingleFilters").build();
+ public PropertyValue filterProperty(PropertyValue value) {
+ return value.setValue(value.getKey() + ":testGetSingleFilters");
}
};
ConfigurationFilter.getSingleValueFilterContext().addFilter(testFilter);
@@ -58,12 +57,12 @@ public class ConfigurationFilterTest {
@Test
public void testRemoveSingleFiltersAt0() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
+ Configuration config = Configuration.current();
assertNotNull(ConfigurationFilter.getSingleValueFilterContext());
PropertyFilter testFilter = new PropertyFilter() {
@Override
- public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- return value.toBuilder().setValue(value.getKey() + ":testGetSingleFilters").build();
+ public PropertyValue filterProperty(PropertyValue value) {
+ return value.setValue(value.getKey() + ":testGetSingleFilters");
}
};
ConfigurationFilter.getSingleValueFilterContext().addFilter(testFilter);
@@ -74,12 +73,12 @@ public class ConfigurationFilterTest {
@Test
public void testGetMapFilters() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
+ Configuration config = Configuration.current();
assertNotNull(ConfigurationFilter.getMapFilterContext());
PropertyFilter testFilter = new PropertyFilter() {
@Override
- public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- return value.toBuilder().setValue(value.getKey() + ":testGetMapFilters").build();
+ public PropertyValue filterProperty(PropertyValue value) {
+ return value.setValue(value.getKey() + ":testGetMapFilters");
}
};
ConfigurationFilter.getMapFilterContext().addFilter(testFilter);
@@ -90,12 +89,12 @@ public class ConfigurationFilterTest {
@Test
public void testRemoveMapFilterAt0() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
+ Configuration config = Configuration.current();
assertNotNull(ConfigurationFilter.getMapFilterContext());
PropertyFilter testFilter = new PropertyFilter() {
@Override
- public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- return value .toBuilder().setValue(value.getKey() + ":testGetMapFilters").build();
+ public PropertyValue filterProperty(PropertyValue value) {
+ return value.setValue(value.getKey() + ":testGetMapFilters");
}
};
ConfigurationFilter.getMapFilterContext().addFilter(testFilter);
@@ -106,12 +105,12 @@ public class ConfigurationFilterTest {
@Test
public void testClearFilters() throws Exception {
- Configuration config = ConfigurationProvider.getConfiguration();
+ Configuration config = Configuration.current();
assertNotNull(ConfigurationFilter.getSingleValueFilterContext());
PropertyFilter testFilter = new PropertyFilter() {
@Override
- public PropertyValue filterProperty(PropertyValue value, FilterContext context) {
- return value.toBuilder().setValue(value.getKey() + ":testGetSingleFilters").build();
+ public PropertyValue filterProperty(PropertyValue value) {
+ return value.setValue(value.getKey() + ":testGetSingleFilters");
}
};
ConfigurationFilter.getSingleValueFilterContext().addFilter(testFilter);
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/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 b6e7bb7..ef28970 100644
--- a/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java
+++ b/modules/filter/src/test/java/org/apache/tamaya/filter/ProgrammableFilterTest.java
@@ -19,6 +19,7 @@
package org.apache.tamaya.filter;
import org.apache.tamaya.spi.ConfigurationContext;
+import org.apache.tamaya.spi.FilterContext;
import org.apache.tamaya.spi.PropertyFilter;
import org.apache.tamaya.spi.PropertyValue;
import org.apache.tamaya.spisupport.DefaultConfigurationContextBuilder;
@@ -32,7 +33,7 @@ import java.util.Map;
import static org.junit.Assert.*;
/**
- * Tests for {@link FilterContext}. Created by atsticks on 11.02.16.
+ * Tests for {@link CompositeFilter}. Created by atsticks on 11.02.16.
*/
public class ProgrammableFilterTest {
@@ -43,85 +44,148 @@ public class ProgrammableFilterTest {
@Test
public void testAddRemoveFilter() throws Exception {
- FilterContext filter = new FilterContext();
+ CompositeFilter filter = new CompositeFilter();
Map<String,PropertyValue> map = new HashMap<>();
- assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext(test1Property, map, context)), test1Property);
- assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext(test2Property, map, context)), test2Property);
- assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext(test3Property, map, context)), test3Property);
- RegexPropertyFilter regexFilter = new RegexPropertyFilter();
- regexFilter.setIncludes("test\\..*");
- filter.addFilter(regexFilter);
- assertNull(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext(test1Property, map, context)));
- assertNull(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext(test2Property, map, context)));
- assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext(test3Property, map, context)), test3Property);
- filter.removeFilter(0);
- assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext(test1Property, map, context)), test1Property);
- assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext(test2Property, map, context)), test2Property);
- assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext(test3Property, map, context)), test3Property);
- filter.addFilter(0, regexFilter);
- assertNull(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext(test1Property, map, context)));
- assertNull(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext(test2Property, map, context)));
- assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext(test3Property, map, context)), test3Property);
+ FilterContext context1 = new FilterContext(test1Property, map, context);
+ FilterContext context2 = new FilterContext(test2Property, map, context);
+ FilterContext context3 = new FilterContext(test3Property, map, context);
+ try{
+ FilterContext.set(context1);
+ assertEquals(filter.filterProperty(test1Property), test1Property);
+ FilterContext.set(context2);
+ assertEquals(filter.filterProperty(test2Property), test2Property);
+ FilterContext.set(context3);
+ assertEquals(filter.filterProperty(test3Property), test3Property);
+ RegexPropertyFilter regexFilter = new RegexPropertyFilter();
+ regexFilter.setIncludes("test\\..*");
+ filter.addFilter(regexFilter);
+ FilterContext.set(context1);
+ assertNull(filter.filterProperty(test1Property));
+ FilterContext.set(context2);
+ assertNull(filter.filterProperty(test2Property));
+ FilterContext.set(context3);
+ assertEquals(filter.filterProperty(test3Property), test3Property);
+ filter.removeFilter(0);
+ FilterContext.set(context1);
+ assertEquals(filter.filterProperty(test1Property), test1Property);
+ FilterContext.set(context2);
+ assertEquals(filter.filterProperty(test2Property), test2Property);
+ FilterContext.set(context3);
+ assertEquals(filter.filterProperty(test3Property), test3Property);
+ filter.addFilter(0, regexFilter);
+ FilterContext.set(context1);
+ assertNull(filter.filterProperty(test1Property));
+ FilterContext.set(context2);
+ assertNull(filter.filterProperty(test2Property));
+ FilterContext.set(context3);
+ assertEquals(filter.filterProperty(test3Property), test3Property);
+ }finally {
+ FilterContext.reset();
+ }
}
@Test
public void testClearFilters() throws Exception {
- FilterContext filter = new FilterContext();
+ CompositeFilter filter = new CompositeFilter();
RegexPropertyFilter regexFilter = new RegexPropertyFilter();
regexFilter.setIncludes("test1.*");
Map<String,String> map = new HashMap<>();
map.put("test1", "test1");
map.put("test2", "test2");
map.put("test.test3", "test.test3");
- assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext(test1Property, context)), test1Property);
- assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext(test2Property, context)), test2Property);
- assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext(test3Property, context)), test3Property);
- filter.addFilter(regexFilter);
- assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext(test1Property, context)), test1Property);
- assertNull(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext(test2Property, context)));
- assertNull(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext(test3Property, context)));
- filter.clearFilters();
- assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext(test1Property, context)), test1Property);
- assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext(test2Property, context)), test2Property);
- assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext(test3Property, context)), test3Property);
+
+ FilterContext context1 = new FilterContext(test1Property, context);
+ FilterContext context2 = new FilterContext(test2Property, context);
+ FilterContext context3 = new FilterContext(test3Property, context);
+ try{
+ FilterContext.set(context1);
+ assertEquals(filter.filterProperty(test1Property), test1Property);
+ FilterContext.set(context2);
+ assertEquals(filter.filterProperty(test2Property), test2Property);
+ FilterContext.set(context3);
+ assertEquals(filter.filterProperty(test3Property), test3Property);
+ filter.addFilter(regexFilter);
+ FilterContext.set(context1);
+ assertEquals(filter.filterProperty(test1Property), test1Property);
+ FilterContext.set(context2);
+ assertNull(filter.filterProperty(test2Property));
+ FilterContext.set(context3);
+ assertNull(filter.filterProperty(test3Property));
+ filter.clearFilters();
+ FilterContext.set(context1);
+ assertEquals(filter.filterProperty(test1Property), test1Property);
+ FilterContext.set(context2);
+ assertEquals(filter.filterProperty(test2Property), test2Property);
+ FilterContext.set(context3);
+ assertEquals(filter.filterProperty(test3Property), test3Property);
+ }finally {
+ FilterContext.reset();
+ }
}
@Test
public void testSetFilters() throws Exception {
- FilterContext filter = new FilterContext();
+ CompositeFilter filter = new CompositeFilter();
RegexPropertyFilter regexFilter = new RegexPropertyFilter();
regexFilter.setIncludes("test\\..*");
Map<String,PropertyValue> map = new HashMap<>();
map.put("test1", test1Property);
map.put("test2", test1Property);
map.put("test.test3", test3Property);
- assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext(test1Property, context)), test1Property);
- assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext(test2Property, map, context)), test2Property);
- assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext(test3Property, map, context)), test3Property);
- filter.setFilters(regexFilter);
- assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext(test3Property, map, context)), test3Property);
- assertNull(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext(test2Property, map, context)));
- assertNull(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext(test1Property, map, context)));
+
+ FilterContext context1 = new FilterContext(test1Property, map, context);
+ FilterContext context2 = new FilterContext(test2Property, map, context);
+ FilterContext context3 = new FilterContext(test3Property, map, context);
+ try{
+ FilterContext.set(context1);
+ assertEquals(filter.filterProperty(test1Property), test1Property);
+ FilterContext.set(context2);
+ assertEquals(filter.filterProperty(test2Property), test2Property);
+ FilterContext.set(context3);
+ assertEquals(filter.filterProperty(test3Property), test3Property);
+ filter.setFilters(regexFilter);
+ FilterContext.set(context1);
+ assertEquals(filter.filterProperty(test3Property), test3Property);
+ FilterContext.set(context2);
+ assertNull(filter.filterProperty(test2Property));
+ FilterContext.set(context3);
+ assertNull(filter.filterProperty(test1Property));
+ }finally {
+ FilterContext.reset();
+ }
}
@Test
public void testSetFilters1() throws Exception {
- FilterContext filter = new FilterContext();
+ CompositeFilter filter = new CompositeFilter();
RegexPropertyFilter regexFilter = new RegexPropertyFilter();
regexFilter.setIncludes("test1.*");
- Map<String,String> map = new HashMap<>();
- assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext(test1Property, context)), test1Property);
- assertEquals(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext(test2Property, context)), test2Property);
- assertEquals(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext(test3Property, context)), test3Property);
- filter.setFilters(Arrays.asList(new PropertyFilter[]{regexFilter}));
- assertEquals(filter.filterProperty(test1Property, new org.apache.tamaya.spi.FilterContext(test1Property, context)), test1Property);
- assertNull(filter.filterProperty(test2Property, new org.apache.tamaya.spi.FilterContext(test2Property, context)));
- assertNull(filter.filterProperty(test3Property, new org.apache.tamaya.spi.FilterContext(test3Property, context)));
+
+ FilterContext context1 = new FilterContext(test1Property, context);
+ FilterContext context2 = new FilterContext(test2Property, context);
+ FilterContext context3 = new FilterContext(test3Property, context);
+ try {
+ FilterContext.set(context1);
+ assertEquals(filter.filterProperty(test1Property), test1Property);
+ FilterContext.set(context2);
+ assertEquals(filter.filterProperty(test2Property), test2Property);
+ FilterContext.set(context3);
+ assertEquals(filter.filterProperty(test3Property), test3Property);
+ filter.setFilters(Arrays.asList(new PropertyFilter[]{regexFilter}));
+ FilterContext.set(context1);
+ assertEquals(filter.filterProperty(test1Property), test1Property);
+ FilterContext.set(context2);
+ assertNull(filter.filterProperty(test2Property));
+ FilterContext.set(context3);
+ assertNull(filter.filterProperty(test3Property));
+ }finally {
+ FilterContext.reset();
+ }
}
@Test
public void testGetFilters() throws Exception {
- FilterContext filter = new FilterContext();
+ CompositeFilter filter = new CompositeFilter();
assertNotNull(filter.getFilters());
assertTrue(filter.getFilters().isEmpty());
RegexPropertyFilter regexFilter = new RegexPropertyFilter();
@@ -135,7 +199,7 @@ public class ProgrammableFilterTest {
@Test
public void testToString() throws Exception {
- FilterContext filter = new FilterContext();
+ CompositeFilter filter = new CompositeFilter();
assertFalse(filter.toString().contains("test\\..*"));
assertTrue(filter.toString().contains("ProgrammableFilter"));
assertFalse(filter.toString().contains("RegexPropertyFilter"));
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/ade6eb8b/modules/formats/base/src/main/java/org/apache/tamaya/format/BaseFormatPropertySourceProvider.java
----------------------------------------------------------------------
diff --git a/modules/formats/base/src/main/java/org/apache/tamaya/format/BaseFormatPropertySourceProvider.java b/modules/formats/base/src/main/java/org/apache/tamaya/format/BaseFormatPropertySourceProvider.java
index a0f1fdd..0e4c72e 100644
--- a/modules/formats/base/src/main/java/org/apache/tamaya/format/BaseFormatPropertySourceProvider.java
+++ b/modules/formats/base/src/main/java/org/apache/tamaya/format/BaseFormatPropertySourceProvider.java
@@ -20,6 +20,7 @@ package org.apache.tamaya.format;
import org.apache.tamaya.spi.PropertySource;
import org.apache.tamaya.spi.PropertySourceProvider;
+import org.apache.tamaya.spi.PropertyValue;
import java.io.IOException;
import java.io.InputStream;
@@ -37,7 +38,7 @@ import java.util.logging.Logger;
* Implementation of a {@link PropertySourceProvider} that reads configuration from some given resource paths
* and using the given formats. The resource path are resolved as classpath resources. This can be changed by
* overriding {@link #getPropertySources()}.
- * For each resource found the configuration formats passed get a chance to read the resource, if they succeed the
+ * For each resource found the configuration formats passed getChild a chance to read the resource, if they succeed the
* result is taken as the providers PropertySources to be exposed.
*/
public abstract class BaseFormatPropertySourceProvider implements PropertySourceProvider {
@@ -129,8 +130,8 @@ public abstract class BaseFormatPropertySourceProvider implements PropertySource
protected abstract Collection<PropertySource> getPropertySources(ConfigurationData data);
/**
- * This method does dynamically resolve the paths using the current ClassLoader set. If no ClassLoader was
- * explcitly set during creation the current Thread context ClassLoader is used. If none of the supported
+ * This method does dynamically resolve the paths using the current ClassLoader setCurrent. If no ClassLoader was
+ * explcitly setCurrent during creation the current Thread context ClassLoader is used. If none of the supported
* formats is able to parse a resource a WARNING log is written.
*
* @return the PropertySources successfully read