bodewig 2003/04/28 05:19:18
Modified: . build.xml src/main/org/apache/tools/ant RuntimeConfigurable.java UnknownElement.java src/main/org/apache/tools/ant/helper ProjectHelper2.java Log: Enable mixed-case task names inside task-containers while trying to keep backwards compatibility for all other cases (all "normal" nested element names get converted to lower case). PR: 19323 Revision Changes Path 1.373 +1 -0 ant/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/ant/build.xml,v retrieving revision 1.372 retrieving revision 1.373 diff -u -r1.372 -r1.373 --- build.xml 25 Apr 2003 14:21:35 -0000 1.372 +++ build.xml 28 Apr 2003 12:19:17 -0000 1.373 @@ -277,6 +277,7 @@ <patternset id="teststhatfail"> <exclude name="${optional.package}/BeanShellScriptTest.java"/> <exclude name="${ant.package}/taskdefs/ImportTest.java"/> + <exclude name="${ant.package}/CaseTest.java"/> </patternset> <!-- 1.32 +22 -9 ant/src/main/org/apache/tools/ant/RuntimeConfigurable.java Index: RuntimeConfigurable.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/RuntimeConfigurable.java,v retrieving revision 1.31 retrieving revision 1.32 diff -u -r1.31 -r1.32 --- RuntimeConfigurable.java 14 Apr 2003 11:58:03 -0000 1.31 +++ RuntimeConfigurable.java 28 Apr 2003 12:19:17 -0000 1.32 @@ -348,16 +348,29 @@ childTask.setRuntimeConfigurableWrapper(child); } - if (configureChildren - && ih.supportsNestedElement(child.getElementTag())) { - child.maybeConfigure(p); - Object container = wrappedObject; - if (container instanceof TaskAdapter) { - container = ((TaskAdapter) container).getProxy(); + if (configureChildren) { + /* + * backwards compatibility - element names of nested + * elements have been all lower-case in Ant, except for + * TaskContainers + */ + + /* XXX + * + * For some reason we don't throw an exception here if + * we find the nested element is unsupported, probably + * because this will happen somewhere else. + */ + String tag = child.getElementTag(); + if (ih.supportsNestedElement(tag.toLowerCase(Locale.US))) { + tag = tag.toLowerCase(Locale.US); + } else if (!ih.supportsNestedElement(tag)) { + continue; } - ProjectHelper.storeChild(p, container, child.wrappedObject, - child.getElementTag() - .toLowerCase(Locale.US)); + + child.maybeConfigure(p); + ProjectHelper.storeChild(p, target, child.wrappedObject, + tag); } } 1.47 +39 -17 ant/src/main/org/apache/tools/ant/UnknownElement.java Index: UnknownElement.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/UnknownElement.java,v retrieving revision 1.46 retrieving revision 1.47 diff -u -r1.46 -r1.47 --- UnknownElement.java 14 Apr 2003 14:47:42 -0000 1.46 +++ UnknownElement.java 28 Apr 2003 12:19:18 -0000 1.47 @@ -54,6 +54,7 @@ package org.apache.tools.ant; +import java.util.Locale; import java.util.Vector; import java.io.IOException; @@ -273,26 +274,20 @@ UnknownElement child = (UnknownElement) children.elementAt(i); Object realChild = null; - if (ih.supportsNestedElement(child.getTag())) { - realChild - = ih.createElement(getProject(), parent, child.getTag()); - childWrapper.setProxy(realChild); - if (realChild instanceof Task) { - Task childTask = (Task) realChild; - childTask.setRuntimeConfigurableWrapper(childWrapper); - childTask.setTaskName(child.getTag()); - childTask.setTaskType(child.getTag()); - } - child.handleChildren(realChild, childWrapper); - + if (handleChild(ih, parent, child, + child.getTag().toLowerCase(Locale.US), + childWrapper)) { } else if (!(parent instanceof TaskContainer)) { ih.throwNotSupported(getProject(), parent, child.getTag()); } else { - // a task container - anything could happen - just add the - // child to the container - TaskContainer container = (TaskContainer) parent; - container.addTask(child); - } + if (!handleChild(ih, parent, child, child.getTag(), + childWrapper)) { + // a task container - anything could happen - just add the + // child to the container + TaskContainer container = (TaskContainer) parent; + container.addTask(child); + } + } } } @@ -413,5 +408,32 @@ } return null; } + + /** + * Try to create a nested element of <code>parent</code> for the + * given tag. + * + * @return whether the creation has been successful + */ + private boolean handleChild(IntrospectionHelper ih, + Object parent, UnknownElement child, + String childTag, + RuntimeConfigurable childWrapper) { + if (ih.supportsNestedElement(childTag)) { + Object realChild + = ih.createElement(getProject(), parent, childTag); + childWrapper.setProxy(realChild); + if (realChild instanceof Task) { + Task childTask = (Task) realChild; + childTask.setRuntimeConfigurableWrapper(childWrapper); + childTask.setTaskName(childTag); + childTask.setTaskType(childTag); + } + child.handleChildren(realChild, childWrapper); + return true; + } + return false; + } + }// UnknownElement 1.18 +0 -17 ant/src/main/org/apache/tools/ant/helper/ProjectHelper2.java Index: ProjectHelper2.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/helper/ProjectHelper2.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- ProjectHelper2.java 6 Apr 2003 09:30:57 -0000 1.17 +++ ProjectHelper2.java 28 Apr 2003 12:19:18 -0000 1.18 @@ -751,23 +751,6 @@ parent = parentWrapper.getProxy(); } - if (parent != null) { - // nested elements. Backward compatibilitiy - only nested elements - // are lower cased in the original processor - qname = qname.toLowerCase(Locale.US); - // XXX What about nested elements that are inside TaskContainers ? - // We can't know that that we need lowercase until we know - // parent is not a TaskContainer. Maybe this test should - // be done in UnknownElement. - - // Note: the original code seems to have a similar problem: the lowercase - // conversion happens only inside ProjectHelper, if we know that the - // parent is not TaskContainer. If the parent is not known - UE are used - // and AFAIK there is no code to deal with that, so the conversion will be - // different based on context ( if the enclosing task is taskdefed in target - // or known at top level ). - } - /* UnknownElement is used for tasks and data types - with delayed eval */ UnknownElement task = new UnknownElement(qname);