You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by ff...@apache.org on 2018/08/15 22:52:37 UTC

[karaf] branch master updated: [KARAF-5868]be able to remove properties during distribution assembly

This is an automated email from the ASF dual-hosted git repository.

ffang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/karaf.git


The following commit(s) were added to refs/heads/master by this push:
     new c35384e  [KARAF-5868]be able to remove properties during distribution assembly
c35384e is described below

commit c35384e1a8de65ceb497ad86e859d128a8e41bc7
Author: Freeman Fang <fr...@gmail.com>
AuthorDate: Thu Aug 16 06:52:25 2018 +0800

    [KARAF-5868]be able to remove properties during distribution assembly
---
 .../org/apache/karaf/tools/utils/KarafPropertiesFile.java     |  7 +++++++
 tooling/utils/src/main/mdo/edits.mdo                          |  4 ++--
 .../apache/karaf/tools/utils/KarafPropertiesEditorTest.java   |  2 ++
 .../resources/org/apache/karaf/tools/utils/test-edits.xml     | 11 +++++++++++
 4 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/tooling/utils/src/main/java/org/apache/karaf/tools/utils/KarafPropertiesFile.java b/tooling/utils/src/main/java/org/apache/karaf/tools/utils/KarafPropertiesFile.java
index 43efd73..11bd1c7 100644
--- a/tooling/utils/src/main/java/org/apache/karaf/tools/utils/KarafPropertiesFile.java
+++ b/tooling/utils/src/main/java/org/apache/karaf/tools/utils/KarafPropertiesFile.java
@@ -59,6 +59,10 @@ public class KarafPropertiesFile {
     public void put(String key, String value) {
         properties.put(key, value);
     }
+    
+    public void remove(String key) {
+        properties.remove(key);
+    }
 
     public void extend(String key, String value, boolean prepend) {
         if (properties.get(key) == null) {
@@ -76,7 +80,10 @@ public class KarafPropertiesFile {
             extend(editSpec.getKey(), editSpec.getValue(), editSpec.getOperation().isPrepend());
         } else if ("put".equals(editSpec.getOperation().getOperation())) {
             put(editSpec.getKey(), editSpec.getValue());
+        } else if ("remove".equals(editSpec.getOperation().getOperation())) {
+            remove(editSpec.getKey());  
         } else {
+        
             throw new IllegalArgumentException("Operation must be 'extend' or 'put', not " + editSpec.getOperation());
         }
     }
diff --git a/tooling/utils/src/main/mdo/edits.mdo b/tooling/utils/src/main/mdo/edits.mdo
index c8072ae..6904449 100644
--- a/tooling/utils/src/main/mdo/edits.mdo
+++ b/tooling/utils/src/main/mdo/edits.mdo
@@ -58,7 +58,7 @@
                     <name>operation</name>
                     <type>String</type>
                     <description>
-                        'extend' to extend the existing value, 'put' to replace.
+                        'extend' to extend the existing value, 'put' to replace, 'remove' to remove a property.
                     </description>
                     <required>true</required>
                 </field>
@@ -85,7 +85,7 @@
                         <multiplicity>1</multiplicity>
                     </association>
                     <description>
-                        The operation to perform: 'put' or 'extend'.
+                        The operation to perform: 'put' or 'extend' or 'remove'
                     </description>
                     <required>true</required>
                 </field>
diff --git a/tooling/utils/src/test/java/org/apache/karaf/tools/utils/KarafPropertiesEditorTest.java b/tooling/utils/src/test/java/org/apache/karaf/tools/utils/KarafPropertiesEditorTest.java
index 0705ede..41bf839 100644
--- a/tooling/utils/src/test/java/org/apache/karaf/tools/utils/KarafPropertiesEditorTest.java
+++ b/tooling/utils/src/test/java/org/apache/karaf/tools/utils/KarafPropertiesEditorTest.java
@@ -32,6 +32,7 @@ import java.nio.file.Path;
 import java.util.Properties;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
 
 /**
  * Test the property editing system.
@@ -74,5 +75,6 @@ public class KarafPropertiesEditorTest {
 
         assertEquals("This is the cereal: shot from guns", properties.getProperty("test-add-one"));
         assertEquals("This is the gun that shoots cereal", properties.getProperty("test-add-two"));
+        assertNull(properties.getProperty("test-add-three"));
     }
 }
diff --git a/tooling/utils/src/test/resources/org/apache/karaf/tools/utils/test-edits.xml b/tooling/utils/src/test/resources/org/apache/karaf/tools/utils/test-edits.xml
index 1fba57f..33321e0 100644
--- a/tooling/utils/src/test/resources/org/apache/karaf/tools/utils/test-edits.xml
+++ b/tooling/utils/src/test/resources/org/apache/karaf/tools/utils/test-edits.xml
@@ -48,5 +48,16 @@
             <key>karaf.name</key>
             <value>prepended</value>
         </edit>
+        <edit>
+            <file>config.properties</file>
+            <operation>put</operation>
+            <key>test-add-three</key>
+            <value>This is a new add to be removed</value>
+        </edit>
+        <edit>
+            <file>config.properties</file>
+            <operation>remove</operation>
+            <key>test-add-three</key>
+        </edit>
     </edits>
 </property-edits>