diff --git a/WHATSNEW b/WHATSNEW index aed19fa2f..fcc2739ba 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -23,6 +23,9 @@ Fixed bugs: , , or tasks was always logged to System.out instead of to the managing Task. +* Incorrect task name with invalid "javac" task after a "presetdef. + Bugzilla reports 31389 and 29499. + Other changes: -------------- diff --git a/src/etc/testcases/taskdefs/presetdef.xml b/src/etc/testcases/taskdefs/presetdef.xml index 1cce733b7..64926eef6 100644 --- a/src/etc/testcases/taskdefs/presetdef.xml +++ b/src/etc/testcases/taskdefs/presetdef.xml @@ -100,4 +100,22 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/main/org/apache/tools/ant/IntrospectionHelper.java b/src/main/org/apache/tools/ant/IntrospectionHelper.java index 723d8c1a1..96be1cfbe 100644 --- a/src/main/org/apache/tools/ant/IntrospectionHelper.java +++ b/src/main/org/apache/tools/ant/IntrospectionHelper.java @@ -490,7 +490,7 @@ public final class IntrospectionHelper implements BuildListener { String msg = getElementName(p, element) + " doesn't support the \"" + attributeName + "\" attribute."; - throw new BuildException(msg); + throw new UnsupportedAttributeException(msg, attributeName); } } try { @@ -564,7 +564,7 @@ public final class IntrospectionHelper implements BuildListener { String elementName) { String msg = project.getElementName(parent) + " doesn't support the nested \"" + elementName + "\" element."; - throw new BuildException(msg); + throw new UnsupportedElementException(msg, elementName); } private NestedCreator getNestedCreator( @@ -825,7 +825,7 @@ public final class IntrospectionHelper implements BuildListener { String msg = "Class " + bean.getName() + " doesn't support the nested \"" + elementName + "\" element."; - throw new BuildException(msg); + throw new UnsupportedElementException(msg, elementName); } return nt; } @@ -848,7 +848,7 @@ public final class IntrospectionHelper implements BuildListener { if (at == null) { String msg = "Class " + bean.getName() + " doesn't support the \"" + attributeName + "\" attribute."; - throw new BuildException(msg); + throw new UnsupportedAttributeException(msg, attributeName); } return at; } @@ -892,7 +892,7 @@ public final class IntrospectionHelper implements BuildListener { String msg = "Class " + bean.getName() + " doesn't support the nested \"" + elementName + "\" element."; - throw new BuildException(msg); + throw new UnsupportedElementException(msg, elementName); } return ((NestedCreator) creator).method; } @@ -914,7 +914,7 @@ public final class IntrospectionHelper implements BuildListener { if (setter == null) { String msg = "Class " + bean.getName() + " doesn't support the \"" + attributeName + "\" attribute."; - throw new BuildException(msg); + throw new UnsupportedAttributeException(msg, attributeName); } return ((AttributeSetter) setter).method; } diff --git a/src/main/org/apache/tools/ant/RuntimeConfigurable.java b/src/main/org/apache/tools/ant/RuntimeConfigurable.java index 4bbe0e489..457fcf98b 100644 --- a/src/main/org/apache/tools/ant/RuntimeConfigurable.java +++ b/src/main/org/apache/tools/ant/RuntimeConfigurable.java @@ -364,9 +364,26 @@ public class RuntimeConfigurable implements Serializable { value = p.replaceProperties(value); try { ih.setAttribute(p, target, name, value); - } catch (BuildException be) { + } catch (UnsupportedAttributeException be) { // 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; } } diff --git a/src/main/org/apache/tools/ant/UnknownElement.java b/src/main/org/apache/tools/ant/UnknownElement.java index e6b3713b2..26c0baa4f 100644 --- a/src/main/org/apache/tools/ant/UnknownElement.java +++ b/src/main/org/apache/tools/ant/UnknownElement.java @@ -328,17 +328,25 @@ public class UnknownElement extends Task { for (int i = 0; it.hasNext(); i++) { RuntimeConfigurable childWrapper = parentWrapper.getChild(i); 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 - * + * @param realThing the configured object * @since ant 1.7 */ public void setRealThing(Object realThing) { diff --git a/src/main/org/apache/tools/ant/UnsupportedAttributeException.java b/src/main/org/apache/tools/ant/UnsupportedAttributeException.java new file mode 100644 index 000000000..33442a999 --- /dev/null +++ b/src/main/org/apache/tools/ant/UnsupportedAttributeException.java @@ -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; + } +} diff --git a/src/main/org/apache/tools/ant/UnsupportedElementException.java b/src/main/org/apache/tools/ant/UnsupportedElementException.java new file mode 100644 index 000000000..03161f36c --- /dev/null +++ b/src/main/org/apache/tools/ant/UnsupportedElementException.java @@ -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; + } + } +} diff --git a/src/testcases/org/apache/tools/ant/taskdefs/PreSetDefTest.java b/src/testcases/org/apache/tools/ant/taskdefs/PreSetDefTest.java index 5d1e6be0d..4d161f24b 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/PreSetDefTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/PreSetDefTest.java @@ -70,6 +70,17 @@ public class PreSetDefTest extends BuildFileTest { 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 */