ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peterrei...@apache.org
Subject svn commit: r539547 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/taskdefs/MacroDef.java src/main/org/apache/tools/ant/taskdefs/MacroInstance.java src/tests/antunit/taskdefs/macrodef-test.xml
Date Fri, 18 May 2007 18:23:54 GMT
Author: peterreilly
Date: Fri May 18 11:23:51 2007
New Revision: 539547

URL: http://svn.apache.org/viewvc?view=rev&rev=539547
Log:
bugzilla request: 42301 add default for text element in macrodef

Added:
    ant/core/trunk/src/tests/antunit/taskdefs/macrodef-test.xml
Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/MacroDef.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/MacroInstance.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?view=diff&rev=539547&r1=539546&r2=539547
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Fri May 18 11:23:51 2007
@@ -150,6 +150,8 @@
 
 * A new logger, BigProjectLogger, lists the project name with every target   
 
+* Default text added to macrodef. Bugzilla report 42301.
+
 
 Changes from Ant 1.6.5 to Ant 1.7.0
 ===================================

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/MacroDef.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/MacroDef.java?view=diff&rev=539547&r1=539546&r2=539547
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/MacroDef.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/MacroDef.java Fri May 18 11:23:51
2007
@@ -431,6 +431,7 @@
         private boolean optional;
         private boolean trim;
         private String  description;
+        private String  defaultString;
 
         /**
          * The name of the attribute.
@@ -501,6 +502,20 @@
         }
 
         /**
+         * @param defaultString default text for the string.
+         */
+        public void setDefault(String defaultString) {
+            this.defaultString = defaultString;
+        }
+
+        /**
+         * @return the default text if set, null otherwise.
+         */
+        public String getDefault() {
+            return defaultString;
+        }
+
+        /**
          * equality method
          *
          * @param obj an <code>Object</code> value
@@ -514,20 +529,10 @@
                 return false;
             }
             Text other = (Text) obj;
-            if (name == null) {
-                if (other.name != null) {
-                    return false;
-                }
-            } else if (!name.equals(other.name)) {
-                return false;
-            }
-            if (optional != other.optional) {
-                return false;
-            }
-            if (trim != other.trim) {
-                return false;
-            }
-            return true;
+            return safeCompare(name, other.name)
+                && optional == other.optional
+                && trim == other.trim
+                && safeCompare(defaultString, other.defaultString);
         }
 
         /**
@@ -536,6 +541,10 @@
         public int hashCode() {
             return objectHashCode(name);
         }
+    }
+
+    private static boolean safeCompare(Object a, Object b) {
+        return a == null ? b == null : a.equals(b);
     }
 
     /**

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/MacroInstance.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/MacroInstance.java?view=diff&rev=539547&r1=539546&r2=539547
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/MacroInstance.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/MacroInstance.java Fri May 18 11:23:51
2007
@@ -361,11 +361,12 @@
         }
         if (macroDef.getText() != null) {
             if (text == null) {
-                if (!macroDef.getText().getOptional()) {
+                String defaultText =  macroDef.getText().getDefault();
+                if (!macroDef.getText().getOptional() && defaultText == null) {
                     throw new BuildException(
                         "required text missing");
                 }
-                text = "";
+                text = defaultText == null ? "" : defaultText;
             }
             if (macroDef.getText().getTrim()) {
                 text = text.trim();

Added: ant/core/trunk/src/tests/antunit/taskdefs/macrodef-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/macrodef-test.xml?view=auto&rev=539547
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/macrodef-test.xml (added)
+++ ant/core/trunk/src/tests/antunit/taskdefs/macrodef-test.xml Fri May 18 11:23:51 2007
@@ -0,0 +1,20 @@
+<project name="length-test" default="antunit"
+         xmlns:au="antlib:org.apache.ant.antunit">
+
+  <import file="../antunit-base.xml" />
+
+  <target name="testDefaultTest">
+    <macrodef name="test-log">
+      <text name="log" default="DEFAULT-LOG-VALUE"/>
+      <sequential>
+        <concat>@{log}</concat>
+      </sequential>
+    </macrodef>
+    <test-log/>
+    <au:assertLogContains text="DEFAULT-LOG-VALUE"/>
+    <test-log>THIS IS NOT DEFAULT LOG</test-log>
+    <au:assertLogContains text="THIS IS NOT DEFAULT LOG"/>
+  </target>
+
+
+</project>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message