[KARAF-5305] Fix issue when cfg file exists

Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/5cc9c81b
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/5cc9c81b
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/5cc9c81b

Branch: refs/heads/model_features
Commit: 5cc9c81b3aadacab6c33614f22680b2acadde20d
Parents: 0cbb268
Author: Christian Schneider <ch...@die-schneider.net>
Authored: Fri Aug 11 11:42:10 2017 +0200
Committer: Christian Schneider <ch...@die-schneider.net>
Committed: Fri Aug 11 11:42:10 2017 +0200

----------------------------------------------------------------------
 .../internal/service/FeatureConfigInstaller.java     |  5 +++--
 .../java/org/apache/karaf/features/AppendTest.java   | 15 ++++++++++++++-
 2 files changed, 17 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/5cc9c81b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureConfigInstaller.java
----------------------------------------------------------------------
diff --git 
a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureConfigInstaller.java
 
b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureConfigInstaller.java
index 77522c5..5a86e53 100644
--- 
a/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureConfigInstaller.java
+++ 
b/features/core/src/main/java/org/apache/karaf/features/internal/service/FeatureConfigInstaller.java
@@ -301,13 +301,14 @@ public class FeatureConfigInstaller {
                         && !FILEINSTALL_FILE_NAME.equals(key)) {
                         List<String> comments = props.getComments(key);
                         List<String> value = props.getRaw(key);
+                        Object writeValue = (value.size() == 1) ? value.get(0) 
: value;
                         if (!properties.containsKey(key)) {
-                            properties.put(key, comments, value);
+                            properties.put(key, comments, writeValue);
                         } else if (!append) {
                             if (comments.isEmpty()) {
                                 comments = properties.getComments(key);
                             }
-                            properties.put(key, comments, value);
+                            properties.put(key, comments, writeValue);
                         }
                     }
                 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/5cc9c81b/features/core/src/test/java/org/apache/karaf/features/AppendTest.java
----------------------------------------------------------------------
diff --git 
a/features/core/src/test/java/org/apache/karaf/features/AppendTest.java 
b/features/core/src/test/java/org/apache/karaf/features/AppendTest.java
index d64da81..434cbc9 100644
--- a/features/core/src/test/java/org/apache/karaf/features/AppendTest.java
+++ b/features/core/src/test/java/org/apache/karaf/features/AppendTest.java
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue;
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.Dictionary;
 import java.util.Hashtable;
@@ -72,9 +73,21 @@ public class AppendTest {
     }
 
     @Test
-    public void testAppend() throws Exception {
+    public void testAppendWhenFileExists() throws Exception {
+        testAppendInternal(true);
+    }
+    
+    @Test
+    public void testAppendWhenNoFileExists() throws Exception {
+        testAppendInternal(false);
+    }
+
+    private void testAppendInternal(boolean cfgFileExists) throws IOException, 
InvalidSyntaxException, FileNotFoundException {
         File cfgFile = new File("target/org.ops4j.pax.web.cfg");
         cfgFile.delete();
+        if (cfgFileExists) {
+            cfgFile.createNewFile();
+        }
         Hashtable<String, Object> original = new Hashtable<>();
         original.put("foo", "bar");
         Configuration config = expectConfig(admin, original);

Reply via email to