When an buildexception is reported in the imported xml, add the importer xml file to the build exception git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275610 13f79535-47bb-0310-9956-ffa450edef68master
@@ -0,0 +1,3 @@ | |||||
<project> | |||||
<<< | |||||
</project> |
@@ -0,0 +1,3 @@ | |||||
<project> | |||||
<import file="bad.xml"/> | |||||
</project> |
@@ -55,6 +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.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; | ||||
@@ -179,7 +180,19 @@ public class ImportTask extends Task { | |||||
return; | return; | ||||
} | } | ||||
helper.parse(getProject(), importedFile); | |||||
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()); | |||||
} | |||||
} | } | ||||
private static String getPath(File file) { | private static String getPath(File file) { | ||||
@@ -54,7 +54,9 @@ | |||||
package org.apache.tools.ant.taskdefs; | package org.apache.tools.ant.taskdefs; | ||||
import org.apache.tools.ant.BuildException; | |||||
import org.apache.tools.ant.BuildFileTest; | import org.apache.tools.ant.BuildFileTest; | ||||
import org.apache.tools.ant.Location; | |||||
import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
/** | /** | ||||
@@ -119,5 +121,27 @@ public class ImportTest extends BuildFileTest { | |||||
expectPropertySet("within-imported", "foo", "bar"); | expectPropertySet("within-imported", "foo", "bar"); | ||||
assertNotNull(getProject().getReference("baz")); | assertNotNull(getProject().getReference("baz")); | ||||
} | } | ||||
public void testImportError() { | |||||
try { | |||||
configureProject( | |||||
"src/etc/testcases/taskdefs/import/import_bad_import.xml"); | |||||
} catch (BuildException ex) { | |||||
Location lo = ex.getLocation(); | |||||
assertTrue( | |||||
"expected location of build exception to be set", | |||||
(lo != null)); | |||||
assertTrue( | |||||
"expected location to contain calling file", | |||||
lo.getFileName().indexOf("import_bad_import.xml") != -1); | |||||
assertTrue( | |||||
"expected message of ex to contain called file", | |||||
ex.getMessage().indexOf("bad.xml") != -1); | |||||
return; | |||||
} | |||||
assertTrue( | |||||
"Did not see build exception", | |||||
false); | |||||
} | |||||
} | } | ||||