# HG changeset patch # User Jaroslav Tulach # Date 1410610783 -7200 # Node ID 93f4fbc4d1b728d55c5e0c3713b22f9ea26ba53c # Parent 35daab73e225396b9832ecf63fcc5e3007da5765 Support processing of lambda also in directories diff -r 35daab73e225 -r 93f4fbc4d1b7 launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/CompileCP.java --- a/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/CompileCP.java Sat Sep 13 13:44:01 2014 +0200 +++ b/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/CompileCP.java Sat Sep 13 14:19:43 2014 +0200 @@ -77,26 +77,9 @@ } if (s != null) { File root = new File(s); - List arr = new ArrayList<>(); - List classes = new ArrayList<>(); - listDir(root, null, classes, arr); StringWriter w = new StringWriter(); try { - Bck2Brwsr.newCompiler() - .addRootClasses(classes.toArray(new String[0])) - .addResources(arr.toArray(new String[0])) - .library() - //.obfuscation(ObfuscationLevel.FULL) - .resources(new EmulationResources() { - @Override - public InputStream get(String resource) throws IOException { - if (r != null) { - final URL url = r.get(resource, 0); - return url == null ? null : url.openStream(); - } - return super.get(resource); - } - }) + Bck2BrwsrJars.configureFrom(null, root) .generate(w); w.flush(); return w.toString(); @@ -109,23 +92,6 @@ return null; } - - private static void listDir(File f, String pref, List classes, List resources) throws IOException { - File[] arr = f.listFiles(); - if (arr == null) { - if (f.getName().endsWith(".class")) { - classes.add(pref + f.getName().substring(0, f.getName().length() - 6)); - } else { - resources.add(pref + f.getName()); - } - } else { - for (File ch : arr) { - - listDir(ch, pref == null ? "" : pref + f.getName() + "/", classes, resources); - } - } - } - static void compileVM(StringBuilder sb, final Res r) throws IOException { final Bck2Brwsr rt; try { @@ -155,26 +121,4 @@ } }).generate(sb); } - - static class EmulationResources implements Bck2Brwsr.Resources { - - @Override - public InputStream get(String name) throws IOException { - Enumeration en = Bck2BrwsrJars.class.getClassLoader().getResources(name); - URL u = null; - while (en.hasMoreElements()) { - u = en.nextElement(); - } - if (u == null) { - LOG.log(Level.WARNING, "Cannot find {0}", name); - return null; - } - if (u.toExternalForm().contains("/rt.jar!")) { - LOG.log(Level.WARNING, "{0}No bootdelegation for ", name); - return null; - } - return u.openStream(); - } - } - } diff -r 35daab73e225 -r 93f4fbc4d1b7 rt/aot/src/main/java/org/apidesign/bck2brwsr/aot/Bck2BrwsrJars.java --- a/rt/aot/src/main/java/org/apidesign/bck2brwsr/aot/Bck2BrwsrJars.java Sat Sep 13 13:44:01 2014 +0200 +++ b/rt/aot/src/main/java/org/apidesign/bck2brwsr/aot/Bck2BrwsrJars.java Sat Sep 13 14:19:43 2014 +0200 @@ -19,6 +19,7 @@ import java.io.BufferedReader; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -45,7 +46,7 @@ */ public final class Bck2BrwsrJars { private static final Logger LOG = Logger.getLogger(Bck2BrwsrJars.class.getName()); - + private Bck2BrwsrJars() { } @@ -66,6 +67,9 @@ * @throws IOException if something goes wrong */ public static Bck2Brwsr configureFrom(Bck2Brwsr c, File jar) throws IOException { + if (jar.isDirectory()) { + return configureDir(c, jar); + } final JarFile jf = new JarFile(jar); final List classes = new ArrayList<>(); List resources = new ArrayList<>(); @@ -228,5 +232,55 @@ } } + private static Bck2Brwsr configureDir(Bck2Brwsr c, final File dir) throws IOException { + List arr = new ArrayList<>(); + List classes = new ArrayList<>(); + class DirRes extends EmulationResources { + public DirRes(List classes) { + super(classes); + } + + @Override + public InputStream get(String name) throws IOException { + InputStream is = super.get(name); + if (is != null) { + return is; + } + File r = new File(dir, name.replace('/', File.separatorChar)); + if (r.exists()) { + return new FileInputStream(r); + } + return null; + } + } + DirRes dirRes = new DirRes(classes); + listDir(dir, null, dirRes, arr); + if (c == null) { + c = Bck2Brwsr.newCompiler(); + } + return c + .addRootClasses(classes.toArray(new String[0])) + .addResources(arr.toArray(new String[0])) + .library() + //.obfuscation(ObfuscationLevel.FULL) + .resources(dirRes); + } + + private static void listDir( + File f, String pref, EmulationResources res, List resources + ) throws IOException { + File[] arr = f.listFiles(); + if (arr == null) { + if (f.getName().endsWith(".class")) { + res.addClassResource(pref + f.getName()); + } else { + resources.add(pref + f.getName()); + } + } else { + for (File ch : arr) { + listDir(ch, pref == null ? "" : pref + f.getName() + "/", res, resources); + } + } + } }