JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
DiagnosticCollector<JavaFileObject> diagnosticCollector =
new DiagnosticCollector<JavaFileObject>();
InMemoryJavaFileManager fileManager = new InMemoryJavaFileManager(
compiler.getStandardFileManager(diagnosticCollector, Locale.getDefault(), UTF_8));
CompilationTask task = compiler.getTask(
null, // explicitly use the default because old versions of javac log some output on stderr
fileManager,
diagnosticCollector,
ImmutableSet.<String>of(),
ImmutableSet.<String>of(),
sources);
task.setProcessors(processors);
boolean successful = task.call();
return new Result(successful, sortDiagnosticsByKind(diagnosticCollector.getDiagnostics()),
fileManager.getOutputFiles());
}