peterreilly 2003/07/17 03:39:07 Modified: src/main/org/apache/tools/ant/taskdefs ImportTask.java src/testcases/org/apache/tools/ant/taskdefs ImportTest.java src/testcases/org/apache/tools/ant BuildFileTest.java Added: src/etc/testcases/taskdefs/import/subdir serial.xml Log: Fix for serial import relative files bug The import task now uses getLocation().getFileName() to get the file that the <import/> task is located and not the importstack. Also the canonical form of the imported file is stored in the importstack. Changed message if imported file is imported more than once. Include unit test for above. PR: 21662 Revision Changes Path 1.15 +9 -4 ant/src/main/org/apache/tools/ant/taskdefs/ImportTask.java Index: ImportTask.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/ImportTask.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- ImportTask.java 17 Jul 2003 09:21:32 -0000 1.14 +++ ImportTask.java 17 Jul 2003 10:39:07 -0000 1.15 @@ -125,14 +125,17 @@ // 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 @@ + 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; } 1.4 +7 -5 ant/src/testcases/org/apache/tools/ant/taskdefs/ImportTest.java Index: ImportTest.java =================================================================== RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/ImportTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ImportTest.java 16 Jul 2003 14:39:08 -0000 1.3 +++ ImportTest.java 17 Jul 2003 10:39:07 -0000 1.4 @@ -74,11 +74,7 @@ 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() { @@ -87,6 +83,12 @@ String log = getLog(); 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"); } } 1.24 +12 -4 ant/src/testcases/org/apache/tools/ant/BuildFileTest.java Index: BuildFileTest.java =================================================================== RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/BuildFileTest.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- BuildFileTest.java 9 Jun 2003 13:38:07 -0000 1.23 +++ BuildFileTest.java 17 Jul 2003 10:39:07 -0000 1.24 @@ -108,17 +108,25 @@ 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); } /** 1.1 ant/src/etc/testcases/taskdefs/import/subdir/serial.xml Index: serial.xml =================================================================== <project name="serial"> <import file="../unnamed1.xml"/> <import file="../unnamed2.xml"/> </project>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]