private static void addServiceLoaderCommands(CommandRunner runner) { ServiceLoader<CommandFactory> factories = ServiceLoader.load(CommandFactory.class, runner.getClass().getClassLoader()); for (CommandFactory factory : factories) { runner.addCommands(factory.getCommands()); } }
private Iterable<Command> getCommands() { List<Command> commands = new ArrayList<Command>(); ServiceLoader<CommandFactory> factories = ServiceLoader.load(CommandFactory.class, getClass().getClassLoader()); for (CommandFactory factory : factories) { for (Command command : factory.getCommands()) { commands.add(convertToForkCommand(command)); } } commands.add(new PromptCommand(this.prompts)); commands.add(new ClearCommand(this.consoleReader)); commands.add(new ExitCommand()); return commands; }