Adopting to JDK8's Nashorn differences. Most tests should now pass with Nashorn now.
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.vm4brwsr;
20 import java.io.BufferedWriter;
22 import java.io.FileWriter;
23 import java.io.IOException;
24 import java.io.Writer;
26 /** Generator of JavaScript from bytecode of classes on classpath of the VM
29 * @author Jaroslav Tulach <jtulach@netbeans.org>
34 public static void main(String... args) throws IOException {
35 final String obfuscate = "--obfuscatelevel";
37 if (args.length < 2) {
38 System.err.println("Bck2Brwsr Translator from Java(tm) to JavaScript, (c) Jaroslav Tulach 2012");
39 System.err.println("Usage: java -cp ... -jar ... [");
40 System.err.print(obfuscate);
41 System.err.print(" [");
43 for (ObfuscationLevel l : ObfuscationLevel.values()) {
45 System.err.print('|');
47 System.err.print(l.name());
51 System.err.println("] <file_to_generate_js_code_to> java/lang/Class org/your/App ...");
55 ObfuscationLevel obfLevel = ObfuscationLevel.NONE;
56 StringArray classes = new StringArray();
57 String generateTo = null;
58 for (int i = 0; i < args.length; i++) {
59 if (obfuscate.equals(args[i])) { // NOI18N
62 obfLevel = ObfuscationLevel.valueOf(args[i]);
63 } catch (Exception e) {
64 System.err.print(obfuscate);
65 System.err.print(" parameter needs to be followed by one of ");
67 for (ObfuscationLevel l : ObfuscationLevel.values()) {
69 System.err.print(", ");
71 System.err.print(l.name());
79 if (generateTo == null) {
82 classes = classes.addAndNew(args[i]);
86 File gt = new File(generateTo);
87 if (Boolean.getBoolean("skip.if.exists") && gt.isFile()) {
88 System.err.println("Skipping as " + gt + " exists.");
92 try (Writer w = new BufferedWriter(new FileWriter(gt))) {
93 Bck2Brwsr.newCompiler().
94 obfuscation(obfLevel).
95 addRootClasses(classes.toArray()).
96 resources(new LdrRsrcs(Main.class.getClassLoader(), true)).