Kapt3: Add 'useLightAnalysis' option to compiler and Gradle plugins
This commit is contained in:
committed by
Yan Zhulanow
parent
e4de840b8a
commit
c2013c4d03
+1
@@ -162,6 +162,7 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pluginOptions += SubpluginOption("aptOnly", "true")
|
pluginOptions += SubpluginOption("aptOnly", "true")
|
||||||
|
pluginOptions += SubpluginOption("useLightAnalysis", "${kaptExtension.useLightAnalysis}")
|
||||||
|
|
||||||
if (project.hasProperty(VERBOSE_OPTION_NAME) && project.property(VERBOSE_OPTION_NAME) == "true") {
|
if (project.hasProperty(VERBOSE_OPTION_NAME) && project.property(VERBOSE_OPTION_NAME) == "true") {
|
||||||
pluginOptions += SubpluginOption("verbose", "true")
|
pluginOptions += SubpluginOption("verbose", "true")
|
||||||
|
|||||||
+2
@@ -26,6 +26,8 @@ open class KaptExtension {
|
|||||||
|
|
||||||
open var inheritedAnnotations: Boolean = true
|
open var inheritedAnnotations: Boolean = true
|
||||||
|
|
||||||
|
open var useLightAnalysis: Boolean = true
|
||||||
|
|
||||||
private var closure: Closure<*>? = null
|
private var closure: Closure<*>? = null
|
||||||
|
|
||||||
open fun arguments(closure: Closure<*>) {
|
open fun arguments(closure: Closure<*>) {
|
||||||
|
|||||||
@@ -47,10 +47,14 @@ class ClasspathBasedKapt3Extension(
|
|||||||
val stubsOutputDir: File?,
|
val stubsOutputDir: File?,
|
||||||
options: Map<String, String>,
|
options: Map<String, String>,
|
||||||
aptOnly: Boolean,
|
aptOnly: Boolean,
|
||||||
|
val useLightAnalysis: Boolean,
|
||||||
pluginInitializedTime: Long,
|
pluginInitializedTime: Long,
|
||||||
logger: KaptLogger
|
logger: KaptLogger
|
||||||
) : AbstractKapt3Extension(annotationProcessingClasspath, javaSourceRoots, sourcesOutputDir,
|
) : AbstractKapt3Extension(annotationProcessingClasspath, javaSourceRoots, sourcesOutputDir,
|
||||||
classFilesOutputDir, options, aptOnly, pluginInitializedTime, logger) {
|
classFilesOutputDir, options, aptOnly, pluginInitializedTime, logger) {
|
||||||
|
override val analyzePartially: Boolean
|
||||||
|
get() = useLightAnalysis
|
||||||
|
|
||||||
override fun loadProcessors(): List<Processor> {
|
override fun loadProcessors(): List<Processor> {
|
||||||
val classLoader = URLClassLoader(annotationProcessingClasspath.map { it.toURI().toURL() }.toTypedArray())
|
val classLoader = URLClassLoader(annotationProcessingClasspath.map { it.toURI().toURL() }.toTypedArray())
|
||||||
val processors = ServiceLoader.load(Processor::class.java, classLoader).toList()
|
val processors = ServiceLoader.load(Processor::class.java, classLoader).toList()
|
||||||
|
|||||||
@@ -56,6 +56,9 @@ object Kapt3ConfigurationKeys {
|
|||||||
|
|
||||||
val APT_ONLY: CompilerConfigurationKey<String> =
|
val APT_ONLY: CompilerConfigurationKey<String> =
|
||||||
CompilerConfigurationKey.create<String>("do only annotation processing")
|
CompilerConfigurationKey.create<String>("do only annotation processing")
|
||||||
|
|
||||||
|
val USE_LIGHT_ANALYSIS: CompilerConfigurationKey<String> =
|
||||||
|
CompilerConfigurationKey.create<String>("do not analyze declaration bodies if can")
|
||||||
}
|
}
|
||||||
|
|
||||||
class Kapt3CommandLineProcessor : CommandLineProcessor {
|
class Kapt3CommandLineProcessor : CommandLineProcessor {
|
||||||
@@ -84,13 +87,16 @@ class Kapt3CommandLineProcessor : CommandLineProcessor {
|
|||||||
|
|
||||||
val APT_ONLY_OPTION: CliOption =
|
val APT_ONLY_OPTION: CliOption =
|
||||||
CliOption("aptOnly", "true | false", "Run only annotation processing, do not compile Kotlin files", required = false)
|
CliOption("aptOnly", "true | false", "Run only annotation processing, do not compile Kotlin files", required = false)
|
||||||
|
|
||||||
|
val USE_LIGHT_ANALYSIS_OPTION: CliOption =
|
||||||
|
CliOption("useLightAnalysis", "true | false", "Do not analyze declaration bodies if can", required = false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val pluginId: String = ANNOTATION_PROCESSING_COMPILER_PLUGIN_ID
|
override val pluginId: String = ANNOTATION_PROCESSING_COMPILER_PLUGIN_ID
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
private fun <T> CompilerConfiguration.appendList(option: CompilerConfigurationKey<List<T>>, value: T) {
|
private fun <T> CompilerConfiguration.appendList(option: CompilerConfigurationKey<List<T>>, value: T) {
|
||||||
val paths = getList(option).toMutableList()
|
val paths = getList(option).toMutableList()
|
||||||
@@ -107,6 +113,7 @@ class Kapt3CommandLineProcessor : CommandLineProcessor {
|
|||||||
STUBS_OUTPUT_DIR_OPTION -> configuration.put(Kapt3ConfigurationKeys.STUBS_OUTPUT_DIR, value)
|
STUBS_OUTPUT_DIR_OPTION -> configuration.put(Kapt3ConfigurationKeys.STUBS_OUTPUT_DIR, value)
|
||||||
VERBOSE_MODE_OPTION -> configuration.put(Kapt3ConfigurationKeys.VERBOSE_MODE, value)
|
VERBOSE_MODE_OPTION -> configuration.put(Kapt3ConfigurationKeys.VERBOSE_MODE, value)
|
||||||
APT_ONLY_OPTION -> configuration.put(Kapt3ConfigurationKeys.APT_ONLY, value)
|
APT_ONLY_OPTION -> configuration.put(Kapt3ConfigurationKeys.APT_ONLY, value)
|
||||||
|
USE_LIGHT_ANALYSIS_OPTION -> configuration.put(Kapt3ConfigurationKeys.USE_LIGHT_ANALYSIS, value)
|
||||||
else -> throw CliOptionProcessingException("Unknown option: ${option.name}")
|
else -> throw CliOptionProcessingException("Unknown option: ${option.name}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,6 +144,7 @@ class Kapt3ComponentRegistrar : ComponentRegistrar {
|
|||||||
|
|
||||||
val isVerbose = configuration.get(Kapt3ConfigurationKeys.VERBOSE_MODE) == "true"
|
val isVerbose = configuration.get(Kapt3ConfigurationKeys.VERBOSE_MODE) == "true"
|
||||||
val isAptOnly = configuration.get(Kapt3ConfigurationKeys.APT_ONLY) == "true"
|
val isAptOnly = configuration.get(Kapt3ConfigurationKeys.APT_ONLY) == "true"
|
||||||
|
val useLightAnalysis = configuration.get(Kapt3ConfigurationKeys.USE_LIGHT_ANALYSIS) == "true"
|
||||||
|
|
||||||
Extensions.getRootArea().getExtensionPoint(DefaultErrorMessages.Extension.EP_NAME).registerExtension(DefaultErrorMessagesKapt3())
|
Extensions.getRootArea().getExtensionPoint(DefaultErrorMessages.Extension.EP_NAME).registerExtension(DefaultErrorMessagesKapt3())
|
||||||
|
|
||||||
@@ -154,7 +162,7 @@ class Kapt3ComponentRegistrar : ComponentRegistrar {
|
|||||||
|
|
||||||
val kapt3AnalysisCompletedHandlerExtension = ClasspathBasedKapt3Extension(
|
val kapt3AnalysisCompletedHandlerExtension = ClasspathBasedKapt3Extension(
|
||||||
classpath, javaSourceRoots, sourcesOutputDir, classFilesOutputDir, stubsOutputDir, apOptions,
|
classpath, javaSourceRoots, sourcesOutputDir, classFilesOutputDir, stubsOutputDir, apOptions,
|
||||||
isAptOnly, System.currentTimeMillis(), logger)
|
isAptOnly, useLightAnalysis, System.currentTimeMillis(), logger)
|
||||||
AnalysisHandlerExtension.registerExtension(project, kapt3AnalysisCompletedHandlerExtension)
|
AnalysisHandlerExtension.registerExtension(project, kapt3AnalysisCompletedHandlerExtension)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user