executor.setWorkingDirectory(getProject().getBaseDir());
executor.setCommandline(commandLine);
try {
executor.execute();
} catch (final IOException ioe) {
throw new BuildException("Error running forked groovyc.", ioe);
}
final int returnCode = executor.getExitValue();
if (returnCode != 0) {
if (failOnError) {
throw new BuildException("Forked groovyc returned error code: " + returnCode);
} else {
log("Forked groovyc returned error code: " + returnCode, Project.MSG_ERR);
}
}
} else {
// hand crank it so we can add our own compiler configuration
try {
Options options = FileSystemCompiler.createCompilationOptions();
PosixParser cliParser = new PosixParser();
CommandLine cli;
cli = cliParser.parse(options, commandLine);
configuration = FileSystemCompiler.generateCompilerConfigurationFromOptions(cli);
configuration.setScriptExtensions(getScriptExtensions());
String tmpExtension = getScriptExtension();
if (tmpExtension.startsWith("*.")) tmpExtension = tmpExtension.substring(1);
configuration.setDefaultScriptExtension(tmpExtension);
// Load the file name list
String[] filenames = FileSystemCompiler.generateFileNamesFromOptions(cli);
boolean fileNameErrors = filenames == null;
fileNameErrors = fileNameErrors && !FileSystemCompiler.validateFiles(filenames);
if (targetBytecode != null) {
configuration.setTargetBytecode(targetBytecode);
}
if (!fileNameErrors) {
FileSystemCompiler.doCompilation(configuration, makeCompileUnit(), filenames);
}
} catch (Exception re) {
Throwable t = re;
if ((re.getClass() == RuntimeException.class) && (re.getCause() != null)) {
// unwrap to the real exception
t = re.getCause();
}
StringWriter writer = new StringWriter();
new ErrorReporter(t, false).write(new PrintWriter(writer));
String message = writer.toString();
if (failOnError) {
log(message, Project.MSG_INFO);
throw new BuildException("Compilation Failed", t, getLocation());
} else {
log(message, Project.MSG_ERR);
}
}
}