From 666c26217e7de2122f44334039b5b780048aaa22 Mon Sep 17 00:00:00 2001 From: Philip Graf Date: Mon, 31 Aug 2015 00:17:02 +0200 Subject: [PATCH] Override JBake properties from plugin configuration This change allows to override JBake properties or define custom properties which can be used in the templates, e.g.: br.com.ingenieux jbake-maven-plugin ... true bar To make this possible an update to JBake 2.4.0 was necessary. This fixes #3 and resolves #11. --- pom.xml | 2 +- .../ingenieux/mojo/jbake/GenerateMojo.java | 25 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index ec5e15b4..714329ee 100644 --- a/pom.xml +++ b/pom.xml @@ -133,7 +133,7 @@ org.jbake jbake-core - 2.3.2 + 2.4.0 org.apache.maven diff --git a/src/main/java/br/com/ingenieux/mojo/jbake/GenerateMojo.java b/src/main/java/br/com/ingenieux/mojo/jbake/GenerateMojo.java index 8436a583..335b7e83 100644 --- a/src/main/java/br/com/ingenieux/mojo/jbake/GenerateMojo.java +++ b/src/main/java/br/com/ingenieux/mojo/jbake/GenerateMojo.java @@ -18,13 +18,19 @@ import com.orientechnologies.orient.core.Orient; +import org.apache.commons.configuration.CompositeConfiguration; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.MapConfiguration; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; +import org.jbake.app.ConfigUtil; import org.jbake.app.Oven; import java.io.File; +import java.util.HashMap; +import java.util.Map; /** * Runs jbake on a folder @@ -53,6 +59,15 @@ public class GenerateMojo extends AbstractMojo { @Parameter(property = "jbake.isClearCache", defaultValue = "false", required = true) protected boolean isClearCache; + /** + * Custom configuration properties. + * These properties override the properties in jbake.properties. + * In the templates the properties can be accessed using the prefix config. + * e.g. config.foo for the property <foo>bar</foo>. + */ + @Parameter(required = false) + protected Map properties = new HashMap<>(); + public final void execute() throws MojoExecutionException { try { executeInternal(); @@ -79,7 +94,7 @@ protected void reRender() throws MojoExecutionException { Orient.instance().startup(); // TODO: At some point, reuse Oven - Oven oven = new Oven(inputDirectory, outputDirectory, isClearCache); + Oven oven = new Oven(inputDirectory, outputDirectory, createConfiguration(), isClearCache); oven.setupPaths(); @@ -90,4 +105,12 @@ protected void reRender() throws MojoExecutionException { throw new MojoExecutionException("Failure when running: ", e); } } + + private CompositeConfiguration createConfiguration() throws ConfigurationException { + final CompositeConfiguration config = new CompositeConfiguration(); + config.addConfiguration(new MapConfiguration(properties)); + config.addConfiguration(ConfigUtil.load(inputDirectory)); + return config; + } + }