Author: bodewig
Date: Mon Aug 31 15:19:47 2009
New Revision: 809623

URL: http://svn.apache.org/viewvc?rev=809623&view=rev
Log:
make nested text in <property> less intrusive on existing build files

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Property.java
    ant/core/trunk/src/tests/antunit/taskdefs/property-test.xml

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Property.java
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Property.java?rev=809623&r1=809622&r2=809623&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Property.java 
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Property.java Mon Aug 
31 15:19:47 2009
@@ -90,6 +90,7 @@
     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 @@
      * @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 @@
      * @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");
+        }
     }
 
     /**

Modified: ant/core/trunk/src/tests/antunit/taskdefs/property-test.xml
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/property-test.xml?rev=809623&r1=809622&r2=809623&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/property-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/property-test.xml Mon Aug 31 
15:19:47 2009
@@ -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>


Reply via email to