costin 2002/12/27 09:59:40 Modified: src/main/org/apache/tools/ant/taskdefs ImportTask.java Log: Remove the dependency on ProjectHelper2. We only need the import stack to avoid loops and some mechanism to let let the helper know we're processing an import. Revision Changes Path 1.2 +41 -28 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ImportTask.java Index: ImportTask.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ImportTask.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ImportTask.java 24 Dec 2002 01:25:09 -0000 1.1 +++ ImportTask.java 27 Dec 2002 17:59:40 -0000 1.2 @@ -59,6 +59,7 @@ import java.io.File; import java.io.IOException; +import java.util.Vector; /** * EXPERIMENTAL @@ -95,50 +96,62 @@ if (file == null) { throw new BuildException("import requires file attribute"); } - - ProjectHelper2.AntXmlContext context; - context=(ProjectHelper2.AntXmlContext)project.getReference("ant.parsing.context"); - context.importlevel++; + ProjectHelper helper= + (ProjectHelper)project.getReference("ant.projectHelper"); + Vector importStack=helper.getImportStack(); + 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; + File buildFileParent=new File(buildFile.getParent()); - project.log("Importing file "+file +" from "+ - context.buildFile.getAbsolutePath() + - "( level=" + context.importlevel + " )", - Project.MSG_VERBOSE); + project.log("Importing file "+ file +" from "+ + buildFile.getAbsolutePath(), Project.MSG_VERBOSE); // Paths are relative to the build file they're imported from, // *not* the current directory (same as entity includes). File importedFile = new File(file); if (!importedFile.isAbsolute()) { - importedFile = new File(context.buildFileParent, file); + importedFile = new File( buildFileParent, file); } + if (!importedFile.exists()) { throw new BuildException("Cannot find "+file+" imported from "+ - context.buildFile.getAbsolutePath()); - } - - // Add parent build file to the map to avoid cycles... - String parentFilename = getPath(context.buildFile); - if (!context.importedFiles.containsKey(parentFilename)) { - context.importedFiles.put(parentFilename, context.buildFile); + buildFile.getAbsolutePath()); } - // Make sure we import the file only once - String importedFilename = getPath(importedFile); - if (context.importedFiles.containsKey(importedFilename)) { - project.log("\nSkipped already imported file:\n "+ - importedFilename+"\n",Project.MSG_WARN); - context.importlevel--; + if( importStack.contains(importedFile) ) { + project.log("\nSkipped already imported file to avoid loop:\n "+ + importedFile + "\n",Project.MSG_WARN); return; - } else { - context.importedFiles.put(importedFilename, importedFile); } - context.ignoreProjectTag=true; - context.helper.parse(project, importedFile, - new ProjectHelper2.RootHandler(context)); +// // Add parent build file to the map to avoid cycles... +// String parentFilename = getPath(buildFile); +// if (!context.importedFiles.containsKey(parentFilename)) { +// context.importedFiles.put(parentFilename, buildFile); +// } +// +// // Make sure we import the file only once +// String importedFilename = getPath(importedFile); +// if (context.importedFiles.containsKey(importedFilename)) { +// project.log("\nSkipped already imported file:\n "+ +// importedFilename+"\n",Project.MSG_WARN); +// return; +// } else { +// context.importedFiles.put(importedFilename, importedFile); +// } + +// context.ignoreProjectTag=true; +// context.helper.parse(project, importedFile, +// new ProjectHelper2.RootHandler(context)); - context.importlevel--; + helper.parse( project, importedFile ); } private static String getPath(File file) {
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>