From 662f68f096613b90eb1448be53d907453492287f Mon Sep 17 00:00:00 2001 From: Conor MacNeill Date: Tue, 1 Apr 2003 14:59:58 +0000 Subject: [PATCH] Change reporting of problems creating elements within Task containers to say that the container does not support the given nested element. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274365 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tools/ant/IntrospectionHelper.java | 11 +++++++--- .../org/apache/tools/ant/UnknownElement.java | 22 ++++++------------- .../tools/ant/helper/ProjectHelper2.java | 5 ----- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/main/org/apache/tools/ant/IntrospectionHelper.java b/src/main/org/apache/tools/ant/IntrospectionHelper.java index 1d1e0f7f9..aab1d4f1c 100644 --- a/src/main/org/apache/tools/ant/IntrospectionHelper.java +++ b/src/main/org/apache/tools/ant/IntrospectionHelper.java @@ -503,6 +503,13 @@ public class IntrospectionHelper implements BuildListener { } } + public void throwNotSupported(Project project, Object parent, + String elementName) { + String msg = project.getElementName(parent) + + " doesn't support the nested \"" + elementName + "\" element."; + throw new BuildException(msg); + } + /** * Creates a named nested element. Depending on the results of the * initial introspection, either a method in the given parent instance @@ -538,9 +545,7 @@ public class IntrospectionHelper implements BuildListener { } } if (nc == null) { - String msg = project.getElementName(parent) + - " doesn't support the nested \"" + elementName + "\" element."; - throw new BuildException(msg); + throwNotSupported(project, parent, elementName); } try { Object nestedElement = nc.create(parent); diff --git a/src/main/org/apache/tools/ant/UnknownElement.java b/src/main/org/apache/tools/ant/UnknownElement.java index 996d622a0..947af5dd4 100644 --- a/src/main/org/apache/tools/ant/UnknownElement.java +++ b/src/main/org/apache/tools/ant/UnknownElement.java @@ -271,10 +271,10 @@ public class UnknownElement extends Task { if (!ih.supportsNestedElement(child.getTag()) && parent instanceof TaskContainer) { - realChild = makeTask(child, childWrapper, false); + realChild = makeTask(child, childWrapper); if (realChild == null) { - throw getNotFoundException("task", child.getTag()); + ih.throwNotSupported(getProject(), parent, child.getTag()); } // XXX DataTypes will be wrapped or treated like normal components @@ -286,7 +286,8 @@ public class UnknownElement extends Task { task.setOwningTarget(this.getOwningTarget()); task.init(); } else { - // What ? Add data type ? createElement ? + // should not happen + ih.throwNotSupported(getProject(), parent, child.getTag()); } } else { realChild @@ -318,7 +319,7 @@ public class UnknownElement extends Task { * @return the task or data type represented by the given unknown element. */ protected Object makeObject(UnknownElement ue, RuntimeConfigurable w) { - Object o = makeTask(ue, w, true); + Object o = makeTask(ue, w); if (o == null) { o = getProject().createDataType(ue.getTag()); } @@ -334,21 +335,12 @@ public class UnknownElement extends Task { * @param ue The UnknownElement to create the real task for. * Must not be null. * @param w Ignored. - * @param onTopLevel Whether or not this is definitely trying to create - * a task. If this is true and the - * task name is not recognised, a BuildException - * is thrown. * * @return the task specified by the given unknown element, or - * null if the task name is not recognised and - * onTopLevel is false. + * null if the task name is not recognised. */ - protected Task makeTask(UnknownElement ue, RuntimeConfigurable w, - boolean onTopLevel) { + protected Task makeTask(UnknownElement ue, RuntimeConfigurable w) { Task task = getProject().createTask(ue.getTag()); - if (task == null && !onTopLevel) { - throw getNotFoundException("task", ue.getTag()); - } if (task != null) { task.setLocation(getLocation()); diff --git a/src/main/org/apache/tools/ant/helper/ProjectHelper2.java b/src/main/org/apache/tools/ant/helper/ProjectHelper2.java index f0ec018f8..50fbd1205 100644 --- a/src/main/org/apache/tools/ant/helper/ProjectHelper2.java +++ b/src/main/org/apache/tools/ant/helper/ProjectHelper2.java @@ -846,11 +846,6 @@ public class ProjectHelper2 extends ProjectHelper { Attributes attrs, AntXMLContext context) throws SAXParseException { - // this element - RuntimeConfigurable wrapper = context.currentWrapper(); - - Object element = wrapper.getProxy(); -// return ProjectHelper2.nestedElementHandler; return ProjectHelper2.elementHandler; }