Rebasing the Inflater support on jzlib which, unlike GNU ClassPath, has correct implementation of Huffman code. Making the implementation more easily testable by turning Inflater and ZipInputStream into pure delegates. Current implementation is going to need proper long support.
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.bck2brwsr.mojo;
20 import java.io.Closeable;
21 import org.apache.maven.plugin.AbstractMojo;
24 import java.io.IOException;
25 import java.net.MalformedURLException;
27 import java.net.URLClassLoader;
28 import java.util.ArrayList;
29 import java.util.Collection;
30 import java.util.List;
31 import org.apache.maven.artifact.Artifact;
32 import org.apache.maven.plugin.MojoExecutionException;
33 import org.apache.maven.plugins.annotations.LifecyclePhase;
34 import org.apache.maven.plugins.annotations.Mojo;
35 import org.apache.maven.plugins.annotations.Parameter;
36 import org.apache.maven.project.MavenProject;
37 import org.apidesign.bck2brwsr.launcher.Launcher;
39 /** Executes given HTML page in a browser. */
40 @Mojo(name="brwsr", defaultPhase=LifecyclePhase.DEPLOY)
41 public class BrswrMojo extends AbstractMojo {
44 /** Resource to show as initial page */
46 private String startpage;
48 @Parameter(defaultValue="${project}")
49 private MavenProject prj;
51 /** Root of the class files */
52 @Parameter(defaultValue="${project.build.directory}/classes")
55 /** Root of all pages, and files, etc. */
57 private File directory;
60 public void execute() throws MojoExecutionException {
61 if (startpage == null) {
62 throw new MojoExecutionException("You have to provide a start page");
67 if (directory != null) {
68 httpServer = Launcher.showDir(directory, startpage);
70 URLClassLoader url = buildClassLoader(classes, prj.getDependencyArtifacts());
72 httpServer = Launcher.showURL(url, startpage());
73 } catch (Exception ex) {
74 throw new MojoExecutionException("Can't open " + startpage(), ex);
79 } catch (IOException ex) {
80 throw new MojoExecutionException("Can't show the browser", ex);
84 private String startpage() {
88 private static URLClassLoader buildClassLoader(File root, Collection<Artifact> deps) throws MalformedURLException {
89 List<URL> arr = new ArrayList<URL>();
90 arr.add(root.toURI().toURL());
91 for (Artifact a : deps) {
92 final File f = a.getFile();
94 arr.add(f.toURI().toURL());
97 return new URLClassLoader(arr.toArray(new URL[0]), BrswrMojo.class.getClassLoader());