Author: stevel
Date: Thu Jan 11 14:01:51 2007
New Revision: 495399
URL: http://svn.apache.org/viewvc?view=rev&rev=495399
Log:
Extra diagnostics. Dump all types in a namespace if the one you ask for isnt
known. Good for identifying typos, and helps you differentiate "library not yet
loaded" from "task unknown"
Modified:
ant/core/trunk/WHATSNEW
ant/core/trunk/src/main/org/apache/tools/ant/ComponentHelper.java
Modified: ant/core/trunk/WHATSNEW
URL:
http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?view=diff&rev=495399&r1=495398&r2=495399
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Thu Jan 11 14:01:51 2007
@@ -63,6 +63,10 @@
* Allow <mapper refid> 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
===================================
Modified: ant/core/trunk/src/main/org/apache/tools/ant/ComponentHelper.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/ComponentHelper.java?view=diff&rev=495399&r1=495398&r2=495399
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/ComponentHelper.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/ComponentHelper.java Thu Jan
11 14:01:51 2007
@@ -33,6 +33,10 @@
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 @@
/**
* 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 @@
}
/**
- * 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 <presetdef>/<macrodef>"
+ " 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 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/*<AntTypeDefinition>*/ 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;
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]