< prev index next >

src/jdk.scripting.nashorn.shell/share/classes/jdk/nashorn/tools/jjs/Main.java

Print this page
rev 48062 : 8192833: JEP 322: Time-Based Release Versioning


 282     }
 283 
 284     private void evalImpl(final Context context, final Global global, final String source,
 285             final PrintWriter err, final boolean doe) {
 286         try {
 287             final Object res = context.eval(global, source, global, "<shell>");
 288             if (res != UNDEFINED) {
 289                 err.println(toString(res, global));
 290             }
 291         } catch (final Exception e) {
 292             err.println(e);
 293             if (doe) {
 294                 e.printStackTrace(err);
 295             }
 296         }
 297     }
 298 
 299     private static String JAVADOC_BASE = "https://docs.oracle.com/javase/%d/docs/api/";
 300     private static void openBrowserForJavadoc(ScriptFunction browse, String relativeUrl) {
 301         try {
 302             final URI uri = new URI(String.format(JAVADOC_BASE, Runtime.version().major()) + relativeUrl);
 303             ScriptRuntime.apply(browse, null, uri);
 304         } catch (Exception ignored) {
 305         }
 306     }
 307 
 308     private static String readJJSScript() {
 309         return AccessController.doPrivileged(
 310             new PrivilegedAction<String>() {
 311                 @Override
 312                 public String run() {
 313                     try {
 314                         final InputStream resStream = Main.class.getResourceAsStream("resources/jjs.js");
 315                         if (resStream == null) {
 316                             throw new RuntimeException("resources/jjs.js is missing!");
 317                         }
 318                         return new String(Source.readFully(resStream));
 319                     } catch (final IOException exp) {
 320                         throw new RuntimeException(exp);
 321                     }
 322                 }


 282     }
 283 
 284     private void evalImpl(final Context context, final Global global, final String source,
 285             final PrintWriter err, final boolean doe) {
 286         try {
 287             final Object res = context.eval(global, source, global, "<shell>");
 288             if (res != UNDEFINED) {
 289                 err.println(toString(res, global));
 290             }
 291         } catch (final Exception e) {
 292             err.println(e);
 293             if (doe) {
 294                 e.printStackTrace(err);
 295             }
 296         }
 297     }
 298 
 299     private static String JAVADOC_BASE = "https://docs.oracle.com/javase/%d/docs/api/";
 300     private static void openBrowserForJavadoc(ScriptFunction browse, String relativeUrl) {
 301         try {
 302             final URI uri = new URI(String.format(JAVADOC_BASE, Runtime.version().feature()) + relativeUrl);
 303             ScriptRuntime.apply(browse, null, uri);
 304         } catch (Exception ignored) {
 305         }
 306     }
 307 
 308     private static String readJJSScript() {
 309         return AccessController.doPrivileged(
 310             new PrivilegedAction<String>() {
 311                 @Override
 312                 public String run() {
 313                     try {
 314                         final InputStream resStream = Main.class.getResourceAsStream("resources/jjs.js");
 315                         if (resStream == null) {
 316                             throw new RuntimeException("resources/jjs.js is missing!");
 317                         }
 318                         return new String(Source.readFully(resStream));
 319                     } catch (final IOException exp) {
 320                         throw new RuntimeException(exp);
 321                     }
 322                 }
< prev index next >