use same code for import and antlib git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275621 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -531,5 +531,31 @@ public class ProjectHelper { | |||||
| } | } | ||||
| return componentName.substring(0, index); | 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); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -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) { | if (target == null) { | ||||
| target = newProject.getDefaultTarget(); | target = newProject.getDefaultTarget(); | ||||
| @@ -413,7 +418,10 @@ public class Ant extends Task { | |||||
| try { | try { | ||||
| log("Entering " + antFile + "...", Project.MSG_VERBOSE); | log("Entering " + antFile + "...", Project.MSG_VERBOSE); | ||||
| newProject.executeTarget(target); | newProject.executeTarget(target); | ||||
| } finally { | |||||
| } catch (BuildException ex) { | |||||
| throw ProjectHelper.addLocationToBuildException( | |||||
| ex, getLocation()); | |||||
| } finally { | |||||
| log("Exiting " + antFile + ".", Project.MSG_VERBOSE); | log("Exiting " + antFile + ".", Project.MSG_VERBOSE); | ||||
| } | } | ||||
| } | } | ||||
| @@ -343,15 +343,8 @@ public abstract class Definer extends DefBase { | |||||
| antlib.setURI(getURI()); | antlib.setURI(getURI()); | ||||
| antlib.perform(); | antlib.perform(); | ||||
| } catch (BuildException ex) { | } 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()); | |||||
| } | } | ||||
| } | } | ||||
| @@ -55,7 +55,7 @@ | |||||
| package org.apache.tools.ant.taskdefs; | package org.apache.tools.ant.taskdefs; | ||||
| import org.apache.tools.ant.BuildException; | 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.Project; | ||||
| import org.apache.tools.ant.ProjectHelper; | import org.apache.tools.ant.ProjectHelper; | ||||
| import org.apache.tools.ant.Task; | import org.apache.tools.ant.Task; | ||||
| @@ -183,15 +183,8 @@ public class ImportTask extends Task { | |||||
| try { | try { | ||||
| helper.parse(getProject(), importedFile); | helper.parse(getProject(), importedFile); | ||||
| } catch (BuildException ex) { | } 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()); | |||||
| } | } | ||||
| } | } | ||||
| @@ -66,10 +66,11 @@ import java.util.Enumeration; | |||||
| import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
| import org.apache.tools.ant.DynamicConfigurator; | 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.Task; | ||||
| import org.apache.tools.ant.TaskContainer; | import org.apache.tools.ant.TaskContainer; | ||||
| import org.apache.tools.ant.UnknownElement; | import org.apache.tools.ant.UnknownElement; | ||||
| import org.apache.tools.ant.RuntimeConfigurable; | |||||
| /** | /** | ||||
| * The class to be placed in the ant type definition. | * 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 | // need to set the project on unknown element | ||||
| UnknownElement c = copy(macroDef.getNestedTask()); | UnknownElement c = copy(macroDef.getNestedTask()); | ||||
| c.init(); | c.init(); | ||||
| c.perform(); | |||||
| try { | |||||
| c.perform(); | |||||
| } catch (BuildException ex) { | |||||
| throw ProjectHelper.addLocationToBuildException( | |||||
| ex, getLocation()); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||