update java compilation to abort on compile errors after each package
This commit is contained in:
parent
12f01889ac
commit
b06493dc93
|
@ -103,7 +103,9 @@ public class CJavaPipeline {
|
|||
*/
|
||||
System.out.println("\n\nInit");
|
||||
System.out.println("Cleaning existing generated output");
|
||||
FileUtils.deleteDirectory(new File(processingOptions.getProperty(GENERATE_TO_DIR)));
|
||||
for (PackageProcessOptions pkg : packages) {
|
||||
FileUtils.deleteDirectory(new File(processingOptions.getProperty(GENERATE_TO_DIR) + "/" + pkg.packageName));
|
||||
}
|
||||
FileUtils.deleteDirectory(new File(processingOptions.getProperty(HEADERS_DIR_PROPERTY)));
|
||||
FileUtils.deleteDirectory(new File(processingOptions.getProperty(COMPILE_DIR_PROPERTY)));
|
||||
FileUtils.deleteDirectory(new File(processingOptions.getProperty(C_IMPLEMENTATION_FILE_PROPERTY)).getParentFile());
|
||||
|
@ -192,7 +194,11 @@ public class CJavaPipeline {
|
|||
MyJavaCompiler compiler = new MyJavaCompiler();
|
||||
|
||||
for (PackageProcessOptions pkg : packages) {
|
||||
compiler.run(new File(processingOptions.get(GENERATE_TO_DIR) + "/" + pkg.packageName), javaOut);
|
||||
if (!compiler.run(new File(processingOptions.get(GENERATE_TO_DIR) + "/" + pkg.packageName), javaOut)) {
|
||||
System.out.println("\n\nAborting due to compile errors (see above).");
|
||||
System.exit(1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,10 +19,9 @@ public class MyJavaCompiler {
|
|||
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public void run(File inDir, File outDir) {
|
||||
public boolean run(File inDir, File outDir) throws Exception {
|
||||
System.out.println("Compiling " + inDir + ", output " + outDir);
|
||||
outDir.delete();
|
||||
outDir.mkdir();
|
||||
outDir.mkdirs();
|
||||
|
||||
List<JavaFileObject> javaFileObjects = new ArrayList<JavaFileObject>();
|
||||
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
|
||||
|
@ -58,15 +57,19 @@ public class MyJavaCompiler {
|
|||
JavaCompiler.CompilationTask compilerTask =
|
||||
compiler.getTask(null, compiler.getStandardFileManager(null, Locale.getDefault(), null), diagnostics, compilationOptions, null, javaFileObjects);
|
||||
|
||||
try {
|
||||
boolean status = compilerTask.call();
|
||||
boolean status = false;
|
||||
|
||||
for (Diagnostic diagnostic : diagnostics.getDiagnostics()){
|
||||
try {
|
||||
status = compilerTask.call();
|
||||
|
||||
for (Diagnostic diagnostic : diagnostics.getDiagnostics()) {
|
||||
System.out.format("Error on line %d in %s", diagnostic.getLineNumber(), diagnostic);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue