Author: bodewig
Date: Fri Dec 5 09:04:04 2008
New Revision: 723790
URL: http://svn.apache.org/viewvc?rev=723790&view=rev
Log:
optionally expand properties in <replace>'s nested elements. PR 11585.
Modified:
ant/core/trunk/WHATSNEW
ant/core/trunk/docs/manual/CoreTasks/replace.html
ant/core/trunk/docs/manual/OptionalTasks/replaceregexp.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=723790&r1=723789&r2=723790&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri Dec 5 09:04:04 2008
@@ -611,6 +611,11 @@
timestamp even if the file is modified.
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
=============================================
Modified: ant/core/trunk/docs/manual/CoreTasks/replace.html
URL:
http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/replace.html?rev=723790&r1=723789&r2=723790&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/replace.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/replace.html Fri Dec 5 09:04:04 2008
@@ -123,7 +123,7 @@
<tr>
<td valign="top">preserveLastModified</td>
<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>
</tr>
</table>
@@ -139,9 +139,24 @@
<p>Since Ant 1.8.0 this task supports any filesystem
based <a href="../CoreTypes/resources.html#collection">resource
collections</a> as nested elements.</p>
+<h4>replacetoken and replacevalue</h4>
<p>If either the text you want to replace or the replacement text
cross line boundaries, you can use nested elements to specify
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>
<blockquote><pre>
<replace dir="${src}" value="wombat">
Modified: ant/core/trunk/docs/manual/OptionalTasks/replaceregexp.html
URL:
http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/OptionalTasks/replaceregexp.html?rev=723790&r1=723789&r2=723790&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/OptionalTasks/replaceregexp.html (original)
+++ ant/core/trunk/docs/manual/OptionalTasks/replaceregexp.html Fri Dec 5
09:04:04 2008
@@ -90,7 +90,7 @@
<tr>
<td valign="top">preserveLastModified</td>
<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>
</tr>
</table>
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=723790&r1=723789&r2=723790&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 Fri Dec
5 09:04:04 2008
@@ -86,9 +86,24 @@
*/
public class NestedString {
+ private boolean expandProperties = false;
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 [EMAIL PROTECTED] #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.
*
* @param val the string to add
@@ -101,7 +116,8 @@
* @return the text
*/
public String getText() {
- return buf.toString();
+ String s = buf.toString();
+ return expandProperties ? getProject().replaceProperties(s) : s;
}
}
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=723790&r1=723789&r2=723790&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/replace-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/replace-test.xml Fri Dec 5
09:04:04 2008
@@ -44,4 +44,27 @@
<au:assertResourceContains
resource="${output}/text.txt" value="Hello, Ant!"/>
</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>