- Removed dependecy of formats module from events module.
- Simplified events module.


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/f71dc11c
Tree: 
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/f71dc11c
Diff: 
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/f71dc11c

Branch: refs/heads/master
Commit: f71dc11c60bfb21dedc94fdacbab518d654a1264
Parents: 65fdcd2
Author: anatole <anat...@apache.org>
Authored: Fri Dec 18 02:45:14 2015 +0100
Committer: Oliver B. Fischer <ple...@apache.org>
Committed: Fri Sep 30 21:29:37 2016 +0200

----------------------------------------------------------------------
 pom.xml                                         | 10 +--
 .../ObservingPropertySourceProvider.java        | 78 ++++++--------------
 ...g.apache.tamaya.events.spi.ConfigObserverSpi | 19 -----
 .../tamaya/events/TestObservingProvider.java    |  4 +-
 4 files changed, 30 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/f71dc11c/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 7eac4c2..f5b384b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -42,11 +42,11 @@ under the License.
             <version>${project.version}</version>
             <scope>provided</scope>
         </dependency>
-        <dependency>
-            <groupId>org.apache.tamaya.ext</groupId>
-            <artifactId>tamaya-formats</artifactId>
-            <version>${project.version}</version>
-        </dependency>
+        <!--<dependency>-->
+            <!--<groupId>org.apache.tamaya.ext</groupId>-->
+            <!--<artifactId>tamaya-formats</artifactId>-->
+            <!--<version>${project.version}</version>-->
+        <!--</dependency>-->
         <dependency>
             <groupId>org.apache.tamaya</groupId>
             <artifactId>tamaya-core</artifactId>

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/f71dc11c/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
 
b/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
index 8387504..d8c869f 100644
--- 
a/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
+++ 
b/src/main/java/org/apache/tamaya/events/folderobserver/ObservingPropertySourceProvider.java
@@ -19,12 +19,10 @@
 package org.apache.tamaya.events.folderobserver;
 
 import org.apache.tamaya.ConfigException;
+import org.apache.tamaya.core.propertysource.BasePropertySource;
 import org.apache.tamaya.events.ConfigEventManager;
 import org.apache.tamaya.events.ConfigurationContextChange;
 import org.apache.tamaya.events.ConfigurationContextChangeBuilder;
-import org.apache.tamaya.format.ConfigurationData;
-import org.apache.tamaya.format.ConfigurationFormat;
-import org.apache.tamaya.format.FlattenedDefaultPropertySource;
 import org.apache.tamaya.spi.PropertySource;
 import org.apache.tamaya.spi.PropertySourceProvider;
 
@@ -35,12 +33,7 @@ import java.net.URL;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
+import java.util.*;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.logging.Level;
@@ -64,29 +57,16 @@ public class ObservingPropertySourceProvider implements 
PropertySourceProvider,
      */
     private final List<PropertySource> propertySources = 
Collections.synchronizedList(new LinkedList<PropertySource>());
     /**
-     * The supported configuration formats of this provider.
-     */
-    private Collection<ConfigurationFormat> formats = new ArrayList<>();
-    /**
      * The thread pool used.
      */
     private ExecutorService executor = Executors.newSingleThreadExecutor();
 
     /**
-     * Constructor, reading the config file from classpath resource and system 
property.
-     */
-    public ObservingPropertySourceProvider(ConfigurationFormat... formats) {
-        this(null, formats);
-    }
-
-    /**
      * Constructorm using an explicit directory, ignoring all kind of 
configuration, if set.
      *
      * @param directory the target directory. If null, the default 
configuration and system property are used.
-     * @param formats   the formats to be used.
      */
-    public ObservingPropertySourceProvider(Path directory, 
ConfigurationFormat... formats) {
-        this.formats = Arrays.asList(formats);
+    public ObservingPropertySourceProvider(Path directory) {
         if (directory == null) {
             directory = getDirectory();
         }
@@ -111,10 +91,7 @@ public class ObservingPropertySourceProvider implements 
PropertySourceProvider,
         try {
             synchronized (propertySources) {
                 for (Path path : Files.newDirectoryStream(directory, "*")) {
-                    ConfigurationData data = loadFile(path);
-                    if (data != null) {
-                        result.addAll(getPropertySources(data));
-                    }
+                    result.addAll(getPropertySources(path));
                 }
                 return result;
             }
@@ -124,8 +101,14 @@ public class ObservingPropertySourceProvider implements 
PropertySourceProvider,
         return result;
     }
 
-    protected Collection<PropertySource> getPropertySources(ConfigurationData 
data) {
-        return Arrays.asList(new PropertySource[]{new 
FlattenedDefaultPropertySource(data)});
+    protected Collection<PropertySource> getPropertySources(final Path file) {
+        return Arrays.asList(new PropertySource[]{new BasePropertySource() {
+            private Map<String,String> props = readProperties(file);
+            @Override
+            public Map<String, String> getProperties() {
+                return props;
+            }
+        }});
     }
 
     /**
@@ -133,33 +116,20 @@ public class ObservingPropertySourceProvider implements 
PropertySourceProvider,
      *
      * @param file the file, not null.
      */
-    protected ConfigurationData loadFile(Path file) {
-        InputStream is = null;
-        for (ConfigurationFormat format : formats) {
-            try {
-                URL url = file.toUri().toURL();
-                if (format.accepts(url)) {
-                    is = url.openStream();
-                    ConfigurationData data = 
format.readConfiguration(file.toString(), is);
-                    if (data != null) {
-                        return data;
-                    }
-                }
-            } catch (IOException e) {
-                LOG.log(Level.INFO, "Error reading file: " + file.toString() +
-                        ", using format: " + format, e);
-            } finally {
-                if (is != null) {
-                    try {
-                        is.close();
-                    } catch (IOException ioe) {
-                        LOG.log(Level.SEVERE, "Failed to rea data...", ioe);
-                    }
-                }
+    protected static Map<String,String> readProperties(Path file) {
+        try (InputStream is = file.toUri().toURL().openStream()){
+            Properties props = new Properties();
+                props.load(is);
+            Map<String,String> result = new HashMap<>();
+            for(Map.Entry en:props.entrySet()){
+                result.put(en.getKey().toString(), en.getValue().toString());
             }
+            return result;
+        } catch (Exception e) {
+            LOG.log(Level.INFO, "Error reading file: " + file.toString() +
+                    ", using format: properties", e);
         }
-        LOG.warning("Error reading file: " + file.toString());
-        return null;
+        return Collections.emptyMap();
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/f71dc11c/src/main/resources/META-INF/services/org.apache.tamaya.events.spi.ConfigObserverSpi
----------------------------------------------------------------------
diff --git 
a/src/main/resources/META-INF/services/org.apache.tamaya.events.spi.ConfigObserverSpi
 
b/src/main/resources/META-INF/services/org.apache.tamaya.events.spi.ConfigObserverSpi
deleted file mode 100644
index 99670e3..0000000
--- 
a/src/main/resources/META-INF/services/org.apache.tamaya.events.spi.ConfigObserverSpi
+++ /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.events.internal.DefaultConfigChangeObserver
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/f71dc11c/src/test/java/org/apache/tamaya/events/TestObservingProvider.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/tamaya/events/TestObservingProvider.java 
b/src/test/java/org/apache/tamaya/events/TestObservingProvider.java
index 896fcf7..2685d3e 100644
--- a/src/test/java/org/apache/tamaya/events/TestObservingProvider.java
+++ b/src/test/java/org/apache/tamaya/events/TestObservingProvider.java
@@ -20,7 +20,6 @@ package org.apache.tamaya.events;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.tamaya.events.folderobserver.ObservingPropertySourceProvider;
-import org.apache.tamaya.format.formats.PropertiesFormat;
 
 import java.io.File;
 import java.nio.file.Files;
@@ -74,8 +73,7 @@ public class TestObservingProvider extends 
ObservingPropertySourceProvider{
     }
 
     public TestObservingProvider(){
-        super(propertyLocation,
-                new PropertiesFormat());
+        super(propertyLocation);
         Logger.getLogger(getClass().getName()).info("Using test directory: " + 
getTestPath());
     }
 

Reply via email to