Repository: incubator-tamaya
Updated Branches:
  refs/heads/configjsr d0e14ed70 -> 063f8adad


Reimplemented (also simjplified) Tamaya core completely based on latest JSR 
API. Moved prior Tamaya API into compat module.

Signed-off-by: Anatole Tresch <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/a31af003
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/a31af003
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/a31af003

Branch: refs/heads/configjsr
Commit: a31af0036a41c9dcf89e243b5649007a108cd2e3
Parents: d0e14ed
Author: Anatole Tresch <[email protected]>
Authored: Wed Dec 13 23:42:52 2017 +0100
Committer: Anatole Tresch <[email protected]>
Committed: Wed Dec 13 23:42:52 2017 +0100

----------------------------------------------------------------------
 code/base/pom.xml                               |  5 --
 .../apache/tamaya/core/OSGIServiceLoader.java   |  2 +-
 .../internal/converters/ClassConverterTest.java |  1 -
 .../internal/converters/URIConverterTest.java   |  1 -
 .../internal/converters/URLConverterTest.java   |  1 -
 .../apache/tamaya/examples/minimal/Main.java    | 31 +++++-----
 examples/02-custom-property-source/pom.xml      |  5 ++
 .../examples/custompropertysource/Main.java     | 43 ++++++-------
 .../SimpleConfigSource.java                     | 64 ++++++++++++++++++++
 .../SimplePropertySource.java                   | 64 --------------------
 .../SimplePropertySourceProvider.java           | 22 ++++---
 11 files changed, 116 insertions(+), 123 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a31af003/code/base/pom.xml
----------------------------------------------------------------------
diff --git a/code/base/pom.xml b/code/base/pom.xml
index dc16016..603c41b 100644
--- a/code/base/pom.xml
+++ b/code/base/pom.xml
@@ -34,11 +34,6 @@ under the License.
 
     <dependencies>
         <dependency>
-            <groupId>org.apache.tamaya</groupId>
-            <artifactId>tamaya-spisupport</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-annotation_1.2_spec</artifactId>
             <version>1.0-alpha-1</version>

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a31af003/code/core/src/main/java/org/apache/tamaya/core/OSGIServiceLoader.java
----------------------------------------------------------------------
diff --git 
a/code/core/src/main/java/org/apache/tamaya/core/OSGIServiceLoader.java 
b/code/core/src/main/java/org/apache/tamaya/core/OSGIServiceLoader.java
index 90e74bc..96e3da9 100644
--- a/code/core/src/main/java/org/apache/tamaya/core/OSGIServiceLoader.java
+++ b/code/core/src/main/java/org/apache/tamaya/core/OSGIServiceLoader.java
@@ -26,7 +26,7 @@ import java.util.*;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import org.apache.tamaya.spisupport.PriorityServiceComparator;
+import org.apache.tamaya.base.PriorityServiceComparator;
 import org.osgi.framework.*;
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a31af003/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ClassConverterTest.java
----------------------------------------------------------------------
diff --git 
a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ClassConverterTest.java
 
b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ClassConverterTest.java
index 933d6ce..08a0cdb 100644
--- 
a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ClassConverterTest.java
+++ 
b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/ClassConverterTest.java
@@ -18,7 +18,6 @@
  */
 package org.apache.tamaya.core.internal.converters;
 
-import org.apache.tamaya.TypeLiteral;
 import org.apache.tamaya.core.converters.ClassConverter;
 import org.apache.tamaya.base.convert.ConversionContext;
 import org.junit.Test;

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a31af003/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URIConverterTest.java
----------------------------------------------------------------------
diff --git 
a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URIConverterTest.java
 
b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URIConverterTest.java
index 2010b1d..deb4ada 100644
--- 
a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URIConverterTest.java
+++ 
b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URIConverterTest.java
@@ -18,7 +18,6 @@
  */
 package org.apache.tamaya.core.internal.converters;
 
-import org.apache.tamaya.TypeLiteral;
 import org.apache.tamaya.core.converters.URIConverter;
 import org.apache.tamaya.base.convert.ConversionContext;
 import org.junit.After;

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a31af003/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URLConverterTest.java
----------------------------------------------------------------------
diff --git 
a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URLConverterTest.java
 
b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URLConverterTest.java
index b12c114..196555c 100644
--- 
a/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URLConverterTest.java
+++ 
b/code/core/src/test/java/org/apache/tamaya/core/internal/converters/URLConverterTest.java
@@ -18,7 +18,6 @@
  */
 package org.apache.tamaya.core.internal.converters;
 
-import org.apache.tamaya.TypeLiteral;
 import org.apache.tamaya.core.converters.URLConverter;
 import org.apache.tamaya.base.convert.ConversionContext;
 import org.junit.Test;

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a31af003/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/Main.java
----------------------------------------------------------------------
diff --git 
a/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/Main.java
 
b/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/Main.java
index aeb44ef..93db446 100644
--- 
a/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/Main.java
+++ 
b/examples/01-minimal/src/main/java/org/apache/tamaya/examples/minimal/Main.java
@@ -18,11 +18,11 @@
  */
 package org.apache.tamaya.examples.minimal;
 
-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.Set;
 import java.util.TreeMap;
 import java.util.logging.LogManager;
 import java.util.logging.Logger;
@@ -34,14 +34,11 @@ import static java.lang.String.format;
  *
  * <p>
  *  Without any additional configuration Tamaya allows you access via
- *  {@link ConfigurationProvider#getConfiguration} all configuration values.
+ *  {@link ConfigProvider#getConfig} all configuration values.
  *  Accessable are all system environment properties, all system properties,
  *  and all properties which are found in {@code 
/META-INF/javaconfiguration.properties}
  *  or {@code /META-INF/javaconfiguration.xml}.
  * </p>
- *
- * @see org.apache.tamaya.spisupport.propertysource.EnvironmentPropertySource
- * @see org.apache.tamaya.spisupport.propertysource.SystemPropertySource
  */
 public class Main {
     /*
@@ -57,28 +54,28 @@ public class Main {
     }
 
     public static void main(String[] args) {
-        Configuration cfg = ConfigurationProvider.getConfiguration();
+        Config cfg = ConfigProvider.getConfig();
 
         
System.out.println("****************************************************");
         System.out.println("Minimal 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();
 
-        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 key : properties) {
+            stream.println(format("\t%s = %s", key, config.getValue(key, 
String.class)));
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a31af003/examples/02-custom-property-source/pom.xml
----------------------------------------------------------------------
diff --git a/examples/02-custom-property-source/pom.xml 
b/examples/02-custom-property-source/pom.xml
index 4fe43b4..05f85b8 100644
--- a/examples/02-custom-property-source/pom.xml
+++ b/examples/02-custom-property-source/pom.xml
@@ -54,6 +54,11 @@ under the License.
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.tamaya</groupId>
+            <artifactId>tamaya-base</artifactId>
+            <version>0.4-incubating-SNAPSHOT</version>
+        </dependency>
     </dependencies>
     
 </project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a31af003/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/Main.java
----------------------------------------------------------------------
diff --git 
a/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/Main.java
 
b/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/Main.java
index dc254e8..1c285b2 100644
--- 
a/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/Main.java
+++ 
b/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/Main.java
@@ -18,24 +18,21 @@
  */
 package org.apache.tamaya.examples.custompropertysource;
 
-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;
 import java.util.logging.LogManager;
 import java.util.logging.Logger;
 
 import static java.lang.String.format;
 
 /**
- * Small example demonstrating the usage of a self-written {@link 
org.apache.tamaya.spi.PropertySource}
- * and {@link org.apache.tamaya.spi.PropertySourceProvider}.
+ * Small example demonstrating the usage of a self-written {@link 
javax.config.spi.ConfigSource}
+ * and {@link javax.config.spi.ConfigSourceProvider}.
  *
  * <p>
- *  {@link SimplePropertySource} is a custom implementation of a
- *  {@link org.apache.tamaya.spi.PropertySource}. It reads its properties from 
a
+ *  {@link org.apache.tamaya.base.configsource.SimpleConfigSource} is a custom 
implementation of a
+ *  {@link javax.config.spi.ConfigSource}. It reads its properties from a
  *  flexibly configurable location. As it is an implementation
  *  of {@code PropertySource} and it is listed as service implementation
  *  in {@code META-INF/services/org.apache.tamaya.spi.PropertySource} Tamaya 
is able
@@ -44,8 +41,8 @@ import static java.lang.String.format;
  *
  * <p>
  *  The same applies to {@link SimplePropertySourceProvider} which is an 
implementation
- *  of {@link org.apache.tamaya.spi.PropertySourceProvider}. Tamaya finds 
implementations
- *  of a {@link org.apache.tamaya.spi.PropertySourceProvider} also through the
+ *  of {@link javax.config.spi.ConfigSourceProvider}. Tamaya finds 
implementations
+ *  of a {@link javax.config.spi.ConfigSourceProvider} also through the
  *  Service Provider Interface service of Java. Therefore it is listed in
  *  {@code META-INF/services/org.apache.tamaya.spi.PropertySourceProvider} 
file.
  * </p>
@@ -64,31 +61,31 @@ public class Main {
     }
 
     public static void main(String[] args) {
-        Configuration cfg = ConfigurationProvider.getConfiguration();
+        Config cfg = ConfigProvider.getConfig();
 
         
System.out.println("*****************************************************");
         System.out.println("Simple Example (with a PropertySource and a 
Provider)");
         
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/blob/a31af003/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimpleConfigSource.java
----------------------------------------------------------------------
diff --git 
a/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimpleConfigSource.java
 
b/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimpleConfigSource.java
new file mode 100644
index 0000000..5aede5f
--- /dev/null
+++ 
b/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimpleConfigSource.java
@@ -0,0 +1,64 @@
+/*
+ * 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.examples.custompropertysource;
+
+import org.apache.tamaya.base.configsource.BaseConfigSource;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+public class SimpleConfigSource extends BaseConfigSource {
+
+    public static final String CONFIG_PROPERTIES_LOCATION = 
"META-INF/MyOtherConfigProperties.properties";
+    private Map<String,String> props = new HashMap<>();
+
+    public SimpleConfigSource() throws IOException {
+        
this(ClassLoader.getSystemClassLoader().getResource(CONFIG_PROPERTIES_LOCATION));
+    }
+    public SimpleConfigSource(URL url) throws IOException {
+        Properties properties = new Properties();
+
+        try(InputStream is = url.openStream()){
+            properties.load(is);
+
+            for(Map.Entry en: properties.entrySet()){
+                props.put(en.getKey().toString(),
+                        en.getValue().toString());
+            }
+        }
+        finally{
+            props = Collections.unmodifiableMap(props);
+        }
+    }
+
+    @Override
+    public String getName() {
+        return CONFIG_PROPERTIES_LOCATION;
+    }
+
+    @Override
+    public Map<String, String> getProperties() {
+        return props;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a31af003/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimplePropertySource.java
----------------------------------------------------------------------
diff --git 
a/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimplePropertySource.java
 
b/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimplePropertySource.java
deleted file mode 100644
index d21230e..0000000
--- 
a/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimplePropertySource.java
+++ /dev/null
@@ -1,64 +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.examples.custompropertysource;
-
-import org.apache.tamaya.spisupport.propertysource.BasePropertySource;
-import org.apache.tamaya.spi.PropertyValue;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-public class SimplePropertySource extends BasePropertySource {
-
-    public static final String CONFIG_PROPERTIES_LOCATION = 
"META-INF/MyOtherConfigProperties.properties";
-    private Map<String,PropertyValue> props = new HashMap<>();
-
-    public SimplePropertySource() throws IOException {
-        URL url = 
ClassLoader.getSystemClassLoader().getResource(CONFIG_PROPERTIES_LOCATION);
-        Properties properties = new Properties();
-
-        try(InputStream is = url.openStream()){
-            properties.load(is);
-
-            for(Map.Entry en: properties.entrySet()){
-                props.put(en.getKey().toString(),
-                        PropertyValue.of(en.getKey().toString(), 
en.getValue().toString(),
-                                getName()));
-            }
-        }
-        finally{
-            props = Collections.unmodifiableMap(props);
-        }
-    }
-
-    @Override
-    public String getName() {
-        return CONFIG_PROPERTIES_LOCATION;
-    }
-
-    @Override
-    public Map<String, PropertyValue> getProperties() {
-        return props;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/a31af003/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimplePropertySourceProvider.java
----------------------------------------------------------------------
diff --git 
a/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimplePropertySourceProvider.java
 
b/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimplePropertySourceProvider.java
index 0573fbd..26a1ac8 100644
--- 
a/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimplePropertySourceProvider.java
+++ 
b/examples/02-custom-property-source/src/main/java/org/apache/tamaya/examples/custompropertysource/SimplePropertySourceProvider.java
@@ -18,30 +18,32 @@
  */
 package org.apache.tamaya.examples.custompropertysource;
 
-import org.apache.tamaya.spisupport.propertysource.SimplePropertySource;
-import org.apache.tamaya.spi.PropertySource;
-import org.apache.tamaya.spi.PropertySourceProvider;
-
+import javax.config.spi.ConfigSource;
+import javax.config.spi.ConfigSourceProvider;
+import java.io.IOException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.List;
 
-public class SimplePropertySourceProvider implements PropertySourceProvider {
+public class SimplePropertySourceProvider implements ConfigSourceProvider {
     private static final String[] RESOURCES = {
         "cfgOther/a.properties", "cfgOther/b.properties", 
"cfgOther/c.properties"
     };
 
     @Override
-    public Collection<PropertySource> getPropertySources() {
-        List<PropertySource> propertySources = new ArrayList<>();
+    public Collection<ConfigSource> getConfigSources(ClassLoader cl) {
+        List<ConfigSource> propertySources = new ArrayList<>();
 
         for (String res : RESOURCES) {
             URL url = ClassLoader.getSystemClassLoader().getResource(res);
-            propertySources.add(new SimplePropertySource(url));
+            try {
+                propertySources.add(new SimpleConfigSource(url));
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
         }
 
-        return Collections.unmodifiableList(propertySources);
+        return propertySources;
     }
 }

Reply via email to