Browse Source

BR 53549

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-ffa450edef68
master
Nicolas Lalevee 13 years ago
parent
commit
d377aa50f3
3 changed files with 53 additions and 28 deletions
  1. +5
    -0
      WHATSNEW
  2. +47
    -0
      src/main/org/apache/tools/ant/ProjectHelper.java
  3. +1
    -28
      src/main/org/apache/tools/ant/helper/ProjectHelper2.java

+ 5
- 0
WHATSNEW View File

@@ -83,6 +83,11 @@ Other changes:
it is more portable. For backwards compatibility reasons "warn"
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
===================================



+ 47
- 0
src/main/org/apache/tools/ant/ProjectHelper.java View File

@@ -606,4 +606,51 @@ public class ProjectHelper {
public String getDefaultBuildFile() {
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);
}
}
}
}

+ 1
- 28
src/main/org/apache/tools/ant/helper/ProjectHelper2.java View File

@@ -180,34 +180,7 @@ public class ProjectHelper2 extends ProjectHelper {
context.getImplicitTarget().execute();

// 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);
}
}



Loading…
Cancel
Save