git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@724377 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -616,6 +616,10 @@ Other changes: | |||||
| expanded. | expanded. | ||||
| Bugzilla Report 11585. | 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 | Changes from Ant 1.7.0 TO Ant 1.7.1 | ||||
| ============================================= | ============================================= | ||||
| @@ -126,6 +126,12 @@ have been regenerated by this task.</p> | |||||
| is(are) modified. <em>since Ant 1.8.0.</em></td> | is(are) modified. <em>since Ant 1.8.0.</em></td> | ||||
| <td valign="top" align="center">No, defaults to false</td> | <td valign="top" align="center">No, defaults to false</td> | ||||
| </tr> | </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> | </table> | ||||
| <h3>Examples</h3> | <h3>Examples</h3> | ||||
| <pre> <replace file="${src}/index.html" token="@@@" value="wombat"/></pre> | <pre> <replace file="${src}/index.html" token="@@@" value="wombat"/></pre> | ||||
| @@ -80,6 +80,7 @@ public class Replace extends MatchingTask { | |||||
| private Union resources; | private Union resources; | ||||
| private boolean preserveLastModified = false; | private boolean preserveLastModified = false; | ||||
| private boolean failOnNoReplacements = false; | |||||
| /** | /** | ||||
| * An inline string to use as the replacement text. | * An inline string to use as the replacement text. | ||||
| @@ -559,6 +560,9 @@ public class Replace extends MatchingTask { | |||||
| log("Replaced " + replaceCount + " occurrences in " | log("Replaced " + replaceCount + " occurrences in " | ||||
| + fileCount + " files.", Project.MSG_INFO); | + fileCount + " files.", Project.MSG_INFO); | ||||
| } | } | ||||
| if (failOnNoReplacements && replaceCount == 0) { | |||||
| throw new BuildException("didn't replace anything"); | |||||
| } | |||||
| } finally { | } finally { | ||||
| replacefilters = savedFilters; | replacefilters = savedFilters; | ||||
| properties = savedProperties; | properties = savedProperties; | ||||
| @@ -894,6 +898,15 @@ public class Replace extends MatchingTask { | |||||
| preserveLastModified = b; | preserveLastModified = b; | ||||
| } | } | ||||
| /** | |||||
| * 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 <replacefilter> element. | * Adds the token and value as first <replacefilter> element. | ||||
| * The token and value are always processed first. | * The token and value are always processed first. | ||||
| @@ -67,4 +67,19 @@ Hello, world! | |||||
| resource="${output}/text.txt" value="Hello, Ant!"/> | resource="${output}/text.txt" value="Hello, Ant!"/> | ||||
| </target> | </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> | </project> | ||||