Make the ProjectHelper class expose the method which properly bind targets and extension points. Thanks to Jean-Louis Boudart git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1373321 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -83,6 +83,11 @@ Other changes: | |||||
| it is more portable. For backwards compatibility reasons "warn" | it is more portable. For backwards compatibility reasons "warn" | ||||
| will still create "gnu" extensions rather than "posix" extensions. | will still create "gnu" extensions rather than "posix" extensions. | ||||
| * The ProjectHelper class now exposes a method to be used by third party | |||||
| implementations to properly resolve the binding between target extensions | |||||
| and extension points. | |||||
| Bugzilla Report 53549. | |||||
| Changes from Ant 1.8.3 TO Ant 1.8.4 | Changes from Ant 1.8.3 TO Ant 1.8.4 | ||||
| =================================== | =================================== | ||||
| @@ -606,4 +606,51 @@ public class ProjectHelper { | |||||
| public String getDefaultBuildFile() { | public String getDefaultBuildFile() { | ||||
| return Main.DEFAULT_BUILD_FILENAME; | return Main.DEFAULT_BUILD_FILENAME; | ||||
| } | } | ||||
| /** | |||||
| * Check extensionStack and inject all targets having extensionOf attributes | |||||
| * into extensionPoint. | |||||
| * <p> | |||||
| * This method allow you to defer injection and have a powerful control of | |||||
| * extensionPoint wiring. | |||||
| * </p> | |||||
| * <p> | |||||
| * This should be invoked by each concrete implementation of ProjectHelper | |||||
| * when the root "buildfile" and all imported/included buildfile are loaded. | |||||
| * </p> | |||||
| * | |||||
| * @param project The project containing the target. Must not be | |||||
| * <code>null</code>. | |||||
| * @exception BuildException if OnMissingExtensionPoint.FAIL and | |||||
| * extensionPoint does not exist | |||||
| * @see OnMissingExtensionPoint | |||||
| * @since 1.9 | |||||
| */ | |||||
| public void resolveExtensionOfAttributes(Project project) | |||||
| throws BuildException { | |||||
| for (String[] extensionInfo : getExtensionStack()) { | |||||
| String tgName = extensionInfo[0]; | |||||
| String name = extensionInfo[1]; | |||||
| OnMissingExtensionPoint missingBehaviour = OnMissingExtensionPoint.valueOf(extensionInfo[2]); | |||||
| Hashtable projectTargets = project.getTargets(); | |||||
| if (!projectTargets.containsKey(tgName)) { | |||||
| String message = "can't add target " + name | |||||
| + " to extension-point " + tgName | |||||
| + " 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); | |||||
| } | |||||
| } else { | |||||
| Target t = (Target) projectTargets.get(tgName); | |||||
| if (!(t instanceof ExtensionPoint)) { | |||||
| throw new BuildException("referenced target " + tgName | |||||
| + " is not an extension-point"); | |||||
| } | |||||
| t.addDependency(name); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -180,34 +180,7 @@ public class ProjectHelper2 extends ProjectHelper { | |||||
| context.getImplicitTarget().execute(); | context.getImplicitTarget().execute(); | ||||
| // resolve extensionOf attributes | // resolve extensionOf attributes | ||||
| for (String[] extensionInfo : getExtensionStack()) { | |||||
| String tgName = extensionInfo[0]; | |||||
| String name = extensionInfo[1]; | |||||
| OnMissingExtensionPoint missingBehaviour = OnMissingExtensionPoint | |||||
| .valueOf(extensionInfo[2]); | |||||
| Hashtable projectTargets = project.getTargets(); | |||||
| if (!projectTargets.containsKey(tgName)) { | |||||
| String message = "can't add target " + name | |||||
| + " to extension-point " + tgName | |||||
| + " 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); | |||||
| context.getProject().log(target, | |||||
| "Warning: " + message, | |||||
| Project.MSG_WARN); | |||||
| } | |||||
| } else { | |||||
| Target t = (Target) projectTargets.get(tgName); | |||||
| if (!(t instanceof ExtensionPoint)) { | |||||
| throw new BuildException("referenced target " | |||||
| + tgName | |||||
| + " is not an extension-point"); | |||||
| } | |||||
| t.addDependency(name); | |||||
| } | |||||
| } | |||||
| resolveExtensionOfAttributes(project); | |||||
| } | } | ||||
| } | } | ||||