PR: 28444 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278272 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -200,6 +200,9 @@ Other changes: | |||||
| can be caused by the test JVM exiting during a test, either via a System.exit() | can be caused by the test JVM exiting during a test, either via a System.exit() | ||||
| call or a JVM crash. | call or a JVM crash. | ||||
| * project name is now used for *all* targets so one can write consistent import | |||||
| build file. bugzilla report 28444. | |||||
| Changes from Ant 1.6.3 to current Ant 1.6 CVS version | Changes from Ant 1.6.3 to current Ant 1.6 CVS version | ||||
| ===================================================== | ===================================================== | ||||
| @@ -0,0 +1,3 @@ | |||||
| <project name="A"> | |||||
| <target name="x"/> | |||||
| </project> | |||||
| @@ -0,0 +1,4 @@ | |||||
| <project name="B"> | |||||
| <import file="a.xml"/> | |||||
| <target name="x" depends="A.x"/> | |||||
| </project> | |||||
| @@ -0,0 +1,4 @@ | |||||
| <project name="C"> | |||||
| <import file="a.xml"/> | |||||
| <import file="b.xml"/> | |||||
| </project> | |||||
| @@ -52,11 +52,27 @@ public class Target implements TaskContainer { | |||||
| /** Description of this target, if any. */ | /** Description of this target, if any. */ | ||||
| private String description = null; | private String description = null; | ||||
| /** Sole constructor. */ | |||||
| /** Default constructor. */ | |||||
| public Target() { | public Target() { | ||||
| //empty | //empty | ||||
| } | } | ||||
| /** | |||||
| * Cloning constructor. | |||||
| * @param other the Target to clone. | |||||
| */ | |||||
| public Target(Target other) { | |||||
| this.name = other.name; | |||||
| this.ifCondition = other.ifCondition; | |||||
| this.unlessCondition = other.unlessCondition; | |||||
| this.dependencies = other.dependencies; | |||||
| this.location = other.location; | |||||
| this.project = other.project; | |||||
| this.description = other.description; | |||||
| // The children are added to after this cloning | |||||
| this.children = other.children; | |||||
| } | |||||
| /** | /** | ||||
| * Sets the project this target belongs to. | * Sets the project this target belongs to. | ||||
| * | * | ||||
| @@ -209,7 +225,7 @@ public class Target implements TaskContainer { | |||||
| * @return an enumeration of the dependencies of this target | * @return an enumeration of the dependencies of this target | ||||
| */ | */ | ||||
| public Enumeration getDependencies() { | public Enumeration getDependencies() { | ||||
| return (dependencies != null ? Collections.enumeration(dependencies) | |||||
| return (dependencies != null ? Collections.enumeration(dependencies) | |||||
| : new CollectionUtils.EmptyEnumeration()); | : new CollectionUtils.EmptyEnumeration()); | ||||
| } | } | ||||
| @@ -222,7 +238,7 @@ public class Target implements TaskContainer { | |||||
| public boolean dependsOn(String other) { | public boolean dependsOn(String other) { | ||||
| Project p = getProject(); | Project p = getProject(); | ||||
| Hashtable t = (p == null) ? null : p.getTargets(); | Hashtable t = (p == null) ? null : p.getTargets(); | ||||
| return (p != null | |||||
| return (p != null | |||||
| && p.topoSort(getName(), t, false).contains(t.get(other))); | && p.topoSort(getName(), t, false).contains(t.get(other))); | ||||
| } | } | ||||
| @@ -438,4 +454,4 @@ public class Target implements TaskContainer { | |||||
| String test = project.replaceProperties(unlessCondition); | String test = project.replaceProperties(unlessCondition); | ||||
| return project.getProperty(test) == null; | return project.getProperty(test) == null; | ||||
| } | } | ||||
| } | |||||
| } | |||||
| @@ -815,38 +815,39 @@ public class ProjectHelper2 extends ProjectHelper { | |||||
| + "a name attribute", context.getLocator()); | + "a name attribute", context.getLocator()); | ||||
| } | } | ||||
| Hashtable currentTargets = project.getTargets(); | |||||
| // Check if this target is in the current build file | |||||
| if (context.getCurrentTargets().get(name) != null) { | |||||
| throw new BuildException( | |||||
| "Duplicate target '" + name + "'", target.getLocation()); | |||||
| } | |||||
| // If the name has already been defined ( import for example ) | |||||
| if (currentTargets.containsKey(name)) { | |||||
| if (context.getCurrentTargets().get(name) != null) { | |||||
| throw new BuildException( | |||||
| "Duplicate target '" + name + "'", target.getLocation()); | |||||
| } | |||||
| // Alter the name. | |||||
| if (context.getCurrentProjectName() != null) { | |||||
| String newName = context.getCurrentProjectName() | |||||
| + "." + name; | |||||
| project.log("Already defined in main or a previous import, " | |||||
| + "define " + name + " as " + newName, | |||||
| Project.MSG_VERBOSE); | |||||
| name = newName; | |||||
| } else { | |||||
| project.log("Already defined in main or a previous import, " | |||||
| + "ignore " + name, Project.MSG_VERBOSE); | |||||
| name = null; | |||||
| } | |||||
| if (depends.length() > 0) { | |||||
| target.setDepends(depends); | |||||
| } | } | ||||
| if (name != null) { | |||||
| Hashtable projectTargets = project.getTargets(); | |||||
| boolean usedTarget = false; | |||||
| // If the name has not already been defined define it | |||||
| if (projectTargets.containsKey(name)) { | |||||
| project.log("Already defined in main or a previous import, " | |||||
| + "ignore " + name, Project.MSG_VERBOSE); | |||||
| } else { | |||||
| target.setName(name); | target.setName(name); | ||||
| context.getCurrentTargets().put(name, target); | context.getCurrentTargets().put(name, target); | ||||
| project.addOrReplaceTarget(name, target); | project.addOrReplaceTarget(name, target); | ||||
| usedTarget = true; | |||||
| } | } | ||||
| // take care of dependencies | |||||
| if (depends.length() > 0) { | |||||
| target.setDepends(depends); | |||||
| if (context.isIgnoringProjectTag() && context.getCurrentProjectName() != null | |||||
| && context.getCurrentProjectName().length() != 0) { | |||||
| // In an impored file (and not completely | |||||
| // ignoring the project tag) | |||||
| String newName = context.getCurrentProjectName() | |||||
| + "." + name; | |||||
| Target newTarget = usedTarget ? new Target(target) : target; | |||||
| newTarget.setName(newName); | |||||
| context.getCurrentTargets().put(newName, newTarget); | |||||
| project.addOrReplaceTarget(newName, newTarget); | |||||
| } | } | ||||
| } | } | ||||
| @@ -163,4 +163,9 @@ public class ImportTest extends BuildFileTest { | |||||
| configureProject("src/etc/testcases/taskdefs/import/importtargetfirst.xml"); | configureProject("src/etc/testcases/taskdefs/import/importtargetfirst.xml"); | ||||
| assertLogContaining("Importing targetfirstAfter target firstAfter importing"); | assertLogContaining("Importing targetfirstAfter target firstAfter importing"); | ||||
| } | } | ||||
| public void testTargetName() { | |||||
| configureProject("src/etc/testcases/taskdefs/import/c.xml"); | |||||
| } | |||||
| } | } | ||||