From 0be94ce296ad1d671cbbfca63d7c2d706d17d7fe Mon Sep 17 00:00:00 2001 From: Costin Manolache Date: Fri, 27 Dec 2002 17:59:40 +0000 Subject: [PATCH] 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. PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273701 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tools/ant/taskdefs/ImportTask.java | 69 +++++++++++-------- 1 file changed, 41 insertions(+), 28 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/ImportTask.java b/src/main/org/apache/tools/ant/taskdefs/ImportTask.java index b59823837..fd8088a86 100644 --- a/src/main/org/apache/tools/ant/taskdefs/ImportTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/ImportTask.java @@ -59,6 +59,7 @@ import org.apache.tools.ant.helper.ProjectHelper2; import java.io.File; import java.io.IOException; +import java.util.Vector; /** * EXPERIMENTAL @@ -95,50 +96,62 @@ public class ImportTask extends Task { 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"); - project.log("Importing file "+file +" from "+ - context.buildFile.getAbsolutePath() + - "( level=" + context.importlevel + " )", - Project.MSG_VERBOSE); +// File buildFile=context.buildFile; +// File buildFileParent=context.buildFileParent; + File buildFile=(File)currentSource; + File buildFileParent=new File(buildFile.getParent()); + + 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()); + 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); - } - - // 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) {