Kapt3: Support 'processors' option in the compiler plugin (KT-8558)
Support specifying qualified names of annotation processors in the kapt3 compiler plugin (feature-parity with javac).
This commit is contained in:
@@ -51,13 +51,14 @@ class ClasspathBasedKapt3Extension(
|
|||||||
stubsOutputDir: File,
|
stubsOutputDir: File,
|
||||||
incrementalDataOutputDir: File?,
|
incrementalDataOutputDir: File?,
|
||||||
options: Map<String, String>,
|
options: Map<String, String>,
|
||||||
|
annotationProcessors: String,
|
||||||
aptOnly: Boolean,
|
aptOnly: Boolean,
|
||||||
val useLightAnalysis: Boolean,
|
val useLightAnalysis: Boolean,
|
||||||
correctErrorTypes: Boolean,
|
correctErrorTypes: Boolean,
|
||||||
pluginInitializedTime: Long,
|
pluginInitializedTime: Long,
|
||||||
logger: KaptLogger
|
logger: KaptLogger
|
||||||
) : AbstractKapt3Extension(compileClasspath, annotationProcessingClasspath, javaSourceRoots, sourcesOutputDir,
|
) : AbstractKapt3Extension(compileClasspath, annotationProcessingClasspath, javaSourceRoots, sourcesOutputDir,
|
||||||
classFilesOutputDir, stubsOutputDir, incrementalDataOutputDir, options,
|
classFilesOutputDir, stubsOutputDir, incrementalDataOutputDir, options, annotationProcessors,
|
||||||
aptOnly, pluginInitializedTime, logger, correctErrorTypes) {
|
aptOnly, pluginInitializedTime, logger, correctErrorTypes) {
|
||||||
override val analyzePartially: Boolean
|
override val analyzePartially: Boolean
|
||||||
get() = useLightAnalysis
|
get() = useLightAnalysis
|
||||||
@@ -102,6 +103,7 @@ abstract class AbstractKapt3Extension(
|
|||||||
val stubsOutputDir: File,
|
val stubsOutputDir: File,
|
||||||
val incrementalDataOutputDir: File?,
|
val incrementalDataOutputDir: File?,
|
||||||
val options: Map<String, String>,
|
val options: Map<String, String>,
|
||||||
|
val annotationProcessors: String,
|
||||||
val aptOnly: Boolean,
|
val aptOnly: Boolean,
|
||||||
val pluginInitializedTime: Long,
|
val pluginInitializedTime: Long,
|
||||||
val logger: KaptLogger,
|
val logger: KaptLogger,
|
||||||
@@ -144,7 +146,7 @@ abstract class AbstractKapt3Extension(
|
|||||||
val (annotationProcessingTime) = measureTimeMillis {
|
val (annotationProcessingTime) = measureTimeMillis {
|
||||||
kaptContext.doAnnotationProcessing(
|
kaptContext.doAnnotationProcessing(
|
||||||
javaSourceFiles, processors, compileClasspath, annotationProcessingClasspath,
|
javaSourceFiles, processors, compileClasspath, annotationProcessingClasspath,
|
||||||
sourcesOutputDir, classFilesOutputDir)
|
annotationProcessors, sourcesOutputDir, classFilesOutputDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info { "Annotation processing took $annotationProcessingTime ms" }
|
logger.info { "Annotation processing took $annotationProcessingTime ms" }
|
||||||
|
|||||||
@@ -67,6 +67,9 @@ object Kapt3ConfigurationKeys {
|
|||||||
val APT_OPTIONS: CompilerConfigurationKey<String> =
|
val APT_OPTIONS: CompilerConfigurationKey<String> =
|
||||||
CompilerConfigurationKey.create<String>("annotation processing options")
|
CompilerConfigurationKey.create<String>("annotation processing options")
|
||||||
|
|
||||||
|
val ANNOTATION_PROCESSORS: CompilerConfigurationKey<String> =
|
||||||
|
CompilerConfigurationKey.create<String>("annotation processor qualified names")
|
||||||
|
|
||||||
val VERBOSE_MODE: CompilerConfigurationKey<String> =
|
val VERBOSE_MODE: CompilerConfigurationKey<String> =
|
||||||
CompilerConfigurationKey.create<String>("verbose mode")
|
CompilerConfigurationKey.create<String>("verbose mode")
|
||||||
|
|
||||||
@@ -104,6 +107,10 @@ class Kapt3CommandLineProcessor : CommandLineProcessor {
|
|||||||
CliOption("apoptions", "options map", "Encoded annotation processor options",
|
CliOption("apoptions", "options map", "Encoded annotation processor options",
|
||||||
required = false, allowMultipleOccurrences = false)
|
required = false, allowMultipleOccurrences = false)
|
||||||
|
|
||||||
|
val ANNOTATION_PROCESSORS_OPTION: CliOption =
|
||||||
|
CliOption("processors", "<fqname,[fqname2,...]>", "Annotation processor qualified names",
|
||||||
|
required = false, allowMultipleOccurrences = true)
|
||||||
|
|
||||||
val VERBOSE_MODE_OPTION: CliOption =
|
val VERBOSE_MODE_OPTION: CliOption =
|
||||||
CliOption("verbose", "true | false", "Enable verbose output", required = false)
|
CliOption("verbose", "true | false", "Enable verbose output", required = false)
|
||||||
|
|
||||||
@@ -122,11 +129,12 @@ class Kapt3CommandLineProcessor : CommandLineProcessor {
|
|||||||
override val pluginOptions: Collection<CliOption> =
|
override val pluginOptions: Collection<CliOption> =
|
||||||
listOf(SOURCE_OUTPUT_DIR_OPTION, ANNOTATION_PROCESSOR_CLASSPATH_OPTION, APT_OPTIONS_OPTION,
|
listOf(SOURCE_OUTPUT_DIR_OPTION, ANNOTATION_PROCESSOR_CLASSPATH_OPTION, APT_OPTIONS_OPTION,
|
||||||
CLASS_OUTPUT_DIR_OPTION, VERBOSE_MODE_OPTION, STUBS_OUTPUT_DIR_OPTION, APT_ONLY_OPTION,
|
CLASS_OUTPUT_DIR_OPTION, VERBOSE_MODE_OPTION, STUBS_OUTPUT_DIR_OPTION, APT_ONLY_OPTION,
|
||||||
USE_LIGHT_ANALYSIS_OPTION, CORRECT_ERROR_TYPES_OPTION)
|
USE_LIGHT_ANALYSIS_OPTION, CORRECT_ERROR_TYPES_OPTION, ANNOTATION_PROCESSORS_OPTION)
|
||||||
|
|
||||||
override fun processOption(option: CliOption, value: String, configuration: CompilerConfiguration) {
|
override fun processOption(option: CliOption, value: String, configuration: CompilerConfiguration) {
|
||||||
when (option) {
|
when (option) {
|
||||||
ANNOTATION_PROCESSOR_CLASSPATH_OPTION -> configuration.appendList(ANNOTATION_PROCESSOR_CLASSPATH, value)
|
ANNOTATION_PROCESSOR_CLASSPATH_OPTION -> configuration.appendList(ANNOTATION_PROCESSOR_CLASSPATH, value)
|
||||||
|
ANNOTATION_PROCESSORS_OPTION -> configuration.put(Kapt3ConfigurationKeys.ANNOTATION_PROCESSORS, value)
|
||||||
APT_OPTIONS_OPTION -> configuration.put(Kapt3ConfigurationKeys.APT_OPTIONS, value)
|
APT_OPTIONS_OPTION -> configuration.put(Kapt3ConfigurationKeys.APT_OPTIONS, value)
|
||||||
SOURCE_OUTPUT_DIR_OPTION -> configuration.put(Kapt3ConfigurationKeys.SOURCE_OUTPUT_DIR, value)
|
SOURCE_OUTPUT_DIR_OPTION -> configuration.put(Kapt3ConfigurationKeys.SOURCE_OUTPUT_DIR, value)
|
||||||
CLASS_OUTPUT_DIR_OPTION -> configuration.put(Kapt3ConfigurationKeys.CLASS_OUTPUT_DIR, value)
|
CLASS_OUTPUT_DIR_OPTION -> configuration.put(Kapt3ConfigurationKeys.CLASS_OUTPUT_DIR, value)
|
||||||
@@ -172,6 +180,8 @@ class Kapt3ComponentRegistrar : ComponentRegistrar {
|
|||||||
val stubsOutputDir = configuration.get(Kapt3ConfigurationKeys.STUBS_OUTPUT_DIR)?.let(::File)
|
val stubsOutputDir = configuration.get(Kapt3ConfigurationKeys.STUBS_OUTPUT_DIR)?.let(::File)
|
||||||
val incrementalDataOutputDir = configuration.get(Kapt3ConfigurationKeys.INCREMENTAL_DATA_OUTPUT_DIR)?.let(::File)
|
val incrementalDataOutputDir = configuration.get(Kapt3ConfigurationKeys.INCREMENTAL_DATA_OUTPUT_DIR)?.let(::File)
|
||||||
|
|
||||||
|
val annotationProcessors = configuration.get(Kapt3ConfigurationKeys.ANNOTATION_PROCESSORS) ?: ""
|
||||||
|
|
||||||
val apClasspath = configuration.get(ANNOTATION_PROCESSOR_CLASSPATH)?.map(::File)
|
val apClasspath = configuration.get(ANNOTATION_PROCESSOR_CLASSPATH)?.map(::File)
|
||||||
|
|
||||||
if (sourcesOutputDir == null || classFilesOutputDir == null || apClasspath == null || stubsOutputDir == null) {
|
if (sourcesOutputDir == null || classFilesOutputDir == null || apClasspath == null || stubsOutputDir == null) {
|
||||||
@@ -215,13 +225,14 @@ class Kapt3ComponentRegistrar : ComponentRegistrar {
|
|||||||
logger.info("Incremental data output directory: $incrementalDataOutputDir")
|
logger.info("Incremental data output directory: $incrementalDataOutputDir")
|
||||||
logger.info("Compile classpath: " + compileClasspath.joinToString())
|
logger.info("Compile classpath: " + compileClasspath.joinToString())
|
||||||
logger.info("Annotation processing classpath: " + apClasspath.joinToString())
|
logger.info("Annotation processing classpath: " + apClasspath.joinToString())
|
||||||
|
logger.info("Annotation processors: " + annotationProcessors)
|
||||||
logger.info("Java source roots: " + javaSourceRoots.joinToString())
|
logger.info("Java source roots: " + javaSourceRoots.joinToString())
|
||||||
logger.info("Options: $apOptions")
|
logger.info("Options: $apOptions")
|
||||||
}
|
}
|
||||||
|
|
||||||
val kapt3AnalysisCompletedHandlerExtension = ClasspathBasedKapt3Extension(
|
val kapt3AnalysisCompletedHandlerExtension = ClasspathBasedKapt3Extension(
|
||||||
compileClasspath, apClasspath, javaSourceRoots, sourcesOutputDir, classFilesOutputDir,
|
compileClasspath, apClasspath, javaSourceRoots, sourcesOutputDir, classFilesOutputDir,
|
||||||
stubsOutputDir, incrementalDataOutputDir, apOptions,
|
stubsOutputDir, incrementalDataOutputDir, apOptions, annotationProcessors,
|
||||||
isAptOnly, useLightAnalysis, correctErrorTypes, System.currentTimeMillis(), logger)
|
isAptOnly, useLightAnalysis, correctErrorTypes, System.currentTimeMillis(), logger)
|
||||||
AnalysisHandlerExtension.registerExtension(project, kapt3AnalysisCompletedHandlerExtension)
|
AnalysisHandlerExtension.registerExtension(project, kapt3AnalysisCompletedHandlerExtension)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ fun KaptContext.doAnnotationProcessing(
|
|||||||
processors: List<Processor>,
|
processors: List<Processor>,
|
||||||
compileClasspath: List<File>,
|
compileClasspath: List<File>,
|
||||||
annotationProcessingClasspath: List<File>,
|
annotationProcessingClasspath: List<File>,
|
||||||
|
annotationProcessors: String,
|
||||||
sourcesOutputDir: File,
|
sourcesOutputDir: File,
|
||||||
classesOutputDir: File,
|
classesOutputDir: File,
|
||||||
additionalSources: JavacList<JCTree.JCCompilationUnit> = JavacList.nil(),
|
additionalSources: JavacList<JCTree.JCCompilationUnit> = JavacList.nil(),
|
||||||
@@ -49,6 +50,7 @@ fun KaptContext.doAnnotationProcessing(
|
|||||||
|
|
||||||
put(Option.CLASSPATH, compileClasspath.joinToString(File.pathSeparator) { it.canonicalPath })
|
put(Option.CLASSPATH, compileClasspath.joinToString(File.pathSeparator) { it.canonicalPath })
|
||||||
put(Option.PROCESSORPATH, annotationProcessingClasspath.joinToString(File.pathSeparator) { it.canonicalPath })
|
put(Option.PROCESSORPATH, annotationProcessingClasspath.joinToString(File.pathSeparator) { it.canonicalPath })
|
||||||
|
put(Option.PROCESSOR, annotationProcessors)
|
||||||
put(Option.S, sourcesOutputDir.canonicalPath)
|
put(Option.S, sourcesOutputDir.canonicalPath)
|
||||||
put(Option.D, classesOutputDir.canonicalPath)
|
put(Option.D, classesOutputDir.canonicalPath)
|
||||||
put(Option.ENCODING, "UTF-8")
|
put(Option.ENCODING, "UTF-8")
|
||||||
|
|||||||
+1
-1
@@ -162,7 +162,7 @@ abstract class AbstractKotlinKapt3IntegrationTest : CodegenTestCase() {
|
|||||||
incrementalDataOutputDir: File
|
incrementalDataOutputDir: File
|
||||||
) : AbstractKapt3Extension(PathUtil.getJdkClassesRoots() + PathUtil.getKotlinPathsForIdeaPlugin().runtimePath,
|
) : AbstractKapt3Extension(PathUtil.getJdkClassesRoots() + PathUtil.getKotlinPathsForIdeaPlugin().runtimePath,
|
||||||
emptyList(), javaSourceRoots, outputDir, outputDir,
|
emptyList(), javaSourceRoots, outputDir, outputDir,
|
||||||
stubsOutputDir, incrementalDataOutputDir, options, true, System.currentTimeMillis(),
|
stubsOutputDir, incrementalDataOutputDir, options, "", true, System.currentTimeMillis(),
|
||||||
KaptLogger(true), correctErrorTypes = true
|
KaptLogger(true), correctErrorTypes = true
|
||||||
) {
|
) {
|
||||||
internal var savedStubs: String? = null
|
internal var savedStubs: String? = null
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ abstract class AbstractKotlinKaptContextTest : AbstractKotlinKapt3Test() {
|
|||||||
try {
|
try {
|
||||||
kaptRunner.doAnnotationProcessing(emptyList(), listOf(JavaKaptContextTest.simpleProcessor()),
|
kaptRunner.doAnnotationProcessing(emptyList(), listOf(JavaKaptContextTest.simpleProcessor()),
|
||||||
compileClasspath = PathUtil.getJdkClassesRoots() + PathUtil.getKotlinPathsForIdeaPlugin().runtimePath,
|
compileClasspath = PathUtil.getJdkClassesRoots() + PathUtil.getKotlinPathsForIdeaPlugin().runtimePath,
|
||||||
annotationProcessingClasspath = emptyList(),
|
annotationProcessingClasspath = emptyList(), annotationProcessors = "",
|
||||||
sourcesOutputDir = sourceOutputDir, classesOutputDir = sourceOutputDir,
|
sourcesOutputDir = sourceOutputDir, classesOutputDir = sourceOutputDir,
|
||||||
additionalSources = compilationUnits, withJdk = true)
|
additionalSources = compilationUnits, withJdk = true)
|
||||||
|
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ class JavaKaptContextTest {
|
|||||||
listOf(processor),
|
listOf(processor),
|
||||||
emptyList(), // compile classpath
|
emptyList(), // compile classpath
|
||||||
emptyList(), // annotation processing classpath
|
emptyList(), // annotation processing classpath
|
||||||
|
"", // list of annotation processor qualified names
|
||||||
outputDir,
|
outputDir,
|
||||||
outputDir,
|
outputDir,
|
||||||
withJdk = true)
|
withJdk = true)
|
||||||
|
|||||||
Reference in New Issue
Block a user