diff options
author | cushon <cushon@google.com> | 2020-01-14 12:54:12 -0800 |
---|---|---|
committer | Colin Decker <cgdecker@gmail.com> | 2020-01-16 15:02:02 -0500 |
commit | df803e51c0a3bd896ffd8c3934794bca908a58c2 (patch) | |
tree | 8f96f5f770df7cae68badbf7ccbbe451fef23b9c | |
parent | 7c214783620cc9e198db5265d430e8bb9c2f12ec (diff) | |
download | turbine-df803e51c0a3bd896ffd8c3934794bca908a58c2.tar.gz |
Allow sources to be empty with annotation processing enabled
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=289711077
-rw-r--r-- | java/com/google/turbine/binder/Binder.java | 2 | ||||
-rw-r--r-- | javatests/com/google/turbine/main/MainTest.java | 36 |
2 files changed, 37 insertions, 1 deletions
diff --git a/java/com/google/turbine/binder/Binder.java b/java/com/google/turbine/binder/Binder.java index 76cbd99..e779748 100644 --- a/java/com/google/turbine/binder/Binder.java +++ b/java/com/google/turbine/binder/Binder.java @@ -97,7 +97,7 @@ public class Binder { classpath, bootclasspath, moduleVersion); - if (!processorInfo.processors().isEmpty()) { + if (!processorInfo.processors().isEmpty() && !units.isEmpty()) { br = Processing.process( log, units, classpath, processorInfo, bootclasspath, br, moduleVersion); diff --git a/javatests/com/google/turbine/main/MainTest.java b/javatests/com/google/turbine/main/MainTest.java index be38d97..ea6f9a8 100644 --- a/javatests/com/google/turbine/main/MainTest.java +++ b/javatests/com/google/turbine/main/MainTest.java @@ -54,6 +54,7 @@ import java.util.jar.JarOutputStream; import java.util.jar.Manifest; import java.util.stream.Stream; import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.RoundEnvironment; import javax.annotation.processing.SupportedAnnotationTypes; import javax.lang.model.SourceVersion; @@ -365,4 +366,39 @@ public class MainTest { } return manifest.build(); } + + @SupportedAnnotationTypes("*") + public static class CrashyProcessor extends AbstractProcessor { + + @Override + public SourceVersion getSupportedSourceVersion() { + return SourceVersion.latestSupported(); + } + + @Override + public synchronized void init(ProcessingEnvironment processingEnv) { + throw new AssertionError(); + } + + @Override + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { + return false; + } + } + + @Test + public void noSourcesProcessing() throws IOException { + // Compilations with no sources shouldn't initialize annotation processors. + File gensrc = temporaryFolder.newFile("gensrc.jar"); + Main.compile( + optionsWithBootclasspath() + .setProcessors(ImmutableList.of(CrashyProcessor.class.getName())) + .setGensrcOutput(gensrc.toString()) + .build()); + try (JarFile jarFile = new JarFile(gensrc); + Stream<JarEntry> entries = jarFile.stream()) { + assertThat(entries.map(JarEntry::getName)) + .containsExactly("META-INF/", "META-INF/MANIFEST.MF"); + } + } } |