diff --git a/src/etc/testcases/taskdefs/import/subdir/serial.xml b/src/etc/testcases/taskdefs/import/subdir/serial.xml new file mode 100644 index 000000000..f2c81dd06 --- /dev/null +++ b/src/etc/testcases/taskdefs/import/subdir/serial.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/src/main/org/apache/tools/ant/taskdefs/ImportTask.java b/src/main/org/apache/tools/ant/taskdefs/ImportTask.java index fbeeab8bb..a8ded92de 100644 --- a/src/main/org/apache/tools/ant/taskdefs/ImportTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/ImportTask.java @@ -125,14 +125,17 @@ public class ImportTask extends Task { // helper that doesn't set the import. throw new BuildException("import requires support in ProjectHelper"); } - Object currentSource = importStack.elementAt(importStack.size() - 1); - // ProjectHelper2.AntXmlContext context; // context=(ProjectHelper2.AntXmlContext)project.getReference("ant.parsing.context"); // File buildFile=context.buildFile; // File buildFileParent=context.buildFileParent; - File buildFile = (File) currentSource; + + if (getLocation() == null || getLocation().getFileName() == null) { + throw new BuildException("Unable to get location of import task"); + } + + File buildFile = new File(getLocation().getFileName()); buildFile = new File(buildFile.getAbsolutePath()); //System.out.println("Importing from " + currentSource); File buildFileParent = new File(buildFile.getParent()); @@ -153,9 +156,11 @@ public class ImportTask extends Task { + buildFile.getAbsolutePath()); } + importedFile = new File(getPath(importedFile)); + if (importStack.contains(importedFile)) { getProject().log( - "\nSkipped already imported file to avoid loop:\n " + "Skipped already imported file:\n " + importedFile + "\n", Project.MSG_WARN); return; } diff --git a/src/testcases/org/apache/tools/ant/BuildFileTest.java b/src/testcases/org/apache/tools/ant/BuildFileTest.java index 883834b79..48e41b185 100644 --- a/src/testcases/org/apache/tools/ant/BuildFileTest.java +++ b/src/testcases/org/apache/tools/ant/BuildFileTest.java @@ -108,17 +108,25 @@ public abstract class BuildFileTest extends TestCase { String realLog = getLog(); assertEquals(log, realLog); } + + /** + * Assert that the given substring is in the log messages + */ + protected void assertLogContaining(String substring) { + String realLog = getLog(); + assertTrue("expecting log to contain \"" + substring + "\" log was \"" + + realLog + "\"", + realLog.indexOf(substring) >= 0); + } + /** * Assert that the given message has been logged with a priority * >= INFO when running the given target. */ protected void expectLogContaining(String target, String log) { executeTarget(target); - String realLog = getLog(); - assertTrue("expecting log to contain \""+log+"\" log was \"" - + realLog + "\"", - realLog.indexOf(log) >= 0); + assertLogContaining(log); } /** diff --git a/src/testcases/org/apache/tools/ant/taskdefs/ImportTest.java b/src/testcases/org/apache/tools/ant/taskdefs/ImportTest.java index f258b729d..27a5e03a3 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/ImportTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/ImportTest.java @@ -74,11 +74,7 @@ public class ImportTest extends BuildFileTest { public void testSimpleImport() { configureProject("src/etc/testcases/taskdefs/import/import.xml"); - String logMessage = getLog(); - String expect = "Before importIn imported topAfter import"; - assertTrue("expecting log to contain \"" + expect + "\" log was \"" - + logMessage + "\"", - logMessage.indexOf(expect) >= 0); + assertLogContaining("Before importIn imported topAfter import"); } public void testUnnamedNesting() { @@ -88,5 +84,11 @@ public class ImportTest extends BuildFileTest { assertTrue("Warnings logged when not expected: " + log, log.length() == 0); } + + public void testSerial() { + configureProject("src/etc/testcases/taskdefs/import/subdir/serial.xml"); + assertLogContaining( + "Unnamed2.xmlUnnamed1.xmlSkipped already imported file"); + } }