diff --git a/WHATSNEW b/WHATSNEW
index af87578c3..f9ab98345 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -88,6 +88,9 @@ Other changes:
and extension points.
Bugzilla Report 53549.
+ * Make extension point bindable to imported prefixed targets
+ Bugzilla Report 53550.
+
Changes from Ant 1.8.3 TO Ant 1.8.4
===================================
diff --git a/src/main/org/apache/tools/ant/ProjectHelper.java b/src/main/org/apache/tools/ant/ProjectHelper.java
index b600de483..d1bc4daff 100644
--- a/src/main/org/apache/tools/ant/ProjectHelper.java
+++ b/src/main/org/apache/tools/ant/ProjectHelper.java
@@ -629,27 +629,52 @@ public class ProjectHelper {
public void resolveExtensionOfAttributes(Project project)
throws BuildException {
for (String[] extensionInfo : getExtensionStack()) {
- String tgName = extensionInfo[0];
- String name = extensionInfo[1];
+ String extPointName = extensionInfo[0];
+ String targetName = extensionInfo[1];
OnMissingExtensionPoint missingBehaviour = OnMissingExtensionPoint.valueOf(extensionInfo[2]);
+ // if the file has been included or imported, it may have a prefix
+ // we should consider when trying to resolve the target it is
+ // extending
+ String prefixAndSep = extensionInfo.length > 3 ? extensionInfo[3] : null;
+
+ // find the target we're extending
Hashtable projectTargets = project.getTargets();
- if (!projectTargets.containsKey(tgName)) {
- String message = "can't add target " + name
- + " to extension-point " + tgName
+ Target extPoint = null;
+ if (prefixAndSep == null) {
+ // no prefix - not from an imported/included build file
+ extPoint = (Target) projectTargets.get(extPointName);
+ } else {
+ // we have a prefix, which means we came from an include/import
+
+ // FIXME: here we handle no particular level of include. We try
+ // the fully prefixed name, and then the non-prefixed name. But
+ // there might be intermediate project in the import stack,
+ // which prefix should be tested before testing the non-prefix
+ // root name.
+
+ extPoint = (Target) projectTargets.get(prefixAndSep + extPointName);
+ if (extPoint == null) {
+ extPoint = (Target) projectTargets.get(extPointName);
+ }
+ }
+
+ // make sure we found a point to extend on
+ if (extPoint == null) {
+ String message = "can't add target " + targetName
+ + " to extension-point " + extPointName
+ " because the extension-point is unknown.";
if (missingBehaviour == OnMissingExtensionPoint.FAIL) {
throw new BuildException(message);
} else if (missingBehaviour == OnMissingExtensionPoint.WARN) {
- Target target = (Target) projectTargets.get(name);
- project.log(target, "Warning: " + message, Project.MSG_WARN);
+ Target t = (Target) projectTargets.get(targetName);
+ project.log(t, "Warning: " + message, Project.MSG_WARN);
}
} else {
- Target t = (Target) projectTargets.get(tgName);
- if (!(t instanceof ExtensionPoint)) {
- throw new BuildException("referenced target " + tgName
+ if (!(extPoint instanceof ExtensionPoint)) {
+ throw new BuildException("referenced target " + extPointName
+ " is not an extension-point");
}
- t.addDependency(name);
+ extPoint.addDependency(targetName);
}
}
}
diff --git a/src/main/org/apache/tools/ant/helper/ProjectHelper2.java b/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
index b6dd419f7..07d3e1679 100644
--- a/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
+++ b/src/main/org/apache/tools/ant/helper/ProjectHelper2.java
@@ -1011,17 +1011,24 @@ public class ProjectHelper2 extends ProjectHelper {
ProjectHelper helper =
(ProjectHelper) context.getProject().
getReference(ProjectHelper.PROJECTHELPER_REFERENCE);
- for (String tgName : Target.parseDepends(extensionPoint, name, "extensionOf")) {
- if (isInIncludeMode()) {
- tgName = prefix + sep + tgName;
- }
+ for (String extPointName : Target.parseDepends(extensionPoint, name, "extensionOf")) {
if (extensionPointMissing == null) {
extensionPointMissing = OnMissingExtensionPoint.FAIL;
}
// defer extensionpoint resolution until the full
// import stack has been processed
- helper.getExtensionStack().add(new String[] {
- tgName, name, extensionPointMissing.name() });
+ if (isInIncludeMode()) {
+ // if in include mode, provide prefix we're including by
+ // so that we can try and resolve extension point from
+ // the local file first
+ helper.getExtensionStack().add(
+ new String[] {extPointName, target.getName(),
+ extensionPointMissing.name(), prefix + sep});
+ } else {
+ helper.getExtensionStack().add(
+ new String[] {extPointName, target.getName(),
+ extensionPointMissing.name()});
+ }
}
}
}
diff --git a/src/tests/antunit/core/extension/include-test.xml b/src/tests/antunit/core/extension/include-test.xml
new file mode 100644
index 000000000..4d3b67483
--- /dev/null
+++ b/src/tests/antunit/core/extension/include-test.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/tests/antunit/core/extension/module1.xml b/src/tests/antunit/core/extension/module1.xml
new file mode 100644
index 000000000..3b6312f6b
--- /dev/null
+++ b/src/tests/antunit/core/extension/module1.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+