git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@539547 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -150,6 +150,8 @@ Other changes: | |||||
| * A new logger, BigProjectLogger, lists the project name with every target | * 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 | Changes from Ant 1.6.5 to Ant 1.7.0 | ||||
| =================================== | =================================== | ||||
| @@ -431,6 +431,7 @@ public class MacroDef extends AntlibDefinition { | |||||
| private boolean optional; | private boolean optional; | ||||
| private boolean trim; | private boolean trim; | ||||
| private String description; | private String description; | ||||
| private String defaultString; | |||||
| /** | /** | ||||
| * The name of the attribute. | * The name of the attribute. | ||||
| @@ -500,6 +501,20 @@ public class MacroDef extends AntlibDefinition { | |||||
| return description; | return description; | ||||
| } | } | ||||
| /** | |||||
| * @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 | * equality method | ||||
| * | * | ||||
| @@ -514,20 +529,10 @@ public class MacroDef extends AntlibDefinition { | |||||
| return false; | return false; | ||||
| } | } | ||||
| Text other = (Text) obj; | 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); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -538,6 +543,10 @@ public class MacroDef extends AntlibDefinition { | |||||
| } | } | ||||
| } | } | ||||
| private static boolean safeCompare(Object a, Object b) { | |||||
| return a == null ? b == null : a.equals(b); | |||||
| } | |||||
| /** | /** | ||||
| * A nested element for the MacroDef task. | * A nested element for the MacroDef task. | ||||
| */ | */ | ||||
| @@ -361,11 +361,12 @@ public class MacroInstance extends Task implements DynamicAttribute, TaskContain | |||||
| } | } | ||||
| if (macroDef.getText() != null) { | if (macroDef.getText() != null) { | ||||
| if (text == null) { | if (text == null) { | ||||
| if (!macroDef.getText().getOptional()) { | |||||
| String defaultText = macroDef.getText().getDefault(); | |||||
| if (!macroDef.getText().getOptional() && defaultText == null) { | |||||
| throw new BuildException( | throw new BuildException( | ||||
| "required text missing"); | "required text missing"); | ||||
| } | } | ||||
| text = ""; | |||||
| text = defaultText == null ? "" : defaultText; | |||||
| } | } | ||||
| if (macroDef.getText().getTrim()) { | if (macroDef.getText().getTrim()) { | ||||
| text = text.trim(); | text = text.trim(); | ||||
| @@ -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> | |||||