Kapt: allow to use Kapt from compileBunchOfSources()
This commit is contained in:
+33
-23
@@ -128,28 +128,8 @@ object KotlinToJVMBytecodeCompiler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val targetDescription = "in targets [" + chunk.joinToString { input -> input.getModuleName() + "-" + input.getModuleType() } + "]"
|
val targetDescription = "in targets [" + chunk.joinToString { input -> input.getModuleName() + "-" + input.getModuleType() } + "]"
|
||||||
var result = analyze(environment, targetDescription)
|
|
||||||
|
val result = repeatAnalysisIfNeeded(analyze(environment, targetDescription), environment, targetDescription)
|
||||||
if (result is AnalysisResult.RetryWithAdditionalJavaRoots) {
|
|
||||||
val oldReadOnlyValue = projectConfiguration.isReadOnly
|
|
||||||
projectConfiguration.isReadOnly = false
|
|
||||||
projectConfiguration.addJavaSourceRoots(result.additionalJavaRoots)
|
|
||||||
projectConfiguration.isReadOnly = oldReadOnlyValue
|
|
||||||
|
|
||||||
if (result.addToEnvironment) {
|
|
||||||
environment.updateClasspath(result.additionalJavaRoots.map { JavaSourceRoot(it, null) })
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear package caches (see KotlinJavaPsiFacade)
|
|
||||||
(PsiManager.getInstance(environment.project).modificationTracker as? PsiModificationTrackerImpl)?.incCounter()
|
|
||||||
|
|
||||||
// Clear all diagnostic messages
|
|
||||||
projectConfiguration[CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY]?.clear()
|
|
||||||
|
|
||||||
// Repeat analysis with additional Java roots (kapt generated sources)
|
|
||||||
result = analyze(environment, targetDescription)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result == null || !result.shouldGenerateCode) return false
|
if (result == null || !result.shouldGenerateCode) return false
|
||||||
|
|
||||||
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled()
|
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled()
|
||||||
@@ -264,6 +244,36 @@ object KotlinToJVMBytecodeCompiler {
|
|||||||
|
|
||||||
return ExitCode.OK
|
return ExitCode.OK
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun repeatAnalysisIfNeeded(
|
||||||
|
result: AnalysisResult?,
|
||||||
|
environment: KotlinCoreEnvironment,
|
||||||
|
targetDescription: String?
|
||||||
|
): AnalysisResult? {
|
||||||
|
if (result is AnalysisResult.RetryWithAdditionalJavaRoots) {
|
||||||
|
val configuration = environment.configuration
|
||||||
|
|
||||||
|
val oldReadOnlyValue = configuration.isReadOnly
|
||||||
|
configuration.isReadOnly = false
|
||||||
|
configuration.addJavaSourceRoots(result.additionalJavaRoots)
|
||||||
|
configuration.isReadOnly = oldReadOnlyValue
|
||||||
|
|
||||||
|
if (result.addToEnvironment) {
|
||||||
|
environment.updateClasspath(result.additionalJavaRoots.map { JavaSourceRoot(it, null) })
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear package caches (see KotlinJavaPsiFacade)
|
||||||
|
(PsiManager.getInstance(environment.project).modificationTracker as? PsiModificationTrackerImpl)?.incCounter()
|
||||||
|
|
||||||
|
// Clear all diagnostic messages
|
||||||
|
configuration[CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY]?.clear()
|
||||||
|
|
||||||
|
// Repeat analysis with additional Java roots (kapt generated sources)
|
||||||
|
return analyze(environment, targetDescription)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
private fun reportExceptionFromScript(exception: Throwable) {
|
private fun reportExceptionFromScript(exception: Throwable) {
|
||||||
// expecting InvocationTargetException from constructor invocation with cause that describes the actual cause
|
// expecting InvocationTargetException from constructor invocation with cause that describes the actual cause
|
||||||
@@ -380,7 +390,7 @@ object KotlinToJVMBytecodeCompiler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun analyzeAndGenerate(environment: KotlinCoreEnvironment): GenerationState? {
|
fun analyzeAndGenerate(environment: KotlinCoreEnvironment): GenerationState? {
|
||||||
val result = analyze(environment, null) ?: return null
|
val result = repeatAnalysisIfNeeded(analyze(environment, null), environment, null) ?: return null
|
||||||
|
|
||||||
if (!result.shouldGenerateCode) return null
|
if (!result.shouldGenerateCode) return null
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -180,7 +180,7 @@ public class ExecuteKotlinScriptMojo extends AbstractMojo {
|
|||||||
|
|
||||||
KotlinCoreEnvironment environment = KotlinCoreEnvironment.createForProduction(rootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
|
KotlinCoreEnvironment environment = KotlinCoreEnvironment.createForProduction(rootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES);
|
||||||
|
|
||||||
GenerationState state = KotlinToJVMBytecodeCompiler.INSTANCE.analyzeAndGenerate(environment);
|
GenerationState state = KotlinToJVMBytecodeCompiler.INSTANCE.analyzeAndGenerate(environment, configuration);
|
||||||
|
|
||||||
if (state == null) {
|
if (state == null) {
|
||||||
throw new ScriptExecutionException(scriptFile, "compile error");
|
throw new ScriptExecutionException(scriptFile, "compile error");
|
||||||
|
|||||||
Reference in New Issue
Block a user