Esempio n. 1
0
File: Main.java Progetto: rebx/jruby
  private Status internalRun() {
    doShowVersion();
    doShowCopyright();

    if (!config.shouldRunInterpreter()) {
      doPrintUsage(false);
      doPrintProperties();
      return new Status();
    }

    InputStream in = config.getScriptSource();
    String filename = config.displayedFileName();

    doProcessArguments(in);

    Ruby runtime = Ruby.newInstance(config);

    try {
      doSetContextClassLoader(runtime);

      if (in == null) {
        // no script to run, return success
        return new Status();
      } else if (config.isxFlag() && !config.hasShebangLine()) {
        // no shebang was found and x option is set
        throw new MainExitException(1, "jruby: no Ruby script found in input (LoadError)");
      } else if (config.isShouldCheckSyntax()) {
        // check syntax only and exit
        return doCheckSyntax(runtime, in, filename);
      } else {
        // proceed to run the script
        return doRunFromMain(runtime, in, filename);
      }
    } finally {
      runtime.tearDown();
    }
  }
Esempio n. 2
-1
  private Status internalRun() {
    doShowVersion();
    doShowCopyright();

    if (!config.getShouldRunInterpreter()) {
      doPrintUsage(false);
      doPrintProperties();
      return new Status();
    }

    InputStream in = config.getScriptSource();
    String filename = config.displayedFileName();

    doProcessArguments(in);

    Ruby _runtime;

    if (DripMain.DRIP_RUNTIME != null) {
      // use drip's runtime, reinitializing config
      _runtime = DripMain.DRIP_RUNTIME;
      _runtime.reinitialize(true);
    } else {
      _runtime = Ruby.newInstance(config);
    }

    final Ruby runtime = _runtime;
    final AtomicBoolean didTeardown = new AtomicBoolean();

    if (config.isHardExit()) {
      // we're the command-line JRuby, and should set a shutdown hook for
      // teardown.
      Runtime.getRuntime()
          .addShutdownHook(
              new Thread() {
                public void run() {
                  if (didTeardown.compareAndSet(false, true)) {
                    runtime.tearDown();
                  }
                }
              });
    }

    try {
      doSetContextClassLoader(runtime);

      if (in == null) {
        // no script to run, return success
        return new Status();
      } else if (config.isXFlag() && !config.hasShebangLine()) {
        // no shebang was found and x option is set
        throw new MainExitException(1, "jruby: no Ruby script found in input (LoadError)");
      } else if (config.getShouldCheckSyntax()) {
        // check syntax only and exit
        return doCheckSyntax(runtime, in, filename);
      } else {
        // proceed to run the script
        return doRunFromMain(runtime, in, filename);
      }
    } finally {
      if (didTeardown.compareAndSet(false, true)) {
        runtime.tearDown();
      }
    }
  }