ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r724377 - in /ant/core/trunk: WHATSNEW docs/manual/CoreTasks/replace.html src/main/org/apache/tools/ant/taskdefs/Replace.java src/tests/antunit/taskdefs/replace-test.xml
Date Mon, 08 Dec 2008 15:13:10 GMT
Author: bodewig
Date: Mon Dec  8 07:13:09 2008
New Revision: 724377

URL: http://svn.apache.org/viewvc?rev=724377&view=rev
Log:
add a failOnNoReplacements attribute to replace.  PR 21064.

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/docs/manual/CoreTasks/replace.html
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Replace.java
    ant/core/trunk/src/tests/antunit/taskdefs/replace-test.xml

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=724377&r1=724376&r2=724377&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Mon Dec  8 07:13:09 2008
@@ -616,6 +616,10 @@
    expanded.
    Bugzilla Report 11585.
 
+ * <replace> has a new attribute failOnNoReplacements that makes the
+   build fail if the task didn't do anything.
+   Bugzilla Report 21064.
+
 Changes from Ant 1.7.0 TO Ant 1.7.1
 =============================================
 

Modified: ant/core/trunk/docs/manual/CoreTasks/replace.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/replace.html?rev=724377&r1=724376&r2=724377&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/replace.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/replace.html Mon Dec  8 07:13:09 2008
@@ -126,6 +126,12 @@
       is(are) modified.  <em>since Ant 1.8.0.</em></td>
     <td valign="top" align="center">No, defaults to false</td>
   </tr>
+  <tr>
+    <td valign="top">failOnNoReplacements</td>
+    <td valign="top">Whether to fail the build if the task didn't do
+      anything.  <em>since Ant 1.8.0.</em></td>
+    <td valign="top" align="center">No, defaults to false</td>
+  </tr>
 </table>
 <h3>Examples</h3>
 <pre>  &lt;replace file=&quot;${src}/index.html&quot; token=&quot;@@@&quot;
value=&quot;wombat&quot;/&gt;</pre>

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Replace.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Replace.java?rev=724377&r1=724376&r2=724377&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Replace.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Replace.java Mon Dec  8 07:13:09
2008
@@ -80,6 +80,7 @@
     private Union resources;
 
     private boolean preserveLastModified = false;
+    private boolean failOnNoReplacements = false;
 
     /**
      * An inline string to use as the replacement text.
@@ -559,6 +560,9 @@
                 log("Replaced " + replaceCount + " occurrences in "
                     + fileCount + " files.", Project.MSG_INFO);
             }
+            if (failOnNoReplacements && replaceCount == 0) {
+                throw new BuildException("didn't replace anything");
+            }
         } finally {
             replacefilters = savedFilters;
             properties = savedProperties;
@@ -895,6 +899,15 @@
     }
 
     /**
+     * Whether the build should fail if nothing has been replaced.
+     *
+     * @since Ant 1.8.0
+     */
+    public void setFailOnNoReplacements(boolean b) {
+        failOnNoReplacements = b;
+    }
+
+    /**
      * Adds the token and value as first &lt;replacefilter&gt; element.
      * The token and value are always processed first.
      * @return a nested <code>Replacefilter</code> object to be configured.

Modified: ant/core/trunk/src/tests/antunit/taskdefs/replace-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/replace-test.xml?rev=724377&r1=724376&r2=724377&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/replace-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/replace-test.xml Mon Dec  8 07:13:09 2008
@@ -67,4 +67,19 @@
        resource="${output}/text.txt" value="Hello, Ant!"/>
   </target>
 
+  <target name="testNoReplace" depends="setUp">
+    <replace token="ant" value="ant" summary="true">
+      <file file="${output}/text.txt"/>
+    </replace>
+    <au:assertLogContains text="Replaced 0 occurrences in 0 files."/>
+  </target>
+
+  <target name="testFailOnNoReplace" depends="setUp">
+    <au:expectfailure expectedMessage="didn't replace anything">
+      <replace token="ant" value="ant" failOnNoReplacements="true">
+        <file file="${output}/text.txt"/>
+      </replace>
+    </au:expectfailure>
+  </target>
+
 </project>



Mime
View raw message