Methods Summary |
---|
public org.apache.tools.ant.types.Path | createClasspath()Classpath to be used when searching for classes and resources.
if (this.classpath == null) {
this.classpath = new Path(getProject());
}
return this.classpath.createPath();
|
public boolean | eval(){@inheritDoc}.
if (classname == null) {
throw new BuildException("No classname defined");
}
Class clazz = loadClass(classname);
if (method != null) {
return isMethodFound(clazz);
}
if (field != null) {
return isFieldFound(clazz);
}
throw new BuildException("Neither method nor field defined");
|
private boolean | isFieldFound(java.lang.Class clazz)
Field[] fields = clazz.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
Field fieldEntry = fields[i];
if (fieldEntry.getName().equals(field)) {
return true;
}
}
return false;
|
private boolean | isMethodFound(java.lang.Class clazz)
Method[] methods = clazz.getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
Method methodEntry = methods[i];
if (methodEntry.getName().equals(method)) {
return true;
}
}
return false;
|
private java.lang.Class | loadClass(java.lang.String classname)Check if a given class can be loaded.
try {
if (ignoreSystemClasses) {
loader = getProject().createClassLoader(classpath);
loader.setParentFirst(false);
loader.addJavaLibraries();
if (loader != null) {
try {
return loader.findClass(classname);
} catch (SecurityException se) {
// class found but restricted name; this is
// actually the case we're looking for in JDK 1.3+,
// so catch the exception and return
return null;
}
} else {
return null;
}
} else if (loader != null) {
return loader.loadClass(classname);
} else {
ClassLoader l = this.getClass().getClassLoader();
// Can return null to represent the bootstrap class loader.
// see API docs of Class.getClassLoader.
if (l != null) {
return Class.forName(classname, true, l);
} else {
return Class.forName(classname);
}
}
} catch (ClassNotFoundException e) {
throw new BuildException("class \"" + classname + "\" was not found");
} catch (NoClassDefFoundError e) {
throw new BuildException("Could not load dependent class \"" + e.getMessage()
+ "\" for class \"" + classname + "\"");
}
|
public void | setClassname(java.lang.String classname)Set the classname attribute.
this.classname = classname;
|
public void | setClasspath(org.apache.tools.ant.types.Path classpath)Set the classpath to be used when searching for classes and resources.
createClasspath().append(classpath);
|
public void | setClasspathRef(org.apache.tools.ant.types.Reference r)Set the classpath by reference.
createClasspath().setRefid(r);
|
public void | setField(java.lang.String field)Set the name of the field.
this.field = field;
|
public void | setIgnoreSystemClasses(boolean ignoreSystemClasses)Set whether to ignore system classes when looking for the class.
this.ignoreSystemClasses = ignoreSystemClasses;
|
public void | setMethod(java.lang.String method)Set the name of the method.
this.method = method;
|