Browse Source

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"

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@495399 13f79535-47bb-0310-9956-ffa450edef68
master
Steve Loughran 18 years ago
parent
commit
b2db0ad087
2 changed files with 48 additions and 7 deletions
  1. +4
    -0
      WHATSNEW
  2. +44
    -7
      src/main/org/apache/tools/ant/ComponentHelper.java

+ 4
- 0
WHATSNEW View File

@@ -63,6 +63,10 @@ Other changes:

* 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
===================================



+ 44
- 7
src/main/org/apache/tools/ant/ComponentHelper.java View File

@@ -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 <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 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/*<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;
}
}
}

Loading…
Cancel
Save