Skip to content

Commit

Permalink
Merge pull request jbake-org#12 from acanda/config-properties
Browse files Browse the repository at this point in the history
Override JBake properties from plugin configuration
  • Loading branch information
aldrinleal committed Feb 23, 2016
2 parents 5a6e6af + 666c262 commit cac88ca
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 cac88ca

Please sign in to comment.