diff --git a/src/main/assembly/assembly.xml b/src/main/assembly/assembly.xml index 5ba59c259..473275df7 100644 --- a/src/main/assembly/assembly.xml +++ b/src/main/assembly/assembly.xml @@ -39,6 +39,13 @@ jbake-core.jar + + ${project.build.directory} + plugin + + **/* + + ${basedir} diff --git a/src/main/java/org/jbake/launcher/Main.java b/src/main/java/org/jbake/launcher/Main.java index c7f3dc8ce..5a808cd7e 100644 --- a/src/main/java/org/jbake/launcher/Main.java +++ b/src/main/java/org/jbake/launcher/Main.java @@ -1,40 +1,22 @@ package org.jbake.launcher; -import java.io.BufferedInputStream; import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; import java.io.StringWriter; -import java.io.UnsupportedEncodingException; -import java.net.URISyntaxException; -import java.net.URL; -import java.net.URLDecoder; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -import org.kohsuke.args4j.CmdLineException; -import org.kohsuke.args4j.CmdLineParser; +import java.util.Iterator; +import java.util.ServiceLoader; import org.apache.commons.configuration.CompositeConfiguration; import org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.configuration.ConfigurationUtils; -import org.eclipse.jetty.server.Handler; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.handler.DefaultHandler; -import org.eclipse.jetty.server.handler.HandlerList; -import org.eclipse.jetty.server.handler.ResourceHandler; -import org.eclipse.jetty.server.nio.NetworkTrafficSelectChannelConnector; import org.jbake.app.ConfigUtil; import org.jbake.app.FileUtil; import org.jbake.app.Oven; -import org.jbake.app.ZipUtil; +import org.jbake.plugins.JBakePlugin; +import org.kohsuke.args4j.CmdLineException; +import org.kohsuke.args4j.CmdLineParser; /** * Launcher for JBake. - * + * * @author Jonathan Bullock * */ @@ -42,17 +24,23 @@ public class Main { // public static final String VERSION = "v2.2"; private final String USAGE_PREFIX = "Usage: jbake"; - + /** * Runs the app with the given arguments. - * + * * @param String[] args */ public static void main(String[] args) { + Iterator plugins = ServiceLoader.load(JBakePlugin.class).iterator(); + while (plugins.hasNext()) { + JBakePlugin plugin = plugins.next(); + plugin.init(); + } + Main m = new Main(); m.run(m.parseArguments(args)); } - + private void run(LaunchOptions options) { try { Oven oven = new Oven(options.getSource(), options.getDestination()); @@ -78,14 +66,14 @@ private LaunchOptions parseArguments(String[] args) { e.printStackTrace(); System.exit(1); } - + System.out.println("JBake " + config.getString("version") + " (" + config.getString("build.timestamp") + ") [http://jbake.org]"); System.out.println(); - + if (res.isHelpNeeded()) { printUsage(parser); } - + if (res.isRunServer()) { if (res.getSource().getPath().equals(".")) { // use the default destination folder @@ -94,7 +82,7 @@ private LaunchOptions parseArguments(String[] args) { runServer(res.getSource().getPath(), config.getString("server.port")); } } - + if (res.isInit()) { initStructure(config); } @@ -119,7 +107,7 @@ private void runServer(String path, String port) { JettyServer.run(path, port); System.exit(0); } - + private void initStructure(CompositeConfiguration config) { Init init = new Init(config); try { diff --git a/src/main/java/org/jbake/plugins/JBakePlugin.java b/src/main/java/org/jbake/plugins/JBakePlugin.java new file mode 100644 index 000000000..d46520e21 --- /dev/null +++ b/src/main/java/org/jbake/plugins/JBakePlugin.java @@ -0,0 +1,6 @@ +package org.jbake.plugins; + +public interface JBakePlugin { + + void init(); +} diff --git a/src/main/scripts/jbake b/src/main/scripts/jbake index 0235aecdb..08d37322b 100755 --- a/src/main/scripts/jbake +++ b/src/main/scripts/jbake @@ -1,3 +1,3 @@ #!/bin/bash JBAKE_HOME="`dirname "$0"`" -java -jar ${JBAKE_HOME}/jbake-core.jar $@ \ No newline at end of file +java -cp "${JBAKE_HOME}/jbake-core.jar:plugin/*" org.jbake.launcher.Main $@ \ No newline at end of file