Skip to content

Commit

Permalink
Merge pull request #5 from fhervieux/errorhandling
Browse files Browse the repository at this point in the history
Better error messages for JIBX compilation
  • Loading branch information
bcorne committed Jul 22, 2015
2 parents 8278636 + d9f8e6a commit bcb30d9
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/main/groovy/com/ullink/gradle/plugins/jibx/JIBXCompile.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.ullink.gradle.plugins.jibx

import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.TaskExecutionException

/**
* A Gradle interface to the JIBX compiler.
Expand Down Expand Up @@ -60,10 +61,29 @@ class JIBXCompile extends DefaultTask {
@TaskAction
def compile() {
def classLoader = URLClassLoader.newInstance(classPathFiles.collect { it -> it.toURI().toURL() } as URL[])
def compilerClass = Class.forName('org.jibx.binding.Compile', true, classLoader)
def compiler = compilerClass.newInstance(verbose, load, verify, trackBranches, errorOverride)
compiler.skipValidate = skipValidate
compiler.compile(classPathFiles as String[], bindingFiles as String[])
def compilerClass
def exceptionClass
try {
compilerClass = Class.forName('org.jibx.binding.Compile', true, classLoader)
exceptionClass = Class.forName('org.jibx.runtime.JiBXException', true, classLoader)
}
catch (ClassNotFoundException e) {
logger.warn("Could not compile JIBX bindings because no JIBX compiler was found in your classpath. Make sure you reference one in the task classpath, for example in the jibxCompile configuration.")
throw new TaskExecutionException(this, e)
}

try {
def compiler = compilerClass.newInstance(verbose, load, verify, trackBranches, errorOverride)
compiler.skipValidate = skipValidate
compiler.compile(classPathFiles as String[], bindingFiles as String[])
}
catch (Exception e) {
if (exceptionClass.isInstance(e) && e.getRootCause() != null) {
logger.warn("An exception occurred during the JIBX compilation: " + e.message)
throw e.getRootCause()
}
throw new TaskExecutionException(this, e)
}
}

}

0 comments on commit bcb30d9

Please sign in to comment.