Browse Source

make error message for bad imports a little better

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-ffa450edef68
master
Peter Reilly 21 years ago
parent
commit
23bebfbdc2
4 changed files with 44 additions and 1 deletions
  1. +3
    -0
      src/etc/testcases/taskdefs/import/bad.xml
  2. +3
    -0
      src/etc/testcases/taskdefs/import/import_bad_import.xml
  3. +14
    -1
      src/main/org/apache/tools/ant/taskdefs/ImportTask.java
  4. +24
    -0
      src/testcases/org/apache/tools/ant/taskdefs/ImportTest.java

+ 3
- 0
src/etc/testcases/taskdefs/import/bad.xml View File

@@ -0,0 +1,3 @@
<project>
<<<
</project>

+ 3
- 0
src/etc/testcases/taskdefs/import/import_bad_import.xml View File

@@ -0,0 +1,3 @@
<project>
<import file="bad.xml"/>
</project>

+ 14
- 1
src/main/org/apache/tools/ant/taskdefs/ImportTask.java View File

@@ -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) {


+ 24
- 0
src/testcases/org/apache/tools/ant/taskdefs/ImportTest.java View 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);
}
} }



Loading…
Cancel
Save