launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java
branchemul
changeset 613 a4a06840209a
parent 583 09f051f10096
child 622 a07253cf2ca4
     1.1 --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java	Fri Jan 25 13:26:28 2013 +0100
     1.2 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java	Wed Jan 30 18:27:57 2013 +0100
     1.3 @@ -64,7 +64,7 @@
     1.4      private Object[] brwsr;
     1.5      private HttpServer server;
     1.6      private CountDownLatch wait;
     1.7 -
     1.8 +    
     1.9      public Bck2BrwsrLauncher(String cmd) {
    1.10          this.cmd = cmd;
    1.11      }
    1.12 @@ -94,7 +94,7 @@
    1.13          if (!startpage.startsWith("/")) {
    1.14              startpage = "/" + startpage;
    1.15          }
    1.16 -        HttpServer s = initServer();
    1.17 +        HttpServer s = initServer(".", true);
    1.18          s.getServerConfiguration().addHttpHandler(new Page(resources, null), "/");
    1.19          try {
    1.20              launchServerAndBrwsr(s, startpage);
    1.21 @@ -103,6 +103,18 @@
    1.22          }
    1.23      }
    1.24  
    1.25 +    void showDirectory(File dir, String startpage) throws IOException {
    1.26 +        if (!startpage.startsWith("/")) {
    1.27 +            startpage = "/" + startpage;
    1.28 +        }
    1.29 +        HttpServer s = initServer(dir.getPath(), false);
    1.30 +        try {
    1.31 +            launchServerAndBrwsr(s, startpage);
    1.32 +        } catch (URISyntaxException | InterruptedException ex) {
    1.33 +            throw new IOException(ex);
    1.34 +        }
    1.35 +    }
    1.36 +
    1.37      @Override
    1.38      public void initialize() throws IOException {
    1.39          try {
    1.40 @@ -122,18 +134,20 @@
    1.41          }
    1.42      }
    1.43      
    1.44 -    private HttpServer initServer() throws IOException {
    1.45 -        HttpServer s = HttpServer.createSimpleServer(".", new PortRange(8080, 65535));
    1.46 +    private HttpServer initServer(String path, boolean addClasses) throws IOException {
    1.47 +        HttpServer s = HttpServer.createSimpleServer(path, new PortRange(8080, 65535));
    1.48  
    1.49          final ServerConfiguration conf = s.getServerConfiguration();
    1.50 -        conf.addHttpHandler(new VM(resources), "/vm.js");
    1.51 -        conf.addHttpHandler(new Classes(resources), "/classes/");
    1.52 +        if (addClasses) {
    1.53 +            conf.addHttpHandler(new VM(resources), "/vm.js");
    1.54 +            conf.addHttpHandler(new Classes(resources), "/classes/");
    1.55 +        }
    1.56          return s;
    1.57      }
    1.58      
    1.59      private void executeInBrowser() throws InterruptedException, URISyntaxException, IOException {
    1.60          wait = new CountDownLatch(1);
    1.61 -        server = initServer();
    1.62 +        server = initServer(".", true);
    1.63          ServerConfiguration conf = server.getServerConfiguration();
    1.64          conf.addHttpHandler(new Page(resources, 
    1.65              "org/apidesign/bck2brwsr/launcher/harness.xhtml"