From 944210b384ccb4e335ce5a5c3ded7f784fd3e581 Mon Sep 17 00:00:00 2001 From: Nicolas Lalevee Date: Wed, 15 Aug 2012 10:40:16 +0000 Subject: [PATCH] BR 53550, thanks to Tim Pokorny Improve the resolution of the extension point to bind to: - first try the extension point which might be in the same file - then try the one in the root file Still some work to do: there might be intermediate file in the import stack which we would to resolve the name against, but the ProjectHelper doesn't hold the prefix stacking. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1373326 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 3 ++ .../org/apache/tools/ant/ProjectHelper.java | 47 ++++++++++++++----- .../tools/ant/helper/ProjectHelper2.java | 19 +++++--- .../antunit/core/extension/include-test.xml | 34 ++++++++++++++ src/tests/antunit/core/extension/module1.xml | 25 ++++++++++ 5 files changed, 111 insertions(+), 17 deletions(-) create mode 100644 src/tests/antunit/core/extension/include-test.xml create mode 100644 src/tests/antunit/core/extension/module1.xml 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 @@ + + + + + + + + + +