launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java
changeset 1926 789849cabcc7
parent 1921 aed8434561fc
child 1927 cff680298793
     1.1 --- a/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java	Sun Apr 17 07:40:34 2016 +0200
     1.2 +++ b/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java	Mon Apr 18 05:15:11 2016 +0200
     1.3 @@ -122,7 +122,7 @@
     1.4          if (!startpage.startsWith("/")) {
     1.5              startpage = "/" + startpage;
     1.6          }
     1.7 -        HttpServer s = initServer(".", true, "");
     1.8 +        HttpServer s = initServer(".", true, "", false);
     1.9          int last = startpage.lastIndexOf('/');
    1.10          String prefix = startpage.substring(0, last);
    1.11          String simpleName = startpage.substring(last);
    1.12 @@ -146,7 +146,7 @@
    1.13                  prefix = startpage.substring(0, last);
    1.14              }
    1.15          }
    1.16 -        HttpServer s = initServer(dir.getPath(), addClasses, prefix);
    1.17 +        HttpServer s = initServer(dir.getPath(), addClasses, prefix, false);
    1.18          try {
    1.19              launchServerAndBrwsr(s, startpage);
    1.20          } catch (Exception ex) {
    1.21 @@ -173,7 +173,7 @@
    1.22          }
    1.23      }
    1.24  
    1.25 -    private HttpServer initServer(String path, boolean addClasses, String vmPrefix) throws IOException {
    1.26 +    private HttpServer initServer(String path, boolean addClasses, String vmPrefix, boolean unitTests) throws IOException {
    1.27          HttpServer s = HttpServer.createSimpleServer(null, new PortRange(8080, 65535));
    1.28          /*
    1.29          ThreadPoolConfig fewThreads = ThreadPoolConfig.defaultConfig().copy().
    1.30 @@ -190,7 +190,7 @@
    1.31          }
    1.32  */
    1.33          final ServerConfiguration conf = s.getServerConfiguration();
    1.34 -        VMAndPages vm = new VMAndPages();
    1.35 +        VMAndPages vm = new VMAndPages(unitTests);
    1.36          conf.addHttpHandler(vm, "/");
    1.37          if (vmPrefix != null) {
    1.38              vm.registerVM(vmPrefix + "/bck2brwsr.js");
    1.39 @@ -217,7 +217,7 @@
    1.40      private static int resourcesCount;
    1.41      private void executeInBrowser() throws InterruptedException, URISyntaxException, IOException {
    1.42          wait = new CountDownLatch(1);
    1.43 -        server = initServer(".", true, "");
    1.44 +        server = initServer(".", true, "", true);
    1.45          final ServerConfiguration conf = server.getServerConfiguration();
    1.46  
    1.47          class DynamicResourceHandler extends HttpHandler {
    1.48 @@ -626,7 +626,7 @@
    1.49          }
    1.50      }
    1.51  
    1.52 -    abstract void generateBck2BrwsrJS(StringBuilder sb, Res loader) throws IOException;
    1.53 +    abstract void generateBck2BrwsrJS(StringBuilder sb, Res loader, String url, boolean unitTestMode) throws IOException;
    1.54      abstract String harnessResource();
    1.55      Object compileJar(URL jar, URL precompiled) throws IOException {
    1.56          return null;
    1.57 @@ -840,10 +840,12 @@
    1.58      }
    1.59  
    1.60      private class VMAndPages extends StaticHttpHandler {
    1.61 +        private final boolean unitTestMode;
    1.62          private String vmResource;
    1.63  
    1.64 -        public VMAndPages() {
    1.65 +        public VMAndPages(boolean unitTestMode) {
    1.66              super((String[]) null);
    1.67 +            this.unitTestMode = unitTestMode;
    1.68          }
    1.69  
    1.70          @Override
    1.71 @@ -856,7 +858,7 @@
    1.72                  response.setCharacterEncoding("UTF-8");
    1.73                  response.setContentType("text/javascript");
    1.74                  StringBuilder sb = new StringBuilder();
    1.75 -                generateBck2BrwsrJS(sb, BaseHTTPLauncher.this.resources);
    1.76 +                generateBck2BrwsrJS(sb, BaseHTTPLauncher.this.resources, request.getRequestURL().toString(), unitTestMode);
    1.77                  response.getWriter().write(sb.toString());
    1.78              } else {
    1.79                  super.service(request, response);