peterreilly 2003/07/16 07:39:47 Modified: src/main/org/apache/tools/ant Target.java src/main/org/apache/tools/ant/helper ProjectHelper2.java src/testcases/org/apache/tools/ant/taskdefs ImportTest.java . build.xml docs/manual/CoreTasks import.html src/main/org/apache/tools/ant/taskdefs ImportTask.java Log: get the tasks imported using <import> to be placed in-line and not at the end of the current tasks Revision Changes Path 1.41 +34 -3 ant/src/main/org/apache/tools/ant/Target.java Index: Target.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/Target.java,v retrieving revision 1.40 retrieving revision 1.41 diff -u -r1.40 -r1.41 --- Target.java 15 Jul 2003 09:05:52 -0000 1.40 +++ Target.java 16 Jul 2003 14:38:54 -0000 1.41 @@ -80,10 +80,17 @@ private List/*<String>*/ dependencies = null; /** Children of this target (tasks and data types). */ private List/*<Task|RuntimeConfigurable>*/ children = new ArrayList(5); + /** Position in task list */ + private int taskPosition = 0; + /** Project this target belongs to. */ private Project project; /** Description of this target, if any. */ private String description = null; + /** If adding top-level imported tasks */ + private boolean addingImportedTasks; + /** Imported tasks/types being added */ + private List importedTasks = null; /** Sole constructor. */ public Target() { @@ -166,12 +173,34 @@ } /** + * This method called when an import file is being processed. + * The top-level tasks/types are placed in the importedTasks array. + * + */ + public void startImportedTasks() { + importedTasks = new ArrayList(); + } + + /** * Adds a task to this target. * * @param task The task to be added. Must not be <code>null</code>. */ public void addTask(Task task) { - children.add(task); + if (importedTasks != null) { + importedTasks.add(task); + } else { + children.add(task); + } + } + + /** + * This method called when an import file is being processed. + * The top-level tasks/types are placed in the importedTasks array. + * + */ + public void endImportedTasks() { + children.addAll(taskPosition + 1, importedTasks); } /** @@ -311,8 +340,10 @@ */ public void execute() throws BuildException { if (testIfCondition() && testUnlessCondition()) { - for (int i = 0; i < children.size(); ++i) { - Object o = children.get(i); + for (taskPosition = 0; + taskPosition < children.size(); + ++taskPosition) { + Object o = children.get(taskPosition); if (o instanceof Task) { Task task = (Task) o; task.perform(); 1.21 +5 -2 ant/src/main/org/apache/tools/ant/helper/ProjectHelper2.java Index: ProjectHelper2.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/helper/ProjectHelper2.java,v retrieving revision 1.20 retrieving revision 1.21 diff -u -r1.20 -r1.21 --- ProjectHelper2.java 4 Jul 2003 14:04:53 -0000 1.20 +++ ProjectHelper2.java 16 Jul 2003 14:39:07 -0000 1.21 @@ -119,7 +119,9 @@ if (this.getImportStack().size() > 1) { // we are in an imported file. context.setIgnoreProjectTag(true); + context.getCurrentTarget().startImportedTasks(); parse(project, source, new RootHandler(context)); + context.getCurrentTarget().endImportedTasks(); } else { // top level file parse(project, source, new RootHandler(context)); @@ -468,6 +470,7 @@ throws SAXParseException { String id = null; String baseDir = null; + boolean nameAttributeSet = false; Project project = context.getProject(); @@ -495,7 +498,7 @@ } else if (key.equals("name")) { if (value != null) { context.setCurrentProjectName(value); - + nameAttributeSet = true; if (!context.isIgnoringProjectTag()) { project.setName(value); project.addReference(value, project); @@ -522,7 +525,7 @@ // XXX Move to Project ( so it is shared by all helpers ) String antFileProp = "ant.file." + context.getCurrentProjectName(); String dup = project.getProperty(antFileProp); - if (dup != null) { + if (dup != null && nameAttributeSet) { File dupFile = new File(dup); if (context.isIgnoringProjectTag() && !dupFile.equals(context.getBuildFile())) { 1.3 +5 -0 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.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ImportTest.java 10 Feb 2003 14:14:45 -0000 1.2 +++ ImportTest.java 16 Jul 2003 14:39:08 -0000 1.3 @@ -74,6 +74,11 @@ 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); } public void testUnnamedNesting() { 1.388 +0 -1 ant/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/ant/build.xml,v retrieving revision 1.387 retrieving revision 1.388 diff -u -r1.387 -r1.388 --- build.xml 14 Jul 2003 12:07:22 -0000 1.387 +++ build.xml 16 Jul 2003 14:39:30 -0000 1.388 @@ -326,7 +326,6 @@ <patternset id="teststhatfail"> <exclude name="${optional.package}/BeanShellScriptTest.java"/> - <exclude name="${ant.package}/taskdefs/ImportTest.java"/> </patternset> <!-- 1.3 +0 -5 ant/docs/manual/CoreTasks/import.html Index: import.html =================================================================== RCS file: /home/cvs/ant/docs/manual/CoreTasks/import.html,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- import.html 10 Jul 2003 07:27:20 -0000 1.2 +++ import.html 16 Jul 2003 14:39:30 -0000 1.3 @@ -16,11 +16,6 @@ contained in the importing file, minus the top <code><project></code> tag.<br> <br> -<b>Important</b>: there is one limitation related to the top level -elements in the imported files. The current implementation will add -them at the end of the top-level ( instead of replacing the import -element - which would be more intuitive ).<br> -<br> There are two further functional aspects that pertain to this task and that are not possible with entity includes:<br> <ul> 1.13 +0 -5 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.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- ImportTask.java 6 Jul 2003 09:57:36 -0000 1.12 +++ ImportTask.java 16 Jul 2003 14:39:44 -0000 1.13 @@ -69,11 +69,6 @@ * It must be 'top level'. On execution it will read another Ant file * into the same Project. * <p> - * <b>Important</b>: there is one limitation related to the top level - * elements in the imported files. The current implementation will - * add them at the end of the top-level ( instead of replacing the - * import element - which would be more intuitive ). - * <p> * <b>Important</b>: we have not finalized how relative file references * will be resolved in deep/complex build hierarchies -such as what happens * when an imported file imports another file. Use absolute references for
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]