diff --git a/src/python/pants/backend/jvm/subsystems/zinc.py b/src/python/pants/backend/jvm/subsystems/zinc.py index 45d275bf8d4..b12cde60cca 100644 --- a/src/python/pants/backend/jvm/subsystems/zinc.py +++ b/src/python/pants/backend/jvm/subsystems/zinc.py @@ -49,13 +49,17 @@ def register_options(cls, register): Shader.exclude_package('scala', recursive=True), Shader.exclude_package('xsbt', recursive=True), Shader.exclude_package('xsbti', recursive=True), + # Unfortunately, is loaded reflectively by the compiler. + Shader.exclude_package('org.apache.logging.log4j', recursive=True), ] cls.register_jvm_tool(register, Zinc.ZINC_COMPILER_TOOL_NAME, classpath=[ JarDependency('org.pantsbuild', 'zinc-compiler_2.11', '0.0.5'), - ]) + ], + main=Zinc.ZINC_COMPILE_MAIN, + custom_rules=shader_rules) cls.register_jvm_tool(register, 'compiler-bridge', @@ -85,7 +89,7 @@ def register_options(cls, register): @classmethod def _zinc(cls, products): - return cls.tool_classpath_from_products(products, Zinc.ZINC_COMPILER_TOOL_NAME, cls.options_scope) + return cls.tool_jar_from_products(products, Zinc.ZINC_COMPILER_TOOL_NAME, cls.options_scope) @classmethod def _compiler_bridge(cls, products): diff --git a/src/python/pants/backend/jvm/tasks/jvm_compile/zinc/zinc_compile.py b/src/python/pants/backend/jvm/tasks/jvm_compile/zinc/zinc_compile.py index cc675715abc..b8ba7ab69c4 100644 --- a/src/python/pants/backend/jvm/tasks/jvm_compile/zinc/zinc_compile.py +++ b/src/python/pants/backend/jvm/tasks/jvm_compile/zinc/zinc_compile.py @@ -268,7 +268,7 @@ def _zinc_cache_dir(self): than compiling it. """ hasher = sha1() - for cp_entry in self._zinc.zinc + [self._zinc.compiler_interface, self._zinc.compiler_bridge]: + for cp_entry in [self._zinc.zinc, self._zinc.compiler_interface, self._zinc.compiler_bridge]: hasher.update(os.path.relpath(cp_entry, self.get_options().pants_workdir)) key = hasher.hexdigest()[:12] return os.path.join(self.get_options().pants_bootstrapdir, 'zinc', key) @@ -353,7 +353,7 @@ def compile(self, ctx, args, classpath, upstream_analysis, fp.write(arg) fp.write(b'\n') - if self.runjava(classpath=self._zinc.zinc, + if self.runjava(classpath=[self._zinc.zinc], main=Zinc.ZINC_COMPILE_MAIN, jvm_options=jvm_options, args=zinc_args, diff --git a/testprojects/3rdparty/com/google/guava/BUILD b/testprojects/3rdparty/com/google/guava/BUILD new file mode 100644 index 00000000000..0d477ba0437 --- /dev/null +++ b/testprojects/3rdparty/com/google/guava/BUILD @@ -0,0 +1,7 @@ +# NB: This is an intentionally ancient guava to attempt to flush out classpath collisions +# with the compiler. +jar_library(name='ancient-guava', + jars=[ + jar('com.google.guava', 'guava', '10.0') + ]) + diff --git a/testprojects/src/java/org/pantsbuild/testproject/annotation/processor/BUILD b/testprojects/src/java/org/pantsbuild/testproject/annotation/processor/BUILD index 6e2d3ab4130..4063f0585db 100644 --- a/testprojects/src/java/org/pantsbuild/testproject/annotation/processor/BUILD +++ b/testprojects/src/java/org/pantsbuild/testproject/annotation/processor/BUILD @@ -7,7 +7,9 @@ annotation_processor( sources=globs('*.java'), processors=['org.pantsbuild.testproject.annotation.processor.ResourceMappingProcessor'], dependencies=[ - '3rdparty:guava', + # NB: We use the oldest guava we can stomach here, in order to flush out classpath + # collisions between the compiler and annotation processors. + 'testprojects/3rdparty/com/google/guava:ancient-guava', ], ) diff --git a/testprojects/src/java/org/pantsbuild/testproject/annotation/processor/ResourceMappingProcessor.java b/testprojects/src/java/org/pantsbuild/testproject/annotation/processor/ResourceMappingProcessor.java index 8ac55597798..bcad553a33e 100644 --- a/testprojects/src/java/org/pantsbuild/testproject/annotation/processor/ResourceMappingProcessor.java +++ b/testprojects/src/java/org/pantsbuild/testproject/annotation/processor/ResourceMappingProcessor.java @@ -4,7 +4,6 @@ package org.pantsbuild.testproject.annotation.processor; import com.google.common.collect.ImmutableSet; -import com.google.common.io.Closer; import java.io.Closeable; import java.io.IOException; import java.io.PrintWriter; @@ -120,24 +119,25 @@ public boolean process(Set annotations, RoundEnvironment } FileObject outputFile = createResourceOrDie("" /* no package */, REPORT_FILE_NAME); - Closer closer = Closer.create(); try { - Set typeNames = new HashSet(); - PrintWriter writer = closer.register(new PrintWriter(outputFile.openWriter())); - for (TypeElement annotation : annotations) { - Set annotatedElements = roundEnv.getElementsAnnotatedWith(annotation); - Set typeElements = ElementFilter.typesIn(annotatedElements); - for (TypeElement typeElement : typeElements) { - String typeName = elementUtils.getBinaryName(typeElement).toString(); - typeNames.add(typeName); - writer.println(typeName); + PrintWriter writer = new PrintWriter(outputFile.openWriter()); + try { + Set typeNames = new HashSet(); + for (TypeElement annotation : annotations) { + Set annotatedElements = roundEnv.getElementsAnnotatedWith(annotation); + Set typeElements = ElementFilter.typesIn(annotatedElements); + for (TypeElement typeElement : typeElements) { + String typeName = elementUtils.getBinaryName(typeElement).toString(); + typeNames.add(typeName); + writer.println(typeName); + } } - } - - closer.close(); - writeResourceMapping(typeNames, outputFile); - log(Diagnostic.Kind.NOTE, "Generated resource '%s'", outputFile.toUri()); + writeResourceMapping(typeNames, outputFile); + log(Diagnostic.Kind.NOTE, "Generated resource '%s'", outputFile.toUri()); + } finally { + writer.close(); + } } catch (IOException e) { throw new RuntimeException(e); }