PR: 27219 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278161 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -181,6 +181,8 @@ Other changes: | |||||
| * <exec> (and hence, <apply>) have an OsFamily attribute, which can restrict | * <exec> (and hence, <apply>) have an OsFamily attribute, which can restrict | ||||
| execution to a single OS family. | 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 | Changes from Ant 1.6.2 to current Ant 1.6 CVS version | ||||
| ===================================================== | ===================================================== | ||||
| @@ -50,6 +50,17 @@ | |||||
| </td> | </td> | ||||
| <td valign="top" align="center">No</td> | <td valign="top" align="center">No</td> | ||||
| </tr> | </tr> | ||||
| <tr> | |||||
| <td valign="top">backtrace</td> | |||||
| <td valign="top"> | |||||
| 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. | |||||
| <em>Since ant 1.7</em>. | |||||
| </td> | |||||
| <td valign="top" align="center">No</td> | |||||
| </tr> | |||||
| </table> | </table> | ||||
| <h3>Parameters specified as nested elements</h3> | <h3>Parameters specified as nested elements</h3> | ||||
| <h4>attribute</h4> | <h4>attribute</h4> | ||||
| @@ -223,4 +223,20 @@ | |||||
| </target> | </target> | ||||
| <target name="backtraceoff"> | |||||
| <macrodef name="nobacktrace" backtrace="false"> | |||||
| <sequential> | |||||
| <fail>This is a failure</fail> | |||||
| </sequential> | |||||
| </macrodef> | |||||
| <nobacktrace/> | |||||
| </target> | |||||
| <target name="backtraceon"> | |||||
| <macrodef name="nobacktrace" backtrace="true"> | |||||
| <sequential> | |||||
| <fail>This is a failure</fail> | |||||
| </sequential> | |||||
| </macrodef> | |||||
| <nobacktrace/> | |||||
| </target> | |||||
| </project> | </project> | ||||
| @@ -42,6 +42,7 @@ import org.apache.tools.ant.UnknownElement; | |||||
| public class MacroDef extends AntlibDefinition { | public class MacroDef extends AntlibDefinition { | ||||
| private NestedSequential nestedSequential; | private NestedSequential nestedSequential; | ||||
| private String name; | private String name; | ||||
| private boolean backTrace = true; | |||||
| private List attributes = new ArrayList(); | private List attributes = new ArrayList(); | ||||
| private Map elements = new HashMap(); | private Map elements = new HashMap(); | ||||
| private String textName = null; | private String textName = null; | ||||
| @@ -92,6 +93,28 @@ public class MacroDef extends AntlibDefinition { | |||||
| return text; | 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. | * This is the sequential nested element of the macrodef. | ||||
| * | * | ||||
| @@ -380,8 +380,12 @@ public class MacroInstance extends Task implements DynamicAttribute, TaskContain | |||||
| try { | try { | ||||
| c.perform(); | c.perform(); | ||||
| } catch (BuildException ex) { | } catch (BuildException ex) { | ||||
| throw ProjectHelper.addLocationToBuildException( | |||||
| ex, getLocation()); | |||||
| if (macroDef.getBackTrace()) { | |||||
| throw ProjectHelper.addLocationToBuildException( | |||||
| ex, getLocation()); | |||||
| } else { | |||||
| throw new BuildException(ex.getMessage(), ex); | |||||
| } | |||||
| } finally { | } finally { | ||||
| presentElements = null; | presentElements = null; | ||||
| localAttributes = null; | localAttributes = null; | ||||
| @@ -18,6 +18,7 @@ | |||||
| package org.apache.tools.ant.taskdefs; | package org.apache.tools.ant.taskdefs; | ||||
| import org.apache.tools.ant.BuildFileTest; | import org.apache.tools.ant.BuildFileTest; | ||||
| import org.apache.tools.ant.BuildException; | |||||
| import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
| import org.apache.tools.ant.Task; | 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", | ||||
| "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"); | |||||
| } | |||||
| } | } | ||||