use of com.google.devtools.build.buildjar.InvalidCommandLineException in project bazel by bazelbuild.
the class BlazeJavacMain method compile.
public static BlazeJavacResult compile(BlazeJavacArguments arguments) {
List<String> javacArguments = arguments.javacOptions();
try {
javacArguments = processPluginArgs(arguments.plugins(), javacArguments);
} catch (InvalidCommandLineException e) {
return BlazeJavacResult.error(e.getMessage());
}
Context context = new Context();
setupBlazeJavaCompiler(arguments.plugins(), context);
boolean ok = false;
StringWriter errOutput = new StringWriter();
// TODO(cushon): where is this used when a diagnostic listener is registered? Consider removing
// it and handling exceptions directly in callers.
PrintWriter errWriter = new PrintWriter(errOutput);
Listener diagnostics = new Listener(context);
BlazeJavaCompiler compiler;
try (JavacFileManager fileManager = new ClassloaderMaskingFileManager()) {
JavacTask task = JavacTool.create().getTask(errWriter, fileManager, diagnostics, javacArguments, ImmutableList.of(), /*classes*/
fileManager.getJavaFileObjectsFromPaths(arguments.sourceFiles()), context);
if (arguments.processors() != null) {
task.setProcessors(arguments.processors());
}
fileManager.setContext(context);
setLocations(fileManager, arguments);
try {
ok = task.call();
} catch (PropagatedException e) {
throw e.getCause();
}
} catch (Throwable t) {
t.printStackTrace(errWriter);
ok = false;
} finally {
compiler = (BlazeJavaCompiler) JavaCompiler.instance(context);
if (ok) {
// or empty source files.
if (compiler.skippedFlowEvents() > 0 && compiler.flowEvents() == 0) {
errWriter.println("Expected at least one FLOW event");
ok = false;
}
}
}
errWriter.flush();
return new BlazeJavacResult(ok, filterDiagnostics(diagnostics.build()), errOutput.toString(), compiler);
}
Aggregations