Search in sources :

Example 1 with CommandInfo

use of com.shulie.instrument.simulator.module.model.info.CommandInfo in project LinkAgent by shulieTech.

the class InfoModule method modules.

@Command(value = "commands", description = "查看所有的命令")
public CommandResponse modules() {
    try {
        List<CommandInfo> commands = new ArrayList<CommandInfo>();
        for (ExtensionModule module : moduleManager.list()) {
            Class<?> classOfModule = module.getClass();
            // 判断模块是否实现了@Information标记
            if (!classOfModule.isAnnotationPresent(ModuleInfo.class)) {
                continue;
            }
            final ModuleInfo info = classOfModule.getAnnotation(ModuleInfo.class);
            if (info == null) {
                continue;
            }
            for (final Method method : getMethodsListWithAnnotation(module.getClass(), Command.class)) {
                final Command commandAnnotation = method.getAnnotation(Command.class);
                if (null == commandAnnotation) {
                    continue;
                }
                CommandInfo commandInfo = new CommandInfo();
                commandInfo.setModuleId(info.id());
                commandInfo.setCommand(commandAnnotation.value());
                commandInfo.setCommandDescription(commandAnnotation.description());
                commands.add(commandInfo);
            }
        }
        return CommandResponse.success(commands);
    } catch (Throwable e) {
        LOGGER.error("SIMULATOR: execute command info/commands error.", e);
        return CommandResponse.failure(e);
    }
}
Also used : CommandInfo(com.shulie.instrument.simulator.module.model.info.CommandInfo) ModuleInfo(com.shulie.instrument.simulator.api.ModuleInfo) Command(com.shulie.instrument.simulator.api.annotation.Command) ArrayList(java.util.ArrayList) ExtensionModule(com.shulie.instrument.simulator.api.ExtensionModule) Method(java.lang.reflect.Method) Command(com.shulie.instrument.simulator.api.annotation.Command)

Aggregations

ExtensionModule (com.shulie.instrument.simulator.api.ExtensionModule)1 ModuleInfo (com.shulie.instrument.simulator.api.ModuleInfo)1 Command (com.shulie.instrument.simulator.api.annotation.Command)1 CommandInfo (com.shulie.instrument.simulator.module.model.info.CommandInfo)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1