public static void checkTaskClass(Class taskClass,
Project project) {
if (!Dispatchable.class.isAssignableFrom(taskClass)) {
// don't have to check for interface, since then
// taskClass would be abstract too.
try {
final Method executeM = taskClass.getMethod("execute", (Class[]) null);
// don't have to check for public, since
// getMethod finds public method only.
// don't have to check for abstract, since then
// taskClass would be abstract too.
if (!Void.TYPE.equals(executeM.getReturnType())) {
final String message = "return type of execute() should be "
+ "void but was \"" + executeM.getReturnType() + "\" in "
+ taskClass;
project.log(message, Project.MSG_WARN);
}
} catch (NoSuchMethodException e) {
final String message = "No public execute() in " + taskClass;
project.log(message, Project.MSG_ERR);
throw new BuildException(message);
} catch (LinkageError e) {
String message = "Could not load " + taskClass + ": " + e;
project.log(message, Project.MSG_ERR);
throw new BuildException(message, e);
}
}
}
Checks whether or not a class is suitable to be adapted by TaskAdapter.
If the class is of type Dispatchable, the check is not performed because
the method that will be executed will be determined only at runtime of
the actual task and not during parse time.
This only checks conditions which are additionally required for
tasks adapted by TaskAdapter. Thus, this method should be called by
Project.checkTaskClass.
Throws a BuildException and logs as Project.MSG_ERR for
conditions that will cause the task execution to fail.
Logs other suspicious conditions with Project.MSG_WARN. |