List of usage examples for jdk.nashorn.internal.runtime.options Options process
public void process(final String[] args)
From source file:io.stallion.plugins.javascript.JavascriptShell.java
License:Open Source License
private static Context makeContext(InputStream in, OutputStream out, OutputStream err, String[] args) { PrintStream pout = out instanceof PrintStream ? (PrintStream) out : new PrintStream(out); PrintStream perr = err instanceof PrintStream ? (PrintStream) err : new PrintStream(err); PrintWriter wout = new PrintWriter(pout, true); PrintWriter werr = new PrintWriter(perr, true); ErrorManager errors = new ErrorManager(werr); Options options = new Options("nashorn", werr); if (args != null) { try {//from ww w . j av a 2s .c o m options.process(args); } catch (IllegalArgumentException var27) { werr.println(bundle.getString("shell.usage")); options.displayHelp(var27); return null; } } return new Context(options, errors, wout, werr, Thread.currentThread().getContextClassLoader()); }
From source file:z.zee.Z.java
License:Open Source License
/** * Make a new Nashorn Context to compile and/or run JavaScript files. * * @param in input stream for Z//from ww w . ja v a 2 s . co m * @param out output stream for Z * @param err error stream for Z * @param args arguments to Z * * @return null if there are problems with option parsing. */ @SuppressWarnings("resource") private static Context makeContext(final InputStream in, final OutputStream out, final OutputStream err, final String[] args) { final PrintStream pout = out instanceof PrintStream ? (PrintStream) out : new PrintStream(out); final PrintStream perr = err instanceof PrintStream ? (PrintStream) err : new PrintStream(err); final PrintWriter wout = new PrintWriter(pout, true); final PrintWriter werr = new PrintWriter(perr, true); // Set up error handler. final ErrorManager errors = new ErrorManager(werr); // Set up options. final Options options = new Options("nashorn", werr); // parse options if (args != null) { try { options.process(args); } catch (final IllegalArgumentException e) { werr.println(bundle.getString("shell.usage")); options.displayHelp(e); return null; } } // detect scripting mode by any source's first character being '#' scripting = options.getBoolean("scripting"); if (!scripting) { for (final String fileName : options.getFiles()) { final File firstFile = new File(fileName); if (firstFile.isFile()) { try (final FileReader fr = new FileReader(firstFile)) { final int firstChar = fr.read(); // starts with '# if (firstChar == '#') { options.set("scripting", true); break; } } catch (final IOException e) { // ignore this. File IO errors will be reported later anyway } } } } return new Context(options, errors, wout, werr, Thread.currentThread().getContextClassLoader()); }