diff options
author | Reinier Zwitserloot <r.zwitserloot@projectlombok.org> | 2020-08-28 00:14:10 +0200 |
---|---|---|
committer | Reinier Zwitserloot <r.zwitserloot@projectlombok.org> | 2020-08-28 00:15:55 +0200 |
commit | 6088e6e3d60f407765a9e6936bf0d06a184282df (patch) | |
tree | 19704daae859bcc724a0bc19598dd028a946b680 | |
parent | edbfdfe8c52c17a38bf2b526d14a4f622c5402f7 (diff) | |
download | lombok-6088e6e3d60f407765a9e6936bf0d06a184282df.tar.gz lombok-6088e6e3d60f407765a9e6936bf0d06a184282df.tar.bz2 lombok-6088e6e3d60f407765a9e6936bf0d06a184282df.zip |
[build] added ant website.open
this serves the site locally and opens your browser
-rw-r--r-- | buildScripts/info.ant.xml | 5 | ||||
-rw-r--r-- | buildScripts/ivy.xml | 1 | ||||
-rw-r--r-- | buildScripts/website.ant.xml | 13 | ||||
-rw-r--r-- | src/support/lombok/website/RunSite.java | 107 |
4 files changed, 126 insertions, 0 deletions
diff --git a/buildScripts/info.ant.xml b/buildScripts/info.ant.xml index 55fea8af..fe6e0ee3 100644 --- a/buildScripts/info.ant.xml +++ b/buildScripts/info.ant.xml @@ -258,6 +258,11 @@ build/website. 'pack' bzips this up, ready to ship to the server. 'publish' sends this to the server and runs a script to deploy. + > ant website.open + + First builds the website, then hosts it locally and opens it in your browser so + you can see the website in its full, template-applied form. + > ant latest-changes.build Makes a changelog variant that lists only the newest changes; it is included diff --git a/buildScripts/ivy.xml b/buildScripts/ivy.xml index 14530f06..40bbad08 100644 --- a/buildScripts/ivy.xml +++ b/buildScripts/ivy.xml @@ -58,6 +58,7 @@ <dependency org="projectlombok.org" name="markdownj" rev="1.02b4" conf="buildtools->build" /> <dependency org="de.java2html" name="java2html" rev="5.0" conf="buildtools->default" /> <dependency org="org.freemarker" name="freemarker" rev="2.3.28" conf="buildtools->default" /> + <dependency org="com.sparkjava" name="spark-core" rev="2.9.2" conf="buildtools->default" /> <dependency org="org.eclipse.jgit" name="org.eclipse.jgit.ant" rev="5.2.0.201812061821-r" conf="supporters->default" /> <dependency org="org.eclipse.jgit" name="org.eclipse.jgit" rev="5.2.0.201812061821-r" conf="supporters->default" /> diff --git a/buildScripts/website.ant.xml b/buildScripts/website.ant.xml index 9efb2668..730b79c2 100644 --- a/buildScripts/website.ant.xml +++ b/buildScripts/website.ant.xml @@ -150,6 +150,19 @@ such as applying the templates to produce the website, converting the changelog <website.make version="${lombok.version.live}" fullversion="${lombok.fullversion.live}" cmd="all" /> </target> + <target name="website.open" depends="website.build, compile.support" description="Builds the website, then serves it locally, opening a browser."> + <local name="dir.build.website" /> + <property name="dir.build.website" location="build/website" /> + <java classname="lombok.website.RunSite" failonerror="true"> + <classpath> + <path refid="cp.buildtools" /> + <pathelement location="build/support" /> + </classpath> + <arg value="${dir.build.website}" /> + <arg value="open" /> + </java> + </target> + <target name="website.print-all-versions" depends="compile.support"> <java classname="lombok.website.WebsiteMaker" failonerror="true"> <classpath> diff --git a/src/support/lombok/website/RunSite.java b/src/support/lombok/website/RunSite.java new file mode 100644 index 00000000..ad4a3731 --- /dev/null +++ b/src/support/lombok/website/RunSite.java @@ -0,0 +1,107 @@ +package lombok.website; + +import static spark.Spark.*; + +import java.awt.Desktop; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import spark.Request; +import spark.Response; +import spark.Route; +import spark.resource.InputStreamResource; + +public class RunSite { + private static final int DEFAULT_PORT = 4569; + private final Path base; + + public RunSite(Path base) { + this.base = base; + } + + public static void main(String[] args) throws Exception { + boolean open = args.length > 1 && args[1].equals("open"); + new RunSite(Paths.get(args[0])).go(open); + } + + private void go(boolean open) throws Exception { + port(DEFAULT_PORT); + get("/", serve("main.html")); + get("/setup/overview", serve("setup/main.html")); + get("/setup", serve("setup/main.html")); + get("/features", serve("features/index.html")); + get("/features/all", serve("features/index.html")); + get("/features/experimental/all", serve("features/experimental/index.html")); + get("/features/experimental", serve("features/experimental/index.html")); + + serveDir("/", base); + + System.out.println("Serving page from " + base + " -- hit enter to stop"); + if (open) Opener.open("http://localhost:" + DEFAULT_PORT + "/"); + System.in.read(); + System.exit(0); + } + + private void serveDir(String sub, Path dir) throws IOException { + DirectoryStream<Path> ds = Files.newDirectoryStream(dir); + try { + for (Path c : ds) { + String n = c.getFileName().toString(); + if (n.equals(".") || n.equals("..")) continue; + if (Files.isDirectory(c)) { + serveDir(sub + n + "/", c); + continue; + } + String rel = base.relativize(c).toString(); + get(sub + n, serve(rel)); + if (n.endsWith(".html")) get(sub + n.substring(0, n.length() - 5), serve(rel)); + } + } finally { + ds.close(); + } + } + + private static class Opener { + public static void open(String url) throws Exception { + Desktop.getDesktop().browse(new URI(url)); + } + } + + private Route serve(final String path) { + final Path tgt = base.resolve(path); + + return new Route() { + @Override public Object handle(Request req, Response res) throws Exception { + res.type(mapMime(path)); + return Files.readAllBytes(tgt); + } + }; + } + + private String mapMime(String path) { + if (path.endsWith(".css")) return "text/css; charset=UTF-8"; + if (path.endsWith(".js")) return "text/javascript; charset=UTF-8"; + if (path.endsWith(".png")) return "image/png"; + if (path.endsWith(".gif")) return "image/gif"; + if (path.endsWith(".jpg")) return "image/jpeg"; + if (path.endsWith(".mp4")) return "video/mp4"; + if (path.endsWith(".m4v")) return "video/mp4"; + if (path.endsWith(".ogv")) return "video/ogg"; + if (path.endsWith(".webm")) return "video/webm"; + if (path.endsWith(".ico")) return "image/x-icon"; + if (path.endsWith(".pdf")) return "application/pdf"; + if (path.endsWith(".json")) return "application/json"; + if (path.endsWith(".xml")) return "text/xml"; + if (path.endsWith(".woff")) return "font/woff"; + if (path.endsWith(".woff2")) return "font/woff2"; + if (path.endsWith(".html")) return "text/html; charset=UTF-8"; + return "text/plain; charset=UTF-8"; + } +} |