in-line and not at the end of the current tasks PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274836 13f79535-47bb-0310-9956-ffa450edef68master
@@ -326,7 +326,6 @@ | |||||
<patternset id="teststhatfail"> | <patternset id="teststhatfail"> | ||||
<exclude name="${optional.package}/BeanShellScriptTest.java"/> | <exclude name="${optional.package}/BeanShellScriptTest.java"/> | ||||
<exclude name="${ant.package}/taskdefs/ImportTest.java"/> | |||||
</patternset> | </patternset> | ||||
<!-- | <!-- | ||||
@@ -16,11 +16,6 @@ Includes as explained in the Ant FAQ</a>, as if the imported file was | |||||
contained in the importing file, minus the top <code><project></code> | contained in the importing file, minus the top <code><project></code> | ||||
tag.<br> | tag.<br> | ||||
<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 | There are two further functional aspects that pertain to this task and | ||||
that are not possible with entity includes:<br> | that are not possible with entity includes:<br> | ||||
<ul> | <ul> | ||||
@@ -80,10 +80,17 @@ public class Target implements TaskContainer { | |||||
private List/*<String>*/ dependencies = null; | private List/*<String>*/ dependencies = null; | ||||
/** Children of this target (tasks and data types). */ | /** Children of this target (tasks and data types). */ | ||||
private List/*<Task|RuntimeConfigurable>*/ children = new ArrayList(5); | private List/*<Task|RuntimeConfigurable>*/ children = new ArrayList(5); | ||||
/** Position in task list */ | |||||
private int taskPosition = 0; | |||||
/** Project this target belongs to. */ | /** Project this target belongs to. */ | ||||
private Project project; | private Project project; | ||||
/** Description of this target, if any. */ | /** Description of this target, if any. */ | ||||
private String description = null; | private String description = null; | ||||
/** If adding top-level imported tasks */ | |||||
private boolean addingImportedTasks; | |||||
/** Imported tasks/types being added */ | |||||
private List importedTasks = null; | |||||
/** Sole constructor. */ | /** Sole constructor. */ | ||||
public Target() { | public Target() { | ||||
@@ -165,13 +172,35 @@ public class Target implements TaskContainer { | |||||
return name; | return name; | ||||
} | } | ||||
/** | |||||
* 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. | * Adds a task to this target. | ||||
* | * | ||||
* @param task The task to be added. Must not be <code>null</code>. | * @param task The task to be added. Must not be <code>null</code>. | ||||
*/ | */ | ||||
public void addTask(Task task) { | 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 class Target implements TaskContainer { | |||||
*/ | */ | ||||
public void execute() throws BuildException { | public void execute() throws BuildException { | ||||
if (testIfCondition() && testUnlessCondition()) { | 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) { | if (o instanceof Task) { | ||||
Task task = (Task) o; | Task task = (Task) o; | ||||
task.perform(); | task.perform(); | ||||
@@ -119,7 +119,9 @@ public class ProjectHelper2 extends ProjectHelper { | |||||
if (this.getImportStack().size() > 1) { | if (this.getImportStack().size() > 1) { | ||||
// we are in an imported file. | // we are in an imported file. | ||||
context.setIgnoreProjectTag(true); | context.setIgnoreProjectTag(true); | ||||
context.getCurrentTarget().startImportedTasks(); | |||||
parse(project, source, new RootHandler(context)); | parse(project, source, new RootHandler(context)); | ||||
context.getCurrentTarget().endImportedTasks(); | |||||
} else { | } else { | ||||
// top level file | // top level file | ||||
parse(project, source, new RootHandler(context)); | parse(project, source, new RootHandler(context)); | ||||
@@ -468,6 +470,7 @@ public class ProjectHelper2 extends ProjectHelper { | |||||
throws SAXParseException { | throws SAXParseException { | ||||
String id = null; | String id = null; | ||||
String baseDir = null; | String baseDir = null; | ||||
boolean nameAttributeSet = false; | |||||
Project project = context.getProject(); | Project project = context.getProject(); | ||||
@@ -495,7 +498,7 @@ public class ProjectHelper2 extends ProjectHelper { | |||||
} else if (key.equals("name")) { | } else if (key.equals("name")) { | ||||
if (value != null) { | if (value != null) { | ||||
context.setCurrentProjectName(value); | context.setCurrentProjectName(value); | ||||
nameAttributeSet = true; | |||||
if (!context.isIgnoringProjectTag()) { | if (!context.isIgnoringProjectTag()) { | ||||
project.setName(value); | project.setName(value); | ||||
project.addReference(value, project); | project.addReference(value, project); | ||||
@@ -522,7 +525,7 @@ public class ProjectHelper2 extends ProjectHelper { | |||||
// XXX Move to Project ( so it is shared by all helpers ) | // XXX Move to Project ( so it is shared by all helpers ) | ||||
String antFileProp = "ant.file." + context.getCurrentProjectName(); | String antFileProp = "ant.file." + context.getCurrentProjectName(); | ||||
String dup = project.getProperty(antFileProp); | String dup = project.getProperty(antFileProp); | ||||
if (dup != null) { | |||||
if (dup != null && nameAttributeSet) { | |||||
File dupFile = new File(dup); | File dupFile = new File(dup); | ||||
if (context.isIgnoringProjectTag() && | if (context.isIgnoringProjectTag() && | ||||
!dupFile.equals(context.getBuildFile())) { | !dupFile.equals(context.getBuildFile())) { | ||||
@@ -69,11 +69,6 @@ import java.util.Vector; | |||||
* It must be 'top level'. On execution it will read another Ant file | * It must be 'top level'. On execution it will read another Ant file | ||||
* into the same Project. | * into the same Project. | ||||
* <p> | * <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 | * <b>Important</b>: we have not finalized how relative file references | ||||
* will be resolved in deep/complex build hierarchies -such as what happens | * will be resolved in deep/complex build hierarchies -such as what happens | ||||
* when an imported file imports another file. Use absolute references for | * when an imported file imports another file. Use absolute references for | ||||
@@ -74,6 +74,11 @@ public class ImportTest extends BuildFileTest { | |||||
public void testSimpleImport() { | public void testSimpleImport() { | ||||
configureProject("src/etc/testcases/taskdefs/import/import.xml"); | 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() { | public void testUnnamedNesting() { | ||||