diff --git a/WHATSNEW b/WHATSNEW index 20c7fd6c6..73ce7f7e6 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -181,6 +181,8 @@ Other changes: * (and hence, ) have an OsFamily attribute, which can restrict execution to a single OS family. +* added "backtrace" attribute to macrodef. Bugzilla report 27219. + Changes from Ant 1.6.2 to current Ant 1.6 CVS version ===================================================== diff --git a/docs/manual/CoreTasks/macrodef.html b/docs/manual/CoreTasks/macrodef.html index 40eaf88fe..ecda2c2a1 100644 --- a/docs/manual/CoreTasks/macrodef.html +++ b/docs/manual/CoreTasks/macrodef.html @@ -50,6 +50,17 @@ No + + backtrace + + This controls the error traceback if they is an + error detected when running the macro. If this is + set to true, there will be an erro trackback, if false + there will not be one. The default value is true. + Since ant 1.7. + + No +

Parameters specified as nested elements

attribute

diff --git a/src/etc/testcases/taskdefs/macrodef.xml b/src/etc/testcases/taskdefs/macrodef.xml index fac274a1b..ed278f022 100644 --- a/src/etc/testcases/taskdefs/macrodef.xml +++ b/src/etc/testcases/taskdefs/macrodef.xml @@ -223,4 +223,20 @@ + + + + This is a failure + + + + + + + + This is a failure + + + + diff --git a/src/main/org/apache/tools/ant/taskdefs/MacroDef.java b/src/main/org/apache/tools/ant/taskdefs/MacroDef.java index cc7f65081..660b7fa78 100644 --- a/src/main/org/apache/tools/ant/taskdefs/MacroDef.java +++ b/src/main/org/apache/tools/ant/taskdefs/MacroDef.java @@ -42,6 +42,7 @@ import org.apache.tools.ant.UnknownElement; public class MacroDef extends AntlibDefinition { private NestedSequential nestedSequential; private String name; + private boolean backTrace = true; private List attributes = new ArrayList(); private Map elements = new HashMap(); private String textName = null; @@ -92,6 +93,28 @@ public class MacroDef extends AntlibDefinition { return text; } + /** + * Set the backTrace attribute. + * + * @param backTrace if true and the macro instance generates has + * an error, a backtrace of the location within + * the macro and call to the macro will be outout. + * if false, only the location of the call to + * macro will be shown. Default is true. + * @since ant 1.7 + */ + public void setBackTrace(boolean backTrace) { + this.backTrace = backTrace; + } + + /** + * @return the backTrace attribute. + * @since ant 1.7 + */ + public boolean getBackTrace() { + return backTrace; + } + /** * This is the sequential nested element of the macrodef. * diff --git a/src/main/org/apache/tools/ant/taskdefs/MacroInstance.java b/src/main/org/apache/tools/ant/taskdefs/MacroInstance.java index 905a58517..5194015c5 100644 --- a/src/main/org/apache/tools/ant/taskdefs/MacroInstance.java +++ b/src/main/org/apache/tools/ant/taskdefs/MacroInstance.java @@ -380,8 +380,12 @@ public class MacroInstance extends Task implements DynamicAttribute, TaskContain try { c.perform(); } catch (BuildException ex) { - throw ProjectHelper.addLocationToBuildException( - ex, getLocation()); + if (macroDef.getBackTrace()) { + throw ProjectHelper.addLocationToBuildException( + ex, getLocation()); + } else { + throw new BuildException(ex.getMessage(), ex); + } } finally { presentElements = null; localAttributes = null; diff --git a/src/testcases/org/apache/tools/ant/taskdefs/MacroDefTest.java b/src/testcases/org/apache/tools/ant/taskdefs/MacroDefTest.java index 793ad25c4..ba1f997d0 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/MacroDefTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/MacroDefTest.java @@ -18,6 +18,7 @@ package org.apache.tools.ant.taskdefs; import org.apache.tools.ant.BuildFileTest; +import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; @@ -128,5 +129,22 @@ public class MacroDefTest extends BuildFileTest { "Only one element allowed when using implicit elements", "Only one element allowed when using implicit elements"); } + + public void testBackTraceOff() { + try { + executeTarget("backtraceoff"); + } catch (BuildException ex) { + if (ex.getMessage().indexOf("following error occurred") != -1) { + fail("error message contained backtrace - " + ex.getMessage()); + } + } + } + + public void testBackTrace() { + expectBuildExceptionContaining( + "backtraceon", + "Checking if a back trace is created", + "following error occurred"); + } }