Skip to content

Commit

Permalink
Merge pull request jbake-org#19 from kwin/feature/13_fail-on-baking-e…
Browse files Browse the repository at this point in the history
…rrors

Fail build on baking errors
  • Loading branch information
jonbullock authored Nov 16, 2018
2 parents 27df4ce + f51050f commit 645e0ab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/main/java/org/jbake/maven/GenerateMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.commons.configuration.MapConfiguration;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
Expand Down Expand Up @@ -57,13 +58,19 @@ public class GenerateMojo extends AbstractMojo {
required = true)
protected File inputDirectory;

/**
* Breaks the build when {@code true} and errors occur during baking in JBake oven.
*/
@Parameter(property = "jbake.failOnError", defaultValue = "true")
protected boolean failOnError;

/**
* Set if cache is present or clear
*/
@Parameter(property = "jbake.isClearCache", defaultValue = "false", required = true)
protected boolean isClearCache;

public final void execute() throws MojoExecutionException {
public final void execute() throws MojoExecutionException, MojoFailureException {
try {
executeInternal();
} finally {
Expand All @@ -79,11 +86,11 @@ protected final void closeQuietly() {
}
}

protected void executeInternal() throws MojoExecutionException {
protected void executeInternal() throws MojoExecutionException, MojoFailureException {
reRender();
}

protected void reRender() throws MojoExecutionException {
protected void reRender() throws MojoExecutionException, MojoFailureException {
try {
// TODO: Smells bad. A lot
Orient.instance().startup();
Expand All @@ -94,6 +101,9 @@ protected void reRender() throws MojoExecutionException {
oven.setupPaths();

oven.bake();
if (failOnError && !oven.getErrors().isEmpty()) {
throw new MojoFailureException("Baked with " + oven.getErrors().size() + " errors. Check output above for details!");
}
} catch (Exception e) {
getLog().info("Oops", e);

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/jbake/maven/WatchMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.jbake.maven.util.DirWatcher;

Expand All @@ -32,7 +33,7 @@
@Mojo(name = "watch", requiresDirectInvocation = true, requiresProject = false)
public class WatchMojo extends GenerateMojo {

public void executeInternal() throws MojoExecutionException {
public void executeInternal() throws MojoExecutionException, MojoFailureException {
reRender();

Long lastProcessed = Long.valueOf(System.currentTimeMillis());
Expand Down

0 comments on commit 645e0ab

Please sign in to comment.