Skip to content

Commit

Permalink
Let the bake task fail if there are errors. Fix for #41
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Oct 4, 2018
1 parent a520ce5 commit b16b3e1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/main/groovy/org/jbake/gradle/JBakeProxy.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ interface JBakeProxy {
def getConfig()

def setConfig(Object config)

List<String> getErrors()
}
9 changes: 9 additions & 0 deletions src/main/groovy/org/jbake/gradle/JBakeProxyImpl.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,13 @@ class JBakeProxyImpl implements JBakeProxy {
def setConfig(Object config) {
jbake.config = config
}

List<String> getErrors() {
try {
return jbake.getErrors()
} catch (Exception e) {
// older versions of the Oven class do not have a getErrors() method
return []
}
}
}
7 changes: 6 additions & 1 deletion src/main/groovy/org/jbake/gradle/JBakeTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.gradle.api.tasks.InputDirectory
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.TaskExecutionException

import java.lang.reflect.Constructor

Expand Down Expand Up @@ -49,6 +50,11 @@ class JBakeTask extends DefaultTask {
jbake.prepare()
mergeConfiguration()
jbake.jbake()
List<String> errors = jbake.getErrors()
if (errors) {
errors.each { logger.error(it) }
throw new TaskExecutionException(this, new IllegalStateException(errors.join('\n')))
}
}

private JBakeProxy createJbake() {
Expand All @@ -58,7 +64,6 @@ class JBakeTask extends DefaultTask {
}

private mergeConfiguration() {
//config = new CompositeConfiguration([createMapConfiguration(), jbake.getConfig()])
def delegate = loadClass('org.apache.commons.configuration.CompositeConfiguration')
Constructor constructor = delegate.getConstructor(Collection)
def config = constructor.newInstance([createMapConfiguration(), jbake.getConfig()])
Expand Down

0 comments on commit b16b3e1

Please sign in to comment.