Browse Source

Provide error stack for [*]ant[*] and macro call

use same code for import and antlib


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275621 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 21 years ago
parent
commit
b5c4bdbec2
5 changed files with 50 additions and 24 deletions
  1. +27
    -1
      src/main/org/apache/tools/ant/ProjectHelper.java
  2. +10
    -2
      src/main/org/apache/tools/ant/taskdefs/Ant.java
  3. +2
    -9
      src/main/org/apache/tools/ant/taskdefs/Definer.java
  4. +3
    -10
      src/main/org/apache/tools/ant/taskdefs/ImportTask.java
  5. +8
    -2
      src/main/org/apache/tools/ant/taskdefs/MacroInstance.java

+ 27
- 1
src/main/org/apache/tools/ant/ProjectHelper.java View File

@@ -531,5 +531,31 @@ public class ProjectHelper {
}
return componentName.substring(0, index);
}
//end class

/**
* Add location to build exception.
* @param ex the build exception, if the build exception
* does not include
* @param newLocation the location of the calling task (may be null)
* @return a new build exception based in the build exception with
* location set to newLocation. If the original exception
* did not have a location, just return the build exception
*/
public static BuildException addLocationToBuildException(
BuildException ex, Location newLocation) {
if (ex.getLocation() == null || ex.getMessage() == null) {
return ex;
}
String errorMessage
= "Following error occured while executing this line"
+ System.getProperty("line.separator")
+ ex.getLocation().toString()
+ ex.getMessage();
if (newLocation == null) {
return new BuildException(errorMessage);
} else {
return new BuildException(
errorMessage, newLocation);
}
}
}

+ 10
- 2
src/main/org/apache/tools/ant/taskdefs/Ant.java View File

@@ -378,7 +378,12 @@ public class Ant extends Task {
}
}

ProjectHelper.configureProject(newProject, new File(antFile));
try {
ProjectHelper.configureProject(newProject, new File(antFile));
} catch (BuildException ex) {
throw ProjectHelper.addLocationToBuildException(
ex, getLocation());
}

if (target == null) {
target = newProject.getDefaultTarget();
@@ -413,7 +418,10 @@ public class Ant extends Task {
try {
log("Entering " + antFile + "...", Project.MSG_VERBOSE);
newProject.executeTarget(target);
} finally {
} catch (BuildException ex) {
throw ProjectHelper.addLocationToBuildException(
ex, getLocation());
} finally {
log("Exiting " + antFile + ".", Project.MSG_VERBOSE);
}
}


+ 2
- 9
src/main/org/apache/tools/ant/taskdefs/Definer.java View File

@@ -343,15 +343,8 @@ public abstract class Definer extends DefBase {
antlib.setURI(getURI());
antlib.perform();
} catch (BuildException ex) {
Location exLocation = ex.getLocation();
if (exLocation == null) {
throw ex;
}
throw new BuildException(
"Error executing antlib"
+ System.getProperty("line.separator")
+ exLocation.toString()
+ " " + ex.getMessage());
throw ProjectHelper.addLocationToBuildException(
ex, getLocation());
}
}



+ 3
- 10
src/main/org/apache/tools/ant/taskdefs/ImportTask.java View File

@@ -55,7 +55,7 @@
package org.apache.tools.ant.taskdefs;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Location;
import org.apache.tools.ant.ProjectHelper;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectHelper;
import org.apache.tools.ant.Task;
@@ -183,15 +183,8 @@ public class ImportTask extends Task {
try {
helper.parse(getProject(), importedFile);
} catch (BuildException ex) {
Location exLocation = ex.getLocation();
if (exLocation == null) {
throw ex;
}
throw new BuildException(
"Error executing import file"
+ System.getProperty("line.separator")
+ exLocation.toString()
+ " " + ex.getMessage());
throw ProjectHelper.addLocationToBuildException(
ex, getLocation());
}
}



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

@@ -66,10 +66,11 @@ import java.util.Enumeration;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DynamicConfigurator;
import org.apache.tools.ant.ProjectHelper;
import org.apache.tools.ant.RuntimeConfigurable;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.TaskContainer;
import org.apache.tools.ant.UnknownElement;
import org.apache.tools.ant.RuntimeConfigurable;

/**
* The class to be placed in the ant type definition.
@@ -264,6 +265,11 @@ public class MacroInstance extends Task implements DynamicConfigurator {
// need to set the project on unknown element
UnknownElement c = copy(macroDef.getNestedTask());
c.init();
c.perform();
try {
c.perform();
} catch (BuildException ex) {
throw ProjectHelper.addLocationToBuildException(
ex, getLocation());
}
}
}

Loading…
Cancel
Save