felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r1807678 - in /felix/trunk/fileinstall/src: main/java/org/apache/felix/fileinstall/internal/ test/java/org/apache/felix/fileinstall/internal/
Date Fri, 08 Sep 2017 08:12:54 GMT
Author: gnodet
Date: Fri Sep  8 08:12:54 2017
New Revision: 1807678

URL: http://svn.apache.org/viewvc?rev=1807678&view=rev
Log:
[FELIX-4416] Ability to specify an encoding for config files

Modified:
    felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/ConfigInstaller.java
    felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
    felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/FileInstall.java
    felix/trunk/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/ConfigInstallerTest.java

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=1807678&r1=1807677&r2=1807678&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 Sep  8 08:12:54 2017
@@ -131,7 +131,10 @@ public class ConfigInstaller implements
                 File file = fileName != null ? fromConfigKey(fileName) : null;
                 if( file != null && file.isFile() ) {
                     TypedProperties props = new TypedProperties( bundleSubstitution() );
-                    props.load( file );
+                    try (Reader r = new InputStreamReader(new FileInputStream(file), encoding()))
+                    {
+                        props.load(r);
+                    }
                     // remove "removed" properties from the cfg file
                     List<String> propertiesToRemove = new ArrayList<>();
                     for( String key : props.keySet() )
@@ -206,6 +209,12 @@ public class ConfigInstaller implements
         return true;
     }
 
+    String encoding()
+    {
+        String str = this.context.getProperty( DirectoryWatcher.CONFIG_ENCODING );
+        return str != null ? str : "ISO-8859-1";
+    }
+
     ConfigurationAdmin getConfigurationAdmin()
     {
         return configAdmin;
@@ -239,7 +248,10 @@ public class ConfigInstaller implements
                 ht.putAll(strMap);
             } else {
                 TypedProperties p = new TypedProperties( bundleSubstitution() );
-                p.load(in);
+                try (Reader r = new InputStreamReader(in, encoding()))
+                {
+                    p.load(r);
+                }
                 for (String k : p.keySet()) {
                     ht.put(k, p.get(k));
                 }

Modified: felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
URL: http://svn.apache.org/viewvc/felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java?rev=1807678&r1=1807677&r2=1807678&view=diff
==============================================================================
--- felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
(original)
+++ felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java
Fri Sep  8 08:12:54 2017
@@ -101,6 +101,7 @@ public class DirectoryWatcher extends Th
     public final static String NO_INITIAL_DELAY = "felix.fileinstall.noInitialDelay";
     public final static String DISABLE_CONFIG_SAVE = "felix.fileinstall.disableConfigSave";
     public final static String ENABLE_CONFIG_SAVE = "felix.fileinstall.enableConfigSave";
+    public final static String CONFIG_ENCODING = "felix.fileinstall.configEncoding";
     public final static String START_LEVEL = "felix.fileinstall.start.level";
     public final static String ACTIVE_LEVEL = "felix.fileinstall.active.level";
     public final static String UPDATE_WITH_LISTENERS = "felix.fileinstall.bundles.updateWithListeners";

Modified: felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/FileInstall.java
URL: http://svn.apache.org/viewvc/felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/FileInstall.java?rev=1807678&r1=1807677&r2=1807678&view=diff
==============================================================================
--- felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/FileInstall.java
(original)
+++ felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/FileInstall.java
Fri Sep  8 08:12:54 2017
@@ -106,6 +106,7 @@ public class FileInstall implements Bund
             set(ht, DirectoryWatcher.NO_INITIAL_DELAY);
             set(ht, DirectoryWatcher.DISABLE_CONFIG_SAVE);
             set(ht, DirectoryWatcher.ENABLE_CONFIG_SAVE);
+            set(ht, DirectoryWatcher.CONFIG_ENCODING);
             set(ht, DirectoryWatcher.START_LEVEL);
             set(ht, DirectoryWatcher.ACTIVE_LEVEL);
             set(ht, DirectoryWatcher.UPDATE_WITH_LISTENERS);

Modified: felix/trunk/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/ConfigInstallerTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/ConfigInstallerTest.java?rev=1807678&r1=1807677&r2=1807678&view=diff
==============================================================================
--- felix/trunk/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/ConfigInstallerTest.java
(original)
+++ felix/trunk/fileinstall/src/test/java/org/apache/felix/fileinstall/internal/ConfigInstallerTest.java
Fri Sep  8 08:12:54 2017
@@ -206,6 +206,7 @@ public class ConfigInstallerTest extends
 
     public void testSetConfiguration() throws Exception
     {
+        EasyMock.expect(mockBundleContext.getProperty(DirectoryWatcher.CONFIG_ENCODING)).andReturn(null);
         EasyMock.expect(mockBundleContext.getProperty(DirectoryWatcher.LOG_DEFAULT)).andReturn(null);
         EasyMock.expect(mockBundleContext.getProperty(DirectoryWatcher.LOG_LEVEL)).andReturn(null);
         EasyMock.expect(mockConfiguration.getProperties()).andReturn(new Hashtable<String,
Object>());



Mime
View raw message