Browse Source

optionally expand properties in <replace>'s nested elements. PR 11585.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@723790 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
e673741d37
5 changed files with 62 additions and 3 deletions
  1. +5
    -0
      WHATSNEW
  2. +16
    -1
      docs/manual/CoreTasks/replace.html
  3. +1
    -1
      docs/manual/OptionalTasks/replaceregexp.html
  4. +17
    -1
      src/main/org/apache/tools/ant/taskdefs/Replace.java
  5. +23
    -0
      src/tests/antunit/taskdefs/replace-test.xml

+ 5
- 0
WHATSNEW View File

@@ -611,6 +611,11 @@ Other changes:
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
=============================================



+ 16
- 1
docs/manual/CoreTasks/replace.html View File

@@ -123,7 +123,7 @@ have been regenerated by this task.</p>
<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 @@ nested <code>&lt;include&gt;</code>, <code>&lt;exclude&gt;</code> and
<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>
&lt;replace dir=&quot;${src}&quot; value=&quot;wombat&quot;&gt;


+ 1
- 1
docs/manual/OptionalTasks/replaceregexp.html View File

@@ -90,7 +90,7 @@ See details in the documentation of the <a href="../CoreTypes/regexp.html#implem
<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>


+ 17
- 1
src/main/org/apache/tools/ant/taskdefs/Replace.java View File

@@ -86,8 +86,23 @@ public class Replace extends MatchingTask {
*/
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 {@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.
*
@@ -101,7 +116,8 @@ public class Replace extends MatchingTask {
* @return the text
*/
public String getText() {
return buf.toString();
String s = buf.toString();
return expandProperties ? getProject().replaceProperties(s) : s;
}
}



+ 23
- 0
src/tests/antunit/taskdefs/replace-test.xml View File

@@ -44,4 +44,27 @@ Hello, world!
<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>

Loading…
Cancel
Save