Search in sources :

Example 1 with Status

use of com.google.devtools.build.java.turbine.javac.JavacTurbineCompileResult.Status in project bazel by bazelbuild.

the class JavacTurbineCompiler method compile.

static JavacTurbineCompileResult compile(JavacTurbineCompileRequest request) throws IOException {
    Map<String, OutputFileObject> files = new LinkedHashMap<>();
    Status status;
    StringWriter sw = new StringWriter();
    Context context = new Context();
    try (PrintWriter pw = new PrintWriter(sw)) {
        setupContext(context, request.strictJavaDepsPlugin());
        CacheFSInfo.preRegister(context);
        try (ZipOutputFileManager fm = new ZipOutputFileManager(files)) {
            JavacTask task = JavacTool.create().getTask(pw, fm, null, /*diagnostics*/
            request.javacOptions(), ImmutableList.of(), /*classes*/
            fm.getJavaFileObjectsFromPaths(request.sources()), context);
            fm.setContext(context);
            fm.setLocationFromPaths(StandardLocation.SOURCE_PATH, Collections.<Path>emptyList());
            fm.setLocationFromPaths(StandardLocation.CLASS_PATH, request.classPath());
            fm.setLocationFromPaths(StandardLocation.PLATFORM_CLASS_PATH, request.bootClassPath());
            fm.setLocationFromPaths(StandardLocation.ANNOTATION_PROCESSOR_PATH, request.processorClassPath());
            status = task.call() ? Status.OK : Status.ERROR;
        } catch (Throwable t) {
            t.printStackTrace(pw);
            status = Status.ERROR;
        }
    }
    return new JavacTurbineCompileResult(ImmutableMap.copyOf(files), status, sw, context);
}
Also used : Status(com.google.devtools.build.java.turbine.javac.JavacTurbineCompileResult.Status) Context(com.sun.tools.javac.util.Context) OutputFileObject(com.google.devtools.build.java.turbine.javac.ZipOutputFileManager.OutputFileObject) StringWriter(java.io.StringWriter) JavacTask(com.sun.source.util.JavacTask) LinkedHashMap(java.util.LinkedHashMap) PrintWriter(java.io.PrintWriter)

Aggregations

Status (com.google.devtools.build.java.turbine.javac.JavacTurbineCompileResult.Status)1 OutputFileObject (com.google.devtools.build.java.turbine.javac.ZipOutputFileManager.OutputFileObject)1 JavacTask (com.sun.source.util.JavacTask)1 Context (com.sun.tools.javac.util.Context)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 LinkedHashMap (java.util.LinkedHashMap)1