public static void exec(Runnable toRun, String[] args, boolean exit, LogInterface logInterface) { // --Init log = logInterface; // (cleanup) ignoredClasspath = new String[0]; runName = "<unnamed>"; outputDB = null; dataDB = null; execDir = null; logger = null; // (bootstrap) Map<String, String> options = parseOptions(args); // get options fillOptions(BOOTSTRAP_CLASSES, options, false); // bootstrap log.bootstrap(); log.startTrack("init"); // (fill options) Class<?>[] visibleClasses = getVisibleClasses(options); // get classes Map<String, Field> optionFields = fillOptions(visibleClasses, options); // fill try { initDatabase(visibleClasses, options, optionFields); // database } catch (DatabaseException e) { log.warn(LOG_TAG, e.getMessage()); } dumpOptions(options); // file dump log.endTrack("init"); log.setup(); // --Run Program try { log.startTrack("main"); toRun.run(); log.endTrack("main"); // ends main log.startTrack("flushing"); if (logger != null) { logger.save(); } } catch (Throwable e) { // catch everything log.exception(e); System.err.flush(); if (logger != null) { exitMessage = e.getClass().getName() + ": " + e.getMessage(); logger.suggestFlush(); // not a save! } log.exit(ExitCode.FATAL_EXCEPTION); } log.endTrack("flushing"); if (exit) { log.exit(ExitCode.OK); // soft exit } }
public static void fillOptions(Properties props, String[] args) { // (convert to map) Map<String, String> options = new HashMap<String, String>(); for (String key : props.stringPropertyNames()) { options.put(key, props.getProperty(key)); } options.putAll(parseOptions(args)); // (bootstrap) fillOptions(BOOTSTRAP_CLASSES, options, false); // bootstrap log.bootstrap(); log.startTrack("init"); // (fill options) Class<?>[] visibleClasses = getVisibleClasses(options); // get classes Map<String, Field> optionFields = fillOptions(visibleClasses, options); // fill }