http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/ConfigCommands.java ---------------------------------------------------------------------- diff --git a/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/ConfigCommands.java b/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/ConfigCommands.java index cccbf9d..60b5fba 100644 --- a/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/ConfigCommands.java +++ b/modules/osgi/common/src/main/java/org/apache/tamaya/osgi/commands/ConfigCommands.java @@ -18,13 +18,12 @@ */ package org.apache.tamaya.osgi.commands; -import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; import org.apache.tamaya.functions.ConfigurationFunctions; import org.apache.tamaya.osgi.Policy; -import org.apache.tamaya.spi.PropertySource; -import org.apache.tamaya.spi.PropertyValue; +import javax.config.Config; +import javax.config.ConfigProvider; +import javax.config.spi.ConfigSource; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; @@ -39,26 +38,25 @@ public final class ConfigCommands { private ConfigCommands(){} public static String getInfo(TamayaConfigService configPlugin) throws IOException { - Configuration config = ConfigurationProvider.getConfiguration(); + Config config = ConfigProvider.getConfig(); return config.toString() + "\n\n" + StringUtil.format("Default Policy:", 30) + configPlugin.getDefaultPolicy() + '\n' + StringUtil.format("Default Enabled: ", 30) + configPlugin.isTamayaEnabledByDefault(); } public static String readTamayaConfig(String section, String filter) { - Configuration config = ConfigurationProvider.getConfiguration(); + Config config = ConfigProvider.getConfig(); if(section!=null){ - config = config - .with(ConfigurationFunctions.section(section, true)); + config = ConfigurationFunctions.section(section, true).apply(config); } if(filter!=null){ - config = config.with(ConfigurationFunctions.section(filter, false)); + config = ConfigurationFunctions.section(filter, false).apply(config); } return "Tamaya Configuration\n" + "--------------------\n" + "Section: "+section +"\n" + (filter!=null?"Filter: "+filter + "\n":"") + - config.query(ConfigurationFunctions.textInfo()); + ConfigurationFunctions.textInfo().apply(config); } public static String readTamayaConfig4PID(String pid, String filter) { @@ -123,37 +121,33 @@ public final class ConfigCommands { } public static String getProperty(String propertysource, String key, boolean extended) throws IOException { - Configuration config = ConfigurationProvider.getConfiguration(); + Config config = ConfigProvider.getConfig(); if(propertysource!=null){ - PropertySource ps = config.getContext().getPropertySource(propertysource); + ConfigSource ps = getPropertySource(config, propertysource); if(ps==null){ return "ERR: No such Property Source: " + propertysource; }else { - PropertyValue val = ps.get(key); + String val = ps.getValue(key); if(val==null){ - return "ERR: Property Source: " + propertysource + " - undefined key: " + key; + return "ERR: Config Source: " + propertysource + " - undefined key: " + key; }else { if(extended) { - return StringUtil.format("Property Source", 25) + StringUtil.format("Value", 25) + '\n' + + return StringUtil.format("Config Source", 25) + StringUtil.format("Value", 25) + '\n' + StringUtil.printRepeat("-", 50) + '\n' + - StringUtil.format(propertysource, 25) + StringUtil.format(val.getValue(), 55); + StringUtil.format(propertysource, 25) + StringUtil.format(val, 55); }else{ - return val.getValue(); + return val; } } } }else{ StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); - pw.println(StringUtil.format("Property Source", 25) + StringUtil.format("Value", 25)); - for(PropertySource ps:config.getContext().getPropertySources()){ - PropertyValue val = ps.get(key); + pw.println(StringUtil.format("Config Source", 25) + StringUtil.format("Value", 25)); + for(ConfigSource ps:config.getConfigSources()){ + String val = ps.getValue(key); if(val!=null){ - if(extended) { - pw.println(StringUtil.format("", 25) + StringUtil.format(val.toString(), 55)); - }else{ - pw.println(StringUtil.format("", 25) + StringUtil.format(val.getValue(), 55)); - } + pw.println(StringUtil.format("", 25) + StringUtil.format(val, 55)); } } pw.flush(); @@ -161,17 +155,26 @@ public final class ConfigCommands { } } + private static ConfigSource getPropertySource(Config config, String propertysource) { + for(ConfigSource cs:config.getConfigSources()){ + if(cs.getName().equals(propertysource)){ + return cs; + } + } + return null; + } + public static String getPropertySource(String propertysource) throws IOException { - Configuration config = ConfigurationProvider.getConfiguration(); + Config config = ConfigProvider.getConfig(); if(propertysource!=null){ - PropertySource ps = config.getContext().getPropertySource(propertysource); + ConfigSource ps = getPropertySource(config, propertysource); if(ps==null){ - return "No such Property Source: " + propertysource; + return "No such Config Source: " + propertysource; }else { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); - pw.println("Property Source"); - pw.println("---------------"); + pw.println("Config Source"); + pw.println("-------------"); pw.println(StringUtil.format("ID:", 20) + ps.getName()); pw.println(StringUtil.format("Ordinal:", 20) + ps.getOrdinal()); pw.println(StringUtil.format("Class:", 20) + ps.getClass().getName()); @@ -181,11 +184,11 @@ public final class ConfigCommands { pw.print(StringUtil.format("Source", 20)); pw.println(StringUtil.format("Meta-Entries", 20)); pw.println(" " + StringUtil.printRepeat("-", 80)); - for(PropertyValue pv:ps.getProperties().values()) { + for(Map.Entry<String,String> pv:ps.getProperties().entrySet()) { pw.print(" " + StringUtil.format(pv.getKey(), 20)); pw.print(StringUtil.format(pv.getValue(), 20)); - pw.print(StringUtil.format(pv.getSource(), 20)); - pw.println(StringUtil.format(pv.getMetaEntries().toString(), 80)); + pw.println(StringUtil.format(ps.getName(), 20)); +// pw.println(StringUtil.format(pv.getMetaEntries().toString(), 80)); } pw.flush(); return sw.toString(); @@ -193,10 +196,10 @@ public final class ConfigCommands { } // Get a name of existing propertysources List<String> result = new ArrayList<>(); - for(PropertySource ps:config.getContext().getPropertySources()){ + for(ConfigSource ps:config.getConfigSources()){ result.add(ps.getName()); } - StringBuilder b = new StringBuilder("Please select a property source:\n"); + StringBuilder b = new StringBuilder("Please select a config source:\n"); for(String name:result){ b.append(name).append('\n'); } @@ -204,17 +207,17 @@ public final class ConfigCommands { } public static String getPropertySourceOverview() throws IOException { - Configuration config = ConfigurationProvider.getConfiguration(); + Config config = ConfigProvider.getConfig(); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); - pw.println("Property Sources"); - pw.println("----------------"); + pw.println("Config Sources"); + pw.println("--------------"); pw.print(StringUtil.format("ID", 30)); pw.print(StringUtil.format("Ordinal", 20)); pw.print(StringUtil.format("Class", 40)); pw.println(StringUtil.format("Size", 5)); pw.println(StringUtil.printRepeat("-", 80)); - for(PropertySource ps:config.getContext().getPropertySources()){ + for(ConfigSource ps:config.getConfigSources()){ pw.print(StringUtil.format(ps.getName(), 30)); pw.print(StringUtil.format(String.valueOf(ps.getOrdinal()), 20)); pw.print(StringUtil.format(ps.getClass().getName(), 40));
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigPluginTest.java ---------------------------------------------------------------------- diff --git a/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigPluginTest.java b/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigPluginTest.java index 65e8499..89eab4b 100644 --- a/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigPluginTest.java +++ b/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/TamayaConfigPluginTest.java @@ -22,6 +22,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.runners.MockitoJUnitRunner; +import javax.config.Config; import java.util.Dictionary; import java.util.Hashtable; @@ -78,10 +79,10 @@ public class TamayaConfigPluginTest extends AbstractOSGITest{ @Test public void getTMUpdateConfig() throws Exception { - org.apache.tamaya.Configuration config = ((TamayaConfigPlugin)tamayaConfigPlugin).getTamayaConfiguration("java."); + Config config = ((TamayaConfigPlugin)tamayaConfigPlugin).getJavaConfiguration("java."); assertNotNull(config); - assertNull(config.get("jlkjllj")); - assertEquals(System.getProperty("java.home"), config.get("home")); + assertNull(config.getOptionalValue("jlkjllj", String.class).orElse(null)); + assertEquals(System.getProperty("java.home"), config.getValue("home", String.class)); } @Test http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/ConfigCommandsTest.java ---------------------------------------------------------------------- diff --git a/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/ConfigCommandsTest.java b/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/ConfigCommandsTest.java index 67bb22e..69834da 100644 --- a/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/ConfigCommandsTest.java +++ b/modules/osgi/common/src/test/java/org/apache/tamaya/osgi/commands/ConfigCommandsTest.java @@ -36,10 +36,9 @@ public class ConfigCommandsTest extends AbstractOSGITest{ String result = ConfigCommands.getInfo(tamayaConfigPlugin); assertNotNull(result); System.out.println(result); - assertTrue(result.contains("Property Sources")); - assertTrue(result.contains("Property Converter")); - assertTrue(result.contains("Property Filter")); - assertTrue(result.contains("ConfigurationContext")); + assertTrue(result.contains("Config Sources")); + assertTrue(result.contains("Converter")); + assertTrue(result.contains("Filter")); assertTrue(result.contains("Configuration")); } @@ -128,7 +127,7 @@ public class ConfigCommandsTest extends AbstractOSGITest{ String result = ConfigCommands.getPropertySource("system-properties"); assertNotNull(result); System.out.println(result); - assertTrue(result.contains("Property Source")); + assertTrue(result.contains("Config Source")); assertTrue(result.contains("ID")); assertTrue(result.contains("system-properties")); assertTrue(result.contains("Ordinal")); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/common/src/test/resources/META-INF/javaconfig.properties ---------------------------------------------------------------------- diff --git a/modules/osgi/common/src/test/resources/META-INF/javaconfig.properties b/modules/osgi/common/src/test/resources/META-INF/javaconfig.properties new file mode 100644 index 0000000..d0b0cb8 --- /dev/null +++ b/modules/osgi/common/src/test/resources/META-INF/javaconfig.properties @@ -0,0 +1,22 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +[tamaya]my.testProperty1=success1 +[tamaya]my.testProperty2=success2 +[tamaya]my.testProperty3=success3 +[tamaya]my.testProperty4=success4 +[tamaya]java.version=Java2000 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/common/src/test/resources/META-INF/javaconfiguration.properties ---------------------------------------------------------------------- diff --git a/modules/osgi/common/src/test/resources/META-INF/javaconfiguration.properties b/modules/osgi/common/src/test/resources/META-INF/javaconfiguration.properties deleted file mode 100644 index d0b0cb8..0000000 --- a/modules/osgi/common/src/test/resources/META-INF/javaconfiguration.properties +++ /dev/null @@ -1,22 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# -[tamaya]my.testProperty1=success1 -[tamaya]my.testProperty2=success2 -[tamaya]my.testProperty3=success3 -[tamaya]my.testProperty4=success4 -[tamaya]java.version=Java2000 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/gogo-shell/bnd.bnd ---------------------------------------------------------------------- diff --git a/modules/osgi/gogo-shell/bnd.bnd b/modules/osgi/gogo-shell/bnd.bnd index 67e951a..357ffbf 100644 --- a/modules/osgi/gogo-shell/bnd.bnd +++ b/modules/osgi/gogo-shell/bnd.bnd @@ -28,7 +28,7 @@ Import-Package: \ org.apache.tamaya,\ org.apache.tamaya.spi,\ org.apache.tamaya.functions,\ - org.apache.tamaya.spisupport,\ + org.apache.tamaya.base,\ org.apache.tamaya.osgi,\ org.apache.tamaya.osgi.commands,\ org.apache.felix.service.command http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/gogo-shell/pom.xml ---------------------------------------------------------------------- diff --git a/modules/osgi/gogo-shell/pom.xml b/modules/osgi/gogo-shell/pom.xml index b1a3845..0c971d9 100644 --- a/modules/osgi/gogo-shell/pom.xml +++ b/modules/osgi/gogo-shell/pom.xml @@ -70,6 +70,12 @@ <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> </dependency> + <dependency> + <groupId>org.apache.tamaya</groupId> + <artifactId>tamaya-core</artifactId> + <version>${project.parent.version}</version> + <scope>test</scope> + </dependency> </dependencies> </project> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/gogo-shell/src/test/java/org/apache/tamaya/gogo/shell/ConfigCommandsTest.java ---------------------------------------------------------------------- diff --git a/modules/osgi/gogo-shell/src/test/java/org/apache/tamaya/gogo/shell/ConfigCommandsTest.java b/modules/osgi/gogo-shell/src/test/java/org/apache/tamaya/gogo/shell/ConfigCommandsTest.java index dde7b42..b4e268f 100644 --- a/modules/osgi/gogo-shell/src/test/java/org/apache/tamaya/gogo/shell/ConfigCommandsTest.java +++ b/modules/osgi/gogo-shell/src/test/java/org/apache/tamaya/gogo/shell/ConfigCommandsTest.java @@ -56,8 +56,8 @@ public class ConfigCommandsTest extends AbstractOSGITest{ commands.tm_propertysources(); return null; }); - assertTrue(out.startsWith("Property Sources")); - assertTrue(out.contains( "----------------")); + assertTrue(out.startsWith("Config Sources")); + assertTrue(out.contains( "--------------")); assertTrue(out.contains("ID")); assertTrue(out.contains("Ordinal")); assertTrue(out.contains("Class")); @@ -83,7 +83,7 @@ public class ConfigCommandsTest extends AbstractOSGITest{ return null; }); assertTrue(out.contains(System.getProperty("java.version"))); - assertTrue(out.contains("Property Source")); + assertTrue(out.contains("Config Source")); assertTrue(out.contains("Value")); assertTrue(out.contains("system-properties")); } @@ -94,13 +94,13 @@ public class ConfigCommandsTest extends AbstractOSGITest{ commands.tm_propertysource("system-properties"); return null; }); - assertTrue(out.startsWith("Property Source")); + assertTrue(out.startsWith("Config Source")); assertTrue(out.contains("ID")); assertTrue(out.contains("system-properties")); assertTrue(out.contains("Ordinal")); assertTrue(out.contains("1000")); assertTrue(out.contains("Class")); - assertTrue(out.contains("SystemPropertySource")); + assertTrue(out.contains("SystemConfigSource")); assertTrue(out.contains("Properties")); assertTrue(out.contains("Key")); assertTrue(out.contains("Value")); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/injection/bnd.bnd ---------------------------------------------------------------------- diff --git a/modules/osgi/injection/bnd.bnd b/modules/osgi/injection/bnd.bnd index 69e9637..cd67c72 100644 --- a/modules/osgi/injection/bnd.bnd +++ b/modules/osgi/injection/bnd.bnd @@ -27,7 +27,7 @@ Import-Package: \ org.apache.tamaya,\ org.apache.tamaya.spi,\ org.apache.tamaya.functions,\ - org.apache.tamaya.spisupport,\ + org.apache.tamaya.base,\ org.apache.tamaya.osgi,\ org.apache.tamaya.inject.api,\ org.apache.tamaya.inject.spi,\ http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/injection/pom.xml ---------------------------------------------------------------------- diff --git a/modules/osgi/injection/pom.xml b/modules/osgi/injection/pom.xml index 692e98f..6c6334f 100644 --- a/modules/osgi/injection/pom.xml +++ b/modules/osgi/injection/pom.xml @@ -67,6 +67,12 @@ <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> </dependency> + <dependency> + <groupId>org.apache.tamaya</groupId> + <artifactId>tamaya-core</artifactId> + <version>${project.parent.version}</version> + <scope>test</scope> + </dependency> </dependencies> </project> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySource.java ---------------------------------------------------------------------- diff --git a/modules/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySource.java b/modules/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySource.java index 6c5b00a..bef34eb 100644 --- a/modules/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySource.java +++ b/modules/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySource.java @@ -18,8 +18,7 @@ */ package org.apache.tamaya.osgi.injection; -import org.apache.tamaya.spi.PropertyValue; -import org.apache.tamaya.spisupport.propertysource.BasePropertySource; +import org.apache.tamaya.base.configsource.BaseConfigSource; import org.osgi.service.cm.Configuration; import org.osgi.service.cm.ConfigurationAdmin; @@ -32,7 +31,7 @@ import java.util.logging.Logger; * This is a Tamaya PropertySource, which internally wraps the OSGI ConfigAdmin service, preconfigured * for a PID and (optionally) location. */ -public class OSGIConfigAdminPropertySource extends BasePropertySource{ +public class OSGIConfigAdminPropertySource extends BaseConfigSource{ private static final Logger LOG = Logger.getLogger(OSGIConfigAdminPropertySource.class.getName()); private ConfigurationAdmin configurationAdmin; @@ -67,14 +66,14 @@ public class OSGIConfigAdminPropertySource extends BasePropertySource{ } @Override - public PropertyValue get(String key) { + public String getValue(String key) { try { Configuration osgiConfig = configurationAdmin.getConfiguration(pid, location); Dictionary<String,Object> props = osgiConfig.getProperties(); if(props!=null){ Object value = props.get(key); if(value!=null) { - return PropertyValue.of(key, String.valueOf(value), "OSGI ConfigAdmin: " + pid); + return String.valueOf(value); } } } catch (IOException e) { @@ -84,17 +83,17 @@ public class OSGIConfigAdminPropertySource extends BasePropertySource{ } @Override - public Map<String, PropertyValue> getProperties() { + public Map<String, String> getProperties() { try { Configuration osgiConfig = configurationAdmin.getConfiguration(pid); Dictionary<String,Object> props = osgiConfig.getProperties(); if(props!=null){ - Map<String, PropertyValue> result = new HashMap<>(); + Map<String, String> result = new HashMap<>(); Enumeration<String> keys = props.keys(); while(keys.hasMoreElements()){ String key = keys.nextElement(); Object value = props.get(key); - result.put(key, PropertyValue.of(key, String.valueOf(value), "OSGI ConfigAdmin: " + pid)); + result.put(key, String.valueOf(value)); } return result; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigurationInjector.java ---------------------------------------------------------------------- diff --git a/modules/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigurationInjector.java b/modules/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigurationInjector.java index dc90449..073f5a0 100644 --- a/modules/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigurationInjector.java +++ b/modules/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/OSGIConfigurationInjector.java @@ -18,11 +18,12 @@ */ package org.apache.tamaya.osgi.injection; -import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; import org.apache.tamaya.inject.ConfigurationInjection; import org.osgi.service.cm.ConfigurationAdmin; +import javax.config.Config; +import javax.config.ConfigProvider; +import javax.config.spi.ConfigProviderResolver; import java.util.Objects; import java.util.function.Supplier; @@ -34,7 +35,7 @@ final class OSGIConfigurationInjector{ /** The OSGI ConfigManager. */ private ConfigurationAdmin cm; /** The corresponding Tamaya configuration. */ - private Configuration tamayaOSGIConfiguration; + private Config javaConfigOSGIConfiguration; /** The target PID. */ private String pid; /** The target location. */ @@ -59,12 +60,10 @@ final class OSGIConfigurationInjector{ this.cm = Objects.requireNonNull(cm); this.pid = Objects.requireNonNull(pid); this.location = location; - tamayaOSGIConfiguration = ConfigurationProvider.createConfiguration( - ConfigurationProvider.getConfigurationContextBuilder() - .addDefaultPropertyConverters() - .addDefaultPropertyFilters() - .addPropertySources(new OSGIConfigAdminPropertySource(cm, pid, location)) - .build()); + javaConfigOSGIConfiguration = ConfigProviderResolver.instance().getBuilder() + .addDiscoveredConverters() + .withSources(new OSGIConfigAdminPropertySource(cm, pid, location)) + .build(); } /** @@ -91,7 +90,7 @@ final class OSGIConfigurationInjector{ */ public <T> T configure(T instance){ return ConfigurationInjection.getConfigurationInjector() - .configure(instance, tamayaOSGIConfiguration); + .configure(instance, javaConfigOSGIConfiguration); } /** @@ -103,7 +102,7 @@ final class OSGIConfigurationInjector{ */ public <T> Supplier<T> getConfiguredSupplier(java.util.function.Supplier<T> supplier){ return ConfigurationInjection.getConfigurationInjector() - .getConfiguredSupplier(supplier, tamayaOSGIConfiguration); + .getConfiguredSupplier(supplier, javaConfigOSGIConfiguration); } /** @@ -115,6 +114,6 @@ final class OSGIConfigurationInjector{ */ public <T> T createTemplate(Class<T> templateType){ return ConfigurationInjection.getConfigurationInjector() - .createTemplate(templateType, tamayaOSGIConfiguration); + .createTemplate(templateType, javaConfigOSGIConfiguration); } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/TamayaOSGIInjector.java ---------------------------------------------------------------------- diff --git a/modules/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/TamayaOSGIInjector.java b/modules/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/TamayaOSGIInjector.java index fe0fe78..18e0bd6 100644 --- a/modules/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/TamayaOSGIInjector.java +++ b/modules/osgi/injection/src/main/java/org/apache/tamaya/osgi/injection/TamayaOSGIInjector.java @@ -18,7 +18,6 @@ */ package org.apache.tamaya.osgi.injection; -import org.apache.tamaya.Configuration; import org.apache.tamaya.osgi.TamayaConfigPlugin; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/Example.java ---------------------------------------------------------------------- diff --git a/modules/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/Example.java b/modules/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/Example.java index b5726ad..ae66e94 100644 --- a/modules/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/Example.java +++ b/modules/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/Example.java @@ -18,7 +18,8 @@ */ package org.apache.tamaya.osgi.injection; -import org.apache.tamaya.inject.api.Config; + +import javax.config.inject.ConfigProperty; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -27,11 +28,11 @@ import static org.junit.Assert.assertNotNull; * Example class to be configured with injection. */ final class Example { - @Config("java.home") + @ConfigProperty(name ="java.home") String javaHome; - @Config("java.version") + @ConfigProperty(name ="java.version") String javaVersion; - @Config(value = "java.used", defaultValue = "true") + @ConfigProperty(name = "java.used", defaultValue = "true") boolean javaUsed; static void checkExampleConfig(Example example) { http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySourceTest.java ---------------------------------------------------------------------- diff --git a/modules/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySourceTest.java b/modules/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySourceTest.java index cff8c3f..a2b4cf4 100644 --- a/modules/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySourceTest.java +++ b/modules/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/OSGIConfigAdminPropertySourceTest.java @@ -18,7 +18,6 @@ */ package org.apache.tamaya.osgi.injection; -import org.apache.tamaya.spi.PropertyValue; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -62,27 +61,20 @@ public class OSGIConfigAdminPropertySourceTest extends AbstractOSGITest{ } @Test - public void isScannable() throws Exception { - assertEquals(true, propertySource.isScannable()); - } - - @Test - public void get() throws Exception { - PropertyValue val = propertySource.get("java.home"); + public void getValue() throws Exception { + String val = propertySource.getValue("java.home"); assertNotNull(val); - assertEquals(val.getKey(), "java.home"); - assertEquals(val.getValue(), System.getProperty("java.home")); - val = propertySource.get("foo.bar"); + assertEquals(val, System.getProperty("java.home")); + val = propertySource.getValue("foo.bar"); assertNull(val); } @Test public void getProperties() throws Exception { - Map<String,PropertyValue> props = propertySource.getProperties(); + Map<String,String> props = propertySource.getProperties(); assertNotNull(props); - PropertyValue val = props.get("java.home"); - assertEquals(val.getKey(), "java.home"); - assertEquals(val.getValue(), System.getProperty("java.home")); + String val = props.get("java.home"); + assertEquals(val, System.getProperty("java.home")); val = props.get("foo.bar"); assertNull(val); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/TemplateExample.java ---------------------------------------------------------------------- diff --git a/modules/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/TemplateExample.java b/modules/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/TemplateExample.java index 4605b4d..1005d2f 100644 --- a/modules/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/TemplateExample.java +++ b/modules/osgi/injection/src/test/java/org/apache/tamaya/osgi/injection/TemplateExample.java @@ -18,19 +18,20 @@ */ package org.apache.tamaya.osgi.injection; -import org.apache.tamaya.inject.api.Config; + +import javax.config.inject.ConfigProperty; /** * Example template interface. */ interface TemplateExample { - @Config("java.home") + @ConfigProperty(name ="java.home") String getJavaHome(); - @Config("java.version") + @ConfigProperty(name ="java.version") String javaVersion(); - @Config(value = "java.used", defaultValue = "true") + @ConfigProperty(name = "java.used", defaultValue = "true") boolean isJavaUsed(); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/karaf-features/src/main/features/features.xml ---------------------------------------------------------------------- diff --git a/modules/osgi/karaf-features/src/main/features/features.xml b/modules/osgi/karaf-features/src/main/features/features.xml index 34949b7..935dcc5 100644 --- a/modules/osgi/karaf-features/src/main/features/features.xml +++ b/modules/osgi/karaf-features/src/main/features/features.xml @@ -20,7 +20,7 @@ limitations under the License. <features name="org-apache-tamaya-configadmin" version="0.4-incubating"> <bundle>mvn:org.apache.tamaya.ext/tamaya-osgi_alpha/0.4-incubating/jar</bundle> <bundle>mvn:org.apache.tamaya.ext/tamaya-functions/0.4-incubating/jar</bundle> - <bundle>mvn:org.apache.tamaya/tamaya-spisupport/0.4-incubating/jar</bundle> + <bundle>mvn:org.apache.tamaya/tamaya-base/0.4-incubating/jar</bundle> <bundle>mvn:org.apache.tamaya.ext/tamaya-osgi-karaf_alpha/0.4-incubating/jar</bundle> <features name="org-apache-tamaya-minimal" version="0.4-incubating"> <feature name="org-apache-tamaya-api" version="0.4-incubating"> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/karaf-shell/bnd.bnd ---------------------------------------------------------------------- diff --git a/modules/osgi/karaf-shell/bnd.bnd b/modules/osgi/karaf-shell/bnd.bnd index 3bed7ca..a1bf0c7 100644 --- a/modules/osgi/karaf-shell/bnd.bnd +++ b/modules/osgi/karaf-shell/bnd.bnd @@ -27,7 +27,7 @@ Import-Package: \ org.apache.tamaya,\ org.apache.tamaya.spi,\ org.apache.tamaya.functions,\ - org.apache.tamaya.spisupport,\ + org.apache.tamaya.base,\ org.apache.tamaya.osgi,\ org.apache.tamaya.osgi.commands,\ org.apache.felix.service.command,\ http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertySourcesCommand.java ---------------------------------------------------------------------- diff --git a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertySourcesCommand.java b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertySourcesCommand.java index 7aa660d..e9d3d4d 100644 --- a/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertySourcesCommand.java +++ b/modules/osgi/karaf-shell/src/main/java/org/apache/tamaya/karaf/shell/PropertySourcesCommand.java @@ -21,10 +21,7 @@ package org.apache.tamaya.karaf.shell; import org.apache.karaf.shell.api.action.Action; import org.apache.karaf.shell.api.action.Command; import org.apache.karaf.shell.api.action.lifecycle.Service; -import org.apache.tamaya.Configuration; -import org.apache.tamaya.ConfigurationProvider; import org.apache.tamaya.osgi.commands.ConfigCommands; -import org.apache.tamaya.spi.PropertySource; import java.io.IOException; http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/updater/bnd.bnd ---------------------------------------------------------------------- diff --git a/modules/osgi/updater/bnd.bnd b/modules/osgi/updater/bnd.bnd index 416db00..69ae1ea 100644 --- a/modules/osgi/updater/bnd.bnd +++ b/modules/osgi/updater/bnd.bnd @@ -29,6 +29,6 @@ Import-Package: \ org.apache.tamaya,\ org.apache.tamaya.spi,\ org.apache.tamaya.functions,\ - org.apache.tamaya.spisupport,\ + org.apache.tamaya.base,\ org.apache.tamaya.events http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/updater/pom.xml ---------------------------------------------------------------------- diff --git a/modules/osgi/updater/pom.xml b/modules/osgi/updater/pom.xml index 2819239..9aaa7ad 100644 --- a/modules/osgi/updater/pom.xml +++ b/modules/osgi/updater/pom.xml @@ -44,13 +44,9 @@ <dependency> <groupId>org.apache.tamaya</groupId> - <artifactId>tamaya-api</artifactId> - <version>${project.parent.version}</version> - </dependency> - <dependency> - <groupId>org.apache.tamaya</groupId> <artifactId>tamaya-core</artifactId> <version>${project.parent.version}</version> + <scope>test</scope> </dependency> <dependency> <groupId>org.apache.tamaya.ext</groupId> @@ -59,7 +55,7 @@ </dependency> <dependency> <groupId>org.apache.tamaya</groupId> - <artifactId>tamaya-spisupport</artifactId> + <artifactId>tamaya-base</artifactId> <version>${project.parent.version}</version> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/updater/src/main/java/org/apache/tamaya/osgi/updater/Activator.java ---------------------------------------------------------------------- diff --git a/modules/osgi/updater/src/main/java/org/apache/tamaya/osgi/updater/Activator.java b/modules/osgi/updater/src/main/java/org/apache/tamaya/osgi/updater/Activator.java index a83f18f..d8a8113 100644 --- a/modules/osgi/updater/src/main/java/org/apache/tamaya/osgi/updater/Activator.java +++ b/modules/osgi/updater/src/main/java/org/apache/tamaya/osgi/updater/Activator.java @@ -19,7 +19,7 @@ package org.apache.tamaya.osgi.updater; import org.apache.tamaya.events.ConfigEventManager; -import org.apache.tamaya.events.ConfigurationChange; +import org.apache.tamaya.events.ConfigChange; import org.apache.tamaya.osgi.commands.TamayaConfigService; import org.osgi.framework.*; import org.osgi.service.cm.ConfigurationAdmin; @@ -51,7 +51,7 @@ public class Activator implements BundleActivator { @Override public void start(BundleContext context) throws Exception { listener = new EventListener(context); - ConfigEventManager.addListener(listener, ConfigurationChange.class); + ConfigEventManager.addListener(listener, ConfigChange.class); LOG.info("Registered Tamaya getConfig trigger for OSGI."); ServiceReference<TamayaConfigService> pluginRef = context.getServiceReference(TamayaConfigService.class); TamayaConfigService tamayaPlugin = context.getService(pluginRef); @@ -67,7 +67,7 @@ public class Activator implements BundleActivator { public void stop(BundleContext context) throws Exception { updateTimer.cancel(); if (listener != null) { - ConfigEventManager.removeListener(this.listener, ConfigurationChange.class); + ConfigEventManager.removeListener(this.listener, ConfigChange.class); LOG.info("Unregistered Tamaya getConfig trigger for OSGI."); ConfigEventManager.enableChangeMonitoring(false); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/updater/src/main/java/org/apache/tamaya/osgi/updater/EventListener.java ---------------------------------------------------------------------- diff --git a/modules/osgi/updater/src/main/java/org/apache/tamaya/osgi/updater/EventListener.java b/modules/osgi/updater/src/main/java/org/apache/tamaya/osgi/updater/EventListener.java index 68e9bcb..97a3159 100644 --- a/modules/osgi/updater/src/main/java/org/apache/tamaya/osgi/updater/EventListener.java +++ b/modules/osgi/updater/src/main/java/org/apache/tamaya/osgi/updater/EventListener.java @@ -20,7 +20,7 @@ package org.apache.tamaya.osgi.updater; import org.apache.tamaya.events.ConfigEvent; import org.apache.tamaya.events.ConfigEventListener; -import org.apache.tamaya.events.ConfigurationChange; +import org.apache.tamaya.events.ConfigChange; import org.apache.tamaya.osgi.Policy; import org.apache.tamaya.osgi.commands.TamayaConfigService; import org.osgi.framework.*; @@ -47,7 +47,7 @@ final class EventListener implements ConfigEventListener{ public void onConfigEvent(ConfigEvent<?> event) { LOG.finest("Tamya Config change triggered: " + event); Set<String> changedPids = new HashSet<>(); - ConfigurationChange cc = (ConfigurationChange)event; + ConfigChange cc = (ConfigChange)event; for(PropertyChangeEvent evt: cc.getChanges()){ String key = evt.getPropertyName(); String pid = getPid(key); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/osgi/updater/src/test/java/org/apache/tamaya/osgi/updater/EventListenerTest.java ---------------------------------------------------------------------- diff --git a/modules/osgi/updater/src/test/java/org/apache/tamaya/osgi/updater/EventListenerTest.java b/modules/osgi/updater/src/test/java/org/apache/tamaya/osgi/updater/EventListenerTest.java index 6ffd618..a51bc7b 100644 --- a/modules/osgi/updater/src/test/java/org/apache/tamaya/osgi/updater/EventListenerTest.java +++ b/modules/osgi/updater/src/test/java/org/apache/tamaya/osgi/updater/EventListenerTest.java @@ -19,7 +19,7 @@ package org.apache.tamaya.osgi.updater; import org.apache.tamaya.events.ConfigEvent; -import org.apache.tamaya.events.ConfigurationChangeBuilder; +import org.apache.tamaya.events.ConfigChangeBuilder; import org.apache.tamaya.osgi.commands.TamayaConfigService; import org.junit.Before; import org.junit.Test; @@ -44,14 +44,14 @@ public class EventListenerTest extends AbstractOSGITest{ @Test public void testEventWithNoDataDoesNotTriggerTamayaServices() throws Exception { - ConfigEvent evt = ConfigurationChangeBuilder.of().addChange("a", "b").build(); + ConfigEvent evt = ConfigChangeBuilder.of().addChange("a", "b").build(); eventListener.onConfigEvent(evt); verify(bundleContext, never()).getServiceReference(TamayaConfigService.class); } @Test public void testEventForPIDDoesTriggerTamayaServices() throws Exception { - ConfigEvent evt = ConfigurationChangeBuilder.of().addChange("[PID.foo]a", "b").build(); + ConfigEvent evt = ConfigChangeBuilder.of().addChange("[PID.foo]a", "b").build(); eventListener.onConfigEvent(evt); verify(bundleContext).getServiceReference(TamayaConfigService.class); verify(tamayaConfigService).updateConfig("PID.foo"); http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/pom.xml ---------------------------------------------------------------------- diff --git a/modules/pom.xml b/modules/pom.xml index bd7abe0..24675fb 100644 --- a/modules/pom.xml +++ b/modules/pom.xml @@ -43,7 +43,7 @@ under the License. <module>spring</module> <module>jndi</module> <module>osgi</module> - <module>microprofile</module> + <!--<module>microprofile</module>--> <module>injection</module> </modules> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ExpressionResolutionFilter.java ---------------------------------------------------------------------- diff --git a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ExpressionResolutionFilter.java b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ExpressionResolutionFilter.java index 75e4624..0786a94 100644 --- a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ExpressionResolutionFilter.java +++ b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ExpressionResolutionFilter.java @@ -19,7 +19,6 @@ package org.apache.tamaya.resolver.internal; import org.apache.tamaya.resolver.spi.ExpressionEvaluator; -import org.apache.tamaya.spi.ConfigValue; import org.apache.tamaya.spi.Filter; import org.apache.tamaya.spi.ServiceContextManager; @@ -82,11 +81,11 @@ public class ExpressionResolutionFilter implements Filter { * @return the resolved value, or the input in case where no expression was detected. */ @Override - public ConfigValue filterProperty(ConfigValue valueToBeFiltered){ - LOG.finest("Resolving " + valueToBeFiltered); - String newVal = evaluator().evaluateExpression(valueToBeFiltered.getKey(), valueToBeFiltered.getValue(), true); + public String filterProperty(String key, String valueToBeFiltered){ + LOG.finest(() -> "Resolving " + valueToBeFiltered + "("+key+")"); + String newVal = evaluator().evaluateExpression(key, valueToBeFiltered, true); if(newVal!=null){ - return valueToBeFiltered.toBuilder().setValue(newVal).build(); + return newVal; } return null; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ResolvableConfig.java ---------------------------------------------------------------------- diff --git a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ResolvableConfig.java b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ResolvableConfig.java index 1abed5b..7dca6d0 100644 --- a/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ResolvableConfig.java +++ b/modules/resolver/src/main/java/org/apache/tamaya/resolver/internal/ResolvableConfig.java @@ -85,15 +85,16 @@ public final class ResolvableConfig implements Config{ @Override public <T> Optional<T> getOptionalValue(String propertyName, Class<T> propertyType) { - ConfigValue value = ConfigValue.of( - propertyName, delegate.getValue(propertyName, String.class), null); - value = filterManager.filterValue(value); - if(value!=null){ - if(String.class.equals(propertyType)) { - return Optional.ofNullable((T) value.getValue()); + Optional<String> value = delegate.getOptionalValue(propertyName, String.class); + if(value.isPresent()) { + String filtered = filterManager.filterValue(propertyName, value.get(), delegate); + if (filtered != null) { + if (String.class.equals(propertyType)) { + return Optional.ofNullable((T) filtered); + } + return Optional.ofNullable( + (T) converterManager.convertValue(filtered, propertyType)); } - return Optional.ofNullable( - (T)converterManager.convertValue(propertyName, value.getValue(), propertyType, this)); } return Optional.empty(); } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/resolver/src/main/java/org/apache/tamaya/resolver/spi/ExpressionEvaluator.java ---------------------------------------------------------------------- diff --git a/modules/resolver/src/main/java/org/apache/tamaya/resolver/spi/ExpressionEvaluator.java b/modules/resolver/src/main/java/org/apache/tamaya/resolver/spi/ExpressionEvaluator.java index 96dbb66..bd3aa87 100644 --- a/modules/resolver/src/main/java/org/apache/tamaya/resolver/spi/ExpressionEvaluator.java +++ b/modules/resolver/src/main/java/org/apache/tamaya/resolver/spi/ExpressionEvaluator.java @@ -41,7 +41,7 @@ import java.util.Collection; * Also multiple expressions are supported, e.g. ${resource:META-INF/version.conf}, ${file:C:/temp/version.txt}, * ${url:http://configserver/name}. * </pre> - * Basically this service is consumed by an instance of {@link org.apache.tamaya.spi.PropertyFilter}, which + * Basically this service is consumed by an instance of {@link org.apache.tamaya.spi.Filter}, which * takes the configuration values found and passes them to this evaluator, when expressions are detected. This * also done iteratively, so also multi-stepped references (references, which themselves must be evaluated as well) * are supported. http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/spring/pom.xml ---------------------------------------------------------------------- diff --git a/modules/spring/pom.xml b/modules/spring/pom.xml index b3a4e1a..97604e0 100644 --- a/modules/spring/pom.xml +++ b/modules/spring/pom.xml @@ -55,12 +55,6 @@ under the License. <scope>test</scope> </dependency> <dependency> - <groupId>org.apache.tamaya</groupId> - <artifactId>tamaya-api</artifactId> - <version>${tamaya-apicore.version}</version> - <scope>provided</scope> - </dependency> - <dependency> <groupId>org.apache.tamaya.ext</groupId> <artifactId>tamaya-injection</artifactId> <version>${project.version}</version> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/spring/src/main/java/org/apache/tamaya/integration/spring/SpringConfigInjectionPostProcessor.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/main/java/org/apache/tamaya/integration/spring/SpringConfigInjectionPostProcessor.java b/modules/spring/src/main/java/org/apache/tamaya/integration/spring/SpringConfigInjectionPostProcessor.java index 0bcc5c3..7cc43d6 100644 --- a/modules/spring/src/main/java/org/apache/tamaya/integration/spring/SpringConfigInjectionPostProcessor.java +++ b/modules/spring/src/main/java/org/apache/tamaya/integration/spring/SpringConfigInjectionPostProcessor.java @@ -21,12 +21,8 @@ package org.apache.tamaya.integration.spring; import org.apache.tamaya.inject.ConfigurationInjection; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.cglib.core.ReflectUtils; -import org.springframework.cglib.proxy.Enhancer; import org.springframework.stereotype.Component; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Proxy; /** * PostProcessor that performs injection of configured values using Tamaya {@link ConfigurationInjection}. @@ -36,7 +32,9 @@ public class SpringConfigInjectionPostProcessor implements BeanPostProcessor{ @Override public Object postProcessBeforeInitialization(Object o, String s) throws BeansException { - ConfigurationInjection.getConfigurationInjector().configure(o); + if(ConfigurationInjection.getConfigurationInjector().isConfigured(o)){ + ConfigurationInjection.getConfigurationInjector().configure(o); + } return o; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaEnvironment.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaEnvironment.java b/modules/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaEnvironment.java index 7f1000e..11393c5 100644 --- a/modules/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaEnvironment.java +++ b/modules/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaEnvironment.java @@ -28,6 +28,6 @@ public class TamayaEnvironment extends StandardEnvironment{ protected void customizePropertySources(MutablePropertySources propertySources) { super.customizePropertySources(propertySources); - propertySources.addLast(new TamayaSpringPropertySource()); + propertySources.addLast(new TamayaSpringConfigSource()); } } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaSpringConfig.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaSpringConfig.java b/modules/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaSpringConfig.java index 7c9966b..14b7a1e 100644 --- a/modules/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaSpringConfig.java +++ b/modules/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaSpringConfig.java @@ -30,7 +30,7 @@ import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; /** - * Spring Configuration Bean adding {@link TamayaSpringPropertySource} to the current + * Spring Configuration Bean adding {@link TamayaSpringConfigSource} to the current * {@link org.springframework.core.env.Environment}. */ @Component @@ -42,14 +42,14 @@ public class TamayaSpringConfig { @PostConstruct public void init() { - env.getPropertySources().addFirst(new TamayaSpringPropertySource()); + env.getPropertySources().addFirst(new TamayaSpringConfigSource()); } @Bean public static PropertySourcesPlaceholderConfigurer placeHolderConfigurer() { PropertySourcesPlaceholderConfigurer cfgBean = new PropertySourcesPlaceholderConfigurer(); MutablePropertySources sources = new MutablePropertySources(); - sources.addFirst(new TamayaSpringPropertySource()); + sources.addFirst(new TamayaSpringConfigSource()); cfgBean.setPropertySources(sources); return cfgBean; } http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaSpringConfigSource.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaSpringConfigSource.java b/modules/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaSpringConfigSource.java new file mode 100644 index 0000000..0c160e1 --- /dev/null +++ b/modules/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaSpringConfigSource.java @@ -0,0 +1,40 @@ +/* + * 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.integration.spring; + + +import org.springframework.core.env.PropertySource; + +import javax.config.ConfigProvider; + +/** + * Spring PropertySource bridging to Tamaya {@link javax.config.Config}. + */ +public class TamayaSpringConfigSource extends PropertySource<String> { + + public TamayaSpringConfigSource() { + super("ApacheTamayaConfig"); + } + + @Override + public String getProperty(String name) { + return ConfigProvider.getConfig().getOptionalValue(name, String.class).orElse(null); + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaSpringPropertySource.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaSpringPropertySource.java b/modules/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaSpringPropertySource.java deleted file mode 100644 index 2e8ac1c..0000000 --- a/modules/spring/src/main/java/org/apache/tamaya/integration/spring/TamayaSpringPropertySource.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.integration.spring; - - -import org.apache.tamaya.ConfigurationProvider; -import org.springframework.core.env.PropertySource; - -/** - * Spring PropertySource bridging to Tamaya {@link org.apache.tamaya.Configuration}. - */ -public class TamayaSpringPropertySource extends PropertySource<String> { - - public TamayaSpringPropertySource() { - super("ApacheTamayaConfig"); - } - - @Override - public String getProperty(String name) { - return ConfigurationProvider.getConfiguration().get(name); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/spring/src/test/java/org/apache/tamaya/integration/spring/ConfiguredSpringBean.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/apache/tamaya/integration/spring/ConfiguredSpringBean.java b/modules/spring/src/test/java/org/apache/tamaya/integration/spring/ConfiguredSpringBean.java index c43dde0..165baa5 100644 --- a/modules/spring/src/test/java/org/apache/tamaya/integration/spring/ConfiguredSpringBean.java +++ b/modules/spring/src/test/java/org/apache/tamaya/integration/spring/ConfiguredSpringBean.java @@ -18,11 +18,12 @@ */ package org.apache.tamaya.integration.spring; -import org.apache.tamaya.inject.api.Config; import org.apache.tamaya.inject.api.ConfigDefaultSections; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; +import javax.config.inject.ConfigProperty; + /** * Created by Anatole on 25.09.2015. */ @@ -34,10 +35,10 @@ public class ConfiguredSpringBean { @Autowired private Environment env; - @Config("java.version") + @ConfigProperty(name="java.version") private String javaVersion; - @Config(defaultValue = "23") + @ConfigProperty(defaultValue = "23") private int testNumber; public String getJavaVersion(){ http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/spring/src/test/java/org/apache/tamaya/integration/spring/SpringConfigTest2.java ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/java/org/apache/tamaya/integration/spring/SpringConfigTest2.java b/modules/spring/src/test/java/org/apache/tamaya/integration/spring/SpringConfigTest2.java index 6eab61d..4e4f8d9 100644 --- a/modules/spring/src/test/java/org/apache/tamaya/integration/spring/SpringConfigTest2.java +++ b/modules/spring/src/test/java/org/apache/tamaya/integration/spring/SpringConfigTest2.java @@ -19,12 +19,8 @@ package org.apache.tamaya.integration.spring; import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/spring/src/test/resources/META-INF/javaconfig.properties ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/resources/META-INF/javaconfig.properties b/modules/spring/src/test/resources/META-INF/javaconfig.properties new file mode 100644 index 0000000..3366128 --- /dev/null +++ b/modules/spring/src/test/resources/META-INF/javaconfig.properties @@ -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. +# +myConfiguredValue=value11 +propertyValue=value2 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/modules/spring/src/test/resources/META-INF/javaconfiguration.properties ---------------------------------------------------------------------- diff --git a/modules/spring/src/test/resources/META-INF/javaconfiguration.properties b/modules/spring/src/test/resources/META-INF/javaconfiguration.properties deleted file mode 100644 index 3366128..0000000 --- a/modules/spring/src/test/resources/META-INF/javaconfiguration.properties +++ /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. -# -myConfiguredValue=value11 -propertyValue=value2 \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/cfb364cd/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 4c45296..c3a17e0 100644 --- a/pom.xml +++ b/pom.xml @@ -44,7 +44,8 @@ under the License. <properties> <!-- Used version of Tamaya API&Core --> - <tamaya-apicore.version>0.4-incubating-SNAPSHOT</tamaya-apicore.version> + <javaconfig.version>1.0-SNAPSHOT</javaconfig.version> + <tamaya-apicore.version>${project.version}</tamaya-apicore.version> <commons-io.version>2.5</commons-io.version> <findbugs.skip>false</findbugs.skip> @@ -332,14 +333,27 @@ under the License. <artifactId>johnzon-core</artifactId> <version>${johnzon.version}</version> </dependency> + <dependency> + <groupId>javax.config</groupId> + <artifactId>javaconfig-api</artifactId> + <version>${javaconfig.version}</version> + </dependency> + <dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-annotation_1.2_spec</artifactId> + <version>1.0-alpha-1</version> + </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> + <groupId>javax.config</groupId> + <artifactId>javaconfig-api</artifactId> + </dependency> + <dependency> <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-annotation_1.2_spec</artifactId> - <version>1.0-alpha-1</version> </dependency> <dependency> <groupId>junit</groupId> @@ -385,7 +399,7 @@ under the License. <dependency> <groupId>org.apache.tamaya</groupId> <artifactId>buildconfigurations</artifactId> - <version>${tamaya-apicore.version}</version> + <version>${tamaya.version}</version> </dependency> <dependency> <groupId>com.puppycrawl.tools</groupId> @@ -437,7 +451,7 @@ under the License. <dependency> <groupId>org.apache.tamaya</groupId> <artifactId>buildconfigurations</artifactId> - <version>${tamaya-apicore.version}</version> + <version>${tamaya.version}</version> </dependency> </dependencies> </plugin>
