diff --git a/WHATSNEW b/WHATSNEW index 07f6c8a2c..38e258017 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -63,6 +63,10 @@ Other changes: * Allow to refer directly to a FileNameMapper instance. +* If you try and use a type in a namespace (or an antlib), and the type is not + recognized but there are other definitions in that namespace, Ant lists what + the known definitions are. This helps you find spelling errors. + Changes from Ant 1.6.5 to Ant 1.7.0 =================================== diff --git a/src/main/org/apache/tools/ant/ComponentHelper.java b/src/main/org/apache/tools/ant/ComponentHelper.java index 8588c918b..1322d3fa1 100644 --- a/src/main/org/apache/tools/ant/ComponentHelper.java +++ b/src/main/org/apache/tools/ant/ComponentHelper.java @@ -33,6 +33,10 @@ import java.util.Iterator; import java.util.Properties; import java.util.Set; import java.util.Stack; +import java.util.List; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import org.apache.tools.ant.taskdefs.Typedef; import org.apache.tools.ant.taskdefs.Definer; @@ -760,6 +764,8 @@ public class ComponentHelper { /** * Called for each component name, check if the * associated URI has been examined for antlibs. + * @param componentName the name of the component, which should include a URI + * prefix if it is in a namespace */ private synchronized void checkNamespace(String componentName) { String uri = ProjectHelper.extractUriFromComponentName(componentName); @@ -929,21 +935,36 @@ public class ComponentHelper { } /** - * Print unknown definition. + * Print unknown definition.forking */ private void printUnknownDefinition( PrintWriter out, String componentName, String dirListing) { boolean isAntlib = componentName.indexOf(MagicNames.ANTLIB_PREFIX) == 0; + String uri=ProjectHelper.extractUriFromComponentName(componentName); out.println("Cause: The name is undefined."); out.println("Action: Check the spelling."); out.println("Action: Check that any custom tasks/types have been declared."); out.println("Action: Check that any /" + " declarations have taken place."); - if (isAntlib) { - out.println(); - out.println("This appears to be an antlib declaration. "); - out.println("Action: Check that the implementing library exists in one of:"); - out.println(dirListing); + if(uri.length()>0) { + List matches = antTypeTable.findMatches(uri); + if(matches.size()>0) { + out.println(); + out.println("The definitions in the namespace "+uri+" are:"); + for(Iterator it=matches.iterator();it.hasNext();) { + AntTypeDefinition def=(AntTypeDefinition) it.next(); + String local = ProjectHelper.extractNameFromComponentName(def.getName()); + out.println(" "+local); + } + } else { + out.println("No types or tasks have been defined in this namespace yet"); + if (isAntlib) { + out.println(); + out.println("This appears to be an antlib declaration. "); + out.println("Action: Check that the implementing library exists in one of:"); + out.println(dirListing); + } + } } } @@ -1035,6 +1056,22 @@ public class ComponentHelper { public boolean containsValue(Object value) { return contains(value); } - } + /** + * Create a list of all definitions that match a prefix, usually the URI + * of a library + * @param prefix prefix to match off + * @return the (possibly empty) list of definitions + */ + public List/**/ findMatches(String prefix) { + ArrayList matches=new ArrayList(); + for (Iterator i = values().iterator(); i.hasNext() ;) { + AntTypeDefinition def = (AntTypeDefinition) (i.next()); + if(def.getName().startsWith(prefix)) { + matches.add(def); + } + } + return matches; + } + } }