Browse Source

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
master
Costin Manolache 23 years ago
parent
commit
0be94ce296
1 changed files with 41 additions and 28 deletions
  1. +41
    -28
      src/main/org/apache/tools/ant/taskdefs/ImportTask.java

+ 41
- 28
src/main/org/apache/tools/ant/taskdefs/ImportTask.java View File

@@ -59,6 +59,7 @@ import org.apache.tools.ant.helper.ProjectHelper2;


import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Vector;


/** /**
* EXPERIMENTAL * EXPERIMENTAL
@@ -95,50 +96,62 @@ public class ImportTask extends Task {
if (file == null) { if (file == null) {
throw new BuildException("import requires file attribute"); 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, // Paths are relative to the build file they're imported from,
// *not* the current directory (same as entity includes). // *not* the current directory (same as entity includes).
File importedFile = new File(file); File importedFile = new File(file);
if (!importedFile.isAbsolute()) { if (!importedFile.isAbsolute()) {
importedFile = new File(context.buildFileParent, file);
importedFile = new File( buildFileParent, file);
} }

if (!importedFile.exists()) { if (!importedFile.exists()) {
throw new BuildException("Cannot find "+file+" imported from "+ 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; 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) { private static String getPath(File file) {


Loading…
Cancel
Save