ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r806154 - in /ant/core/trunk: ./ docs/manual/OptionalTasks/ src/etc/testcases/taskdefs/optional/ src/main/org/apache/tools/ant/taskdefs/optional/ src/tests/junit/org/apache/tools/ant/taskdefs/optional/
Date Thu, 20 Aug 2009 13:01:19 GMT
Author: jhm
Date: Thu Aug 20 13:01:18 2009
New Revision: 806154

URL: http://svn.apache.org/viewvc?rev=806154&view=rev
Log:
<propertyfile> now support deletion of entries

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/docs/manual/OptionalTasks/propertyfile.html
    ant/core/trunk/src/etc/testcases/taskdefs/optional/propertyfile.xml
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java
    ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=806154&r1=806153&r2=806154&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Thu Aug 20 13:01:18 2009
@@ -857,6 +857,8 @@
  * It is now possible to suppress the "FAILED" lines sent to Ant's
    logging system via <junit>'s new logFailedTests attribute.
    Bugzilla Report 35073.
+   
+ * <propertyfile> now can delete entries.
 
 Changes from Ant 1.7.0 TO Ant 1.7.1
 =============================================

Modified: ant/core/trunk/docs/manual/OptionalTasks/propertyfile.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/OptionalTasks/propertyfile.html?rev=806154&r1=806153&r2=806154&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/OptionalTasks/propertyfile.html (original)
+++ ant/core/trunk/docs/manual/OptionalTasks/propertyfile.html Thu Aug 20 13:01:18 2009
@@ -24,26 +24,12 @@
 <body>
 
 <h1>PropertyFile</h1>
-<p>by</p>
-<!-- Names are in alphabetical order, on last name -->
-<ul>
-  <li>Thomas Christen (<a href="mailto:chr@active.ch">chr@active.ch</a>)</li>
-  <li>Jeremy Mawson (<a href="mailto:jem@loftinspace.com.au">jem@loftinspace.com/au</a>)</li>
-</ul>
-
-<hr>
-<h2>Table of Contents</h2>
-<ul>
-  <li><a href="#introduction">Introduction</a></li>
-  <li><a href="#proptask">PropertyFile Task</a></li>
-  <li><a href="#entryElement">Entry Task</a></li>
-</ul>
 
 <hr>
 <h2><a name="introduction">Introduction</a></h2>
-<p>Ant provides an optional task for editing property files.  This is very useful
+<p>Ant provides an optional task for editing property files. This is very useful
 when wanting to make unattended modifications to configuration files for application
-servers and applications.  Currently, the task maintains a working property file with
+servers and applications. Currently, the task maintains a working property file with
 the ability to add properties or make changes to existing ones. Comments and layout
 of the original properties file are preserved.</p>
 
@@ -93,7 +79,7 @@
   <tr>
     <td valign="top">value</td>
     <td valign="top">Value to set (=), to add (+) or subtract (-)</td>
-    <td valign="top" align="center" rowspan="2">At least one must be specified</td>
+    <td valign="top" align="center" rowspan="2">At least one must be specified, if
<i>operation</i> is not <i>delete</i></td>
   </tr>
   <tr>
     <td valign="top">default</td>
@@ -108,7 +94,14 @@
   </tr>
   <tr>
     <td valign="top">operation</td>
-    <td valign="top">&quot;+&quot; or &quot;=&quot; (default) for all
datatypes<br>&quot;-&quot; (for date and int only).<br>
+    <td valign="top">One of the following operations:<br><br>
+    <b>for all datatypes:</b><ul>
+      <li>&quot;del&quot; : deletes an entry</li>
+      <li>&quot;+&quot; : adds a value to the existing value</li>
+      <li>&quot;=&quot; : sets a value instead of the existing value (default)</li>
+    </ul><br><b>for date and int only:</b><ul>
+      <li>&quot;-&quot; : subtracts a value from the existing value</li>
+    </ul>
     </td>
     <td valign="top" align="center">No</td>
   </tr>

Modified: ant/core/trunk/src/etc/testcases/taskdefs/optional/propertyfile.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/etc/testcases/taskdefs/optional/propertyfile.xml?rev=806154&r1=806153&r2=806154&view=diff
==============================================================================
--- ant/core/trunk/src/etc/testcases/taskdefs/optional/propertyfile.xml (original)
+++ ant/core/trunk/src/etc/testcases/taskdefs/optional/propertyfile.xml Thu Aug 20 13:01:18
2009
@@ -38,7 +38,15 @@
         <entry  key="age"       default="${age}" type="int"/>
         <entry  key="date"      default="${date}" type="date"/>
       </propertyfile>
+   </target>
 
+   <target name="delete-properties">
+    <echoproperties/>
+      <propertyfile
+          file="${test.propertyfile}"
+          comment="unit test for the property file task..." >
+        <entry  key="firstname" operation="del" />
+      </propertyfile>
    </target>
 
    <target name="exercise">
@@ -85,15 +93,19 @@
      </propertyfile>
      <property file="${test.propertyfile}"/>
    </target>
+   
     <target name="createfile">
        <echo file="${overwrite.test.propertyfile}">
  foo=3
        </echo>
     </target>
+    
     <target name="bugDemo1" depends="createfile,bugDemoInit"/>
+    
     <target name="bugDemo2" depends="bugDemoInit">
         <property file="${overwrite.test.propertyfile}"/>
     </target>
+
     <target name="bugDemoInit">
        <propertyfile file="${overwrite.test.propertyfile}">
           <entry key="foo" default="0" value="1" operation="+" type="int"/>

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java?rev=806154&r1=806153&r2=806154&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java Thu Aug
20 13:01:18 2009
@@ -347,6 +347,11 @@
          */
         protected void executeOn(Properties props) throws BuildException {
             checkParameters();
+            
+            if (operation == Operation.DELETE_OPER) {
+                props.remove(key);
+                return;
+            }
 
             // type may be null because it wasn't set
             String oldValue = (String) props.get(key);
@@ -508,7 +513,7 @@
                 throw new BuildException("- is not supported for string "
                                          + "properties (key:" + key + ")");
             }
-            if (value == null && defaultValue == null) {
+            if (value == null && defaultValue == null  && operation != Operation.DELETE_OPER)
{
                 throw new BuildException("\"value\" and/or \"default\" "
                                          + "attribute must be specified (key:" + key + ")");
             }
@@ -574,10 +579,12 @@
             public static final int DECREMENT_OPER =   1;
             /** = */
             public static final int EQUALS_OPER =      2;
+            /** del */
+            public static final int DELETE_OPER =      3;
 
             /** {@inheritDoc}. */
             public String[] getValues() {
-                return new String[] {"+", "-", "="};
+                return new String[] {"+", "-", "=", "del"};
             }
 
             /**
@@ -590,6 +597,8 @@
                     return INCREMENT_OPER;
                 } else if ("-".equals(oper)) {
                     return DECREMENT_OPER;
+                } else if ("del".equals(oper)) {
+                    return DELETE_OPER;
                 }
                 return EQUALS_OPER;
             }

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java?rev=806154&r1=806153&r2=806154&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java
(original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java
Thu Aug 20 13:01:18 2009
@@ -93,6 +93,22 @@
         assertEquals(NEW_AGE, afterUpdate.getProperty(AGE_KEY));
         assertEquals(NEW_DATE, afterUpdate.getProperty(DATE_KEY));
     }
+    
+    public void testDeleteProperties() throws Exception {
+        Properties beforeUpdate = getTestProperties();
+        assertEquals("Property '" + FNAME_KEY + "' should exist before deleting",
+            FNAME, beforeUpdate.getProperty(FNAME_KEY));
+        assertEquals("Property '" + LNAME_KEY + "' should exist before deleting",
+            LNAME, beforeUpdate.getProperty(LNAME_KEY));
+        
+        executeTarget("delete-properties");
+        Properties afterUpdate = getTestProperties();
+
+        assertEquals("Property '" + LNAME_KEY + "' should exist after deleting",
+            LNAME, afterUpdate.getProperty(LNAME_KEY));
+        assertNull("Property '" + FNAME_KEY + "' should be deleted",
+            afterUpdate.getProperty(FNAME_KEY));
+    }
 
     public void testExerciseDefaultAndIncrement() throws Exception {
         executeTarget("exercise");



Mime
View raw message