/** This *MUST* NOT be called within a shutdown hook, otherwise, the thread will deadlock */ private static void doExit(final String message, final int exitCode) { logExitMessage(message, exitCode); System.exit(exitCode); }
/** TODO: set a property to this value to eliminate the dependency on reflection. */ private static AbstractCommandLineModule getCommandLineModule(final String[] arguments) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { final Class<? extends AbstractCommandLineModule> commandLineModuleClass = getCommandLineModuleClass(); final Constructor<? extends AbstractCommandLineModule> commandLineModuleConstructor = commandLineModuleClass.getDeclaredConstructor(); AbstractCommandLineModule module = commandLineModuleConstructor.newInstance(); module.setArguments(arguments); return (module); }
public static void main(final String[] arguments) throws Exception { COMMAND_LINE_MODULE = getCommandLineModule(arguments); GuiceHelper.addModule(COMMAND_LINE_MODULE); GuiceHelper.setup(); try { COMMAND_LINE_MODULE.doRun(arguments); doExit("Finished execution, exiting ...", 0); } catch (Exception e) { LOGGER.error("Error running", e); doExit("Error running", 1); } }
public static void loadFromCommandLine(final Properties properties, final String[] arguments) { try { final Map<Integer, Option> optionMap = new HashMap<>(); final CommandLineParser parser = new DefaultParser(); final Iterable<Class<? extends GuiceProperty>> guiceProperties = PropertyUtil.getProperties(); final Options options = buildOptions(guiceProperties, optionMap); final CommandLine commandLine = parser.parse(options, arguments); int i = 0; for (final Class<? extends GuiceProperty> guiceProperty : guiceProperties) { setValue(properties, commandLine, optionMap.get(i++), guiceProperty); } } catch (ParseException e) { LOGGER.warn("error parsing CLI options", e); throw (new RuntimeException(e)); } }
@Override protected final void configure() { CLIUtil.loadFromCommandLine(properties, arguments); super.configure(); doConfigure(); }