Exemple #1
0
 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
   }
 }
Exemple #2
0
 private static final void ensureScalaPath(Map<String, String> options, String[] cp) {
   // (check if it's in the classpath)
   try {
     Class.forName("scala.None", false, ClassLoader.getSystemClassLoader());
   } catch (ClassNotFoundException e) {
     // (case: scala library not in the classpath)
     if (options.containsKey(SCALA_PATH)) {
       // (case: scala_path option set)
       try {
         String path = options.get(SCALA_PATH);
         if (!(new File(path).exists())) {
           System.err.println("The library strongly integrates with the Scala runtime, ");
           System.err.println("however it could not find the Scala library (scala-library.jar) ");
           System.err.println(
               "at the path given by the command line option '" + SCALA_PATH + "': " + path);
           log.exit(ExitCode.BAD_OPTION);
         }
         URL url = new File(path).toURI().toURL();
         URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader();
         Class<URLClassLoader> sysclass = URLClassLoader.class;
         Method method = sysclass.getDeclaredMethod("addURL", url.getClass());
         boolean savedAccessible = method.isAccessible();
         method.setAccessible(true);
         method.invoke(sysloader, new Object[] {url});
         method.setAccessible(savedAccessible);
         Class.forName("scala.None", false, ClassLoader.getSystemClassLoader());
       } catch (Exception ex) {
         throw log.fail(ex);
       } // end try catch
     } else {
       // (case: we cannot find the scala library at all)
       System.err.println("The library strongly integrates with the Scala runtime, ");
       System.err.println(
           "however it could not find the Scala library (scala-library.jar) in the classpath, ");
       System.err.println("and the '" + SCALA_PATH + "' command line argument is not set.");
       log.exit(ExitCode.BAD_OPTION);
     }
   }
   options.remove(SCALA_PATH);
 }