Search in sources :

Example 1 with AutoOneOfProcessor

use of com.google.auto.value.processor.AutoOneOfProcessor in project auto by google.

the class CompileWithEclipseTest method compileWithEclipse.

private void compileWithEclipse(String version, Predicate<File> predicate) throws IOException {
    File sourceRootFile = new File(SOURCE_ROOT);
    File javaDir = new File(sourceRootFile, "src/main/java");
    File javatestsDir = new File(sourceRootFile, "src/test/java");
    Set<File> sources = new ImmutableSet.Builder<File>().addAll(filesUnderDirectory(javaDir, predicate)).addAll(filesUnderDirectory(javatestsDir, predicate)).build();
    assertThat(sources).isNotEmpty();
    JavaCompiler compiler = new EclipseCompiler();
    StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
    // This hack is only needed in a Google-internal Java 8 environment where symbolic links make it
    // hard for ecj to find the boot class path. Elsewhere it is unnecessary but harmless. Notably,
    // on Java 9+ there is no rt.jar. There, fileManager.getLocation(PLATFORM_CLASS_PATH) returns
    // null, because the relevant classes are in modules inside
    // fileManager.getLocation(SYSTEM_MODULES).
    File rtJar = new File(JAVA_HOME.value() + "/lib/rt.jar");
    if (rtJar.exists()) {
        List<File> bootClassPath = ImmutableList.<File>builder().add(rtJar).addAll(fileManager.getLocation(StandardLocation.PLATFORM_CLASS_PATH)).build();
        fileManager.setLocation(StandardLocation.PLATFORM_CLASS_PATH, bootClassPath);
    }
    Iterable<? extends JavaFileObject> sourceFileObjects = fileManager.getJavaFileObjectsFromFiles(sources);
    String outputDir = tmp.getRoot().toString();
    ImmutableList<String> options = ImmutableList.of("-d", outputDir, "-s", outputDir, "-source", version, "-target", version, "-warn:-warningToken,-intfAnnotation");
    JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, null, options, null, sourceFileObjects);
    // Explicitly supply an empty list of extensions for AutoValueProcessor, because otherwise this
    // test will pick up a test one and get confused.
    AutoValueProcessor autoValueProcessor = new AutoValueProcessor(ImmutableList.of());
    ImmutableList<? extends Processor> processors = ImmutableList.of(autoValueProcessor, new AutoOneOfProcessor(), new AutoAnnotationProcessor(), new AutoBuilderProcessor());
    task.setProcessors(processors);
    assertWithMessage("Compilation should succeed").that(task.call()).isTrue();
}
Also used : AutoOneOfProcessor(com.google.auto.value.processor.AutoOneOfProcessor) AutoValueProcessor(com.google.auto.value.processor.AutoValueProcessor) JavaCompiler(javax.tools.JavaCompiler) AutoAnnotationProcessor(com.google.auto.value.processor.AutoAnnotationProcessor) EclipseCompiler(org.eclipse.jdt.internal.compiler.tool.EclipseCompiler) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ImmutableSet(com.google.common.collect.ImmutableSet) StandardJavaFileManager(javax.tools.StandardJavaFileManager) AutoBuilderProcessor(com.google.auto.value.processor.AutoBuilderProcessor) File(java.io.File)

Aggregations

AutoAnnotationProcessor (com.google.auto.value.processor.AutoAnnotationProcessor)1 AutoBuilderProcessor (com.google.auto.value.processor.AutoBuilderProcessor)1 AutoOneOfProcessor (com.google.auto.value.processor.AutoOneOfProcessor)1 AutoValueProcessor (com.google.auto.value.processor.AutoValueProcessor)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)1 File (java.io.File)1 JavaCompiler (javax.tools.JavaCompiler)1 StandardJavaFileManager (javax.tools.StandardJavaFileManager)1 EclipseCompiler (org.eclipse.jdt.internal.compiler.tool.EclipseCompiler)1