Skip to content

Commit

Permalink
Override JBake properties from plugin configuration
Browse files Browse the repository at this point in the history
This change allows to override JBake properties or define custom
properties which can be used in the templates, e.g.:
<plugin>
    <groupId>br.com.ingenieux</groupId>
    <artifactId>jbake-maven-plugin</artifactId>
    <executions>
        ...
    </executions>
    <configuration>
        <properties>
            <!-- override jbake property -->
            <render.feed>true</render.feed>
            <!-- define custom property -->
            <foo>bar</foo>
        </properties>
    </configuration>
</plugin>

To make this possible an update to JBake 2.4.0 was necessary.

This fixes #3 and resolves #11.
  • Loading branch information
acanda committed Aug 30, 2015
1 parent 5a6e6af commit 666c262
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
<dependency>
<groupId>org.jbake</groupId>
<artifactId>jbake-core</artifactId>
<version>2.3.2</version>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
Expand Down
25 changes: 24 additions & 1 deletion src/main/java/br/com/ingenieux/mojo/jbake/GenerateMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <code>jbake.properties</code>.
* In the templates the properties can be accessed using the prefix <code>config.</code>
* e.g. <code>config.foo</code> for the property <code>&lt;foo>bar&lt/foo></code>.
*/
@Parameter(required = false)
protected Map<String, Object> properties = new HashMap<>();

public final void execute() throws MojoExecutionException {
try {
executeInternal();
Expand All @@ -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();

Expand All @@ -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;
}

}

0 comments on commit 666c262

Please sign in to comment.