in odps-console-basic/src/main/java/com/aliyun/openservices/odps/console/utils/CommandParserUtils.java [591:632]
private static AbstractCommand reflectCommandObject(String commandName, Class<?>[] argTypes,
Object... args) throws ODPSConsoleException {
Class<?> commandClass = null;
try {
commandClass = getClassFromPlugin(commandName);
Method parseMethod = commandClass.getDeclaredMethod("parse", argTypes);
Object commandObject = parseMethod.invoke(null, args);
if (commandObject != null) {
return (AbstractCommand) commandObject;
} else {
return null;
}
} catch (SecurityException e) {
throw new AssertionError("Cannot find the parse method on the command: " + commandName);
} catch (NoSuchMethodException e) {
//FOR there's two kind of command,not throw exception
return null;
} catch (IllegalArgumentException e) {
throw new AssertionError("Failed to invoke the parse method on the command:" + commandName);
} catch (IllegalAccessException e) {
throw new AssertionError("Failed to invoke the parse method on the command:" + commandName);
} catch (InvocationTargetException e) {
if (e.getCause() instanceof ODPSConsoleException) {
String msg = e.getCause().getMessage();
if (!StringUtils.isNullOrEmpty(msg) && msg.contains(ODPSConsoleConstants.BAD_COMMAND)
&& commandClass != null) {
String output = getCommandUsageString(commandClass,
(ExecutionContext) args[args.length - 1]);
if (output != null) {
throw new ODPSConsoleException(e.getCause().getMessage() + "\n" + output);
}
}
throw (ODPSConsoleException) e.getCause();
} else {
throw new ODPSConsoleException(e.getCause());
}
}
}