AbstractTestProcessor testProcessor, File tmpDir, ImmutableMap<String, String> classToSource)
throws IOException {
JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
DiagnosticCollector<JavaFileObject> diagnosticCollector =
new DiagnosticCollector<JavaFileObject>();
StandardJavaFileManager fileManager =
javac.getStandardFileManager(diagnosticCollector, null, null);
StringWriter compilerOut = new StringWriter();
List<String> options = ImmutableList.of(
"-sourcepath", tmpDir.getPath(),
"-d", tmpDir.getPath(),
"-Xlint");
javac.getTask(compilerOut, fileManager, diagnosticCollector, options, null, null);
// This doesn't compile anything but communicates the paths to the JavaFileManager.
ImmutableList.Builder<JavaFileObject> javaFilesBuilder = ImmutableList.builder();
for (String className : classToSource.keySet()) {
JavaFileObject sourceFile = fileManager.getJavaFileForInput(
StandardLocation.SOURCE_PATH, className, Kind.SOURCE);
javaFilesBuilder.add(sourceFile);
}
// Compile the empty source file to trigger the annotation processor.