2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012-2015 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.bck2brwsr.launcher;
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.io.StringWriter;
24 import java.net.JarURLConnection;
25 import java.net.URISyntaxException;
28 import java.util.logging.Logger;
29 import org.apidesign.bck2brwsr.aot.Bck2BrwsrJars;
30 import org.apidesign.bck2brwsr.launcher.BaseHTTPLauncher.Res;
31 import org.apidesign.vm4brwsr.Bck2Brwsr;
35 * @author Jaroslav Tulach
38 private static final Logger LOG = Logger.getLogger(CompileCP.class.getName());
39 static String compileJAR(final File jar, Set<String> testClasses)
41 StringWriter w = new StringWriter();
43 Bck2BrwsrJars.configureFrom(null, jar)
44 .addExported(testClasses.toArray(new String[0]))
48 } catch (IOException ex) {
50 } catch (Throwable ex) {
51 throw new IOException("Cannot compile: ", ex);
57 static String compileFromClassPath(URL u, final Res r) throws IOException {
60 f = new File(u.toURI());
61 } catch (URISyntaxException ex) {
62 throw new IOException(ex);
64 String s = f.isDirectory() ? f.getPath() : null;
66 for (String candidate : System.getProperty("java.class.path").split(File.pathSeparator)) {
70 if (f.getPath().startsWith(candidate)) {
75 File root = new File(s);
76 StringWriter w = new StringWriter();
78 Bck2BrwsrJars.configureFrom(null, root)
82 } catch (ClassFormatError ex) {
83 throw new IOException(ex);
91 static void compileVM(StringBuilder sb, final Res r) throws IOException {
94 URL u = r.get(InterruptedException.class.getName().replace('.', '/') + ".class", 0);
95 JarURLConnection juc = (JarURLConnection)u.openConnection();
96 rt = Bck2BrwsrJars.configureFrom(null, new File(juc.getJarFileURL().toURI()));
97 } catch (URISyntaxException ex) {
98 throw new IOException(ex);
102 URL u = r.get(Bck2Brwsr.class.getName().replace('.', '/') + ".class", 0);
103 JarURLConnection juc = (JarURLConnection)u.openConnection();
104 all = Bck2BrwsrJars.configureFrom(rt, new File(juc.getJarFileURL().toURI()));
105 } catch (URISyntaxException ex) {
106 throw new IOException(ex);
111 //.obfuscation(ObfuscationLevel.FULL)
112 .resources(new Bck2Brwsr.Resources() {
114 public InputStream get(String resource) throws IOException {
115 final URL url = r.get(resource, 0);
116 return url == null ? null : url.openStream();