You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by gn...@apache.org on 2017/04/07 14:35:18 UTC

svn commit: r1790563 - in /felix/trunk/fileinstall: pom.xml src/main/java/org/apache/felix/fileinstall/internal/ConfigInstaller.java

Author: gnodet
Date: Fri Apr  7 14:35:18 2017
New Revision: 1790563

URL: http://svn.apache.org/viewvc?rev=1790563&view=rev
Log:
[FELIX-5609] Full support for both untyped and typed configurations

Modified:
    felix/trunk/fileinstall/pom.xml
    felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/ConfigInstaller.java

Modified: felix/trunk/fileinstall/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/fileinstall/pom.xml?rev=1790563&r1=1790562&r2=1790563&view=diff
==============================================================================
--- felix/trunk/fileinstall/pom.xml (original)
+++ felix/trunk/fileinstall/pom.xml Fri Apr  7 14:35:18 2017
@@ -29,7 +29,7 @@
   <name>Apache Felix File Install</name>
   <description>A utility to automatically install bundles from a directory.</description>
   <url>http://felix.apache.org/site/apache-felix-file-install.html</url>
-  <version>3.5.9-SNAPSHOT</version>
+  <version>3.6.0-SNAPSHOT</version>
   <artifactId>org.apache.felix.fileinstall</artifactId>
   <scm>
     <connection>scm:svn:http://svn.apache.org/repos/asf/felix/trunk/fileinstall</connection>
@@ -60,7 +60,7 @@
     <dependency>
       <groupId>org.apache.felix</groupId>
       <artifactId>org.apache.felix.utils</artifactId>
-      <version>1.8.4</version>
+      <version>1.10.0-SNAPSHOT</version>
     </dependency>
   </dependencies>
   <build>
@@ -105,7 +105,6 @@
             </Bundle-DocURL>
             <_versionpolicy>[$(version;==;$(@)),$(version;+;$(@)))</_versionpolicy>
             <Embed-Dependency>
-                org.apache.felix.configadmin;inline="org/apache/felix/cm/file/ConfigurationHandler.class",
                 org.apache.felix.utils;inline="org/apache/felix/utils/collections/DictionaryAsMap*.class"
             </Embed-Dependency>
           </instructions>

Modified: felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/ConfigInstaller.java
URL: http://svn.apache.org/viewvc/felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/ConfigInstaller.java?rev=1790563&r1=1790562&r2=1790563&view=diff
==============================================================================
--- felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/ConfigInstaller.java (original)
+++ felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/ConfigInstaller.java Fri Apr  7 14:35:18 2017
@@ -24,12 +24,12 @@ import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.*;
 
-import org.apache.felix.cm.file.ConfigurationHandler;
 import org.apache.felix.fileinstall.ArtifactInstaller;
 import org.apache.felix.fileinstall.ArtifactListener;
 import org.apache.felix.fileinstall.internal.Util.Logger;
 import org.apache.felix.utils.collections.DictionaryAsMap;
 import org.apache.felix.utils.properties.InterpolationHelper;
+import org.apache.felix.utils.properties.TypedProperties;
 import org.osgi.framework.*;
 import org.osgi.service.cm.*;
 
@@ -129,61 +129,36 @@ public class ConfigInstaller implements
                 Dictionary dict = config.getProperties();
                 String fileName = (String) dict.get( DirectoryWatcher.FILENAME );
                 File file = fileName != null ? fromConfigKey(fileName) : null;
-                if( file != null && file.isFile()   ) {
-                    if( fileName.endsWith( ".cfg" ) )
+                if( file != null && file.isFile() ) {
+                    TypedProperties props = new TypedProperties( context );
+                    props.load( file );
+                    // remove "removed" properties from the cfg file
+                    List<String> propertiesToRemove = new ArrayList<>();
+                    for( String key : props.keySet() )
                     {
-                        org.apache.felix.utils.properties.Properties props = new org.apache.felix.utils.properties.Properties( file, context );
-                        // remove "removed" properties from the cfg file
-                        List<String> propertiesToRemove = new ArrayList<String>();
-                        for( String key : props.keySet() )
-                        {
-                            if( dict.get(key) == null
-                                    && !Constants.SERVICE_PID.equals(key)
-                                    && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key)
-                                    && !DirectoryWatcher.FILENAME.equals(key) ) {
-                                propertiesToRemove.add(key);
-                            }
-                        }
-                        for( Enumeration e  = dict.keys(); e.hasMoreElements(); )
-                        {
-                            String key = e.nextElement().toString();
-                            if( !Constants.SERVICE_PID.equals(key)
-                                    && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key)
-                                    && !DirectoryWatcher.FILENAME.equals(key) )
-                            {
-                                String val = dict.get( key ).toString();
-                                props.put( key, val );
-                            }
-                        }
-                        for( String key : propertiesToRemove )
-                        {
-                            props.remove(key);
+                        if( dict.get(key) == null
+                                && !Constants.SERVICE_PID.equals(key)
+                                && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key)
+                                && !DirectoryWatcher.FILENAME.equals(key) ) {
+                            propertiesToRemove.add(key);
                         }
-                        props.save();
                     }
-                    else if( fileName.endsWith( ".config" ) )
+                    for( Enumeration e  = dict.keys(); e.hasMoreElements(); )
                     {
-                        OutputStream fos = new FileOutputStream( file );
-                        Properties props = new Properties();
-                        for( Enumeration e  = dict.keys(); e.hasMoreElements(); )
-                        {
-                            String key = e.nextElement().toString();
-                            if( !Constants.SERVICE_PID.equals(key)
-                                    && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key)
-                                    && !DirectoryWatcher.FILENAME.equals(key) )
-                            {
-                                props.put( key, dict.get( key ) );
-                            }
-                        }
-                        try
+                        String key = e.nextElement().toString();
+                        if( !Constants.SERVICE_PID.equals(key)
+                                && !ConfigurationAdmin.SERVICE_FACTORYPID.equals(key)
+                                && !DirectoryWatcher.FILENAME.equals(key) )
                         {
-                            ConfigurationHandler.write( fos, props );
-                        }
-                        finally
-                        {
-                            fos.close();
+                            Object val = dict.get( key );
+                            props.put( key, val );
                         }
                     }
+                    for( String key : propertiesToRemove )
+                    {
+                        props.remove(key);
+                    }
+                    props.save( file );
                     // we're just writing out what's already loaded into ConfigAdmin, so
                     // update file checksum since lastModified gets updated when writing
                     fileInstall.updateChecksum(file);
@@ -225,36 +200,27 @@ public class ConfigInstaller implements
      */
     boolean setConfig(final File f) throws Exception
     {
-        final Hashtable<String, Object> ht = new Hashtable<String, Object>();
+        final Hashtable<String, Object> ht = new Hashtable<>();
         final InputStream in = new BufferedInputStream(new FileInputStream(f));
         try
         {
-            if ( f.getName().endsWith( ".cfg" ) )
-            {
+            in.mark(1);
+            boolean isXml = in.read() == '<';
+            in.reset();
+            if (isXml) {
                 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<String, String>();
+                p.loadFromXML(in);
+                Map<String, String> strMap = new HashMap<>();
                 for (Object k : p.keySet()) {
                     strMap.put(k.toString(), p.getProperty(k.toString()));
                 }
                 InterpolationHelper.performSubstitution(strMap, context);
                 ht.putAll(strMap);
-            }
-            else if ( f.getName().endsWith( ".config" ) )
-            {
-                final Dictionary config = ConfigurationHandler.read(in);
-                final Enumeration i = config.keys();
-                while ( i.hasMoreElements() )
-                {
-                    final Object key = i.nextElement();
-                    ht.put(key.toString(), config.get(key));
+            } else {
+                TypedProperties p = new TypedProperties(context);
+                p.load(in);
+                for (String k : p.keySet()) {
+                    ht.put(k, p.get(k));
                 }
             }
         }
@@ -267,7 +233,7 @@ public class ConfigInstaller implements
         Configuration config = getConfiguration(toConfigKey(f), pid[0], pid[1]);
 
         Dictionary<String, Object> props = config.getProperties();
-        Hashtable<String, Object> old = props != null ? new Hashtable<String, Object>(new DictionaryAsMap<String, Object>(props)) : null;
+        Hashtable<String, Object> old = props != null ? new Hashtable<String, Object>(new DictionaryAsMap<>(props)) : null;
         if (old != null) {
         	old.remove( DirectoryWatcher.FILENAME );
         	old.remove( Constants.SERVICE_PID );