Browse Source

add backtrace attribute to <macrodef>

PR: 27219


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278161 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 20 years ago
parent
commit
eaef2bfdbe
6 changed files with 76 additions and 2 deletions
  1. +2
    -0
      WHATSNEW
  2. +11
    -0
      docs/manual/CoreTasks/macrodef.html
  3. +16
    -0
      src/etc/testcases/taskdefs/macrodef.xml
  4. +23
    -0
      src/main/org/apache/tools/ant/taskdefs/MacroDef.java
  5. +6
    -2
      src/main/org/apache/tools/ant/taskdefs/MacroInstance.java
  6. +18
    -0
      src/testcases/org/apache/tools/ant/taskdefs/MacroDefTest.java

+ 2
- 0
WHATSNEW View File

@@ -181,6 +181,8 @@ Other changes:
* <exec> (and hence, <apply>) 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
=====================================================



+ 11
- 0
docs/manual/CoreTasks/macrodef.html View File

@@ -50,6 +50,17 @@
</td>
<td valign="top" align="center">No</td>
</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>
<h3>Parameters specified as nested elements</h3>
<h4>attribute</h4>


+ 16
- 0
src/etc/testcases/taskdefs/macrodef.xml View File

@@ -223,4 +223,20 @@

</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>

+ 23
- 0
src/main/org/apache/tools/ant/taskdefs/MacroDef.java View File

@@ -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.
*


+ 6
- 2
src/main/org/apache/tools/ant/taskdefs/MacroInstance.java View File

@@ -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;


+ 18
- 0
src/testcases/org/apache/tools/ant/taskdefs/MacroDefTest.java View File

@@ -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");
}
}


Loading…
Cancel
Save