# HG changeset patch # User Jaroslav Tulach # Date 1359566877 -3600 # Node ID a4a06840209a5c8a1c32ece3edc5dc6503503b80 # Parent 4bc57543ab71abe83b8c3585b6b6ea1ff99492fe Using internal server to execute the HTML page diff -r 4bc57543ab71 -r a4a06840209a javaquery/demo-calculator/nbactions.xml --- a/javaquery/demo-calculator/nbactions.xml Wed Jan 30 17:36:45 2013 +0100 +++ b/javaquery/demo-calculator/nbactions.xml Wed Jan 30 18:27:57 2013 +0100 @@ -23,7 +23,7 @@ run process-classes - org.codehaus.mojo:exec-maven-plugin:1.2.1:exec + org.apidesign.bck2brwsr:mojo:0.3-SNAPSHOT:brwsr diff -r 4bc57543ab71 -r a4a06840209a javaquery/demo-calculator/pom.xml --- a/javaquery/demo-calculator/pom.xml Wed Jan 30 17:36:45 2013 +0100 +++ b/javaquery/demo-calculator/pom.xml Wed Jan 30 18:27:57 2013 +0100 @@ -16,34 +16,21 @@ - - org.apidesign.bck2brwsr - mojo - 0.3-SNAPSHOT - - - - j2js - - - - - org.codehaus.mojo - exec-maven-plugin - 1.2.1 + org.apidesign.bck2brwsr + mojo + 0.3-SNAPSHOT - exec + j2js + brwsr - xdg-open - - ${project.build.directory}/${project.build.finalName}-bck2brwsr/public_html/index.xhtml - + ${project.build.directory}/${project.build.finalName}-bck2brwsr/public_html/ + index.xhtml diff -r 4bc57543ab71 -r a4a06840209a launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java Wed Jan 30 17:36:45 2013 +0100 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java Wed Jan 30 18:27:57 2013 +0100 @@ -64,7 +64,7 @@ private Object[] brwsr; private HttpServer server; private CountDownLatch wait; - + public Bck2BrwsrLauncher(String cmd) { this.cmd = cmd; } @@ -94,7 +94,7 @@ if (!startpage.startsWith("/")) { startpage = "/" + startpage; } - HttpServer s = initServer(); + HttpServer s = initServer(".", true); s.getServerConfiguration().addHttpHandler(new Page(resources, null), "/"); try { launchServerAndBrwsr(s, startpage); @@ -103,6 +103,18 @@ } } + void showDirectory(File dir, String startpage) throws IOException { + if (!startpage.startsWith("/")) { + startpage = "/" + startpage; + } + HttpServer s = initServer(dir.getPath(), false); + try { + launchServerAndBrwsr(s, startpage); + } catch (URISyntaxException | InterruptedException ex) { + throw new IOException(ex); + } + } + @Override public void initialize() throws IOException { try { @@ -122,18 +134,20 @@ } } - private HttpServer initServer() throws IOException { - HttpServer s = HttpServer.createSimpleServer(".", new PortRange(8080, 65535)); + private HttpServer initServer(String path, boolean addClasses) throws IOException { + HttpServer s = HttpServer.createSimpleServer(path, new PortRange(8080, 65535)); final ServerConfiguration conf = s.getServerConfiguration(); - conf.addHttpHandler(new VM(resources), "/vm.js"); - conf.addHttpHandler(new Classes(resources), "/classes/"); + if (addClasses) { + conf.addHttpHandler(new VM(resources), "/vm.js"); + conf.addHttpHandler(new Classes(resources), "/classes/"); + } return s; } private void executeInBrowser() throws InterruptedException, URISyntaxException, IOException { wait = new CountDownLatch(1); - server = initServer(); + server = initServer(".", true); ServerConfiguration conf = server.getServerConfiguration(); conf.addHttpHandler(new Page(resources, "org/apidesign/bck2brwsr/launcher/harness.xhtml" diff -r 4bc57543ab71 -r a4a06840209a launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Launcher.java --- a/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Launcher.java Wed Jan 30 17:36:45 2013 +0100 +++ b/launcher/src/main/java/org/apidesign/bck2brwsr/launcher/Launcher.java Wed Jan 30 18:27:57 2013 +0100 @@ -18,6 +18,7 @@ package org.apidesign.bck2brwsr.launcher; import java.io.Closeable; +import java.io.File; import java.io.IOException; import java.net.URLClassLoader; import org.apidesign.vm4brwsr.Bck2Brwsr; @@ -60,4 +61,10 @@ l.showURL(startpage); return l; } + public static Closeable showDir(File directory, String startpage) throws IOException { + Bck2BrwsrLauncher l = new Bck2BrwsrLauncher(null); + l.showDirectory(directory, startpage); + return l; + } + } diff -r 4bc57543ab71 -r a4a06840209a mojo/src/main/java/org/apidesign/bck2brwsr/mojo/BrswrMojo.java --- a/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/BrswrMojo.java Wed Jan 30 17:36:45 2013 +0100 +++ b/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/BrswrMojo.java Wed Jan 30 18:27:57 2013 +0100 @@ -51,21 +51,28 @@ /** Root of the class files */ @Parameter(defaultValue="${project.build.directory}/classes") private File classes; + + /** Root of all pages, and files, etc. */ + @Parameter + private File directory; @Override public void execute() throws MojoExecutionException { if (startpage == null) { throw new MojoExecutionException("You have to provide a start page"); } - + try { - URLClassLoader url = buildClassLoader(classes, prj.getDependencyArtifacts()); - Closeable httpServer; - try { - httpServer = Launcher.showURL(url, startpage()); - } catch (Exception ex) { - throw new MojoExecutionException("Can't open " + startpage(), ex); + if (directory != null) { + httpServer = Launcher.showDir(directory, startpage); + } else { + URLClassLoader url = buildClassLoader(classes, prj.getDependencyArtifacts()); + try { + httpServer = Launcher.showURL(url, startpage()); + } catch (Exception ex) { + throw new MojoExecutionException("Can't open " + startpage(), ex); + } } System.in.read(); httpServer.close();