diff -r d4ee65642d8d -r 36746c46716a launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/CompileCP.java --- a/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/CompileCP.java Thu May 22 15:29:40 2014 +0200 +++ b/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/CompileCP.java Mon May 26 17:52:56 2014 +0200 @@ -17,28 +17,22 @@ */ package org.apidesign.bck2brwsr.launcher; -import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.io.StringWriter; import java.net.JarURLConnection; import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; import java.util.Enumeration; -import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.zip.ZipEntry; +import org.apidesign.bck2brwsr.aot.Bck2BrwsrJars; import org.apidesign.bck2brwsr.launcher.BaseHTTPLauncher.Res; import org.apidesign.vm4brwsr.Bck2Brwsr; -import org.apidesign.vm4brwsr.ObfuscationLevel; /** * @@ -46,31 +40,11 @@ */ class CompileCP { private static final Logger LOG = Logger.getLogger(CompileCP.class.getName()); - static String compileJAR(final JarFile jar, Set testClasses) + static String compileJAR(final File jar, Set testClasses) throws IOException { - List arr = new ArrayList<>(); - List classes = new ArrayList<>(); - Set keep = new HashSet(testClasses); - listJAR(jar, classes, arr, keep); - StringWriter w = new StringWriter(); try { - class JarRes extends EmulationResources implements Bck2Brwsr.Resources { - @Override - public InputStream get(String resource) throws IOException { - InputStream is = jar.getInputStream(new ZipEntry(resource)); - return is == null ? super.get(resource) : is; - } - } - - Bck2Brwsr.newCompiler() - .addClasses(classes.toArray(new String[0])) - .addExported(keep.toArray(new String[0])) - .addResources(arr.toArray(new String[0])) - //.obfuscation(ObfuscationLevel.FULL) - .library(true) - .resources(new JarRes()) - .generate(w); + Bck2BrwsrJars.configureFrom(null, jar).generate(w); w.flush(); return w.toString(); } catch (IOException ex) { @@ -126,56 +100,7 @@ return null; } - private static void listJAR( - JarFile j, List classes, - List resources, Set keep - ) throws IOException { - Enumeration en = j.entries(); - while (en.hasMoreElements()) { - JarEntry e = en.nextElement(); - final String n = e.getName(); - if (n.endsWith("/")) { - continue; - } - int last = n.lastIndexOf('/'); - String pkg = n.substring(0, last + 1); - if (skipPkg(pkg)) { - continue; - } - if (n.endsWith(".class")) { - classes.add(n.substring(0, n.length() - 6)); - } else { - resources.add(n); - if (n.startsWith("META-INF/services/") && keep != null) { - BufferedReader r = new BufferedReader(new InputStreamReader(j.getInputStream(e))); - for (;;) { - String l = r.readLine(); - if (l == null) { - break; - } - if (l.startsWith("#")) { - continue; - } - keep.add(l.replace('.', '/')); - } - } - } - } - String exp = j.getManifest().getMainAttributes().getValue("Export-Package"); - if (exp != null && keep != null) { - for (String def : exp.split(",")) { - for (String sep : def.split(";")) { - keep.add(sep.replace('.', '/') + "/"); - break; - } - } - } - } - private static boolean skipPkg(String pkg) { - return pkg.equals("org/apidesign/bck2brwsr/launcher/"); - } - private static void listDir(File f, String pref, List classes, List resources) throws IOException { File[] arr = f.listFiles(); if (arr == null) { @@ -193,21 +118,24 @@ } static void compileVM(StringBuilder sb, final Res r) throws IOException { - List arr = new ArrayList<>(); - List classes = new ArrayList<>(); - - { + final Bck2Brwsr rt; + try { URL u = r.get(InterruptedException.class.getName().replace('.', '/') + ".class", 0); JarURLConnection juc = (JarURLConnection)u.openConnection(); - listJAR(juc.getJarFile(), classes, arr, null); + rt = Bck2BrwsrJars.configureFrom(null, new File(juc.getJarFileURL().toURI())); + } catch (URISyntaxException ex) { + throw new IOException(ex); } - { + final Bck2Brwsr all; + try { URL u = r.get(Bck2Brwsr.class.getName().replace('.', '/') + ".class", 0); JarURLConnection juc = (JarURLConnection)u.openConnection(); - listJAR(juc.getJarFile(), classes, arr, null); + all = Bck2BrwsrJars.configureFrom(rt, new File(juc.getJarFileURL().toURI())); + } catch (URISyntaxException ex) { + throw new IOException(ex); } - Bck2Brwsr.newCompiler().addRootClasses(classes.toArray(new String[0])) + all.library(false) //.obfuscation(ObfuscationLevel.FULL) .resources(new Bck2Brwsr.Resources() { @Override @@ -222,7 +150,7 @@ @Override public InputStream get(String name) throws IOException { - Enumeration en = CompileCP.class.getClassLoader().getResources(name); + Enumeration en = Bck2BrwsrJars.class.getClassLoader().getResources(name); URL u = null; while (en.hasMoreElements()) { u = en.nextElement(); @@ -232,10 +160,11 @@ return null; } if (u.toExternalForm().contains("/rt.jar!")) { - LOG.warning(name + "No bootdelegation for "); + LOG.log(Level.WARNING, "{0}No bootdelegation for ", name); return null; } return u.openStream(); } } + }