Rewrite/adaptation based on JSR API. Signed-off-by: Anatole Tresch <[email protected]>
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/cfb364cd Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/cfb364cd Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/cfb364cd Branch: refs/heads/configjsr Commit: cfb364cd4e201d59102343209eafbb7e4c0196ce Parents: 4869d94 Author: Anatole Tresch <[email protected]> Authored: Wed Jan 3 00:55:22 2018 +0100 Committer: Anatole Tresch <[email protected]> Committed: Wed Jan 3 00:55:32 2018 +0100 ---------------------------------------------------------------------- .../tamaya/ext/examples/resources/Main.java | 29 ++- .../resources/MyPathConfigSourceProvider.java | 39 +++ .../resources/MyPathPropertySourceProvider.java | 39 --- ...org.apache.tamaya.spi.PropertySourceProvider | 2 +- .../tamay/ext/examples/resolver/Main.java | 29 ++- .../tamaya/ext/examples/injection/Example.java | 6 +- .../ext/examples/injection/ExampleTemplate.java | 6 +- .../ext/examples/injection/MinimalTest.java | 45 ++-- .../resources/META-INF/javaconfig.properties | 25 ++ .../META-INF/javaconfiguration.properties | 25 -- .../events/FileConfigSourceProvider.java | 71 ++++++ .../events/FilePropertySourceProvider.java | 73 ------ .../apache/tamaya/ext/examples/events/Main.java | 14 +- .../javax.config.spi.ConfigSourceProvider | 20 ++ ...org.apache.tamaya.spi.PropertySourceProvider | 20 -- .../tamaya/springexample/ColorConverter.java | 8 +- .../tamaya/springexample/WelcomeController.java | 29 ++- modules/features/pom.xml | 14 +- .../org/apache/tamaya/features/Features.java | 16 +- .../apache/tamaya/features/FeaturesTest.java | 9 +- .../tamaya/features/FeaturesTestNoOnly.java | 4 +- modules/filter/bnd.bnd | 6 +- modules/filter/pom.xml | 13 +- .../tamaya/filter/ConfigurationFilter.java | 114 +++++---- .../java/org/apache/tamaya/filter/Context.java | 123 ++++++++++ .../filter/internal/DefaultMetadataFilter.java | 14 +- .../services/org.apache.tamaya.spi.Filter | 19 ++ .../org.apache.tamaya.spi.PropertyFilter | 19 -- .../tamaya/filter/ConfigurationFilterTest.java | 123 ---------- .../tamaya/filter/ProgrammableFilterTest.java | 149 ----------- .../filter/ConfigurationFilterTest.java | 95 +++++++ .../filter/ProgrammableFilterTest.java | 183 ++++++++++++++ modules/formats/base/pom.xml | 8 +- .../format/BaseFormatConfigSourceProvider.java | 159 ++++++++++++ .../BaseFormatPropertySourceProvider.java | 160 ------------ .../tamaya/format/ConfigurationFormats.java | 46 ++-- .../MappedConfigurationDataConfigSource.java | 152 ++++++++++++ .../MappedConfigurationDataPropertySource.java | 157 ------------ .../format/formats/IniConfigurationFormat.java | 3 +- .../format/FormatConfigSourceProviderTest.java | 58 +++++ .../FormatPropertySourceProviderTest.java | 50 ---- ...ppedConfigurationDataPropertySourceTest.java | 43 ++-- modules/formats/json/pom.xml | 9 +- .../apache/tamaya/json/JSONConfigSource.java | 148 +++++++++++ .../apache/tamaya/json/JSONPropertySource.java | 155 ------------ .../org/apache/tamaya/json/JSONVisitor.java | 54 +++- .../org/apache/tamaya/json/JSONVisitorTest.java | 3 +- .../yaml/CommonJSONTestCaseCollection.java | 84 +++---- .../org/apache/tamaya/yaml/JSONFormatTest.java | 8 +- .../tamaya/yaml/JSONPropertySourceTest.java | 13 +- .../resources/configs/invalid/with-array.json | 27 -- .../resources/configs/valid/with-array.json | 27 ++ .../configs/valid/with-explicit-priority.json | 2 +- modules/injection/cdi/pom.xml | 8 +- .../tamaya/cdi/CDIAwareServiceContext.java | 34 ++- .../apache/tamaya/cdi/CDIConfiguredField.java | 4 +- .../apache/tamaya/cdi/CDIConfiguredMethod.java | 4 +- .../apache/tamaya/cdi/CDIConfiguredType.java | 4 +- .../org/apache/tamaya/cdi/ConfigProducer.java | 200 +++++++++++++++ .../tamaya/cdi/ConfigurationProducer.java | 202 --------------- .../apache/tamaya/cdi/DefaultDynamicValue.java | 67 +++-- .../tamaya/cdi/ServiceLoaderServiceContext.java | 34 ++- .../tamaya/cdi/TamayaCDIInjectionExtension.java | 68 +++-- .../tamaya/cdi/TamayaSEInjectionExtension.java | 6 +- .../cdi/extra/ConfiguredVetoExtension.java | 5 +- .../tamaya/cdi/BaseTestConfiguration.java | 4 +- .../tamaya/cdi/ConfigurationProducerTest.java | 42 ++-- .../org/apache/tamaya/cdi/ConfiguredClass.java | 25 +- .../org/apache/tamaya/cdi/ConfiguredTest.java | 8 +- .../org/apache/tamaya/cdi/InjectedClass.java | 21 +- .../apache/tamaya/cdi/NotFoundNoDefault.java | 13 +- .../tamaya/cdi/cfg/ProvidedConfigSource.java | 60 +++++ .../tamaya/cdi/cfg/ProvidedPropertySource.java | 66 ----- .../tamaya/cdi/cfg/TestConfigProvider.java | 13 +- .../tamaya/cdi/cfg/TestPropertySource.java | 22 +- .../cdi/extra/ConfiguredVetoExtensionTest.java | 40 ++- .../resources/META-INF/javaconfig.properties | 35 +++ .../META-INF/javaconfiguration.properties | 35 --- modules/injection/injection-api/pom.xml | 8 +- .../org/apache/tamaya/inject/api/Config.java | 125 ---------- .../tamaya/inject/api/ConfigAutoDetect.java | 51 ++++ .../tamaya/inject/api/ConfigAutoInject.java | 51 ---- .../inject/api/ConfigDefaultSections.java | 2 +- .../tamaya/inject/api/ConfigFallbackKeys.java | 45 ++++ .../apache/tamaya/inject/api/DynamicValue.java | 7 +- .../apache/tamaya/inject/api/LoadPolicy.java | 4 +- .../tamaya/inject/api/OptionalConfig.java | 37 +++ .../apache/tamaya/inject/api/UpdatePolicy.java | 10 - .../tamaya/inject/api/WithConfigOperator.java | 45 ---- .../apache/tamaya/inject/api/WithConverter.java | 45 ++++ .../inject/api/WithPropertyConverter.java | 46 ---- .../apache/tamaya/inject/api/package-info.java | 2 +- .../tamaya/inject/spi/BaseDynamicValue.java | 66 ++--- .../tamaya/inject/spi/ConfiguredField.java | 5 +- .../tamaya/inject/spi/ConfiguredMethod.java | 7 +- .../tamaya/inject/spi/ConfiguredType.java | 5 +- .../tamaya/inject/spi/InjectionEvaluator.java | 159 ++++++++++++ .../tamaya/inject/spi/InjectionUtils.java | 130 ---------- .../tamaya/inject/spi/BaseDynamicValueTest.java | 14 +- .../tamaya/inject/spi/InjectionUtilsTest.java | 24 +- modules/injection/pom.xml | 9 + modules/injection/standalone/pom.xml | 2 +- .../tamaya/inject/ConfigurationInjector.java | 16 +- .../ConfigTemplateInvocationHandler.java | 10 +- .../inject/internal/ConfiguredFieldImpl.java | 52 ++-- .../inject/internal/ConfiguredSetterMethod.java | 32 +-- .../inject/internal/ConfiguredTypeImpl.java | 36 +-- .../internal/DefaultConfigurationInjector.java | 47 ++-- .../inject/internal/DefaultDynamicValue.java | 104 ++++---- .../tamaya/inject/internal/InjectionHelper.java | 210 ++++++++-------- .../java/annottext/AnnotatedConfigBean.java | 17 +- .../java/annottext/AnnotatedConfigTemplate.java | 16 +- .../annottext/InheritedAnnotatedConfigBean.java | 5 +- .../java/annottext/NonAnnotatedConfigBean.java | 7 - .../apache/tamaya/inject/TestConfigSource.java | 69 ++++++ .../tamaya/inject/TestPropertySource.java | 73 ------ .../internal/DefaultDynamicValueTest.java | 77 +++--- .../services/javax.config.spi.ConfigSource | 19 ++ .../org.apache.tamaya.spi.PropertySource | 19 -- modules/jndi/pom.xml | 8 +- .../apache/tamaya/jndi/JNDIConfigSource.java | 182 ++++++++++++++ .../apache/tamaya/jndi/JNDIPropertySource.java | 188 -------------- .../org.apache.tamaya.spi.PropertySource | 2 +- .../tamaya/jndi/JNDIConfigSourceTest.java | 72 ++++++ .../tamaya/jndi/JNDIPropertySourceTest.java | 75 ------ modules/microprofile/bnd.bnd | 34 --- modules/microprofile/pom.xml | 166 ------------- .../microprofile/MicroprofileAdapter.java | 185 -------------- .../tamaya/microprofile/MicroprofileConfig.java | 100 -------- .../microprofile/MicroprofileConfigBuilder.java | 140 ----------- .../MicroprofileConfigProviderResolver.java | 82 ------- .../microprofile/MicroprofileConfigSource.java | 78 ------ .../MicroprofileConfigSourceProvider.java | 64 ----- .../microprofile/MicroprofileConverter.java | 50 ---- .../MicroprofileDefaultProperties.java | 33 --- .../microprofile/TamayaConfiguration.java | 93 ------- .../microprofile/TamayaPropertyConverter.java | 48 ---- .../microprofile/TamayaPropertySource.java | 78 ------ .../TamayaPropertySourceProvider.java | 56 ----- .../microprofile/cdi/BridgingConfigBean.java | 95 ------- .../microprofile/cdi/ConfiguredField.java | 65 ----- .../microprofile/cdi/ConfiguredMethod.java | 65 ----- .../tamaya/microprofile/cdi/ConfiguredType.java | 86 ------- .../cdi/MicroprofileCDIExtension.java | 127 ---------- .../cdi/MicroprofileConfigurationProducer.java | 156 ------------ .../converter/BooleanAsIntegerConverterFix.java | 61 ----- .../converter/ProviderConverter.java | 98 -------- .../javax.enterprise.inject.spi.Extension | 20 -- .../org.apache.tamaya.spi.PropertyConverter | 21 -- .../org.apache.tamaya.spi.PropertySource | 20 -- ...croprofile.config.spi.ConfigProviderResolver | 20 -- .../microprofile/src/main/resources/beans.xml | 25 -- .../microprofile/BuildableConfigSource.java | 180 -------------- .../tamaya/microprofile/ConfigSourceParis.java | 45 ---- .../microprofile/ConfigSourceProviderMinsk.java | 31 --- .../microprofile/MicroprofileAdapterTest.java | 246 ------------------- .../MicroprofileConfigBuilderTest.java | 127 ---------- .../MicroprofileConfigProviderResolverTest.java | 73 ------ .../MicroprofileConfigProviderTest.java | 62 ----- .../MicroprofileConfigSourceProviderTest.java | 44 ---- .../microprofile/MicroprofileConfigTest.java | 95 ------- .../microprofile/MicroprofileConverterTest.java | 42 ---- .../MicroprofileDefaultPropertiesTest.java | 32 --- .../microprofile/TamayaPropertySourceTest.java | 50 ---- .../tamaya/microprofile/UppercaseConverter.java | 34 --- .../UppercasePropertyConverter.java | 36 --- .../tck/TamayaConfigArchiveProcessor.java | 79 ------ .../microprofile/tck/TamayaConfigExtension.java | 36 --- .../src/test/resources/META-INF/beans.xml | 24 -- .../META-INF/microprofile-config.properties | 105 -------- ...eclipse.microprofile.config.spi.ConfigSource | 19 -- ...microprofile.config.spi.ConfigSourceProvider | 19 -- ....jboss.arquillian.core.spi.LoadableExtension | 19 -- .../src/test/resources/sampleconfig.yaml | 18 -- modules/microprofile/src/test/tck-suite.xml | 27 -- modules/mutable-config/pom.xml | 7 +- .../mutableconfig/ChangePropagationPolicy.java | 10 +- .../mutableconfig/ConfigChangeRequest.java | 4 +- .../mutableconfig/MutableConfiguration.java | 31 +-- .../MutableConfigurationProvider.java | 60 +++-- .../internal/DefaultMutableConfiguration.java | 86 ++----- .../DefaultMutableConfigurationSpi.java | 7 +- .../MutablePropertiesConfigSource.java | 159 ++++++++++++ .../MutablePropertiesPropertySource.java | 164 ------------- .../MutableXmlPropertiesConfigSource.java | 162 ++++++++++++ .../MutableXmlPropertiesPropertySource.java | 171 ------------- .../mutableconfig/spi/MutableConfigSource.java | 49 ++++ .../spi/MutableConfigurationProviderSpi.java | 5 +- .../spi/MutablePropertySource.java | 48 ---- .../MutableConfigurationProviderTest.java | 7 +- .../mutableconfig/MutableConfigurationTest.java | 21 +- .../PropertiesFileConfigBackendTest.java | 4 +- .../internal/WritablePropertiesSource.java | 6 +- .../internal/WritableXmlPropertiesSource.java | 6 +- .../services/javax.config.spi.ConfigSource | 20 ++ .../org.apache.tamaya.spi.PropertySource | 20 -- modules/optional/pom.xml | 7 - .../tamaya/optional/OptionalConfiguration.java | 23 +- modules/osgi/common/bnd.bnd | 2 +- modules/osgi/common/pom.xml | 10 +- .../org/apache/tamaya/osgi/ConfigChanger.java | 40 +-- .../apache/tamaya/osgi/TamayaConfigPlugin.java | 5 +- .../tamaya/osgi/commands/ConfigCommands.java | 81 +++--- .../tamaya/osgi/TamayaConfigPluginTest.java | 7 +- .../osgi/commands/ConfigCommandsTest.java | 9 +- .../resources/META-INF/javaconfig.properties | 22 ++ .../META-INF/javaconfiguration.properties | 22 -- modules/osgi/gogo-shell/bnd.bnd | 2 +- modules/osgi/gogo-shell/pom.xml | 6 + .../tamaya/gogo/shell/ConfigCommandsTest.java | 10 +- modules/osgi/injection/bnd.bnd | 2 +- modules/osgi/injection/pom.xml | 6 + .../OSGIConfigAdminPropertySource.java | 15 +- .../injection/OSGIConfigurationInjector.java | 23 +- .../osgi/injection/TamayaOSGIInjector.java | 1 - .../apache/tamaya/osgi/injection/Example.java | 9 +- .../OSGIConfigAdminPropertySourceTest.java | 22 +- .../tamaya/osgi/injection/TemplateExample.java | 9 +- .../src/main/features/features.xml | 2 +- modules/osgi/karaf-shell/bnd.bnd | 2 +- .../karaf/shell/PropertySourcesCommand.java | 3 - modules/osgi/updater/bnd.bnd | 2 +- modules/osgi/updater/pom.xml | 8 +- .../apache/tamaya/osgi/updater/Activator.java | 6 +- .../tamaya/osgi/updater/EventListener.java | 4 +- .../tamaya/osgi/updater/EventListenerTest.java | 6 +- modules/pom.xml | 2 +- .../internal/ExpressionResolutionFilter.java | 9 +- .../resolver/internal/ResolvableConfig.java | 17 +- .../resolver/spi/ExpressionEvaluator.java | 2 +- modules/spring/pom.xml | 6 - .../SpringConfigInjectionPostProcessor.java | 8 +- .../integration/spring/TamayaEnvironment.java | 2 +- .../integration/spring/TamayaSpringConfig.java | 6 +- .../spring/TamayaSpringConfigSource.java | 40 +++ .../spring/TamayaSpringPropertySource.java | 39 --- .../spring/ConfiguredSpringBean.java | 7 +- .../integration/spring/SpringConfigTest2.java | 4 - .../resources/META-INF/javaconfig.properties | 20 ++ .../META-INF/javaconfiguration.properties | 20 -- pom.xml | 22 +- 241 files changed, 3802 insertions(+), 7326 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/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..f6b3d6f 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 @@ -18,9 +18,8 @@ */ package org.apache.tamaya.ext.examples.resources; -import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; - +import javax.config.Config; +import javax.config.ConfigProvider; import java.io.PrintStream; import java.util.Map; import java.util.TreeMap; @@ -43,7 +42,7 @@ public class Main { } public static void main(String[] args){ - Configuration cfg = ConfigurationProvider.getConfiguration(); + Config cfg = ConfigProvider.getConfig(); System.out.println("****************************************************"); System.out.println("Example for an property sources using a "); @@ -51,23 +50,23 @@ public class Main { System.out.println("****************************************************"); System.out.println(); System.out.println("Example Metadata:"); - System.out.println("\tType : " + cfg.get("example.type")); - System.out.println("\tName : " + cfg.get("example.name")); - System.out.println("\tDescription : " + cfg.get("example.description")); - System.out.println("\tVersion : " + cfg.get("example.version")); - System.out.println("\tAuthor : " + cfg.get("example.author")); + System.out.println("\tType : " + cfg.getValue("example.type", String.class)); + System.out.println("\tName : " + cfg.getValue("example.name", String.class)); + System.out.println("\tDescription : " + cfg.getValue("example.description", String.class)); + System.out.println("\tVersion : " + cfg.getValue("example.version", String.class)); + System.out.println("\tAuthor : " + cfg.getValue("example.author", String.class)); System.out.println(); - System.out.println("\tPath : " + cfg.get("Path")); - System.out.println("\taProp : " + cfg.get("aProp")); + System.out.println("\tPath : " + cfg.getValue("Path", String.class)); + System.out.println("\taProp : " + cfg.getValue("aProp", String.class)); System.out.println(); - dump(cfg.getProperties(), System.out); + dump(cfg.getPropertyNames(), System.out, cfg); } - private static void dump(Map<String, String> properties, PrintStream stream) { + private static void dump(Iterable<String> properties, PrintStream stream, Config config) { stream.println("FULL DUMP:\n\n"); - for (Map.Entry<String, String> en : new TreeMap<>(properties).entrySet()) { - stream.println(format("\t%s = %s", en.getKey(), en.getValue())); + for (String en : properties) { + stream.println(format("\t%s = %s", en, config.getValue(en, String.class))); } } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/examples/01-resources-example/src/main/java/org/apache/tamaya/ext/examples/resources/MyPathConfigSourceProvider.java ---------------------------------------------------------------------- diff --git a/examples/01-resources-example/src/main/java/org/apache/tamaya/ext/examples/resources/MyPathConfigSourceProvider.java b/examples/01-resources-example/src/main/java/org/apache/tamaya/ext/examples/resources/MyPathConfigSourceProvider.java new file mode 100644 index 0000000..cbf88b6 --- /dev/null +++ b/examples/01-resources-example/src/main/java/org/apache/tamaya/ext/examples/resources/MyPathConfigSourceProvider.java @@ -0,0 +1,39 @@ +/* + * 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.ext.examples.resources; + +import org.apache.tamaya.base.configsource.SimpleConfigSource; +import org.apache.tamaya.resource.AbstractPathConfigSourceProvider; + +import javax.config.spi.ConfigSource; +import java.net.URL; +import java.util.Arrays; +import java.util.Collection; + +public class MyPathConfigSourceProvider extends AbstractPathConfigSourceProvider { + + public MyPathConfigSourceProvider(){ + super("cfgOther/**/*.properties", "META-INF/MyOtherConfigProperties.*"); + } + + @Override + protected Collection<ConfigSource> getConfigSources(URL url) { + return Arrays.asList(new ConfigSource[]{new SimpleConfigSource(url)}); + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/examples/01-resources-example/src/main/java/org/apache/tamaya/ext/examples/resources/MyPathPropertySourceProvider.java ---------------------------------------------------------------------- diff --git a/examples/01-resources-example/src/main/java/org/apache/tamaya/ext/examples/resources/MyPathPropertySourceProvider.java b/examples/01-resources-example/src/main/java/org/apache/tamaya/ext/examples/resources/MyPathPropertySourceProvider.java deleted file mode 100644 index 0348157..0000000 --- a/examples/01-resources-example/src/main/java/org/apache/tamaya/ext/examples/resources/MyPathPropertySourceProvider.java +++ /dev/null @@ -1,39 +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.ext.examples.resources; - -import org.apache.tamaya.spisupport.propertysource.SimplePropertySource; -import org.apache.tamaya.resource.AbstractPathPropertySourceProvider; -import org.apache.tamaya.spi.PropertySource; - -import java.net.URL; -import java.util.Arrays; -import java.util.Collection; - -public class MyPathPropertySourceProvider extends AbstractPathPropertySourceProvider { - - public MyPathPropertySourceProvider(){ - super("cfgOther/**/*.properties", "META-INF/MyOtherConfigProperties.*"); - } - - @Override - protected Collection<PropertySource> getPropertySources(URL url) { - return Arrays.asList(new PropertySource[]{new SimplePropertySource(url)}); - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/examples/01-resources-example/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider ---------------------------------------------------------------------- diff --git a/examples/01-resources-example/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider b/examples/01-resources-example/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider index c0a9448..f2bf636 100644 --- a/examples/01-resources-example/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider +++ b/examples/01-resources-example/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider @@ -16,4 +16,4 @@ # specific language governing permissions and limitations # under the License. # -org.apache.tamaya.ext.examples.resources.MyPathPropertySourceProvider \ No newline at end of file +org.apache.tamaya.ext.examples.resources.MyPathConfigSourceProvider \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/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..24b6f98 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 @@ -18,9 +18,8 @@ */ package org.apache.tamay.ext.examples.resolver; -import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; - +import javax.config.Config; +import javax.config.ConfigProvider; import java.io.PrintStream; import java.util.Map; import java.util.TreeMap; @@ -47,32 +46,32 @@ public class Main { } public static void main(String[] args){ - Configuration cfg = ConfigurationProvider.getConfiguration(); + Config cfg = ConfigProvider.getConfig(); System.out.println("****************************************************"); System.out.println("Resolver Example"); System.out.println("****************************************************"); System.out.println(); System.out.println("Example Metadata:"); - System.out.println("\tType : " + cfg.get("example.type")); - System.out.println("\tName : " + cfg.get("example.name")); - System.out.println("\tDescription : " + cfg.get("example.description")); - System.out.println("\tVersion : " + cfg.get("example.version")); - System.out.println("\tAuthor : " + cfg.get("example.author")); + System.out.println("\tType : " + cfg.getValue("example.type", String.class)); + System.out.println("\tName : " + cfg.getValue("example.name", String.class)); + System.out.println("\tDescription : " + cfg.getValue("example.description", String.class)); + System.out.println("\tVersion : " + cfg.getValue("example.version", String.class)); + System.out.println("\tAuthor : " + cfg.getValue("example.author", String.class)); System.out.println(); System.out.println("Resolved Data:"); - System.out.println("\tFullName : " + cfg.get("example.fullName")); - System.out.println("\tFullVersion : " + cfg.get("example.fullVersion")); + System.out.println("\tFullName : " + cfg.getValue("example.fullName", String.class)); + System.out.println("\tFullVersion : " + cfg.getValue("example.fullVersion", String.class)); System.out.println(); - dump(cfg.getProperties(), System.out); + dump(cfg.getPropertyNames(), System.out, cfg); } - private static void dump(Map<String, String> properties, PrintStream stream) { + private static void dump(Iterable<String> properties, PrintStream stream, Config config) { stream.println("FULL DUMP:\n\n"); - for (Map.Entry<String, String> en : new TreeMap<>(properties).entrySet()) { - stream.println(format("\t%s = %s", en.getKey(), en.getValue())); + for (String en : properties) { + stream.println(format("\t%s = %s", en, config.getValue(en, String.class))); } } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/examples/03-injection-example/src/main/java/org/apache/tamaya/ext/examples/injection/Example.java ---------------------------------------------------------------------- diff --git a/examples/03-injection-example/src/main/java/org/apache/tamaya/ext/examples/injection/Example.java b/examples/03-injection-example/src/main/java/org/apache/tamaya/ext/examples/injection/Example.java index 6f78e58..c770f02 100644 --- a/examples/03-injection-example/src/main/java/org/apache/tamaya/ext/examples/injection/Example.java +++ b/examples/03-injection-example/src/main/java/org/apache/tamaya/ext/examples/injection/Example.java @@ -18,8 +18,8 @@ */ package org.apache.tamaya.ext.examples.injection; -import org.apache.tamaya.inject.api.Config; import org.apache.tamaya.inject.api.ConfigDefaultSections; +import javax.config.inject.ConfigProperty; /** * Simple example bean, mapped by default names mostly. @@ -30,10 +30,10 @@ public class Example { private String type; private String name; - @Config(defaultValue = "No description available.") + @ConfigProperty(defaultValue = "No description available.") private String description; private int version; - @Config("author") + @ConfigProperty(name="author") private String exampleAuthor; @Override http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/examples/03-injection-example/src/main/java/org/apache/tamaya/ext/examples/injection/ExampleTemplate.java ---------------------------------------------------------------------- diff --git a/examples/03-injection-example/src/main/java/org/apache/tamaya/ext/examples/injection/ExampleTemplate.java b/examples/03-injection-example/src/main/java/org/apache/tamaya/ext/examples/injection/ExampleTemplate.java index 8eb6839..c5457cd 100644 --- a/examples/03-injection-example/src/main/java/org/apache/tamaya/ext/examples/injection/ExampleTemplate.java +++ b/examples/03-injection-example/src/main/java/org/apache/tamaya/ext/examples/injection/ExampleTemplate.java @@ -18,8 +18,8 @@ */ package org.apache.tamaya.ext.examples.injection; -import org.apache.tamaya.inject.api.Config; import org.apache.tamaya.inject.api.ConfigDefaultSections; +import javax.config.inject.ConfigProperty; /** * Simple example bean, mapped by default names mostly. @@ -31,12 +31,12 @@ public interface ExampleTemplate { String getName(); - @Config(defaultValue = "No description available.") + @ConfigProperty(defaultValue = "No description available.") String getDescription(); int getVersion(); - @Config("author") + @ConfigProperty(name="author") String getExampleAuthor(); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/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..ac03302 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 @@ -18,21 +18,20 @@ */ package org.apache.tamaya.ext.examples.injection; -import org.apache.tamaya.ConfigException; -import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; import org.junit.BeforeClass; import org.junit.Test; +import javax.config.Config; +import javax.config.ConfigProvider; import java.math.BigInteger; public class MinimalTest { - private static Configuration config; + private static Config config; @BeforeClass public static void before() throws InterruptedException { - config = ConfigurationProvider.getConfiguration(); + config = ConfigProvider.getConfig(); Thread.sleep(100L); } @@ -43,53 +42,53 @@ public class MinimalTest { System.out.println("****************************************************"); System.out.println(); System.out.println("Example Metadata:"); - System.out.println("\tType : " + config.get("example.type")); - System.out.println("\tName : " + config.get("example.name")); - System.out.println("\tDescription : " + config.get("example.description")); - System.out.println("\tVersion : " + config.get("example.version")); - System.out.println("\tAuthor : " + config.get("example.author")); + System.out.println("\tType : " + config.getValue("example.type", String.class)); + System.out.println("\tName : " + config.getValue("example.name", String.class)); + System.out.println("\tDescription : " + config.getValue("example.description", String.class)); + System.out.println("\tVersion : " + config.getValue("example.version", String.class)); + System.out.println("\tAuthor : " + config.getValue("example.author", String.class)); System.out.println(); } - @Test(expected = ConfigException.class) + @Test(expected = IllegalArgumentException.class) public void getNumberValueTooLong() { - String value = config.get("example.number"); + String value = config.getValue("example.number", String.class); System.err.println("**** example.number(String)=" + value); - int number = config.get("example.number",int.class); + int number = config.getValue("example.number",int.class); System.out.println("----\n example.number(int)=" + number); } @Test public void getNumberValueAsInt_BadCase() { - String value = config.get("example.numberAsHex"); - int number = config.get("example.numberAsHex",int.class); + String value = config.getValue("example.numberAsHex", String.class); + int number = config.getValue("example.numberAsHex",int.class); print("example.numberAsHex", number); } @Test public void getNumberValueAsBigInteger() { - String value = config.get("example.number"); - BigInteger number = config.get("example.number", BigInteger.class); + String value = config.getValue("example.number", String.class); + BigInteger number = config.getValue("example.number", BigInteger.class); print("example.number", number); } - @Test(expected = ConfigException.class) + @Test(expected = IllegalArgumentException.class) public void getNumberValueAsLongHex() { - String value = config.get("example.numberAsLongHex"); - long number = config.get("example.numberAsLongHex",int.class); + String value = config.getValue("example.numberAsLongHex", String.class); + long number = config.getValue("example.numberAsLongHex",int.class); print("example.numberAsLongHex", number); } @Test public void getEnum() { - String value = config.get("example.testEnum"); - TestEnum en = config.get("example.testEnum", TestEnum.class); + String value = config.getValue("example.testEnum", String.class); + TestEnum en = config.getValue("example.testEnum", TestEnum.class); print("example.testEnum", en); } protected void print(String key, Object value) { System.out.println("----\n" + - " " + key + "(String)=" + config.get(key) + " " + key + "(String)=" + config.getValue(key, String.class) + "\n " + key + "(" + value.getClass().getSimpleName() + ")=" + value); } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/examples/03-injection-example/src/test/resources/META-INF/javaconfig.properties ---------------------------------------------------------------------- diff --git a/examples/03-injection-example/src/test/resources/META-INF/javaconfig.properties b/examples/03-injection-example/src/test/resources/META-INF/javaconfig.properties new file mode 100644 index 0000000..acb9caf --- /dev/null +++ b/examples/03-injection-example/src/test/resources/META-INF/javaconfig.properties @@ -0,0 +1,25 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy current the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +tamaya.ordinal=-1 +example.description=A minimal example only using API and RI, now partially overridden! + +example.number=35333333333333333333333333333333333333333333333333333333333330 +example.numberAsHex=0xFA +example.numberAsLongHex=0xFFFSFSFF +example.testEnum=V1 http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/examples/03-injection-example/src/test/resources/META-INF/javaconfiguration.properties ---------------------------------------------------------------------- diff --git a/examples/03-injection-example/src/test/resources/META-INF/javaconfiguration.properties b/examples/03-injection-example/src/test/resources/META-INF/javaconfiguration.properties deleted file mode 100644 index acb9caf..0000000 --- a/examples/03-injection-example/src/test/resources/META-INF/javaconfiguration.properties +++ /dev/null @@ -1,25 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy current the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -tamaya.ordinal=-1 -example.description=A minimal example only using API and RI, now partially overridden! - -example.number=35333333333333333333333333333333333333333333333333333333333330 -example.numberAsHex=0xFA -example.numberAsLongHex=0xFFFSFSFF -example.testEnum=V1 http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FileConfigSourceProvider.java ---------------------------------------------------------------------- diff --git a/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FileConfigSourceProvider.java b/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FileConfigSourceProvider.java new file mode 100644 index 0000000..e8c831a --- /dev/null +++ b/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FileConfigSourceProvider.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tamaya.ext.examples.events; + + +import org.apache.tamaya.base.configsource.BaseConfigSource; +import org.apache.tamaya.resource.AbstractPathConfigSourceProvider; + +import javax.config.spi.ConfigSource; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.*; + +import static org.apache.tamaya.ext.examples.events.Main.getPropertiesFilePath; + +public class FileConfigSourceProvider extends AbstractPathConfigSourceProvider { + public FileConfigSourceProvider() { + super(getPropertiesFilePath().toString()); + } + + @Override + protected Collection<ConfigSource> getConfigSources(URL url) { + return Arrays.asList(new ConfigSource[] { new DumbReloadingPropertySource(url) }); + } + + public static class DumbReloadingPropertySource extends BaseConfigSource { + private final URL propertiesFile; + + public DumbReloadingPropertySource(URL url) { + propertiesFile = url; + } + + @Override + public Map<String, String> getProperties() { + + Map<String, String> properties = new HashMap<>(); + try (InputStream stream = propertiesFile.openStream()) { + Properties props = new Properties(); + if (stream != null) { + props.load(stream); + } + + for (String key : props.stringPropertyNames()) { + properties.put(key, props.getProperty(key)); + } + } catch (IOException e) { + throw new IllegalStateException("Error loading properties from " + propertiesFile, e); + } + + return properties; + + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FilePropertySourceProvider.java ---------------------------------------------------------------------- diff --git a/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FilePropertySourceProvider.java b/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FilePropertySourceProvider.java deleted file mode 100644 index a15ad6e..0000000 --- a/examples/04-events-example/src/main/java/org/apache/tamaya/ext/examples/events/FilePropertySourceProvider.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tamaya.ext.examples.events; - - -import org.apache.tamaya.ConfigException; -import org.apache.tamaya.spisupport.propertysource.BasePropertySource; -import org.apache.tamaya.resource.AbstractPathPropertySourceProvider; -import org.apache.tamaya.spi.PropertySource; -import org.apache.tamaya.spi.PropertyValue; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.*; - -import static org.apache.tamaya.ext.examples.events.Main.getPropertiesFilePath; - -public class FilePropertySourceProvider extends AbstractPathPropertySourceProvider { - public FilePropertySourceProvider() { - super(getPropertiesFilePath().toString()); - } - - @Override - protected Collection<PropertySource> getPropertySources(URL url) { - return Arrays.asList(new PropertySource[] { new DumbReloadingPropertySource(url) }); - } - - public static class DumbReloadingPropertySource extends BasePropertySource { - private final URL propertiesFile; - - public DumbReloadingPropertySource(URL url) { - propertiesFile = url; - } - - @Override - public Map<String, PropertyValue> getProperties() { - - Map<String, PropertyValue> properties = new HashMap<>(); - try (InputStream stream = propertiesFile.openStream()) { - Properties props = new Properties(); - if (stream != null) { - props.load(stream); - } - - for (String key : props.stringPropertyNames()) { - properties.put(key, PropertyValue.of(key, props.getProperty(key), getName())); - } - } catch (IOException e) { - throw new ConfigException("Error loading properties from " + propertiesFile, e); - } - - return properties; - - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/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..6b319d9 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 @@ -18,15 +18,15 @@ */ package org.apache.tamaya.ext.examples.events; -import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; import org.apache.tamaya.events.ConfigEvent; import org.apache.tamaya.events.ConfigEventListener; import org.apache.tamaya.events.ConfigEventManager; -import org.apache.tamaya.events.ConfigurationChange; +import org.apache.tamaya.events.ConfigChange; import org.joda.time.DateTime; import org.joda.time.Duration; +import javax.config.Config; +import javax.config.ConfigProvider; import java.beans.PropertyChangeEvent; import java.io.IOException; import java.nio.charset.Charset; @@ -64,10 +64,10 @@ public class Main { ConfigEventManager.addListener(new ConfigurationChangeListener()); ConfigEventManager.setChangeMonitoringPeriod(1_000L); ConfigEventManager.enableChangeMonitoring(true); - Configuration configuration = ConfigurationProvider.getConfiguration(); + Config config = ConfigProvider.getConfig(); - for (Map.Entry<String, String> e : configuration.getProperties().entrySet()) { - System.out.println(e.getKey() + ": " + e.getValue()); + for (String key : config.getPropertyNames()) { + System.out.println(key + ": " + config.getValue(key, String.class)); } @@ -108,7 +108,7 @@ public class Main { @Override public void onConfigEvent(ConfigEvent<?> event) { - ConfigurationChange c = (ConfigurationChange) event; + ConfigChange c = (ConfigChange) event; if (c.isKeyAffected("a")) { // Looking for the change event of property a. Not recomanded http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/examples/04-events-example/src/main/resources/META-INF/services/javax.config.spi.ConfigSourceProvider ---------------------------------------------------------------------- diff --git a/examples/04-events-example/src/main/resources/META-INF/services/javax.config.spi.ConfigSourceProvider b/examples/04-events-example/src/main/resources/META-INF/services/javax.config.spi.ConfigSourceProvider new file mode 100644 index 0000000..bc9e368 --- /dev/null +++ b/examples/04-events-example/src/main/resources/META-INF/services/javax.config.spi.ConfigSourceProvider @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy current the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +org.apache.tamaya.ext.examples.events.FileConfigSourceProvider + http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/examples/04-events-example/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider ---------------------------------------------------------------------- diff --git a/examples/04-events-example/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider b/examples/04-events-example/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider deleted file mode 100644 index a0d95fb..0000000 --- a/examples/04-events-example/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertySourceProvider +++ /dev/null @@ -1,20 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy current the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -org.apache.tamaya.ext.examples.events.FilePropertySourceProvider - http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/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..60c93a0 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,18 +15,16 @@ */ package org.apache.tamaya.springexample; -import org.apache.tamaya.spi.ConversionContext; -import org.apache.tamaya.spi.PropertyConverter; - +import javax.config.spi.Converter; import java.awt.*; /** * Simple demo converter for Color. */ -public class ColorConverter implements PropertyConverter<Color>{ +public class ColorConverter implements Converter<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/cfb364cd/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 172c4d5..04f1619 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 @@ -18,18 +18,18 @@ package org.apache.tamaya.springexample; import java.awt.*; import java.util.Date; import java.util.Map; +import java.util.Optional; -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; import org.apache.tamaya.inject.api.UpdatePolicy; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; -import javax.websocket.server.PathParam; +import javax.config.Config; +import javax.config.ConfigProvider; +import javax.config.inject.ConfigProperty; @Controller public class WelcomeController { @@ -37,14 +37,14 @@ public class WelcomeController { @Value("${application.message:Hello World}") private String message = "Hello World"; - @Config(value = "background.color", required = false) - private String backgroundColor = "#BBBBBB"; + @ConfigProperty(name = "background.color", defaultValue = "#BBBBBB") + private Optional<String> backgroundColor; - @Config(value = "foreground.color", required = false, defaultValue = "#DDDDDD") + @ConfigProperty(name = "foreground.color", defaultValue = "#DDDDDD") private DynamicValue<String> foregroundColor; - @Config(value = "background.color", required = false) - private Color bgColor; + @ConfigProperty(name = "background.color") + private Optional<Color> bgColor; @GetMapping("/") public String welcome(Map<String, Object> model) { @@ -72,19 +72,18 @@ public class WelcomeController { @GetMapping("/config") public String config(Map<String, Object> model) { - Configuration config = ConfigurationProvider.getConfiguration(); + Config config = ConfigProvider.getConfig(); model.put("filter", "NO FILTER"); - model.put("config", config - .query(ConfigurationFunctions.textInfo())); + model.put("config", ConfigurationFunctions.textInfo().apply(config)); return "config"; } @GetMapping(value="/config/{path}") public String config(@PathVariable("path") String path, Map<String, Object> model) { - Configuration config = ConfigurationProvider.getConfiguration(); + Config config = ConfigProvider.getConfig(); model.put("filter", path); - model.put("config", config.with(ConfigurationFunctions.section(path)) - .query(ConfigurationFunctions.textInfo())); + model.put("config", ConfigurationFunctions.textInfo() + .apply(ConfigurationFunctions.section(path).apply(config))); return "config"; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/features/pom.xml ---------------------------------------------------------------------- diff --git a/modules/features/pom.xml b/modules/features/pom.xml index db616aa..8924bb2 100644 --- a/modules/features/pom.xml +++ b/modules/features/pom.xml @@ -35,12 +35,6 @@ under the License. <dependencies> <dependency> <groupId>org.apache.tamaya</groupId> - <artifactId>tamaya-api</artifactId> - <version>${tamaya-apicore.version}</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.tamaya</groupId> <artifactId>tamaya-core</artifactId> <version>${tamaya-apicore.version}</version> <scope>provided</scope> @@ -54,6 +48,12 @@ under the License. <artifactId>junit</artifactId> </dependency> <dependency> + <groupId>org.apache.tamaya</groupId> + <artifactId>tamaya-compat</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.apache.tamaya.ext</groupId> <artifactId>tamaya-injection</artifactId> <version>${project.version}</version> @@ -109,7 +109,7 @@ under the License. </dependency> <dependency> <groupId>org.apache.tamaya</groupId> - <artifactId>tamaya-spisupport</artifactId> + <artifactId>tamaya-base</artifactId> <version>${project.version}</version> <scope>test</scope> </dependency> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/features/src/main/java/org/apache/tamaya/features/Features.java ---------------------------------------------------------------------- diff --git a/modules/features/src/main/java/org/apache/tamaya/features/Features.java b/modules/features/src/main/java/org/apache/tamaya/features/Features.java index 32834fa..6418179 100644 --- a/modules/features/src/main/java/org/apache/tamaya/features/Features.java +++ b/modules/features/src/main/java/org/apache/tamaya/features/Features.java @@ -50,7 +50,7 @@ public final class Features { * @return true, if <i>tamaya-core</i> is on the classpath. */ public static boolean tamayaCoreAvailable() { - return checkClassIsLoadable("org.apache.tamaya.core.internal.CoreConfiguration"); + return checkClassIsLoadable("org.apache.tamaya.core.TamayaConfigProviderResolver"); } /** @@ -105,8 +105,16 @@ public final class Features { * Checks if <i>tamaya-spisupport</i> is on the classpath. * @return true, if <i>tamaya-spisupport</i> is on the classpath. */ - public static boolean spiSupportAvailable() { - return checkClassIsLoadable("org.apache.tamaya.spisupport.PropertySourceComparator"); + public static boolean baseSupportAvailable() { + return checkClassIsLoadable("org.apache.tamaya.base.PriorityServiceComparator"); + } + + /** + * Checks if <i>tamaya-spisupport</i> is on the classpath. + * @return true, if <i>tamaya-spisupport</i> is on the classpath. + */ + public static boolean compatSupportAvailable() { + return checkClassIsLoadable("org.apache.tamaya.spi.PropertyConverter"); } /** @@ -130,7 +138,7 @@ public final class Features { * @return true, if <i>tamaya-jndi</i> is on the classpath. */ public static boolean jndiAvailable() { - return checkClassIsLoadable("org.apache.tamaya.jndi.JNDIPropertySource"); + return checkClassIsLoadable("org.apache.tamaya.jndi.JNDIConfigSource"); } /** http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/features/src/test/java/org/apache/tamaya/features/FeaturesTest.java ---------------------------------------------------------------------- diff --git a/modules/features/src/test/java/org/apache/tamaya/features/FeaturesTest.java b/modules/features/src/test/java/org/apache/tamaya/features/FeaturesTest.java index db6e16c..98ca520 100644 --- a/modules/features/src/test/java/org/apache/tamaya/features/FeaturesTest.java +++ b/modules/features/src/test/java/org/apache/tamaya/features/FeaturesTest.java @@ -72,8 +72,13 @@ public class FeaturesTest { } @Test - public void spiSupportAvailable() throws Exception { - assertTrue(Features.spiSupportAvailable()); + public void baseSupportAvailable() throws Exception { + assertTrue(Features.baseSupportAvailable()); + } + + @Test + public void compatSupportAvailable() throws Exception { + assertTrue(Features.compatSupportAvailable()); } @Test http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/features/src/test/java/org/apache/tamaya/features/FeaturesTestNoOnly.java ---------------------------------------------------------------------- diff --git a/modules/features/src/test/java/org/apache/tamaya/features/FeaturesTestNoOnly.java b/modules/features/src/test/java/org/apache/tamaya/features/FeaturesTestNoOnly.java index 1bcb64b..8a5008a 100644 --- a/modules/features/src/test/java/org/apache/tamaya/features/FeaturesTestNoOnly.java +++ b/modules/features/src/test/java/org/apache/tamaya/features/FeaturesTestNoOnly.java @@ -92,8 +92,8 @@ public class FeaturesTestNoOnly { } @Test - public void spiSupportAvailable() throws Exception { - assertFalse(Features.spiSupportAvailable()); + public void baseSupportAvailable() throws Exception { + assertFalse(Features.baseSupportAvailable()); } @Test http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/filter/bnd.bnd ---------------------------------------------------------------------- diff --git a/modules/filter/bnd.bnd b/modules/filter/bnd.bnd index 006f58e..228fd37 100644 --- a/modules/filter/bnd.bnd +++ b/modules/filter/bnd.bnd @@ -11,7 +11,7 @@ javac.target: 1.8 Bundle-Version: ${version}.${tstamp} Bundle-Name: Apache Tamaya - Filter -Bundle-SymbolicName: org.apache.tamaya.filter +Bundle-SymbolicName: org.apache.tamaya.spisupport.filter Bundle-Description: Apacha Tamaya Config - Filtered Config Access Bundle-Category: Implementation Bundle-Copyright: (C) Apache Foundation @@ -23,6 +23,6 @@ Export-Package: \ org.apache.tamaya.filter Import-Package: \ org.apache.tamaya,\ - org.apache.tamaya.spi + org.apache.tamaya.base Export-Service: \ - org.apache.tamaya.spi.PropertyFilter + org.apache.tamaya.spi.Filter http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/filter/pom.xml ---------------------------------------------------------------------- diff --git a/modules/filter/pom.xml b/modules/filter/pom.xml index 88ebfa6..20f7eca 100644 --- a/modules/filter/pom.xml +++ b/modules/filter/pom.xml @@ -35,15 +35,14 @@ under the License. <dependencies> <dependency> <groupId>org.apache.tamaya</groupId> - <artifactId>tamaya-api</artifactId> - <version>${tamaya-apicore.version}</version> - <scope>provided</scope> + <artifactId>tamaya-base</artifactId> + <version>${project.version}</version> </dependency> <dependency> <groupId>org.apache.tamaya</groupId> <artifactId>tamaya-core</artifactId> <version>${tamaya-apicore.version}</version> - <scope>provided</scope> + <scope>test</scope> </dependency> <dependency> <groupId>org.hamcrest</groupId> @@ -54,12 +53,6 @@ under the License. <artifactId>junit</artifactId> </dependency> <dependency> - <groupId>org.apache.tamaya</groupId> - <artifactId>tamaya-spisupport</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> - <dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.compendium</artifactId> <version>5.0.0</version> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/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..1c16c07 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 @@ -18,10 +18,11 @@ */ package org.apache.tamaya.filter; -import org.apache.tamaya.spi.PropertyFilter; -import org.apache.tamaya.spi.PropertyValue; +import org.apache.tamaya.spi.Filter; import org.osgi.service.component.annotations.Component; +import java.util.*; + /** * Hereby @@ -40,28 +41,11 @@ import org.osgi.service.component.annotations.Component; * active. */ @Component -public final class ConfigurationFilter implements PropertyFilter{ - - static final ThreadLocal<Boolean> THREADED_METADATA_FILTERED = new ThreadLocal<Boolean>(){ - @Override - protected Boolean initialValue() { - return Boolean.TRUE; - } - }; +public final class ConfigurationFilter implements Filter{ - private static final ThreadLocal<FilterContext> THREADED_MAP_FILTERS = new ThreadLocal<FilterContext>(){ - @Override - protected FilterContext initialValue() { - return new FilterContext(); - } - }; + private static final ThreadLocal<Boolean> THREADED_METADATA_FILTERED = ThreadLocal.withInitial(() -> Boolean.TRUE); - private static final ThreadLocal<FilterContext> THREADED_VALUE_FILTERS = new ThreadLocal<FilterContext>(){ - @Override - protected FilterContext initialValue() { - return new FilterContext(); - } - }; + private static final ThreadLocal<List<Filter>> THREADED_FILTERS = ThreadLocal.withInitial(ArrayList::new); /** * Flag if metadata entries (starting with an '_') are filtered out on when accessing multiple properties, default @@ -82,44 +66,88 @@ public final class ConfigurationFilter implements PropertyFilter{ } /** - * Access the filtering configuration that is used on the current thread for - * filtering single property values accessed. + * Access the filtering configuration that is used on the current thread. * * @return the filtering config, never null. */ - public static FilterContext getSingleValueFilterContext(){ - return THREADED_VALUE_FILTERS.get(); + public static List<Filter> getFilters(){ + return Collections.unmodifiableList(THREADED_FILTERS.get()); } /** - * Access the filtering configuration that is used used on the current thread - * for filtering configuration properties accessed as full - * map. - * @return the filtering config, never null. + * Add a filter. + * @param filter the filter. + */ + public static void addFilter(Filter filter){ + if(!THREADED_FILTERS.get().contains(filter)) { + THREADED_FILTERS.get().add(filter); + } + } + + /** + * Adds a filter at given position. + * @param pos the position. + * @param filter the filter. + */ + public static void addFilter(int pos, Filter filter){ + if(!THREADED_FILTERS.get().contains(filter)) { + THREADED_FILTERS.get().add(pos, filter); + } + } + + /** + * Removes a filter at a given position. + * @param pos the position. + * @return the filter removed, or null. + */ + public static Filter removeFilter(int pos){ + return THREADED_FILTERS.get().remove(pos); + } + + /** + * Removes a filter. + * @param filter the filter to be removed, not null. + */ + public static void removeFilter(Filter filter) { + THREADED_FILTERS.get().remove(filter); + } + + /** + * Clears all filters. + */ + public static void clearFilters(){ + THREADED_FILTERS.get().clear(); + } + + /** + * Set the filters. + * @param filters the filters to be applied. + */ + public static void setFilters(Filter... filters){ + setFilters(Arrays.asList(filters)); + } + + /** + * Set the filters. + * @param filters the filters to be applied. */ - public static FilterContext getMapFilterContext(){ - return THREADED_MAP_FILTERS.get(); + public static void setFilters(Collection<Filter> filters) { + THREADED_FILTERS.get().clear(); + THREADED_FILTERS.get().addAll(filters); } /** * Removes all programmable filters active on the current thread. */ public static void cleanupFilterContext(){ - THREADED_MAP_FILTERS.get().clearFilters(); - THREADED_VALUE_FILTERS.get().clearFilters(); + THREADED_FILTERS.get().clear(); THREADED_METADATA_FILTERED.set(true); } @Override - public PropertyValue filterProperty(PropertyValue valueToBeFiltered, org.apache.tamaya.spi.FilterContext context) { - if(context.isSinglePropertyScoped()){ - for(PropertyFilter pred: THREADED_VALUE_FILTERS.get().getFilters()){ - valueToBeFiltered = pred.filterProperty(valueToBeFiltered, context); - } - }else{ - for(PropertyFilter pred: THREADED_MAP_FILTERS.get().getFilters()){ - valueToBeFiltered = pred.filterProperty(valueToBeFiltered, context); - } + public String filterProperty(String key, String valueToBeFiltered) { + for(Filter pred: THREADED_FILTERS.get()){ + valueToBeFiltered = pred.filterProperty(key, valueToBeFiltered); } return valueToBeFiltered; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/filter/src/main/java/org/apache/tamaya/filter/Context.java ---------------------------------------------------------------------- diff --git a/modules/filter/src/main/java/org/apache/tamaya/filter/Context.java b/modules/filter/src/main/java/org/apache/tamaya/filter/Context.java new file mode 100644 index 0000000..c6c4ba6 --- /dev/null +++ b/modules/filter/src/main/java/org/apache/tamaya/filter/Context.java @@ -0,0 +1,123 @@ +/* + * 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.ConfigValue; +import org.apache.tamaya.spi.Filter; + +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 Context implements Filter{ + /** The filters. */ + private List<Filter> filters = new ArrayList<>(); + + /** + * Add a filter. + * @param filter the filter. + */ + public void addFilter(Filter filter){ + if(!filters.contains(filter)) { + filters.add(filter); + } + } + + /** + * Adds a filter at given position. + * @param pos the position. + * @param filter the filter. + */ + public void addFilter(int pos, Filter filter){ + if(!filters.contains(filter)) { + filters.add(pos, filter); + } + } + + /** + * Removes a filter at a given position. + * @param pos the position. + * @return the filter removed, or null. + */ + public Filter removeFilter(int pos){ + return filters.remove(pos); + } + + /** + * Removes a filter. + * @param filter the filter to be removed, not null. + */ + public void removeFilter(Filter 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(Filter... filters){ + setFilters(Arrays.asList(filters)); + } + + /** + * Set the filters. + * @param filters the filters to be applied. + */ + public void setFilters(Collection<Filter> filters) { + this.filters.clear(); + this.filters.addAll(filters); + } + + /** + * Get all filters. + * @return all filters. + */ + public List<Filter> getFilters(){ + return Collections.unmodifiableList(filters); + } + + @Override + public String filterProperty(String key, String valueToBeFiltered) { + for(Filter filter: filters){ + valueToBeFiltered = filter.filterProperty(key, valueToBeFiltered); + } + return valueToBeFiltered; + } + + @Override + public String toString() { + return "ProgrammableFilter{" + + "filters=" + filters + + '}'; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/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..ba78930 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 @@ -18,23 +18,23 @@ */ package org.apache.tamaya.filter.internal; +import org.apache.tamaya.base.filter.FilterContext; 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.Filter; /** * Default property filter that hides metadta entries starting with an '_', similar ti {@code etcd}. */ -public final class DefaultMetadataFilter implements PropertyFilter{ +public final class DefaultMetadataFilter implements Filter{ @Override - public PropertyValue filterProperty(PropertyValue valueToBeFiltered, FilterContext context) { - if(context.isSinglePropertyScoped()){ + public String filterProperty(String key, String valueToBeFiltered) { + FilterContext context = FilterContext.getContext(); + if(context==null || context.isSinglePropertyScoped()){ // When accessing keys explicitly, do not hide anything. return valueToBeFiltered; } if(ConfigurationFilter.isMetadataFiltered()) { - if (context.getProperty().getKey().startsWith("_")) { + if (key.startsWith("_")) { // Hide metadata entries. return null; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/filter/src/main/resources/META-INF/services/org.apache.tamaya.spi.Filter ---------------------------------------------------------------------- diff --git a/modules/filter/src/main/resources/META-INF/services/org.apache.tamaya.spi.Filter b/modules/filter/src/main/resources/META-INF/services/org.apache.tamaya.spi.Filter new file mode 100644 index 0000000..806b833 --- /dev/null +++ b/modules/filter/src/main/resources/META-INF/services/org.apache.tamaya.spi.Filter @@ -0,0 +1,19 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy current the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +org.apache.tamaya.filter.ConfigurationFilter \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/filter/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter ---------------------------------------------------------------------- diff --git a/modules/filter/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter b/modules/filter/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter deleted file mode 100644 index 806b833..0000000 --- a/modules/filter/src/main/resources/META-INF/services/org.apache.tamaya.spi.PropertyFilter +++ /dev/null @@ -1,19 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy current the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -org.apache.tamaya.filter.ConfigurationFilter \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/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 deleted file mode 100644 index a3a75a3..0000000 --- a/modules/filter/src/test/java/org/apache/tamaya/filter/ConfigurationFilterTest.java +++ /dev/null @@ -1,123 +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.Configuration; -import org.apache.tamaya.ConfigurationProvider; -import org.apache.tamaya.spi.FilterContext; -import org.apache.tamaya.spi.PropertyFilter; -import org.apache.tamaya.spi.PropertyValue; -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Tests for {@link ConfigurationFilter}. Created by atsticks on 11.02.16. - */ -public class ConfigurationFilterTest { - - @Test - public void testMetadataFiltered() throws Exception { - ConfigurationFilter.setMetadataFiltered(true); - assertTrue(ConfigurationFilter.isMetadataFiltered()); - ConfigurationFilter.setMetadataFiltered(false); - assertFalse(ConfigurationFilter.isMetadataFiltered()); - } - - @Test - public void testGetSingleFilters() throws Exception { - Configuration config = ConfigurationProvider.getConfiguration(); - assertNotNull(ConfigurationFilter.getSingleValueFilterContext()); - PropertyFilter testFilter = new PropertyFilter() { - @Override - public PropertyValue filterProperty(PropertyValue value, FilterContext context) { - return value.toBuilder().setValue(value.getKey() + ":testGetSingleFilters").build(); - } - }; - ConfigurationFilter.getSingleValueFilterContext().addFilter(testFilter); - assertEquals("user.home:testGetSingleFilters", config.get("user.home")); - ConfigurationFilter.getSingleValueFilterContext().removeFilter(testFilter); - assertNotSame("user.home:testGetSingleFilters", config.get("user.home")); - } - - @Test - public void testRemoveSingleFiltersAt0() throws Exception { - Configuration config = ConfigurationProvider.getConfiguration(); - assertNotNull(ConfigurationFilter.getSingleValueFilterContext()); - PropertyFilter testFilter = new PropertyFilter() { - @Override - public PropertyValue filterProperty(PropertyValue value, FilterContext context) { - return value.toBuilder().setValue(value.getKey() + ":testGetSingleFilters").build(); - } - }; - ConfigurationFilter.getSingleValueFilterContext().addFilter(testFilter); - assertEquals("user.home:testGetSingleFilters", config.get("user.home")); - ConfigurationFilter.getSingleValueFilterContext().removeFilter(0); - assertNotSame("user.home:testGetSingleFilters", config.get("user.home")); - } - - @Test - public void testGetMapFilters() throws Exception { - Configuration config = ConfigurationProvider.getConfiguration(); - assertNotNull(ConfigurationFilter.getMapFilterContext()); - PropertyFilter testFilter = new PropertyFilter() { - @Override - public PropertyValue filterProperty(PropertyValue value, FilterContext context) { - return value.toBuilder().setValue(value.getKey() + ":testGetMapFilters").build(); - } - }; - ConfigurationFilter.getMapFilterContext().addFilter(testFilter); - assertEquals("user.home:testGetMapFilters", config.getProperties().get("user.home")); - ConfigurationFilter.getSingleValueFilterContext().removeFilter(testFilter); - assertNotSame("user.home:testGetSingleFilters", config.getProperties().get("user.home")); - } - - @Test - public void testRemoveMapFilterAt0() throws Exception { - Configuration config = ConfigurationProvider.getConfiguration(); - assertNotNull(ConfigurationFilter.getMapFilterContext()); - PropertyFilter testFilter = new PropertyFilter() { - @Override - public PropertyValue filterProperty(PropertyValue value, FilterContext context) { - return value .toBuilder().setValue(value.getKey() + ":testGetMapFilters").build(); - } - }; - ConfigurationFilter.getMapFilterContext().addFilter(testFilter); - assertEquals("user.home:testGetMapFilters", config.getProperties().get("user.home")); - ConfigurationFilter.getMapFilterContext().removeFilter(0); - assertNotSame("user.home:testGetSingleFilters", config.getProperties().get("user.home")); - } - - @Test - public void testClearFilters() throws Exception { - Configuration config = ConfigurationProvider.getConfiguration(); - assertNotNull(ConfigurationFilter.getSingleValueFilterContext()); - PropertyFilter testFilter = new PropertyFilter() { - @Override - public PropertyValue filterProperty(PropertyValue value, FilterContext context) { - return value.toBuilder().setValue(value.getKey() + ":testGetSingleFilters").build(); - } - }; - ConfigurationFilter.getSingleValueFilterContext().addFilter(testFilter); - assertEquals("user.home:testGetSingleFilters", config.get("user.home")); - ConfigurationFilter.cleanupFilterContext(); - assertNotSame("user.home:testGetSingleFilters", config.get("user.home")); - } - -} \ No newline at end of file
