Use provided loader to load libraries closure
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 29 Apr 2014 14:28:52 +0200
branchclosure
changeset 1504d058edd87424
parent 1503 e0f2f3503eed
child 1505 706b66d8c481
Use provided loader to load libraries
launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java
launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java
launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/CompileCP.java
launcher/http/src/test/java/org/apidesign/bck2brwsr/launcher/CompileCPTest.java
     1.1 --- a/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java	Tue Apr 29 14:27:36 2014 +0200
     1.2 +++ b/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java	Tue Apr 29 14:28:52 2014 +0200
     1.3 @@ -500,7 +500,7 @@
     1.4      String compileJar(JarFile jar) throws IOException {
     1.5          return null;
     1.6      }
     1.7 -    String compileFromClassPath(URL f) {
     1.8 +    String compileFromClassPath(URL f, Res loader) {
     1.9          return null;
    1.10      }
    1.11  
    1.12 @@ -509,7 +509,7 @@
    1.13              return BaseHTTPLauncher.this.compileJar(jar);
    1.14          }
    1.15          String compileFromClassPath(URL f) {
    1.16 -            return BaseHTTPLauncher.this.compileFromClassPath(f);
    1.17 +            return BaseHTTPLauncher.this.compileFromClassPath(f, this);
    1.18          }
    1.19          public URL get(String resource) throws IOException {
    1.20              URL u = null;
     2.1 --- a/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java	Tue Apr 29 14:27:36 2014 +0200
     2.2 +++ b/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java	Tue Apr 29 14:28:52 2014 +0200
     2.3 @@ -17,12 +17,9 @@
     2.4   */
     2.5  package org.apidesign.bck2brwsr.launcher;
     2.6  
     2.7 -import java.io.File;
     2.8  import java.io.IOException;
     2.9 -import java.io.InputStream;
    2.10  import java.net.URL;
    2.11  import java.util.jar.JarFile;
    2.12 -import org.apidesign.vm4brwsr.Bck2Brwsr;
    2.13  
    2.14  /**
    2.15   * Lightweight server to launch Bck2Brwsr applications and tests.
    2.16 @@ -45,9 +42,9 @@
    2.17          return CompileCP.compileJAR(jar);
    2.18      }
    2.19  
    2.20 -    @Override String compileFromClassPath(URL f) {
    2.21 +    @Override String compileFromClassPath(URL f, Res loader) {
    2.22          try {
    2.23 -            return CompileCP.compileFromClassPath(f);
    2.24 +            return CompileCP.compileFromClassPath(f, loader);
    2.25          } catch (Exception ex) {
    2.26              ex.printStackTrace();
    2.27              return null;
     3.1 --- a/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/CompileCP.java	Tue Apr 29 14:27:36 2014 +0200
     3.2 +++ b/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/CompileCP.java	Tue Apr 29 14:28:52 2014 +0200
     3.3 @@ -67,7 +67,7 @@
     3.4          }
     3.5      }
     3.6      
     3.7 -    static String compileFromClassPath(URL u) throws IOException, URISyntaxException {
     3.8 +    static String compileFromClassPath(URL u, final Res r) throws IOException, URISyntaxException {
     3.9          File f = new File(u.toURI());
    3.10          for (String s : System.getProperty("java.class.path").split(File.pathSeparator)) {
    3.11              if (!f.getPath().startsWith(s)) {
    3.12 @@ -83,7 +83,12 @@
    3.13                      .addRootClasses(classes.toArray(new String[0]))
    3.14                      .addResources(arr.toArray(new String[0]))
    3.15                      .library(true)
    3.16 -                    .resources(new EmulationResources())
    3.17 +                    .resources(new EmulationResources() {
    3.18 +                        @Override
    3.19 +                        public InputStream get(String resource) throws IOException {
    3.20 +                            return r != null ? r.get(resource).openStream() : super.get(resource);
    3.21 +                        }
    3.22 +                    })
    3.23                      .generate(w);
    3.24                  w.flush();
    3.25                  return w.toString();
    3.26 @@ -127,6 +132,9 @@
    3.27      private static void listDir(File f, String pref, List<String> classes, List<String> resources) throws IOException {
    3.28          File[] arr = f.listFiles();
    3.29          if (arr == null) {
    3.30 +            if (f.getName().equals("package-info.class")) {
    3.31 +                return;
    3.32 +            }
    3.33              if (f.getName().endsWith(".class")) {
    3.34                  classes.add(pref + f.getName().substring(0, f.getName().length() - 6));
    3.35              } else {
    3.36 @@ -140,7 +148,7 @@
    3.37          }
    3.38      }
    3.39  
    3.40 -    static void compileVM(StringBuilder sb, Res r) throws IOException {
    3.41 +    static void compileVM(StringBuilder sb, final Res r) throws IOException {
    3.42          URL u = r.get(InterruptedException.class.getName().replace('.', '/') + ".class");
    3.43          JarURLConnection juc = (JarURLConnection)u.openConnection();
    3.44          
    3.45 @@ -149,8 +157,12 @@
    3.46          listJAR(juc.getJarFile(), classes, arr);
    3.47  
    3.48          Bck2Brwsr.newCompiler().addRootClasses(classes.toArray(new String[0]))
    3.49 -            .resources(new EmulationResources())
    3.50 -            .generate(sb);
    3.51 +            .resources(new Bck2Brwsr.Resources() {
    3.52 +                @Override
    3.53 +                public InputStream get(String resource) throws IOException {
    3.54 +                    return r.get(resource).openStream();
    3.55 +                }
    3.56 +            }).generate(sb);
    3.57      }
    3.58  
    3.59      static class EmulationResources implements Bck2Brwsr.Resources {
     4.1 --- a/launcher/http/src/test/java/org/apidesign/bck2brwsr/launcher/CompileCPTest.java	Tue Apr 29 14:27:36 2014 +0200
     4.2 +++ b/launcher/http/src/test/java/org/apidesign/bck2brwsr/launcher/CompileCPTest.java	Tue Apr 29 14:28:52 2014 +0200
     4.3 @@ -35,7 +35,7 @@
     4.4          assertNotNull(u, "URL found");
     4.5          assertEquals(u.getProtocol(), "file", "It comes from a disk");
     4.6          
     4.7 -        String resources = CompileCP.compileFromClassPath(u);
     4.8 +        String resources = CompileCP.compileFromClassPath(u, null);
     4.9          assertNotNull(resources, "something compiled");
    4.10      }
    4.11  }