exception thrown by IntrospectionHelper PR: 31389 and 29499 Reported by: Tamas Szeredi and Jesse Glick git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276882 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -23,6 +23,9 @@ Fixed bugs: | |||||
| <exec>, <apply>, or <java> tasks was always logged to System.out | <exec>, <apply>, or <java> tasks was always logged to System.out | ||||
| instead of to the managing Task. | instead of to the managing Task. | ||||
| * Incorrect task name with invalid "javac" task after a "presetdef. | |||||
| Bugzilla reports 31389 and 29499. | |||||
| Other changes: | Other changes: | ||||
| -------------- | -------------- | ||||
| @@ -100,4 +100,22 @@ | |||||
| </el.order2> | </el.order2> | ||||
| </target> | </target> | ||||
| <target name="correct_taskname_badattr"> | |||||
| <presetdef name="mytask"> | |||||
| <javac srcdir="whatever"/> | |||||
| </presetdef> | |||||
| <javac srcdir="whatever" badattr="whatever"/> | |||||
| </target> | |||||
| <target name="correct_taskname_badel"> | |||||
| <presetdef name="mytask"> | |||||
| <javac srcdir="whatever"/> | |||||
| </presetdef> | |||||
| <javac srcdir="whatever"> | |||||
| <badel/> | |||||
| </javac> | |||||
| </target> | |||||
| </project> | </project> | ||||
| @@ -490,7 +490,7 @@ public final class IntrospectionHelper implements BuildListener { | |||||
| String msg = getElementName(p, element) | String msg = getElementName(p, element) | ||||
| + " doesn't support the \"" + attributeName | + " doesn't support the \"" + attributeName | ||||
| + "\" attribute."; | + "\" attribute."; | ||||
| throw new BuildException(msg); | |||||
| throw new UnsupportedAttributeException(msg, attributeName); | |||||
| } | } | ||||
| } | } | ||||
| try { | try { | ||||
| @@ -564,7 +564,7 @@ public final class IntrospectionHelper implements BuildListener { | |||||
| String elementName) { | String elementName) { | ||||
| String msg = project.getElementName(parent) | String msg = project.getElementName(parent) | ||||
| + " doesn't support the nested \"" + elementName + "\" element."; | + " doesn't support the nested \"" + elementName + "\" element."; | ||||
| throw new BuildException(msg); | |||||
| throw new UnsupportedElementException(msg, elementName); | |||||
| } | } | ||||
| private NestedCreator getNestedCreator( | private NestedCreator getNestedCreator( | ||||
| @@ -825,7 +825,7 @@ public final class IntrospectionHelper implements BuildListener { | |||||
| String msg = "Class " + bean.getName() | String msg = "Class " + bean.getName() | ||||
| + " doesn't support the nested \"" + elementName | + " doesn't support the nested \"" + elementName | ||||
| + "\" element."; | + "\" element."; | ||||
| throw new BuildException(msg); | |||||
| throw new UnsupportedElementException(msg, elementName); | |||||
| } | } | ||||
| return nt; | return nt; | ||||
| } | } | ||||
| @@ -848,7 +848,7 @@ public final class IntrospectionHelper implements BuildListener { | |||||
| if (at == null) { | if (at == null) { | ||||
| String msg = "Class " + bean.getName() | String msg = "Class " + bean.getName() | ||||
| + " doesn't support the \"" + attributeName + "\" attribute."; | + " doesn't support the \"" + attributeName + "\" attribute."; | ||||
| throw new BuildException(msg); | |||||
| throw new UnsupportedAttributeException(msg, attributeName); | |||||
| } | } | ||||
| return at; | return at; | ||||
| } | } | ||||
| @@ -892,7 +892,7 @@ public final class IntrospectionHelper implements BuildListener { | |||||
| String msg = "Class " + bean.getName() | String msg = "Class " + bean.getName() | ||||
| + " doesn't support the nested \"" + elementName | + " doesn't support the nested \"" + elementName | ||||
| + "\" element."; | + "\" element."; | ||||
| throw new BuildException(msg); | |||||
| throw new UnsupportedElementException(msg, elementName); | |||||
| } | } | ||||
| return ((NestedCreator) creator).method; | return ((NestedCreator) creator).method; | ||||
| } | } | ||||
| @@ -914,7 +914,7 @@ public final class IntrospectionHelper implements BuildListener { | |||||
| if (setter == null) { | if (setter == null) { | ||||
| String msg = "Class " + bean.getName() | String msg = "Class " + bean.getName() | ||||
| + " doesn't support the \"" + attributeName + "\" attribute."; | + " doesn't support the \"" + attributeName + "\" attribute."; | ||||
| throw new BuildException(msg); | |||||
| throw new UnsupportedAttributeException(msg, attributeName); | |||||
| } | } | ||||
| return ((AttributeSetter) setter).method; | return ((AttributeSetter) setter).method; | ||||
| } | } | ||||
| @@ -364,9 +364,26 @@ public class RuntimeConfigurable implements Serializable { | |||||
| value = p.replaceProperties(value); | value = p.replaceProperties(value); | ||||
| try { | try { | ||||
| ih.setAttribute(p, target, name, value); | ih.setAttribute(p, target, name, value); | ||||
| } catch (BuildException be) { | |||||
| } catch (UnsupportedAttributeException be) { | |||||
| // id attribute must be set externally | // id attribute must be set externally | ||||
| if (!name.equals("id")) { | |||||
| if (name.equals("id")) { | |||||
| // Do nothing | |||||
| } else if (getElementTag() == null) { | |||||
| throw be; | |||||
| } else { | |||||
| be.setMessage( | |||||
| getElementTag() | |||||
| + " doesn't support the \"" | |||||
| + be.getAttribute() | |||||
| + "\" attribute"); | |||||
| throw be; | |||||
| } | |||||
| } catch (BuildException be) { | |||||
| if (name.equals("id")) { | |||||
| // Assume that this is an not supported attribute type | |||||
| // thrown for example by a dymanic attribute task | |||||
| // Do nothing | |||||
| } else { | |||||
| throw be; | throw be; | ||||
| } | } | ||||
| } | } | ||||
| @@ -328,17 +328,25 @@ public class UnknownElement extends Task { | |||||
| for (int i = 0; it.hasNext(); i++) { | for (int i = 0; it.hasNext(); i++) { | ||||
| RuntimeConfigurable childWrapper = parentWrapper.getChild(i); | RuntimeConfigurable childWrapper = parentWrapper.getChild(i); | ||||
| UnknownElement child = (UnknownElement) it.next(); | UnknownElement child = (UnknownElement) it.next(); | ||||
| if (!handleChild( | |||||
| parentUri, ih, parent, child, childWrapper)) { | |||||
| 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); | |||||
| try { | |||||
| if (!handleChild( | |||||
| parentUri, ih, parent, child, childWrapper)) { | |||||
| 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); | |||||
| } | |||||
| } | } | ||||
| } catch (UnsupportedElementException ex) { | |||||
| ex.setMessage( | |||||
| parentWrapper.getElementTag() | |||||
| + " doesn't support the nested \"" + ex.getElement() | |||||
| + "\" element."); | |||||
| throw ex; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -530,7 +538,7 @@ public class UnknownElement extends Task { | |||||
| /** | /** | ||||
| * Set the configured object | * Set the configured object | ||||
| * | |||||
| * @param realThing the configured object | |||||
| * @since ant 1.7 | * @since ant 1.7 | ||||
| */ | */ | ||||
| public void setRealThing(Object realThing) { | public void setRealThing(Object realThing) { | ||||
| @@ -0,0 +1,64 @@ | |||||
| /* | |||||
| * Copyright 2004 The Apache Software Foundation | |||||
| * | |||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||||
| * you may not use this file except in compliance with the License. | |||||
| * You may obtain a copy of the License at | |||||
| * | |||||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||||
| * | |||||
| * Unless required by applicable law or agreed to in writing, software | |||||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
| * See the License for the specific language governing permissions and | |||||
| * limitations under the License. | |||||
| * | |||||
| */ | |||||
| package org.apache.tools.ant; | |||||
| /** | |||||
| * Used to report attempts to set an unsupported attribute | |||||
| * | |||||
| * @since Ant 1.7 | |||||
| */ | |||||
| public class UnsupportedAttributeException extends BuildException { | |||||
| private String myMessage; | |||||
| private String attribute; | |||||
| /** | |||||
| * Constructs an unsupport attribute exception | |||||
| * @param msg The string containing the message | |||||
| * @param attribute The unsupported attribute | |||||
| */ | |||||
| public UnsupportedAttributeException(String msg, String attribute) { | |||||
| super(msg); | |||||
| this.attribute = attribute; | |||||
| this.myMessage = msg; | |||||
| } | |||||
| /** | |||||
| * The attribute that is wrong | |||||
| * | |||||
| * @return the attribute name | |||||
| */ | |||||
| public String getAttribute() { | |||||
| return attribute; | |||||
| } | |||||
| /** | |||||
| * Override throwable#getMessage | |||||
| * @return the message | |||||
| */ | |||||
| public String getMessage() { | |||||
| return myMessage; | |||||
| } | |||||
| /** | |||||
| * Set the message | |||||
| * @param message a new message | |||||
| */ | |||||
| public void setMessage(String message) { | |||||
| this.myMessage = message; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,78 @@ | |||||
| /* | |||||
| * Copyright 2004 The Apache Software Foundation | |||||
| * | |||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||||
| * you may not use this file except in compliance with the License. | |||||
| * You may obtain a copy of the License at | |||||
| * | |||||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||||
| * | |||||
| * Unless required by applicable law or agreed to in writing, software | |||||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
| * See the License for the specific language governing permissions and | |||||
| * limitations under the License. | |||||
| * | |||||
| */ | |||||
| package org.apache.tools.ant; | |||||
| /** | |||||
| * Used to report attempts to set an unsupported element | |||||
| * When the attempt to set the element is made, | |||||
| * the code does not not know the name of the task/type | |||||
| * based on a mapping from the classname to the task/type. | |||||
| * However one class may be used by a lot of task/types. | |||||
| * This exception may be caught by code that does know | |||||
| * the task/type and it will reset the message to the | |||||
| * correct message. | |||||
| * This will be done once (in the case of a recursive | |||||
| * call to handlechildren). | |||||
| * | |||||
| * @since Ant 1.6.3 or Ant 1.7 ? | |||||
| */ | |||||
| public class UnsupportedElementException extends BuildException { | |||||
| private String myMessage = null; | |||||
| private String element; | |||||
| /** | |||||
| * Constructs an unsupport element exception | |||||
| * @param msg The string containing the message | |||||
| * @param element The name of the incorrect element | |||||
| */ | |||||
| public UnsupportedElementException(String msg, String element) { | |||||
| super(msg); | |||||
| this.element = element; | |||||
| } | |||||
| /** | |||||
| * The element that is wrong | |||||
| * | |||||
| * @return the element name | |||||
| */ | |||||
| public String getElement() { | |||||
| return element; | |||||
| } | |||||
| /** | |||||
| * Override throwable#getMessage | |||||
| * @return the message | |||||
| */ | |||||
| public String getMessage() { | |||||
| if (myMessage == null) { | |||||
| return super.getMessage(); | |||||
| } else { | |||||
| return myMessage; | |||||
| } | |||||
| } | |||||
| /** | |||||
| * Set the message (If not set already) | |||||
| * @param message a new message | |||||
| */ | |||||
| public void setMessage(String message) { | |||||
| if (this.myMessage == null) { | |||||
| this.myMessage = message; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -70,6 +70,17 @@ public class PreSetDefTest extends BuildFileTest { | |||||
| expectLog("antTypeTest", ""); | expectLog("antTypeTest", ""); | ||||
| } | } | ||||
| public void testCorrectTaskNameBadAttr() { | |||||
| expectBuildExceptionContaining( | |||||
| "correct_taskname_badattr", "attribute message", "javac doesn't support the"); | |||||
| } | |||||
| public void testCorrectTaskNameBadEl() { | |||||
| expectBuildExceptionContaining( | |||||
| "correct_taskname_badel", "element message", "javac doesn't support the"); | |||||
| } | |||||
| /** | /** | ||||
| * A test class to check default properties | * A test class to check default properties | ||||
| */ | */ | ||||