peterreilly 2005/05/16 11:59:58 Modified: . WHATSNEW src/testcases/org/apache/tools/ant/taskdefs ImportTest.java src/main/org/apache/tools/ant Target.java src/main/org/apache/tools/ant/helper ProjectHelper2.java Added: src/etc/testcases/taskdefs/import a.xml b.xml c.xml Log: Allways create qualified targets in imported build files PR: 28444 Revision Changes Path 1.822 +3 -0 ant/WHATSNEW Index: WHATSNEW =================================================================== RCS file: /home/cvs/ant/WHATSNEW,v retrieving revision 1.821 retrieving revision 1.822 diff -u -r1.821 -r1.822 --- WHATSNEW 13 May 2005 22:12:29 -0000 1.821 +++ WHATSNEW 16 May 2005 18:59:57 -0000 1.822 @@ -200,6 +200,9 @@ can be caused by the test JVM exiting during a test, either via a System.exit() 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 ===================================================== 1.17 +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.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- ImportTest.java 25 Apr 2005 10:15:11 -0000 1.16 +++ ImportTest.java 16 May 2005 18:59:57 -0000 1.17 @@ -163,4 +163,9 @@ configureProject("src/etc/testcases/taskdefs/import/importtargetfirst.xml"); assertLogContaining("Importing targetfirstAfter target firstAfter importing"); } + + public void testTargetName() { + configureProject("src/etc/testcases/taskdefs/import/c.xml"); + } + } 1.59 +20 -4 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.58 retrieving revision 1.59 diff -u -r1.58 -r1.59 --- Target.java 10 Mar 2005 12:50:57 -0000 1.58 +++ Target.java 16 May 2005 18:59:57 -0000 1.59 @@ -52,12 +52,28 @@ /** Description of this target, if any. */ private String description = null; - /** Sole constructor. */ + /** Default constructor. */ public Target() { //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. * * @param project The project this target belongs to. @@ -209,7 +225,7 @@ * @return an enumeration of the dependencies of this target */ public Enumeration getDependencies() { - return (dependencies != null ? Collections.enumeration(dependencies) + return (dependencies != null ? Collections.enumeration(dependencies) : new CollectionUtils.EmptyEnumeration()); } @@ -222,7 +238,7 @@ public boolean dependsOn(String other) { Project p = getProject(); Hashtable t = (p == null) ? null : p.getTargets(); - return (p != null + return (p != null && p.topoSort(getName(), t, false).contains(t.get(other))); } @@ -438,4 +454,4 @@ String test = project.replaceProperties(unlessCondition); return project.getProperty(test) == null; } -} \ No newline at end of file +} 1.1 ant/src/etc/testcases/taskdefs/import/a.xml Index: a.xml =================================================================== <project name="A"> <target name="x"/> </project> 1.1 ant/src/etc/testcases/taskdefs/import/b.xml Index: b.xml =================================================================== <project name="B"> <import file="a.xml"/> <target name="x" depends="A.x"/> </project> 1.1 ant/src/etc/testcases/taskdefs/import/c.xml Index: c.xml =================================================================== <project name="C"> <import file="a.xml"/> <import file="b.xml"/> </project> 1.55 +25 -24 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.54 retrieving revision 1.55 diff -u -r1.54 -r1.55 --- ProjectHelper2.java 26 Apr 2005 11:55:18 -0000 1.54 +++ ProjectHelper2.java 16 May 2005 18:59:58 -0000 1.55 @@ -815,38 +815,39 @@ + "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); context.getCurrentTargets().put(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); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]