tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anat...@apache.org
Subject [2/3] incubator-tamaya git commit: TAMAYA-121: Removed unused felix and karaf deps, so we depend on OSGI only ; )
Date Tue, 13 Oct 2015 23:31:59 GMT
TAMAYA-121: Removed unused felix and karaf deps, so we depend on OSGI only ;)


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

Branch: refs/heads/master
Commit: 6935776aa32ee7ef7046d6dcbd942c562b3ed548
Parents: c1ec24c
Author: anatole <anatole@apache.org>
Authored: Wed Oct 14 01:30:55 2015 +0200
Committer: anatole <anatole@apache.org>
Committed: Wed Oct 14 01:31:47 2015 +0200

----------------------------------------------------------------------
 modules/integration/osgi/pom.xml                | 17 ++--
 .../tamaya/integration/osgi/Configurations.java | 92 --------------------
 .../integration/osgi/TamayaConfigAdminImpl.java | 34 ++++----
 .../osgi/TamayaConfigurationImpl.java           | 36 ++++++--
 4 files changed, 54 insertions(+), 125 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/6935776a/modules/integration/osgi/pom.xml
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/pom.xml b/modules/integration/osgi/pom.xml
index 2b7352e..a8766dc 100644
--- a/modules/integration/osgi/pom.xml
+++ b/modules/integration/osgi/pom.xml
@@ -27,17 +27,15 @@
         <version>0.2-incubating-SNAPSHOT</version>
     </parent>
 
-    <artifactId>karaf-tamayacm</artifactId>
+    <artifactId>tamaya-osgi-config</artifactId>
     <packaging>bundle</packaging>
-    <name>Apache Karaf :: OSGi Services :: Tamaya Based ConfigAdmin</name>
+    <name>Apache Tamaya :: OSGi Services :: Tamaya Based OSGI ConfigAdmin</name>
     <description>Tamaya Based ConfigAdmin Service</description>
 
     <properties>
         <osgi.version>6.0.0</osgi.version>
         <osgi.compendium.version>5.0.0</osgi.compendium.version>
-        <karaf.version>4.0.0</karaf.version>
         <felix.plugin.version>2.5.4</felix.plugin.version>
-        <felix.utils.version>1.8.0</felix.utils.version>
     </properties>
 
     <build>
@@ -103,17 +101,16 @@
             <version>${osgi.compendium.version}</version>
         </dependency>
         <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.utils</artifactId>
-            <version>${felix.utils.version}</version>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
             <version>${osgi.version}</version>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.tamaya.ext</groupId>
+            <artifactId>tamaya-functions</artifactId>
+            <version>${project.version}</version>
+        </dependency>
     </dependencies>
 
 </project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/6935776a/modules/integration/osgi/src/main/java/org/tamaya/integration/osgi/Configurations.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/src/main/java/org/tamaya/integration/osgi/Configurations.java
b/modules/integration/osgi/src/main/java/org/tamaya/integration/osgi/Configurations.java
deleted file mode 100644
index 7c6fd2f..0000000
--- a/modules/integration/osgi/src/main/java/org/tamaya/integration/osgi/Configurations.java
+++ /dev/null
@@ -1,92 +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.tamaya.integration.osgi;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-import org.apache.felix.utils.properties.InterpolationHelper;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.service.cm.Configuration;
-
-public class Configurations {
-
-    public static List<Configuration> loadConfigurations(BundleContext context, File
directory) throws IOException {
-        Map<String, Map<String, String>> configs = new HashMap<>();
-        File[] files = directory.listFiles();
-        if (files != null) {
-            for (File file : files) {
-                if (file.getName().endsWith(".cfg")) {
-                    try (InputStream in = new BufferedInputStream(new FileInputStream(file)))
{
-                        final Properties p = new Properties();
-                        in.mark(1);
-                        boolean isXml = in.read() == '<';
-                        in.reset();
-                        if (isXml) {
-                            p.loadFromXML(in);
-                        } else {
-                            p.load(in);
-                        }
-                        Map<String, String> strMap = new HashMap<>();
-                        for (Object k : p.keySet()) {
-                            strMap.put(k.toString(), p.getProperty(k.toString()));
-                        }
-                        configs.put(file.getName(), strMap);
-                    }
-                }
-            }
-        }
-        return createConfigurations(context, configs);
-    }
-
-    public static List<Configuration> createConfigurations(BundleContext context, Map<String,
Map<String, String>> configs) {
-        List<Configuration> configurations = new ArrayList<>();
-        for (Map.Entry<String, Map<String, String>> entry : configs.entrySet())
{
-            String pid[] = parsePid(entry.getKey());
-            Map<String, String> cfg = entry.getValue();
-            InterpolationHelper.performSubstitution(cfg, context);
-            cfg.put(Constants.SERVICE_PID, pid[0]);
-            configurations.add(new TamayaConfigurationImpl(pid[0], pid[1], new Hashtable<String,
Object>(cfg)));
-        }
-        return configurations;
-    }
-
-    private static String[] parsePid(String path) {
-        String pid = path.substring(0, path.lastIndexOf('.'));
-        int n = pid.indexOf('-');
-        if (n > 0) {
-            String factoryPid = pid.substring(n + 1);
-            pid = pid.substring(0, n);
-            return new String[] { pid, factoryPid };
-        } else {
-            return new String[] { pid, null };
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/6935776a/modules/integration/osgi/src/main/java/org/tamaya/integration/osgi/TamayaConfigAdminImpl.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/src/main/java/org/tamaya/integration/osgi/TamayaConfigAdminImpl.java
b/modules/integration/osgi/src/main/java/org/tamaya/integration/osgi/TamayaConfigAdminImpl.java
index 333e8ab..c9c7f00 100644
--- a/modules/integration/osgi/src/main/java/org/tamaya/integration/osgi/TamayaConfigAdminImpl.java
+++ b/modules/integration/osgi/src/main/java/org/tamaya/integration/osgi/TamayaConfigAdminImpl.java
@@ -20,7 +20,9 @@ package org.tamaya.integration.osgi;
 
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.List;
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
@@ -29,13 +31,16 @@ import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.cm.ManagedService;
 import org.osgi.service.cm.ManagedServiceFactory;
 import org.osgi.util.tracker.ServiceTracker;
 
+/**
+ * Tamaya based implementation of an OSGI {@link ConfigurationAdmin}.
+ */
 public class TamayaConfigAdminImpl implements ConfigurationAdmin {
     private final BundleContext context;
+    private Map<String,Configuration> configs = new ConcurrentHashMap<>();
 
     public TamayaConfigAdminImpl(BundleContext context) throws IOException {
         this.context = context;
@@ -117,29 +122,24 @@ public class TamayaConfigAdminImpl implements ConfigurationAdmin {
 
     @Override
     public Configuration getConfiguration(String pid) throws IOException {
-//        for (Configuration config : configurations) {
-//            if (config.getPid().equals(pid) && config.getFactoryPid() == null)
{
-//                return config;
-//            }
-//        }
-        return null;
+        return new TamayaConfigurationImpl(pid, null);
     }
 
     @Override
     public Configuration[] listConfigurations(String filter) throws IOException, InvalidSyntaxException
{
-        List<Configuration> configs;
+        Collection<Configuration> result;
         if (filter == null) {
-//            configs = configurations;
+            result = this.configs.values();
         } else {
-            configs = new ArrayList<>();
+            result = new ArrayList<>();
             Filter flt = context.createFilter(filter);
-//            for (Configuration config : configurations) {
-//                if (flt.match(config.getProperties())) {
-//                    configs.add(config);
-//                }
-//            }
+            for (Configuration config : this.configs.values()) {
+                if (flt.match(config.getProperties())) {
+                    result.add(config);
+                }
+            }
         }
-        return null; //configs.isEmpty() ? null : configs.toArray(new Configuration[configs.size()]);
+        return result.isEmpty() ? null : result.toArray(new Configuration[configs.size()]);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/6935776a/modules/integration/osgi/src/main/java/org/tamaya/integration/osgi/TamayaConfigurationImpl.java
----------------------------------------------------------------------
diff --git a/modules/integration/osgi/src/main/java/org/tamaya/integration/osgi/TamayaConfigurationImpl.java
b/modules/integration/osgi/src/main/java/org/tamaya/integration/osgi/TamayaConfigurationImpl.java
index 8cb5803..085b1d9 100644
--- a/modules/integration/osgi/src/main/java/org/tamaya/integration/osgi/TamayaConfigurationImpl.java
+++ b/modules/integration/osgi/src/main/java/org/tamaya/integration/osgi/TamayaConfigurationImpl.java
@@ -23,17 +23,34 @@ import java.util.Dictionary;
 import java.util.Hashtable;
 import java.util.Map;
 
+import org.apache.tamaya.ConfigurationProvider;
+import org.apache.tamaya.functions.BiPredicate;
+import org.apache.tamaya.functions.ConfigurationFunctions;
 import org.osgi.service.cm.Configuration;
 
+/**
+ * Tamaya based implementation of an OSGI {@link Configuration}.
+ */
 public class TamayaConfigurationImpl implements Configuration {
     private final String pid;
     private final String factoryPid;
-    private final Map<String, Object> properties;
+    private Map<String, String> properties;
+    private org.apache.tamaya.Configuration config;
 
-    public TamayaConfigurationImpl(String pid, String factoryPid, Map<String, Object>
properties) {
-        this.pid = pid;
+    public TamayaConfigurationImpl(String confPid, String factoryPid) {
+        this.pid = confPid;
         this.factoryPid = factoryPid;
-        this.properties = properties;
+        this.config = ConfigurationProvider.getConfiguration();
+        this.properties = config.with(ConfigurationFunctions.filter(new BiPredicate<String,
String>() {
+            @Override
+            public boolean test(String key, String value) {
+                // TODO define name space / SPI
+                if(key.startsWith("bundle." + pid)){
+                    return true;
+                }
+                return false;
+            }
+        })).getProperties();
     }
 
     @Override
@@ -43,7 +60,7 @@ public class TamayaConfigurationImpl implements Configuration {
 
     @Override
     public Dictionary<String, Object> getProperties() {
-        return new Hashtable<>(properties);
+        return new Hashtable<String, Object>(properties);
     }
 
     @Override
@@ -63,7 +80,14 @@ public class TamayaConfigurationImpl implements Configuration {
 
     @Override
     public void update() throws IOException {
-        throw new UnsupportedOperationException();
+        this.config = ConfigurationProvider.getConfiguration();
+        this.properties = config.with(ConfigurationFunctions.filter(new BiPredicate<String,
String>() {
+            @Override
+            public boolean test(String key, String value) {
+// TODO define name space / SPI
+                return false;
+            }
+        })).getProperties();
     }
 
     @Override


Mime
View raw message