git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1035335 13f79535-47bb-0310-9956-ffa450edef68remotes/1773166218076623039/tmp_3691c213c5bbfaee5289ab833167a7f4ed946eb6
| @@ -83,21 +83,57 @@ public class ProjectHelper { | |||
| } | |||
| /** | |||
| * Possible value for target's onMissingExtensionPoint attribute: | |||
| * fail if the extension-point is not defined. | |||
| */ | |||
| public static final String MISSING_EP_FAIL = "fail"; | |||
| /** | |||
| * Possible value for target's onMissingExtensionPoint attribute: | |||
| * warn if the extension-point is not defined. | |||
| */ | |||
| public static final String MISSING_EP_WARN = "warn"; | |||
| /** | |||
| * Possible value for target's onMissingExtensionPoint attribute: | |||
| * ignore the extensionOf attribute if the extension-point is not | |||
| * defined. | |||
| * Possible value for target's onMissingExtensionPoint attribute. It determines how to deal with | |||
| * targets that want to extend missing extension-points. | |||
| * <p> | |||
| * This class behaves like a Java 1.5 Enum class. | |||
| * | |||
| * @since 1.8.2 | |||
| */ | |||
| public static final String MISSING_EP_IGNORE = "ignore"; | |||
| public final static class OnMissingExtensionPoint { | |||
| /** fail if the extension-point is not defined */ | |||
| public static final OnMissingExtensionPoint FAIL = new OnMissingExtensionPoint( | |||
| "fail"); | |||
| /** warn if the extension-point is not defined */ | |||
| public static final OnMissingExtensionPoint WARN = new OnMissingExtensionPoint( | |||
| "warn"); | |||
| /** ignore the extensionOf attribute if the extension-point is not defined */ | |||
| public static final OnMissingExtensionPoint IGNORE = new OnMissingExtensionPoint( | |||
| "ignore"); | |||
| private static final OnMissingExtensionPoint[] values = new OnMissingExtensionPoint[] { | |||
| FAIL, WARN, IGNORE }; | |||
| private final String name; | |||
| private OnMissingExtensionPoint(String name) { | |||
| this.name = name; | |||
| } | |||
| public String name() { | |||
| return name; | |||
| } | |||
| public String toString() { | |||
| return name; | |||
| } | |||
| public static OnMissingExtensionPoint valueOf(String name) { | |||
| if (name == null) { | |||
| throw new NullPointerException(); | |||
| } | |||
| for (int i = 0; i < values.length; i++) { | |||
| if (name.equals(values[i].name())) { | |||
| return values[i]; | |||
| } | |||
| } | |||
| throw new IllegalArgumentException( | |||
| "Unknown onMissingExtensionPoint " + name); | |||
| } | |||
| } | |||
| /** Default constructor */ | |||
| public ProjectHelper() { | |||
| @@ -127,9 +163,8 @@ public class ProjectHelper { | |||
| * | |||
| * @return a list of three element string arrays where the first | |||
| * element is the name of the extensionpoint, the second the name | |||
| * of the target and the third one of the MISSINS_EP constants | |||
| * defined inside this class - it determines how to deal with | |||
| * targets that want to extend missing extension-points. | |||
| * of the target and the third the name of the enum like class | |||
| * {@link OnMissingExtensionPoint}. | |||
| */ | |||
| public List getExtensionStack() { | |||
| return extensionStack; | |||
| @@ -184,15 +184,16 @@ public class ProjectHelper2 extends ProjectHelper { | |||
| String[] extensionInfo = (String[]) i.next(); | |||
| String tgName = extensionInfo[0]; | |||
| String name = extensionInfo[1]; | |||
| String missingBehaviour = extensionInfo[2]; | |||
| 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.equals(MISSING_EP_FAIL)) { | |||
| if (missingBehaviour == OnMissingExtensionPoint.FAIL) { | |||
| throw new BuildException(message); | |||
| } else if (missingBehaviour.equals(MISSING_EP_WARN)) { | |||
| } else if (missingBehaviour == OnMissingExtensionPoint.WARN) { | |||
| Target target = (Target) projectTargets.get(name); | |||
| context.getProject().log(target, | |||
| "Warning: " + message, | |||
| @@ -914,7 +915,7 @@ public class ProjectHelper2 extends ProjectHelper { | |||
| String name = null; | |||
| String depends = ""; | |||
| String extensionPoint = null; | |||
| String extensionPointMissing = null; | |||
| OnMissingExtensionPoint extensionPointMissing = null; | |||
| Project project = context.getProject(); | |||
| Target target = "target".equals(tag) | |||
| @@ -951,7 +952,11 @@ public class ProjectHelper2 extends ProjectHelper { | |||
| } else if (key.equals("extensionOf")) { | |||
| extensionPoint = value; | |||
| } else if (key.equals("onMissingExtensionPoint")) { | |||
| extensionPointMissing = value; | |||
| try { | |||
| extensionPointMissing = OnMissingExtensionPoint.valueOf(value); | |||
| } catch (IllegalArgumentException e) { | |||
| throw new BuildException("Invalid onMissingExtensionPoint " + value); | |||
| } | |||
| } else { | |||
| throw new SAXParseException("Unexpected attribute \"" + key + "\"", context | |||
| .getLocator()); | |||
| @@ -1039,25 +1044,12 @@ public class ProjectHelper2 extends ProjectHelper { | |||
| tgName = prefix + sep + tgName; | |||
| } | |||
| if (extensionPointMissing == null) { | |||
| extensionPointMissing = MISSING_EP_FAIL; | |||
| } | |||
| if (extensionPointMissing.equals(MISSING_EP_FAIL) || | |||
| extensionPointMissing.equals(MISSING_EP_IGNORE) || | |||
| extensionPointMissing.equals(MISSING_EP_WARN)) { | |||
| // defer extensionpoint resolution until the full | |||
| // import stack has been processed | |||
| helper.getExtensionStack().add(new String[] { | |||
| tgName, name, extensionPointMissing | |||
| }); | |||
| } else { | |||
| throw new BuildException("onMissingExtensionPoint" | |||
| + " attribute can only be '" | |||
| + MISSING_EP_FAIL | |||
| + "', '" + MISSING_EP_WARN | |||
| + "' or '" + MISSING_EP_IGNORE | |||
| + "'", | |||
| target.getLocation()); | |||
| extensionPointMissing = OnMissingExtensionPoint.FAIL; | |||
| } | |||
| // defer extensionpoint resolution until the full | |||
| // import stack has been processed | |||
| helper.getExtensionStack().add(new String[] { | |||
| tgName, name, extensionPointMissing.name() }); | |||
| } | |||
| } | |||
| } | |||
| @@ -23,6 +23,7 @@ import java.util.List; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.ProjectHelper; | |||
| import org.apache.tools.ant.ProjectHelper.OnMissingExtensionPoint; | |||
| import org.apache.tools.ant.Task; | |||
| /** | |||
| @@ -34,13 +35,21 @@ public class BindTargets extends Task { | |||
| private List/* <String> */targets = new ArrayList(); | |||
| private String onMissingExtensionPoint; | |||
| private OnMissingExtensionPoint onMissingExtensionPoint; | |||
| public void setExtensionPoint(String extensionPoint) { | |||
| this.extensionPoint = extensionPoint; | |||
| } | |||
| public void setOnMissingExtensionPoint(String onMissingExtensionPoint) { | |||
| try { | |||
| this.onMissingExtensionPoint = OnMissingExtensionPoint.valueOf(onMissingExtensionPoint); | |||
| } catch (IllegalArgumentException e) { | |||
| throw new BuildException("Invalid onMissingExtensionPoint: " + onMissingExtensionPoint); | |||
| } | |||
| } | |||
| public void setOnMissingExtensionPoint(OnMissingExtensionPoint onMissingExtensionPoint) { | |||
| this.onMissingExtensionPoint = onMissingExtensionPoint; | |||
| } | |||
| @@ -66,18 +75,7 @@ public class BindTargets extends Task { | |||
| } | |||
| if (onMissingExtensionPoint == null) { | |||
| onMissingExtensionPoint = ProjectHelper.MISSING_EP_FAIL; | |||
| } | |||
| if (!onMissingExtensionPoint.equals(ProjectHelper.MISSING_EP_FAIL) | |||
| && !onMissingExtensionPoint | |||
| .equals(ProjectHelper.MISSING_EP_IGNORE) | |||
| && !onMissingExtensionPoint | |||
| .equals(ProjectHelper.MISSING_EP_WARN)) { | |||
| throw new BuildException("onMissingExtensionPoint" | |||
| + " attribute can only be '" | |||
| + ProjectHelper.MISSING_EP_FAIL + "', '" | |||
| + ProjectHelper.MISSING_EP_WARN + "' or '" | |||
| + ProjectHelper.MISSING_EP_IGNORE + "'", getLocation()); | |||
| onMissingExtensionPoint = OnMissingExtensionPoint.FAIL; | |||
| } | |||
| ProjectHelper helper = (ProjectHelper) getProject().getReference( | |||
| ProjectHelper.PROJECTHELPER_REFERENCE); | |||
| @@ -86,7 +84,7 @@ public class BindTargets extends Task { | |||
| while (itTarget.hasNext()) { | |||
| helper.getExtensionStack().add( | |||
| new String[] { extensionPoint, (String) itTarget.next(), | |||
| onMissingExtensionPoint }); | |||
| onMissingExtensionPoint.name() }); | |||
| } | |||
| } | |||