Browse Source

Allways create qualified targets in imported build files

PR: 28444


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278272 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 20 years ago
parent
commit
3d66f4ef91
7 changed files with 64 additions and 28 deletions
  1. +3
    -0
      WHATSNEW
  2. +3
    -0
      src/etc/testcases/taskdefs/import/a.xml
  3. +4
    -0
      src/etc/testcases/taskdefs/import/b.xml
  4. +4
    -0
      src/etc/testcases/taskdefs/import/c.xml
  5. +20
    -4
      src/main/org/apache/tools/ant/Target.java
  6. +25
    -24
      src/main/org/apache/tools/ant/helper/ProjectHelper2.java
  7. +5
    -0
      src/testcases/org/apache/tools/ant/taskdefs/ImportTest.java

+ 3
- 0
WHATSNEW View File

@@ -200,6 +200,9 @@ Other changes:
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
=====================================================



+ 3
- 0
src/etc/testcases/taskdefs/import/a.xml View File

@@ -0,0 +1,3 @@
<project name="A">
<target name="x"/>
</project>

+ 4
- 0
src/etc/testcases/taskdefs/import/b.xml View File

@@ -0,0 +1,4 @@
<project name="B">
<import file="a.xml"/>
<target name="x" depends="A.x"/>
</project>

+ 4
- 0
src/etc/testcases/taskdefs/import/c.xml View File

@@ -0,0 +1,4 @@
<project name="C">
<import file="a.xml"/>
<import file="b.xml"/>
</project>

+ 20
- 4
src/main/org/apache/tools/ant/Target.java View File

@@ -52,11 +52,27 @@ public class Target implements TaskContainer {
/** 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.
*
@@ -209,7 +225,7 @@ public class Target implements TaskContainer {
* @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 class Target implements TaskContainer {
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 @@ public class Target implements TaskContainer {
String test = project.replaceProperties(unlessCondition);
return project.getProperty(test) == null;
}
}
}

+ 25
- 24
src/main/org/apache/tools/ant/helper/ProjectHelper2.java View File

@@ -815,38 +815,39 @@ public class ProjectHelper2 extends ProjectHelper {
+ "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);
}
}



+ 5
- 0
src/testcases/org/apache/tools/ant/taskdefs/ImportTest.java View File

@@ -163,4 +163,9 @@ public class ImportTest extends BuildFileTest {
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");
}

}

Loading…
Cancel
Save