Browse Source

support nested text in <property>. PR 32917. Submitted by Alexey Solofnenko

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@808449 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
6e6aa3020f
4 changed files with 55 additions and 4 deletions
  1. +3
    -0
      WHATSNEW
  2. +7
    -3
      docs/manual/CoreTasks/property.html
  3. +19
    -1
      src/main/org/apache/tools/ant/taskdefs/Property.java
  4. +26
    -0
      src/tests/antunit/taskdefs/property-test.xml

+ 3
- 0
WHATSNEW View File

@@ -936,6 +936,9 @@ Other changes:

* <path> can now optionally cache its contents.

* <property> can now specify values as nested text.
Bugzilla Report 32917.

Changes from Ant 1.7.0 TO Ant 1.7.1
=============================================



+ 7
- 3
docs/manual/CoreTasks/property.html View File

@@ -31,9 +31,10 @@
resource) in the project. Properties are case sensitive.</p>
Properties are immutable: whoever sets a property first freezes it for the
rest of the build; they are most definitely not variables.
<p>There are six ways to set properties:</p>
<p>There are seven ways to set properties:</p>
<ul>
<li>By supplying both the <i>name</i> and <i>value</i> attribute.</li>
<li>By supplying the <i>name</i> and nested text.</li>
<li>By supplying both the <i>name</i> and <i>refid</i> attribute.</li>
<li>By setting the <i>file</i> attribute with the filename of the property
file to load. This property file has the format as defined by the file used
@@ -86,8 +87,8 @@ SYSTEM).
<tr>
<td valign="top">value</td>
<td valign="top">the value of the property.</td>
<td valign="middle" align="center" rowspan="3">One of these, when using the
name attribute</td>
<td valign="middle" align="center" rowspan="3">One of these or
nested text, when using the name attribute</td>
</tr>
<tr>
<td valign="top">location</td>
@@ -165,6 +166,9 @@ href="../using.html#path">PATH like structure</a> and can also be set via a nest
<pre> &lt;property name=&quot;foo.dist&quot; value=&quot;dist&quot;/&gt;</pre>
<p>sets the property <code>foo.dist</code> to the value &quot;dist&quot;.</p>

<pre> &lt;property name=&quot;foo.dist&quot;&gt;dist&lt;/property&gt;</pre>
<p>sets the property <code>foo.dist</code> to the value &quot;dist&quot;.</p>

<pre> &lt;property file=&quot;foo.properties&quot;/&gt;</pre>
<p>reads a set of properties from a file called &quot;foo.properties&quot;.</p>



+ 19
- 1
src/main/org/apache/tools/ant/taskdefs/Property.java View File

@@ -44,13 +44,17 @@ import org.apache.tools.ant.property.ResolvePropertyMap;
* resource) in the project. </p>
* Properties are immutable: whoever sets a property first freezes it for the
* rest of the build; they are most definitely not variable.
* <p>There are five ways to set properties:</p>
* <p>There are seven ways to set properties:</p>
* <ul>
* <li>By supplying both the <i>name</i> and <i>value</i> attribute.</li>
* <li>By supplying the <i>name</i> and nested text.</li>
* <li>By supplying both the <i>name</i> and <i>refid</i> attribute.</li>
* <li>By setting the <i>file</i> attribute with the filename of the property
* file to load. This property file has the format as defined by the file used
* in the class java.util.Properties.</li>
* <li>By setting the <i>url</i> attribute with the url from which to load the
* properties. This url must be directed to a file that has the format as defined
* by the file used in the class java.util.Properties.</li>
* <li>By setting the <i>resource</i> attribute with the resource name of the
* property file to load. This property file has the format as defined by the
* file used in the class java.util.Properties.</li>
@@ -172,6 +176,20 @@ public class Property extends Task {
setValue((Object) value);
}

/**
* Set a (multiline) property as nested text.
* @param msg the text to append to the output text
* @since Ant 1.8.0
*/
public void addText(String msg) {
msg = getProject().replaceProperties(msg);
String currentValue = getValue();
if (currentValue != null) {
msg = currentValue + msg;
}
setValue(msg);
}

/**
* Get the property value.
* @return the property value


+ 26
- 0
src/tests/antunit/taskdefs/property-test.xml View File

@@ -0,0 +1,26 @@
<?xml version="1.0"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit">

<import file="../antunit-base.xml" />

<target name="testNestedText">
<property name="foo">bar</property>
<au:assertPropertyEquals name="foo" value="bar"/>
</target>
</project>

Loading…
Cancel
Save