You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by gl...@apache.org on 2001/07/04 21:02:47 UTC
cvs commit: jakarta-ant/src/main/org/apache/tools/ant IntrospectionHelper.java ProjectHelper.java RuntimeConfigurable.java UnknownElement.java
glennm 01/07/04 12:02:47
Modified: src/main/org/apache/tools/ant IntrospectionHelper.java
ProjectHelper.java RuntimeConfigurable.java
UnknownElement.java
Log:
Provide more descriptive error messages whenunknown attributes and elements are encountered in the build file.Bugzilla: 1722
Revision Changes Path
1.15 +44 -10 jakarta-ant/src/main/org/apache/tools/ant/IntrospectionHelper.java
Index: IntrospectionHelper.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/IntrospectionHelper.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- IntrospectionHelper.java 2001/05/23 16:57:12 1.14
+++ IntrospectionHelper.java 2001/07/04 19:02:43 1.15
@@ -219,8 +219,9 @@
throws BuildException {
AttributeSetter as = (AttributeSetter) attributeSetters.get(attributeName);
if (as == null) {
- String msg = "Class " + element.getClass().getName() +
- " doesn't support the \"" + attributeName + "\" attribute";
+ String msg = getElementName(p, element) +
+ //String msg = "Class " + element.getClass().getName() +
+ " doesn't support the \"" + attributeName + "\" attribute.";
throw new BuildException(msg);
}
try {
@@ -240,10 +241,11 @@
/**
* Adds PCDATA areas.
*/
- public void addText(Object element, String text) {
+ public void addText(Project project, Object element, String text) {
if (addText == null) {
- String msg = "Class " + element.getClass().getName() +
- " doesn't support nested text elements";
+ String msg = getElementName(project, element) +
+ //String msg = "Class " + element.getClass().getName() +
+ " doesn't support nested text data.";
throw new BuildException(msg);
}
try {
@@ -263,12 +265,13 @@
/**
* Creates a named nested element.
*/
- public Object createElement(Object element, String elementName)
+ public Object createElement(Project project, Object element, String elementName)
throws BuildException {
NestedCreator nc = (NestedCreator) nestedCreators.get(elementName);
if (nc == null) {
- String msg = "Class " + element.getClass().getName() +
- " doesn't support the nested \"" + elementName + "\" element";
+ String msg = getElementName(project, element) +
+ //String msg = "Class " + element.getClass().getName() +
+ " doesn't support the nested \"" + elementName + "\" element.";
throw new BuildException(msg);
}
try {
@@ -296,7 +299,7 @@
Class nt = (Class) nestedTypes.get(elementName);
if (nt == null) {
String msg = "Class " + bean.getName() +
- " doesn't support the nested \"" + elementName + "\" element";
+ " doesn't support the nested \"" + elementName + "\" element.";
throw new BuildException(msg);
}
return nt;
@@ -310,7 +313,7 @@
Class at = (Class) attributeTypes.get(attributeName);
if (at == null) {
String msg = "Class " + bean.getName() +
- " doesn't support the \"" + attributeName + "\" attribute";
+ " doesn't support the \"" + attributeName + "\" attribute.";
throw new BuildException(msg);
}
return at;
@@ -498,6 +501,37 @@
}
return null;
+ }
+
+ protected String getElementName(Project project, Object element)
+ {
+ Hashtable elements = project.getTaskDefinitions();
+ String typeName = "task";
+ if (!elements.contains( element.getClass() ))
+ {
+ elements = project.getDataTypeDefinitions();
+ typeName = "data type";
+ if (!elements.contains( element.getClass() ))
+ {
+ elements = null;
+ }
+ }
+
+ if (elements != null)
+ {
+ Enumeration e = elements.keys();
+ while (e.hasMoreElements())
+ {
+ String elementName = (String) e.nextElement();
+ Class elementClass = (Class) elements.get( elementName );
+ if ( element.getClass().equals( elementClass ) )
+ {
+ return "The <" + elementName + "> " + typeName;
+ }
+ }
+ }
+
+ return "Class " + element.getClass().getName();
}
/**
1.52 +8 -8 jakarta-ant/src/main/org/apache/tools/ant/ProjectHelper.java
Index: ProjectHelper.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/ProjectHelper.java,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- ProjectHelper.java 2001/06/08 10:11:27 1.51
+++ ProjectHelper.java 2001/07/04 19:02:44 1.52
@@ -490,7 +490,7 @@
public void characters(char[] buf, int start, int end) throws SAXParseException {
if (wrapper == null) {
try {
- addText(task, buf, start, end);
+ addText(project, task, buf, start, end);
} catch (BuildException exc) {
throw new SAXParseException(exc.getMessage(), locator, exc);
}
@@ -536,7 +536,7 @@
child = new UnknownElement(propType.toLowerCase());
((UnknownElement) target).addChild((UnknownElement) child);
} else {
- child = ih.createElement(target, propType.toLowerCase());
+ child = ih.createElement(project, target, propType.toLowerCase());
}
configureId(child, attrs);
@@ -556,7 +556,7 @@
public void characters(char[] buf, int start, int end) throws SAXParseException {
if (parentWrapper == null) {
try {
- addText(child, buf, start, end);
+ addText(project, child, buf, start, end);
} catch (BuildException exc) {
throw new SAXParseException(exc.getMessage(), locator, exc);
}
@@ -609,7 +609,7 @@
public void characters(char[] buf, int start, int end) throws SAXParseException {
try {
- addText(element, buf, start, end);
+ addText(project, element, buf, start, end);
} catch (BuildException exc) {
throw new SAXParseException(exc.getMessage(), locator, exc);
}
@@ -648,15 +648,15 @@
/**
* Adds the content of #PCDATA sections to an element.
*/
- public static void addText(Object target, char[] buf, int start, int end)
+ public static void addText(Project project, Object target, char[] buf, int start, int end)
throws BuildException {
- addText(target, new String(buf, start, end));
+ addText(project, target, new String(buf, start, end));
}
/**
* Adds the content of #PCDATA sections to an element.
*/
- public static void addText(Object target, String text)
+ public static void addText(Project project, Object target, String text)
throws BuildException {
if (text == null || text.trim().length() == 0) {
@@ -666,7 +666,7 @@
if(target instanceof TaskAdapter)
target = ((TaskAdapter) target).getProxy();
- IntrospectionHelper.getHelper(target.getClass()).addText(target, text);
+ IntrospectionHelper.getHelper(target.getClass()).addText(project, target, text);
}
1.6 +1 -1 jakarta-ant/src/main/org/apache/tools/ant/RuntimeConfigurable.java
Index: RuntimeConfigurable.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/RuntimeConfigurable.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- RuntimeConfigurable.java 2001/05/23 16:57:14 1.5
+++ RuntimeConfigurable.java 2001/07/04 19:02:44 1.6
@@ -135,7 +135,7 @@
attributes = null;
}
if (characters.length() != 0) {
- ProjectHelper.addText(wrappedObject, characters.toString());
+ ProjectHelper.addText(p, wrappedObject, characters.toString());
characters.setLength(0);
}
Enumeration enum = children.elements();
1.6 +1 -1 jakarta-ant/src/main/org/apache/tools/ant/UnknownElement.java
Index: UnknownElement.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/UnknownElement.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- UnknownElement.java 2001/05/23 16:57:17 1.5
+++ UnknownElement.java 2001/07/04 19:02:45 1.6
@@ -140,7 +140,7 @@
for (int i=0; i<children.size(); i++) {
UnknownElement child = (UnknownElement) children.elementAt(i);
- Object realChild = ih.createElement(parent, child.getTag());
+ Object realChild = ih.createElement(project, parent, child.getTag());
RuntimeConfigurable childWrapper = parentWrapper.getChild(i);
childWrapper.setProxy(realChild);
child.handleChildren(realChild, childWrapper);