# HG changeset patch # User Jaroslav Tulach # Date 1402299483 -7200 # Node ID 80e39583b35d65835c2bc9c4bd1fe09fc3a4f8ac # Parent 8eba262bd8cd6f3a575d2793b09caf4a3fcbb9ee Launching the application from a fully built distrution directory structure diff -r 8eba262bd8cd -r 80e39583b35d javaquery/demo-calculator/nbactions.xml --- a/javaquery/demo-calculator/nbactions.xml Tue Jun 03 16:05:21 2014 +0200 +++ b/javaquery/demo-calculator/nbactions.xml Mon Jun 09 09:38:03 2014 +0200 @@ -23,10 +23,11 @@ run package - bck2brwsr:brwsr + bck2brwsr:show true + NONE diff -r 8eba262bd8cd -r 80e39583b35d javaquery/demo-calculator/pom.xml --- a/javaquery/demo-calculator/pom.xml Tue Jun 03 16:05:21 2014 +0200 +++ b/javaquery/demo-calculator/pom.xml Mon Jun 09 09:38:03 2014 +0200 @@ -13,6 +13,7 @@ UTF-8 FULL + NONE @@ -24,7 +25,7 @@ aot - brwsr + show diff -r 8eba262bd8cd -r 80e39583b35d launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java --- a/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java Tue Jun 03 16:05:21 2014 +0200 +++ b/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java Mon Jun 09 09:38:03 2014 +0200 @@ -131,10 +131,12 @@ if (!startpage.startsWith("/")) { startpage = "/" + startpage; } - String prefix = ""; - int last = startpage.lastIndexOf('/'); - if (last >= 0) { - prefix = startpage.substring(0, last); + String prefix = null; + if (!new File(dir, "bck2brwsr.js").exists()) { + int last = startpage.lastIndexOf('/'); + if (last >= 0) { + prefix = startpage.substring(0, last); + } } HttpServer s = initServer(dir.getPath(), addClasses, prefix); try { diff -r 8eba262bd8cd -r 80e39583b35d rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/ShowMojo.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/ShowMojo.java Mon Jun 09 09:38:03 2014 +0200 @@ -0,0 +1,84 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.mojo; + +import java.io.Closeable; +import org.apache.maven.plugin.AbstractMojo; + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.model.Resource; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.project.MavenProject; +import org.apidesign.bck2brwsr.launcher.Launcher; + +/** Executes given HTML page in a browser. */ +@Mojo( + name="show", + requiresDependencyResolution = ResolutionScope.RUNTIME, + defaultPhase=LifecyclePhase.NONE +) +public class ShowMojo extends AbstractMojo { + public ShowMojo() { + } + + /** The identification of a launcher to use. Known values fxbrwsr, + * bck2brwsr, or + * name of an external process to execute. + */ + @Parameter + private String launcher; + + + /** Resource to show as initial page */ + @Parameter + private String startpage; + + /** 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"); + } + if (directory == null) { + throw new MojoExecutionException("You have to provide a root directory"); + } + try { + Closeable httpServer; + httpServer = Launcher.showDir(launcher, directory, null, startpage); + System.in.read(); + httpServer.close(); + } catch (IOException ex) { + throw new MojoExecutionException("Can't show the browser", ex); + } + } +}