in jmh/src/main/java/com/uber/nullaway/jmh/NullawayJavac.java [158:208]
private NullawayJavac(
List<JavaFileObject> compilationUnits,
String annotatedPackages,
@Nullable String classpath,
List<String> extraErrorProneArgs,
String extraProcessorPath)
throws IOException {
this.compilationUnits = compilationUnits;
this.compiler = ToolProvider.getSystemJavaCompiler();
this.diagnosticListener =
diagnostic -> {
// do nothing
};
// uncomment this if you want to see compile errors get printed out
// this.diagnosticListener = null;
this.fileManager = compiler.getStandardFileManager(diagnosticListener, null, null);
Path outputDir = Files.createTempDirectory("classes");
outputDir.toFile().deleteOnExit();
this.options = new ArrayList<>();
if (classpath != null) {
options.addAll(Arrays.asList("-classpath", classpath));
}
String processorPath =
System.getProperty("java.class.path") + File.pathSeparator + extraProcessorPath;
options.addAll(
Arrays.asList(
"-processorpath",
processorPath,
"-d",
outputDir.toAbsolutePath().toString(),
"-XDcompilePolicy=simple",
"--should-stop=ifError=FLOW",
"-Xplugin:ErrorProne -XepDisableAllChecks -Xep:NullAway:ERROR -XepOpt:NullAway:AnnotatedPackages="
+ annotatedPackages
+ String.join(" ", extraErrorProneArgs)));
// add these options since we have at least one benchmark that only compiles with access to
// javac-internal APIs
options.addAll(
Arrays.asList(
"--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
"--add-exports=jdk.compiler/com.sun.source.tree=ALL-UNNAMED"));
}