From 07df603a04491d704c8e817e06949ba0a9e047d0 Mon Sep 17 00:00:00 2001 From: Carter Kozak Date: Thu, 13 May 2021 13:57:57 -0400 Subject: [PATCH] Enable gradle incremental annotation processing for tritium-processor (#1085) Enable gradle incremental annotation processing for tritium-processor --- changelog/@unreleased/pr-1085.v2.yml | 5 +++++ tritium-processor/build.gradle | 3 --- .../processor/TritiumAnnotationProcessor.java | 13 +++++++++---- .../gradle/incremental.annotation.processors | 1 + .../services/javax.annotation.processing.Processor | 1 + 5 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 changelog/@unreleased/pr-1085.v2.yml create mode 100644 tritium-processor/src/main/resources/META-INF/gradle/incremental.annotation.processors create mode 100644 tritium-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor diff --git a/changelog/@unreleased/pr-1085.v2.yml b/changelog/@unreleased/pr-1085.v2.yml new file mode 100644 index 000000000..e1411fdae --- /dev/null +++ b/changelog/@unreleased/pr-1085.v2.yml @@ -0,0 +1,5 @@ +type: improvement +improvement: + description: Enable gradle incremental annotation processing for tritium-processor + links: + - https://github.com/palantir/tritium/pull/1085 diff --git a/tritium-processor/build.gradle b/tritium-processor/build.gradle index 4ff28bbe8..1196fef3b 100644 --- a/tritium-processor/build.gradle +++ b/tritium-processor/build.gradle @@ -14,9 +14,6 @@ dependencies { compile 'com.google.code.findbugs:jsr305' compile 'com.palantir.safe-logging:preconditions' - annotationProcessor 'com.google.auto.service:auto-service' - compileOnly 'com.google.auto.service:auto-service-annotations' - testImplementation 'com.google.testing.compile:compile-testing' testImplementation 'com.google.guava:guava' testImplementation 'org.assertj:assertj-core' diff --git a/tritium-processor/src/main/java/com/palantir/tritium/processor/TritiumAnnotationProcessor.java b/tritium-processor/src/main/java/com/palantir/tritium/processor/TritiumAnnotationProcessor.java index c9343b974..35acf6279 100644 --- a/tritium-processor/src/main/java/com/palantir/tritium/processor/TritiumAnnotationProcessor.java +++ b/tritium-processor/src/main/java/com/palantir/tritium/processor/TritiumAnnotationProcessor.java @@ -17,7 +17,6 @@ package com.palantir.tritium.processor; import com.google.auto.common.GeneratedAnnotations; -import com.google.auto.service.AutoService; import com.google.common.base.Throwables; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; @@ -53,7 +52,6 @@ import javax.annotation.processing.Filer; import javax.annotation.processing.Messager; import javax.annotation.processing.ProcessingEnvironment; -import javax.annotation.processing.Processor; import javax.annotation.processing.RoundEnvironment; import javax.lang.model.SourceVersion; import javax.lang.model.element.Element; @@ -72,7 +70,6 @@ import javax.lang.model.util.Types; import javax.tools.Diagnostic.Kind; -@AutoService(Processor.class) public final class TritiumAnnotationProcessor extends AbstractProcessor { private static final String DELEGATE_NAME = "delegate"; @@ -213,7 +210,9 @@ private JavaFile generate( } } - TypeSpec.Builder specBuilder = TypeSpec.classBuilder(className).addModifiers(Modifier.PUBLIC, Modifier.FINAL); + TypeSpec.Builder specBuilder = TypeSpec.classBuilder(className) + .addModifiers(Modifier.PUBLIC, Modifier.FINAL) + .addOriginatingElement(typeElement); GeneratedAnnotations.generatedAnnotation(elements, SourceVersion.latest()) .ifPresent(te -> specBuilder.addAnnotation(AnnotationSpec.builder(ClassName.get(te)) @@ -328,6 +327,12 @@ public Void visitExecutable(ExecutableElement method, Void _param) { .addStatement("return builder(delegate).withTaggedMetrics(registry).withTracing().build()") .build()); + if (specBuilder.originatingElements.size() != 1) { + messager.printMessage( + Kind.ERROR, + "The generated type must have exactly one originating element: " + specBuilder.originatingElements, + typeElement); + } return JavaFile.builder(packageName, specBuilder.build()) .skipJavaLangImports(true) .indent(" ") diff --git a/tritium-processor/src/main/resources/META-INF/gradle/incremental.annotation.processors b/tritium-processor/src/main/resources/META-INF/gradle/incremental.annotation.processors new file mode 100644 index 000000000..33cc61eb3 --- /dev/null +++ b/tritium-processor/src/main/resources/META-INF/gradle/incremental.annotation.processors @@ -0,0 +1 @@ +com.palantir.tritium.processor.TritiumAnnotationProcessor,ISOLATING diff --git a/tritium-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/tritium-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor new file mode 100644 index 000000000..81bbe8e0a --- /dev/null +++ b/tritium-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -0,0 +1 @@ +com.palantir.tritium.processor.TritiumAnnotationProcessor