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.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;
27 import java.util.ArrayList;
28 import java.util.Enumeration;
29 import java.util.List;
31 import java.util.logging.Level;
32 import java.util.logging.Logger;
33 import org.apidesign.bck2brwsr.aot.Bck2BrwsrJars;
34 import org.apidesign.bck2brwsr.launcher.BaseHTTPLauncher.Res;
35 import org.apidesign.vm4brwsr.Bck2Brwsr;
39 * @author Jaroslav Tulach
42 private static final Logger LOG = Logger.getLogger(CompileCP.class.getName());
43 static String compileJAR(final File jar, Set<String> testClasses)
45 StringWriter w = new StringWriter();
47 Bck2BrwsrJars.configureFrom(null, jar)
48 .addExported(testClasses.toArray(new String[0]))
52 } catch (IOException ex) {
54 } catch (Throwable ex) {
55 throw new IOException("Cannot compile: ", ex);
61 static String compileFromClassPath(URL u, final Res r) throws IOException {
64 f = new File(u.toURI());
65 } catch (URISyntaxException ex) {
66 throw new IOException(ex);
68 String s = f.isDirectory() ? f.getPath() : null;
70 for (String candidate : System.getProperty("java.class.path").split(File.pathSeparator)) {
74 if (f.getPath().startsWith(candidate)) {
79 File root = new File(s);
80 StringWriter w = new StringWriter();
82 Bck2BrwsrJars.configureFrom(null, root)
86 } catch (ClassFormatError ex) {
87 throw new IOException(ex);
95 static void compileVM(StringBuilder sb, final Res r) throws IOException {
98 URL u = r.get(InterruptedException.class.getName().replace('.', '/') + ".class", 0);
99 JarURLConnection juc = (JarURLConnection)u.openConnection();
100 rt = Bck2BrwsrJars.configureFrom(null, new File(juc.getJarFileURL().toURI()));
101 } catch (URISyntaxException ex) {
102 throw new IOException(ex);
106 URL u = r.get(Bck2Brwsr.class.getName().replace('.', '/') + ".class", 0);
107 JarURLConnection juc = (JarURLConnection)u.openConnection();
108 all = Bck2BrwsrJars.configureFrom(rt, new File(juc.getJarFileURL().toURI()));
109 } catch (URISyntaxException ex) {
110 throw new IOException(ex);
115 //.obfuscation(ObfuscationLevel.FULL)
116 .resources(new Bck2Brwsr.Resources() {
118 public InputStream get(String resource) throws IOException {
119 final URL url = r.get(resource, 0);
120 return url == null ? null : url.openStream();