Browse Source

make nested text in <property> less intrusive on existing build files

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@809623 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
6c014111ca
2 changed files with 26 additions and 1 deletions
  1. +12
    -1
      src/main/org/apache/tools/ant/taskdefs/Property.java
  2. +14
    -0
      src/tests/antunit/taskdefs/property-test.xml

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

@@ -90,6 +90,7 @@ public class Property extends Task {
protected String prefix;
private Project fallback;
private Object untypedValue;
private boolean valueAttributeUsed = false;

protected boolean userProperty; // set read-only properties
// CheckStyle:VisibilityModifier ON
@@ -161,6 +162,11 @@ public class Property extends Task {
* @param value the value to use.
*/
public void setValue(Object value) {
valueAttributeUsed = true;
internalSetValue(value);
}

private void internalSetValue(Object value) {
this.untypedValue = value;
//preserve protected string value for subclasses :(
this.value = value == null ? null : value.toString();
@@ -182,12 +188,17 @@ public class Property extends Task {
* @since Ant 1.8.0
*/
public void addText(String msg) {
if (!valueAttributeUsed) {
msg = getProject().replaceProperties(msg);
String currentValue = getValue();
if (currentValue != null) {
msg = currentValue + msg;
}
setValue(msg);
internalSetValue(msg);
} else if (msg.trim().length() > 0) {
throw new BuildException("can't combine nested text with value"
+ " attribute");
}
}

/**


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

@@ -23,4 +23,18 @@
<property name="foo">bar</property>
<au:assertPropertyEquals name="foo" value="bar"/>
</target>

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

<target name="testNestedTextAndValueAttribute">
<au:expectfailure>
<property name="foo" value="bar">
hello
</property>
</au:expectfailure>
</target>
</project>

Loading…
Cancel
Save