git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@723790 13f79535-47bb-0310-9956-ffa450edef68master
@@ -611,6 +611,11 @@ Other changes: | |||||
timestamp even if the file is modified. | timestamp even if the file is modified. | ||||
Bugzilla Report 39002. | Bugzilla Report 39002. | ||||
* The <replace> child-elements <replacetoken> and <replacevalue> have | |||||
a new attribute that controls whether properties in nested text get | |||||
expanded. | |||||
Bugzilla Report 11585. | |||||
Changes from Ant 1.7.0 TO Ant 1.7.1 | Changes from Ant 1.7.0 TO Ant 1.7.1 | ||||
============================================= | ============================================= | ||||
@@ -123,7 +123,7 @@ have been regenerated by this task.</p> | |||||
<tr> | <tr> | ||||
<td valign="top">preserveLastModified</td> | <td valign="top">preserveLastModified</td> | ||||
<td valign="top">Keep the file timestamp(s) even if the file(s) | <td valign="top">Keep the file timestamp(s) even if the file(s) | ||||
is(are) modified.</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> | ||||
</table> | </table> | ||||
@@ -139,9 +139,24 @@ nested <code><include></code>, <code><exclude></code> and | |||||
<p>Since Ant 1.8.0 this task supports any filesystem | <p>Since Ant 1.8.0 this task supports any filesystem | ||||
based <a href="../CoreTypes/resources.html#collection">resource | based <a href="../CoreTypes/resources.html#collection">resource | ||||
collections</a> as nested elements.</p> | collections</a> as nested elements.</p> | ||||
<h4>replacetoken and replacevalue</h4> | |||||
<p>If either the text you want to replace or the replacement text | <p>If either the text you want to replace or the replacement text | ||||
cross line boundaries, you can use nested elements to specify | cross line boundaries, you can use nested elements to specify | ||||
them.</p> | them.</p> | ||||
<p>The elements support attributes:</p> | |||||
<table border="1" cellpadding="2" cellspacing="0"> | |||||
<tr> | |||||
<td valign="top"><b>Attribute</b></td> | |||||
<td valign="top"><b>Description</b></td> | |||||
<td align="center" valign="top"><b>Required</b></td> | |||||
</tr> | |||||
<tr> | |||||
<td valign="top">expandProperties</td> | |||||
<td valign="top">Whether to expand properties in the nested text. | |||||
<em>since Ant 1.8.0.</em></td> | |||||
<td align="center">No, defaults to true.</td> | |||||
</tr> | |||||
</table> | |||||
<h3>Examples</h3> | <h3>Examples</h3> | ||||
<blockquote><pre> | <blockquote><pre> | ||||
<replace dir="${src}" value="wombat"> | <replace dir="${src}" value="wombat"> | ||||
@@ -90,7 +90,7 @@ See details in the documentation of the <a href="../CoreTypes/regexp.html#implem | |||||
<tr> | <tr> | ||||
<td valign="top">preserveLastModified</td> | <td valign="top">preserveLastModified</td> | ||||
<td valign="top">Keep the file timestamp(s) even if the file(s) | <td valign="top">Keep the file timestamp(s) even if the file(s) | ||||
is(are) modified.</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> | ||||
</table> | </table> | ||||
@@ -86,8 +86,23 @@ public class Replace extends MatchingTask { | |||||
*/ | */ | ||||
public class NestedString { | public class NestedString { | ||||
private boolean expandProperties = false; | |||||
private StringBuffer buf = new StringBuffer(); | private StringBuffer buf = new StringBuffer(); | ||||
/** | |||||
* Whether properties should be expanded in nested test. | |||||
* | |||||
* <p>If you use this class via its Java interface the text | |||||
* you add via {@link #addText addText} has most likely been | |||||
* expanded already so you do <b>not</b> want to set this to | |||||
* true.</p> | |||||
* | |||||
* @since Ant 1.8.0 | |||||
*/ | |||||
public void setExpandProperties(boolean b) { | |||||
expandProperties = b; | |||||
} | |||||
/** | /** | ||||
* The text of the element. | * The text of the element. | ||||
* | * | ||||
@@ -101,7 +116,8 @@ public class Replace extends MatchingTask { | |||||
* @return the text | * @return the text | ||||
*/ | */ | ||||
public String getText() { | public String getText() { | ||||
return buf.toString(); | |||||
String s = buf.toString(); | |||||
return expandProperties ? getProject().replaceProperties(s) : s; | |||||
} | } | ||||
} | } | ||||
@@ -44,4 +44,27 @@ Hello, world! | |||||
<au:assertResourceContains | <au:assertResourceContains | ||||
resource="${output}/text.txt" value="Hello, Ant!"/> | resource="${output}/text.txt" value="Hello, Ant!"/> | ||||
</target> | </target> | ||||
<target name="testNoPropertyExpansion" depends="setUp"> | |||||
<property name="ant" value="Ant"/> | |||||
<replace> | |||||
<file file="${output}/text.txt"/> | |||||
<replacetoken>world</replacetoken> | |||||
<replacevalue>${ant}</replacevalue> | |||||
</replace> | |||||
<au:assertResourceDoesntContain | |||||
resource="${output}/text.txt" value="Hello, Ant!"/> | |||||
</target> | |||||
<target name="testPropertyExpansion" depends="setUp"> | |||||
<property name="ant" value="Ant"/> | |||||
<replace> | |||||
<file file="${output}/text.txt"/> | |||||
<replacetoken>world</replacetoken> | |||||
<replacevalue expandproperties="true">${ant}</replacevalue> | |||||
</replace> | |||||
<au:assertResourceContains | |||||
resource="${output}/text.txt" value="Hello, Ant!"/> | |||||
</target> | |||||
</project> | </project> |