593
594
return c.toString();
596
private static Project getProject(Object o) {
597
if (o instanceof ProjectComponent) {
598
return ((ProjectComponent) o).getProject();
601
Method m = o.getClass().getMethod("getProject", (Class[]) null);
602
if (Project.class == m.getReturnType()) {
603
return (Project) m.invoke(o, (Object[]) null);
605
} catch (Exception e) {
612
598
* Check if definition is a valid definition--it may be a
613
599
* definition of an optional task that does not exist.
776
762
* Called for each component name, check if the
777
763
* associated URI has been examined for antlibs.
764
* @param componentName the name of the component, which should include a URI
765
* prefix if it is in a namespace
779
767
private synchronized void checkNamespace(String componentName) {
780
768
String uri = ProjectHelper.extractUriFromComponentName(componentName);
853
841
AntTypeDefinition def = getDefinition(componentName);
854
842
if (def == null) {
855
843
//not a known type
856
boolean isAntlib = componentName.indexOf(MagicNames.ANTLIB_PREFIX) == 0;
857
out.println("Cause: The name is undefined.");
858
out.println("Action: Check the spelling.");
859
out.println("Action: Check that any custom tasks/types have been declared.");
860
out.println("Action: Check that any <presetdef>/<macrodef>"
861
+ " declarations have taken place.");
864
out.println("This appears to be an antlib declaration. ");
865
out.println("Action: Check that the implementing library exists in one of:");
866
out.println(dirListing);
844
printUnknownDefinition(out, componentName, dirListing);
868
845
definitions = true;
870
847
//we are defined, so it is an instantiation problem
879
856
clazz = def.innerGetTypeClass();
880
857
} catch (ClassNotFoundException e) {
881
out.println("Cause: the class " + classname + " was not found.");
884
out.println(" This looks like one of Ant's optional components.");
885
out.println("Action: Check that the appropriate optional JAR exists in");
886
out.println(dirListing);
888
out.println("Action: Check that the component has been correctly declared");
889
out.println(" and that the implementing JAR is in one of:");
890
out.println(dirListing);
891
860
definitions = true;
862
printClassNotFound(out, classname, optional, dirListing);
893
863
} catch (NoClassDefFoundError ncdfe) {
895
out.println("Cause: Could not load a dependent class "
896
+ ncdfe.getMessage());
898
out.println(" It is not enough to have Ant's optional JARs");
899
out.println(" you need the JAR files that the"
900
+ " optional tasks depend upon.");
901
out.println(" Ant's optional task dependencies are"
902
+ " listed in the manual.");
904
out.println(" This class may be in a separate JAR"
905
+ " that is not installed.");
907
out.println("Action: Determine what extra JAR files are"
908
+ " needed, and place them in one of:");
909
out.println(dirListing);
865
printNotLoadDependentClass(out, optional, ncdfe, dirListing);
911
867
//here we successfully loaded the class or failed.
912
868
if (clazz != null) {
935
* Print unknown definition.forking
937
private void printUnknownDefinition(
938
PrintWriter out, String componentName, String dirListing) {
939
boolean isAntlib = componentName.indexOf(MagicNames.ANTLIB_PREFIX) == 0;
940
String uri=ProjectHelper.extractUriFromComponentName(componentName);
941
out.println("Cause: The name is undefined.");
942
out.println("Action: Check the spelling.");
943
out.println("Action: Check that any custom tasks/types have been declared.");
944
out.println("Action: Check that any <presetdef>/<macrodef>"
945
+ " declarations have taken place.");
947
List matches = antTypeTable.findMatches(uri);
948
if(matches.size()>0) {
950
out.println("The definitions in the namespace "+uri+" are:");
951
for(Iterator it=matches.iterator();it.hasNext();) {
952
AntTypeDefinition def=(AntTypeDefinition) it.next();
953
String local = ProjectHelper.extractNameFromComponentName(def.getName());
954
out.println(" "+local);
957
out.println("No types or tasks have been defined in this namespace yet");
960
out.println("This appears to be an antlib declaration. ");
961
out.println("Action: Check that the implementing library exists in one of:");
962
out.println(dirListing);
969
* Print class not found.
971
private void printClassNotFound(
972
PrintWriter out, String classname, boolean optional,
974
out.println("Cause: the class " + classname + " was not found.");
976
out.println(" This looks like one of Ant's optional components.");
977
out.println("Action: Check that the appropriate optional JAR exists in");
978
out.println(dirListing);
980
out.println("Action: Check that the component has been correctly declared");
981
out.println(" and that the implementing JAR is in one of:");
982
out.println(dirListing);
987
* Print could not load dependent class.
989
private void printNotLoadDependentClass(
990
PrintWriter out, boolean optional, NoClassDefFoundError ncdfe,
992
out.println("Cause: Could not load a dependent class "
993
+ ncdfe.getMessage());
995
out.println(" It is not enough to have Ant's optional JARs");
996
out.println(" you need the JAR files that the"
997
+ " optional tasks depend upon.");
998
out.println(" Ant's optional task dependencies are"
999
+ " listed in the manual.");
1001
out.println(" This class may be in a separate JAR"
1002
+ " that is not installed.");
1004
out.println("Action: Determine what extra JAR files are"
1005
+ " needed, and place them in one of:");
1006
out.println(dirListing);
979
1010
* Map that contains the component definitions.
981
1012
private static class AntTypeTable extends Hashtable {
1013
private static final long serialVersionUID = -3060442320477772028L;
982
1015
private Project project;
984
1017
AntTypeTable(Project project) {
1022
1055
public boolean containsValue(Object value) {
1023
1056
return contains(value);
1060
* Create a list of all definitions that match a prefix, usually the URI
1062
* @param prefix prefix to match off
1063
* @return the (possibly empty) list of definitions
1065
public List/*<AntTypeDefinition>*/ findMatches(String prefix) {
1066
ArrayList matches=new ArrayList();
1067
for (Iterator i = values().iterator(); i.hasNext() ;) {
1068
AntTypeDefinition def = (AntTypeDefinition) (i.next());
1069
if(def.getName().startsWith(prefix)) {