[Gradle] Implement KotlinToolingDiagnosticsSetupAction
KT-61634
This commit is contained in:
committed by
Space Team
parent
1c568c2a10
commit
234e5735e3
+1
-44
@@ -30,11 +30,6 @@ import org.jetbrains.kotlin.gradle.internal.KOTLIN_COMPILER_EMBEDDABLE
|
||||
import org.jetbrains.kotlin.gradle.internal.KOTLIN_MODULE_GROUP
|
||||
import org.jetbrains.kotlin.gradle.logging.kotlinDebug
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformAndroidGradlePluginCompatibilityHealthCheck.runMultiplatformAndroidGradlePluginCompatibilityHealthCheckWhenAndroidIsApplied
|
||||
import org.jetbrains.kotlin.gradle.plugin.diagnostics.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.diagnostics.ToolingDiagnosticRenderingOptions
|
||||
import org.jetbrains.kotlin.gradle.plugin.diagnostics.UsesKotlinToolingDiagnostics
|
||||
import org.jetbrains.kotlin.gradle.plugin.diagnostics.kotlinToolingDiagnosticsCollectorProvider
|
||||
import org.jetbrains.kotlin.gradle.plugin.diagnostics.launchKotlinGradleProjectCheckers
|
||||
import org.jetbrains.kotlin.gradle.plugin.internal.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinUsages
|
||||
@@ -48,8 +43,8 @@ import org.jetbrains.kotlin.gradle.targets.js.KotlinWasmTargetAttribute
|
||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.DefaultUnameExecutorVariantFactory
|
||||
import org.jetbrains.kotlin.gradle.targets.js.nodejs.UnameExecutor
|
||||
import org.jetbrains.kotlin.gradle.targets.metadata.isKotlinGranularMetadataEnabled
|
||||
import org.jetbrains.kotlin.gradle.targets.native.internal.CInteropKlibLibraryElements
|
||||
import org.jetbrains.kotlin.gradle.targets.native.internal.CInteropCommonizerArtifactTypeAttribute
|
||||
import org.jetbrains.kotlin.gradle.targets.native.internal.CInteropKlibLibraryElements
|
||||
import org.jetbrains.kotlin.gradle.targets.native.internal.CommonizerTargetAttribute
|
||||
import org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompileTool
|
||||
import org.jetbrains.kotlin.gradle.testing.internal.KotlinTestsRegistry
|
||||
@@ -262,8 +257,6 @@ abstract class KotlinBasePluginWrapper : DefaultKotlinBasePlugin() {
|
||||
plugin.apply(project)
|
||||
|
||||
project.runKotlinProjectSetupActions()
|
||||
|
||||
project.setupDiagnosticsChecksAndReporting()
|
||||
}
|
||||
|
||||
internal open fun createTestRegistry(project: Project) = KotlinTestsRegistry(project)
|
||||
@@ -273,42 +266,6 @@ abstract class KotlinBasePluginWrapper : DefaultKotlinBasePlugin() {
|
||||
): Plugin<Project>
|
||||
}
|
||||
|
||||
private fun Project.setupDiagnosticsChecksAndReporting() {
|
||||
val collectorProvider = kotlinToolingDiagnosticsCollectorProvider
|
||||
val diagnosticRenderingOptions = ToolingDiagnosticRenderingOptions.forProject(this)
|
||||
|
||||
// Setup reporting from tasks
|
||||
tasks.withType(UsesKotlinToolingDiagnostics::class.java).configureEach {
|
||||
it.usesService(collectorProvider)
|
||||
it.toolingDiagnosticsCollector.value(collectorProvider)
|
||||
it.diagnosticRenderingOptions.set(diagnosticRenderingOptions)
|
||||
}
|
||||
|
||||
// Launch checkers. Note that they are invoked eagerly to give them a fine-grained
|
||||
// control over the lifecycle
|
||||
launchKotlinGradleProjectCheckers()
|
||||
|
||||
// Setup a task that will abort the build if errors will be reported. This task should be the first in the taskgraph
|
||||
project.locateOrRegisterCheckKotlinGradlePluginErrorsTask()
|
||||
|
||||
// Schedule diagnostics rendering
|
||||
launch {
|
||||
configurationResult.await()
|
||||
renderReportedDiagnostics(
|
||||
collectorProvider.get().getDiagnosticsForProject(project),
|
||||
logger,
|
||||
diagnosticRenderingOptions
|
||||
)
|
||||
}
|
||||
|
||||
// Schedule switching of Collector to transparent mode, so that any diagnostics reported
|
||||
// after projects are evaluated will be transparently rendered right away instead of being
|
||||
// silently swallowed
|
||||
gradle.projectsEvaluated {
|
||||
collectorProvider.get().switchToTransparentMode()
|
||||
}
|
||||
}
|
||||
|
||||
abstract class AbstractKotlinPluginWrapper(
|
||||
protected val registry: ToolingModelBuilderRegistry,
|
||||
) : KotlinBasePluginWrapper() {
|
||||
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.plugin.diagnostics
|
||||
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinProjectSetupAction
|
||||
import org.jetbrains.kotlin.gradle.plugin.configurationResult
|
||||
import org.jetbrains.kotlin.gradle.plugin.launch
|
||||
|
||||
internal val KotlinToolingDiagnosticsSetupAction = KotlinProjectSetupAction {
|
||||
val collectorProvider = kotlinToolingDiagnosticsCollectorProvider
|
||||
val diagnosticRenderingOptions = ToolingDiagnosticRenderingOptions.forProject(this)
|
||||
|
||||
// Setup reporting from tasks
|
||||
tasks.withType(UsesKotlinToolingDiagnostics::class.java).configureEach {
|
||||
it.usesService(collectorProvider)
|
||||
it.toolingDiagnosticsCollector.value(collectorProvider)
|
||||
it.diagnosticRenderingOptions.set(diagnosticRenderingOptions)
|
||||
}
|
||||
|
||||
// Launch checkers. Note that they are invoked eagerly to give them a fine-grained
|
||||
// control over the lifecycle
|
||||
launchKotlinGradleProjectCheckers()
|
||||
|
||||
// Setup a task that will abort the build if errors will be reported. This task should be the first in the taskgraph
|
||||
project.locateOrRegisterCheckKotlinGradlePluginErrorsTask()
|
||||
|
||||
// Schedule diagnostics rendering
|
||||
launch {
|
||||
configurationResult.await()
|
||||
renderReportedDiagnostics(
|
||||
collectorProvider.get().getDiagnosticsForProject(project),
|
||||
logger,
|
||||
diagnosticRenderingOptions
|
||||
)
|
||||
}
|
||||
|
||||
// Schedule switching of Collector to transparent mode, so that any diagnostics reported
|
||||
// after projects are evaluated will be transparently rendered right away instead of being
|
||||
// silently swallowed
|
||||
gradle.projectsEvaluated {
|
||||
collectorProvider.get().switchToTransparentMode()
|
||||
}
|
||||
}
|
||||
+2
@@ -9,6 +9,7 @@ import org.gradle.api.Project
|
||||
import org.jetbrains.kotlin.gradle.dsl.AndroidMainSourceSetConventionsChecker
|
||||
import org.jetbrains.kotlin.gradle.dsl.IosSourceSetConventionChecker
|
||||
import org.jetbrains.kotlin.gradle.dsl.PlatformSourceSetConventionsChecker
|
||||
import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinToolingDiagnosticsSetupAction
|
||||
import org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinGradleProjectChecker
|
||||
import org.jetbrains.kotlin.gradle.plugin.diagnostics.checkers.AndroidPluginWithoutAndroidTargetChecker
|
||||
import org.jetbrains.kotlin.gradle.plugin.diagnostics.checkers.AndroidSourceSetLayoutV1SourceSetsNotFoundChecker
|
||||
@@ -36,6 +37,7 @@ internal fun Project.registerKotlinPluginExtensions() {
|
||||
KotlinProjectSetupAction.extensionPoint.apply {
|
||||
register(project, AddNpmDependencyExtensionProjectSetupAction)
|
||||
register(project, RegisterBuildKotlinToolingMetadataTask)
|
||||
register(project, KotlinToolingDiagnosticsSetupAction)
|
||||
}
|
||||
|
||||
KotlinGradleProjectChecker.extensionPoint.apply {
|
||||
|
||||
Reference in New Issue
Block a user