[Gradle] Minor: rename verboseDiagnostics -> useParsableDiagnosticsFormat

^KT-59615 Fixed
This commit is contained in:
Dmitry Savvinov
2023-07-27 09:38:40 +02:00
committed by Space Team
parent 83c53b7ce3
commit e334523fd8
11 changed files with 51 additions and 51 deletions
@@ -280,7 +280,7 @@ abstract class BaseGradleIT {
val withReports: List<BuildReportType> = emptyList(), val withReports: List<BuildReportType> = emptyList(),
val enableKpmModelMapping: Boolean? = null, val enableKpmModelMapping: Boolean? = null,
val useDaemonFallbackStrategy: Boolean = false, val useDaemonFallbackStrategy: Boolean = false,
val useVerboseDiagnosticsReporting: Boolean = true, val useParsableDiagnosticsFormatting: Boolean = true,
) { ) {
val safeAndroidGradlePluginVersion: AGPVersion val safeAndroidGradlePluginVersion: AGPVersion
get() = androidGradlePluginVersion ?: error("AGP version is expected to be set") get() = androidGradlePluginVersion ?: error("AGP version is expected to be set")
@@ -937,8 +937,8 @@ abstract class BaseGradleIT {
add("-Dorg.gradle.unsafe.configuration-cache=${options.configurationCache}") add("-Dorg.gradle.unsafe.configuration-cache=${options.configurationCache}")
add("-Dorg.gradle.unsafe.configuration-cache-problems=${options.configurationCacheProblems.name.lowercase(Locale.getDefault())}") add("-Dorg.gradle.unsafe.configuration-cache-problems=${options.configurationCacheProblems.name.lowercase(Locale.getDefault())}")
if (options.useVerboseDiagnosticsReporting) { if (options.useParsableDiagnosticsFormatting) {
add("-Pkotlin.internal.verboseDiagnostics=true") add("-Pkotlin.internal.diagnostics.useParsableFormatting=true")
} }
// Workaround: override a console type set in the user machine gradle.properties (since Gradle 4.3): // Workaround: override a console type set in the user machine gradle.properties (since Gradle 4.3):
@@ -19,7 +19,7 @@ class MppDiagnosticsIt : KGPBaseTest() {
fun testDiagnosticsRenderingSmoke(gradleVersion: GradleVersion) { fun testDiagnosticsRenderingSmoke(gradleVersion: GradleVersion) {
project("diagnosticsRenderingSmoke", gradleVersion) { project("diagnosticsRenderingSmoke", gradleVersion) {
build { build {
assertEqualsToFile(expectedOutputFile(), extractProjectsAndTheirVerboseDiagnostics()) assertEqualsToFile(expectedOutputFile(), extractProjectsAndTheirDiagnostics())
} }
} }
} }
@@ -52,22 +52,22 @@ class MppDiagnosticsIt : KGPBaseTest() {
project("errorDiagnosticBuildFails", gradleVersion) { project("errorDiagnosticBuildFails", gradleVersion) {
// 'assemble' (triggers compileKotlin-tasks indirectly): fail // 'assemble' (triggers compileKotlin-tasks indirectly): fail
buildAndFail("assemble") { buildAndFail("assemble") {
assertEqualsToFile(expectedOutputFile("assemble"), extractProjectsAndTheirVerboseDiagnostics()) assertEqualsToFile(expectedOutputFile("assemble"), extractProjectsAndTheirDiagnostics())
} }
// 'clean', not directly relevant to Kotlin tasks: build is OK // 'clean', not directly relevant to Kotlin tasks: build is OK
build("clean") { build("clean") {
assertEqualsToFile(expectedOutputFile("clean"), extractProjectsAndTheirVerboseDiagnostics()) assertEqualsToFile(expectedOutputFile("clean"), extractProjectsAndTheirDiagnostics())
} }
// Custom task, irrelevant to Kotlin tasks: build is OK // Custom task, irrelevant to Kotlin tasks: build is OK
build("myTask", "--rerun-tasks") { build("myTask", "--rerun-tasks") {
assertEqualsToFile(expectedOutputFile("customTask"), extractProjectsAndTheirVerboseDiagnostics()) assertEqualsToFile(expectedOutputFile("customTask"), extractProjectsAndTheirDiagnostics())
} }
// commonizer task: build is OK (otherwise IDE will be bricked) // commonizer task: build is OK (otherwise IDE will be bricked)
build("commonize") { build("commonize") {
assertEqualsToFile(expectedOutputFile("commonize"), extractProjectsAndTheirVerboseDiagnostics()) assertEqualsToFile(expectedOutputFile("commonize"), extractProjectsAndTheirDiagnostics())
} }
} }
} }
@@ -79,13 +79,13 @@ class MppDiagnosticsIt : KGPBaseTest() {
project("errorDiagnosticBuildFails", gradleVersion) { project("errorDiagnosticBuildFails", gradleVersion) {
buildAndFail("assemble", buildOptions = buildOptions.copy(configurationCache = true)) { buildAndFail("assemble", buildOptions = buildOptions.copy(configurationCache = true)) {
assertConfigurationCacheStored() assertConfigurationCacheStored()
assertEqualsToFile(expectedOutputFile("assemble"), extractProjectsAndTheirVerboseDiagnostics()) assertEqualsToFile(expectedOutputFile("assemble"), extractProjectsAndTheirDiagnostics())
} }
// fails again // fails again
buildAndFail("assemble", buildOptions = buildOptions.copy(configurationCache = true)) { buildAndFail("assemble", buildOptions = buildOptions.copy(configurationCache = true)) {
assertConfigurationCacheReused() assertConfigurationCacheReused()
assertEqualsToFile(expectedOutputFile("assemble-cache-reused"), extractProjectsAndTheirVerboseDiagnostics()) assertEqualsToFile(expectedOutputFile("assemble-cache-reused"), extractProjectsAndTheirDiagnostics())
} }
} }
} }
@@ -94,10 +94,10 @@ class MppDiagnosticsIt : KGPBaseTest() {
fun testErrorDiagnosticBuildSucceeds(gradleVersion: GradleVersion) { fun testErrorDiagnosticBuildSucceeds(gradleVersion: GradleVersion) {
project("errorDiagnosticBuildSucceeds", gradleVersion) { project("errorDiagnosticBuildSucceeds", gradleVersion) {
build("assemble") { build("assemble") {
assertEqualsToFile(expectedOutputFile("assemble"), extractProjectsAndTheirVerboseDiagnostics()) assertEqualsToFile(expectedOutputFile("assemble"), extractProjectsAndTheirDiagnostics())
} }
build("myTask", "--rerun-tasks") { build("myTask", "--rerun-tasks") {
assertEqualsToFile(expectedOutputFile("customTask"), extractProjectsAndTheirVerboseDiagnostics()) assertEqualsToFile(expectedOutputFile("customTask"), extractProjectsAndTheirDiagnostics())
} }
} }
} }
@@ -107,7 +107,7 @@ class MppDiagnosticsIt : KGPBaseTest() {
project("suppressGradlePluginErrors", gradleVersion) { project("suppressGradlePluginErrors", gradleVersion) {
// build succeeds // build succeeds
build("assemble") { build("assemble") {
assertEqualsToFile(expectedOutputFile(), extractProjectsAndTheirVerboseDiagnostics()) assertEqualsToFile(expectedOutputFile(), extractProjectsAndTheirDiagnostics())
} }
} }
} }
@@ -116,7 +116,7 @@ class MppDiagnosticsIt : KGPBaseTest() {
fun testSuppressGradlePluginWarnings(gradleVersion: GradleVersion) { fun testSuppressGradlePluginWarnings(gradleVersion: GradleVersion) {
project("suppressGradlePluginWarnings", gradleVersion) { project("suppressGradlePluginWarnings", gradleVersion) {
build("assemble") { build("assemble") {
assertEqualsToFile(expectedOutputFile(), extractProjectsAndTheirVerboseDiagnostics()) assertEqualsToFile(expectedOutputFile(), extractProjectsAndTheirDiagnostics())
} }
} }
} }
@@ -128,7 +128,7 @@ class MppDiagnosticsIt : KGPBaseTest() {
// Gradle 8.0+ for some reason renders exception twice in the build log // Gradle 8.0+ for some reason renders exception twice in the build log
val testDataSuffixIfAny = if (gradleVersion < GradleVersion.version(TestVersions.Gradle.G_8_0)) "gradle-6.8.3" else null val testDataSuffixIfAny = if (gradleVersion < GradleVersion.version(TestVersions.Gradle.G_8_0)) "gradle-6.8.3" else null
assertEqualsToFile(expectedOutputFile(testDataSuffixIfAny), extractProjectsAndTheirVerboseDiagnostics()) assertEqualsToFile(expectedOutputFile(testDataSuffixIfAny), extractProjectsAndTheirDiagnostics())
} }
} }
} }
@@ -137,24 +137,24 @@ class MppDiagnosticsIt : KGPBaseTest() {
fun testErrorsFailOnlyRelevantProjects(gradleVersion: GradleVersion) { fun testErrorsFailOnlyRelevantProjects(gradleVersion: GradleVersion) {
project("errorsFailOnlyRelevantProjects", gradleVersion) { project("errorsFailOnlyRelevantProjects", gradleVersion) {
buildAndFail("brokenProjectA:assemble") { buildAndFail("brokenProjectA:assemble") {
assertEqualsToFile(expectedOutputFile("brokenA"), extractProjectsAndTheirVerboseDiagnostics()) assertEqualsToFile(expectedOutputFile("brokenA"), extractProjectsAndTheirDiagnostics())
} }
buildAndFail("brokenProjectB:assemble") { buildAndFail("brokenProjectB:assemble") {
assertEqualsToFile(expectedOutputFile("brokenB"), extractProjectsAndTheirVerboseDiagnostics()) assertEqualsToFile(expectedOutputFile("brokenB"), extractProjectsAndTheirDiagnostics())
} }
build("healthyProject:assemble") { build("healthyProject:assemble") {
assertEqualsToFile(expectedOutputFile("healthy"), extractProjectsAndTheirVerboseDiagnostics()) assertEqualsToFile(expectedOutputFile("healthy"), extractProjectsAndTheirDiagnostics())
} }
// Turn off parallel execution so that order of execution (and therefore the testdata) is stable // Turn off parallel execution so that order of execution (and therefore the testdata) is stable
buildAndFail("assemble", buildOptions = buildOptions.copy(parallel = false)) { buildAndFail("assemble", buildOptions = buildOptions.copy(parallel = false)) {
assertEqualsToFile(expectedOutputFile("root"), extractProjectsAndTheirVerboseDiagnostics()) assertEqualsToFile(expectedOutputFile("root"), extractProjectsAndTheirDiagnostics())
} }
buildAndFail("assemble", "--continue", buildOptions = buildOptions.copy(parallel = false)) { buildAndFail("assemble", "--continue", buildOptions = buildOptions.copy(parallel = false)) {
assertEqualsToFile(expectedOutputFile("root-with-continue"), extractProjectsAndTheirVerboseDiagnostics()) assertEqualsToFile(expectedOutputFile("root-with-continue"), extractProjectsAndTheirDiagnostics())
} }
} }
} }
@@ -163,7 +163,7 @@ class MppDiagnosticsIt : KGPBaseTest() {
fun testEarlyTasksMaterializationDoesntBreakReports(gradleVersion: GradleVersion) { fun testEarlyTasksMaterializationDoesntBreakReports(gradleVersion: GradleVersion) {
project("earlyTasksMaterializationDoesntBreakReports", gradleVersion) { project("earlyTasksMaterializationDoesntBreakReports", gradleVersion) {
buildAndFail("assemble") { buildAndFail("assemble") {
assertEqualsToFile(expectedOutputFile(), extractProjectsAndTheirVerboseDiagnostics()) assertEqualsToFile(expectedOutputFile(), extractProjectsAndTheirDiagnostics())
} }
} }
} }
@@ -43,7 +43,7 @@ data class BuildOptions(
val usePreciseOutputsBackup: Boolean? = null, val usePreciseOutputsBackup: Boolean? = null,
val keepIncrementalCompilationCachesInMemory: Boolean? = null, val keepIncrementalCompilationCachesInMemory: Boolean? = null,
val useDaemonFallbackStrategy: Boolean = false, val useDaemonFallbackStrategy: Boolean = false,
val verboseDiagnostics: Boolean = true, val useParsableDiagnosticsFormatting: Boolean = true,
val nativeOptions: NativeOptions = NativeOptions(), val nativeOptions: NativeOptions = NativeOptions(),
val compilerExecutionStrategy: KotlinCompilerExecutionStrategy? = null, val compilerExecutionStrategy: KotlinCompilerExecutionStrategy? = null,
val runViaBuildToolsApi: Boolean? = null, val runViaBuildToolsApi: Boolean? = null,
@@ -175,8 +175,8 @@ data class BuildOptions(
arguments.add("-Pkotlin.daemon.useFallbackStrategy=$useDaemonFallbackStrategy") arguments.add("-Pkotlin.daemon.useFallbackStrategy=$useDaemonFallbackStrategy")
if (verboseDiagnostics) { if (useParsableDiagnosticsFormatting) {
arguments.add("-Pkotlin.internal.verboseDiagnostics=$verboseDiagnostics") arguments.add("-Pkotlin.internal.diagnostics.useParsableFormatting=$useParsableDiagnosticsFormatting")
} }
if (compilerExecutionStrategy != null) { if (compilerExecutionStrategy != null) {
@@ -69,12 +69,12 @@ fun String.assertNoDiagnostic(diagnosticFactory: ToolingDiagnosticFactory, withS
} }
/** /**
* NB: Needs verbose mode of diagnostics, see [org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.internalVerboseDiagnostics] * NB: Needs parsable formatting of diagnostics, see [org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.internalDiagnosticsUseParsableFormat]
* Because this mode is enabled by the 'kotlin.internal'-property, actual output will always contain * Because this mode is enabled by the 'kotlin.internal'-property, actual output will always contain
* [org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinToolingDiagnostics.InternalKotlinGradlePluginPropertiesUsed]. * [org.jetbrains.kotlin.gradle.plugin.diagnostics.KotlinToolingDiagnostics.InternalKotlinGradlePluginPropertiesUsed].
* For the sake of clarity, this diagnostic is filtered by default. * For the sake of clarity, this diagnostic is filtered by default.
*/ */
fun BuildResult.extractProjectsAndTheirVerboseDiagnostics(): String = buildString { fun BuildResult.extractProjectsAndTheirDiagnostics(): String = buildString {
var diagnosticStarted = false var diagnosticStarted = false
val currentDiagnostic = mutableListOf<String>() val currentDiagnostic = mutableListOf<String>()
@@ -101,10 +101,10 @@ fun BuildResult.extractProjectsAndTheirVerboseDiagnostics(): String = buildStrin
currentDiagnostic += line currentDiagnostic += line
// Suppress InternalKotlinGradlePluginProperties, but only if the single property it complains about is // Suppress InternalKotlinGradlePluginProperties, but only if the single property it complains about is
// 'kotlin.internal.verboseDiagnostics' // 'kotlin.internal.diagnostics.useParsableFormatting'
val offendingProperties = currentDiagnostic.asSequence().filter { it.startsWith("kotlin.internal.") } val offendingProperties = currentDiagnostic.asSequence().filter { it.startsWith("kotlin.internal.") }
if (KotlinToolingDiagnostics.InternalKotlinGradlePluginPropertiesUsed.id !in currentDiagnostic.first() || if (KotlinToolingDiagnostics.InternalKotlinGradlePluginPropertiesUsed.id !in currentDiagnostic.first() ||
offendingProperties.singleOrNull() != "kotlin.internal.verboseDiagnostics" offendingProperties.singleOrNull() != "kotlin.internal.diagnostics.useParsableFormatting"
) { ) {
appendLine(currentDiagnostic.joinToString(separator = "\n", postfix = "\n")) appendLine(currentDiagnostic.joinToString(separator = "\n", postfix = "\n"))
} }
@@ -2,7 +2,7 @@
w: [InternalKotlinGradlePluginPropertiesUsed | WARNING] ATTENTION! This build uses the following Kotlin Gradle Plugin properties: w: [InternalKotlinGradlePluginPropertiesUsed | WARNING] ATTENTION! This build uses the following Kotlin Gradle Plugin properties:
kotlin.internal.suppressGradlePluginErrors kotlin.internal.suppressGradlePluginErrors
kotlin.internal.verboseDiagnostics kotlin.internal.diagnostics.useParsableFormatting
kotlin.internal-properties are not recommended for production use. kotlin.internal-properties are not recommended for production use.
Stability and future compatibility of the build is not guaranteed. Stability and future compatibility of the build is not guaranteed.
@@ -294,7 +294,7 @@ private fun Project.setupDiagnosticsChecksAndReporting() {
renderReportedDiagnostics( renderReportedDiagnostics(
collectorProvider.get().getDiagnosticsForProject(project), collectorProvider.get().getDiagnosticsForProject(project),
logger, logger,
diagnosticRenderingOptions.isVerbose diagnosticRenderingOptions.useParsableFormat
) )
} }
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLI
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_COMPILER_USE_PRECISE_COMPILATION_RESULTS_BACKUP import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_COMPILER_USE_PRECISE_COMPILATION_RESULTS_BACKUP
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_CREATE_DEFAULT_MULTIPLATFORM_PUBLICATIONS import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_CREATE_DEFAULT_MULTIPLATFORM_PUBLICATIONS
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_EXPERIMENTAL_TRY_K2 import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_EXPERIMENTAL_TRY_K2
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_INTERNAL_VERBOSE_DIAGNOSTICS import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_INTERNAL_DIAGNOSTICS_USE_PARSABLE_FORMATTING
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_JS_KARMA_BROWSERS import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_JS_KARMA_BROWSERS
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_JS_STDLIB_DOM_API_INCLUDED import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_JS_STDLIB_DOM_API_INCLUDED
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ALLOW_LEGACY_DEPENDENCIES import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.PropertyNames.KOTLIN_MPP_ALLOW_LEGACY_DEPENDENCIES
@@ -524,8 +524,8 @@ internal class PropertiesProvider private constructor(private val project: Proje
} }
.orElse(false) .orElse(false)
val internalVerboseDiagnostics: Boolean val internalDiagnosticsUseParsableFormat: Boolean
get() = booleanProperty(KOTLIN_INTERNAL_VERBOSE_DIAGNOSTICS) ?: false get() = booleanProperty(KOTLIN_INTERNAL_DIAGNOSTICS_USE_PARSABLE_FORMATTING) ?: false
val suppressedGradlePluginWarnings: List<String> val suppressedGradlePluginWarnings: List<String>
get() = property(PropertyNames.KOTLIN_SUPPRESS_GRADLE_PLUGIN_WARNINGS)?.split(",").orEmpty() get() = property(PropertyNames.KOTLIN_SUPPRESS_GRADLE_PLUGIN_WARNINGS)?.split(",").orEmpty()
@@ -650,7 +650,7 @@ internal class PropertiesProvider private constructor(private val project: Proje
**/ **/
val KOTLIN_MPP_HIERARCHICAL_STRUCTURE_BY_DEFAULT = property("$KOTLIN_INTERNAL_NAMESPACE.mpp.hierarchicalStructureByDefault") val KOTLIN_MPP_HIERARCHICAL_STRUCTURE_BY_DEFAULT = property("$KOTLIN_INTERNAL_NAMESPACE.mpp.hierarchicalStructureByDefault")
val KOTLIN_CREATE_DEFAULT_MULTIPLATFORM_PUBLICATIONS = property("$KOTLIN_INTERNAL_NAMESPACE.mpp.createDefaultMultiplatformPublications") val KOTLIN_CREATE_DEFAULT_MULTIPLATFORM_PUBLICATIONS = property("$KOTLIN_INTERNAL_NAMESPACE.mpp.createDefaultMultiplatformPublications")
val KOTLIN_INTERNAL_VERBOSE_DIAGNOSTICS = property("$KOTLIN_INTERNAL_NAMESPACE.verboseDiagnostics") val KOTLIN_INTERNAL_DIAGNOSTICS_USE_PARSABLE_FORMATTING = property("$KOTLIN_INTERNAL_NAMESPACE.diagnostics.useParsableFormatting")
val KOTLIN_SUPPRESS_GRADLE_PLUGIN_ERRORS = property("$KOTLIN_INTERNAL_NAMESPACE.suppressGradlePluginErrors") val KOTLIN_SUPPRESS_GRADLE_PLUGIN_ERRORS = property("$KOTLIN_INTERNAL_NAMESPACE.suppressGradlePluginErrors")
val MPP_13X_FLAGS_SET_BY_PLUGIN = property("$KOTLIN_INTERNAL_NAMESPACE.mpp.13X.flags.setByPlugin") val MPP_13X_FLAGS_SET_BY_PLUGIN = property("$KOTLIN_INTERNAL_NAMESPACE.mpp.13X.flags.setByPlugin")
} }
@@ -29,7 +29,7 @@ internal abstract class CheckKotlinGradlePluginConfigurationErrors : DefaultTask
@TaskAction @TaskAction
fun checkNoErrors() { fun checkNoErrors() {
if (errorDiagnostics.get().isNotEmpty()) { if (errorDiagnostics.get().isNotEmpty()) {
renderReportedDiagnostics(errorDiagnostics.get(), logger, renderingOptions.get().isVerbose) renderReportedDiagnostics(errorDiagnostics.get(), logger, renderingOptions.get().useParsableFormat)
throw InvalidUserCodeException("Kotlin Gradle Plugin reported errors. Check the log for details") throw InvalidUserCodeException("Kotlin Gradle Plugin reported errors. Check the log for details")
} }
} }
@@ -39,7 +39,7 @@ internal abstract class KotlinToolingDiagnosticsCollector : BuildService<BuildSe
fun report(task: UsesKotlinToolingDiagnostics, diagnostic: ToolingDiagnostic) { fun report(task: UsesKotlinToolingDiagnostics, diagnostic: ToolingDiagnostic) {
val options = task.diagnosticRenderingOptions.get() val options = task.diagnosticRenderingOptions.get()
if (!diagnostic.isSuppressed(options)) { if (!diagnostic.isSuppressed(options)) {
renderReportedDiagnostic(diagnostic, task.logger, options.isVerbose) renderReportedDiagnostic(diagnostic, task.logger, options.useParsableFormat)
} }
} }
@@ -62,10 +62,10 @@ internal abstract class KotlinToolingDiagnosticsCollector : BuildService<BuildSe
private fun handleDiagnostic(project: Project, diagnostic: ToolingDiagnostic) { private fun handleDiagnostic(project: Project, diagnostic: ToolingDiagnostic) {
if (diagnostic.isSuppressed(ToolingDiagnosticRenderingOptions.forProject(project))) return if (diagnostic.isSuppressed(ToolingDiagnosticRenderingOptions.forProject(project))) return
val isVerbose = project.kotlinPropertiesProvider.internalVerboseDiagnostics val useParsableFormat = project.kotlinPropertiesProvider.internalDiagnosticsUseParsableFormat
if (isTransparent) { if (isTransparent) {
renderReportedDiagnostic(diagnostic, project.logger, isVerbose) renderReportedDiagnostic(diagnostic, project.logger, useParsableFormat)
return return
} }
@@ -9,14 +9,14 @@ import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.kotlinPropertiesProvider import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider.Companion.kotlinPropertiesProvider
internal class ToolingDiagnosticRenderingOptions( internal class ToolingDiagnosticRenderingOptions(
val isVerbose: Boolean, val useParsableFormat: Boolean,
val suppressedWarningIds: List<String>, val suppressedWarningIds: List<String>,
val suppressedErrorIds: List<String> val suppressedErrorIds: List<String>
) { ) {
companion object { companion object {
fun forProject(project: Project): ToolingDiagnosticRenderingOptions = with(project.kotlinPropertiesProvider) { fun forProject(project: Project): ToolingDiagnosticRenderingOptions = with(project.kotlinPropertiesProvider) {
ToolingDiagnosticRenderingOptions( ToolingDiagnosticRenderingOptions(
internalVerboseDiagnostics, internalDiagnosticsUseParsableFormat,
suppressedGradlePluginWarnings, suppressedGradlePluginWarnings,
suppressedGradlePluginErrors suppressedGradlePluginErrors
) )
@@ -9,34 +9,34 @@ import org.gradle.api.InvalidUserCodeException
import org.gradle.api.logging.Logger import org.gradle.api.logging.Logger
import org.jetbrains.kotlin.gradle.plugin.diagnostics.ToolingDiagnostic.Severity.* import org.jetbrains.kotlin.gradle.plugin.diagnostics.ToolingDiagnostic.Severity.*
internal fun renderReportedDiagnostics(diagnostics: Collection<ToolingDiagnostic>, logger: Logger, isVerbose: Boolean) { internal fun renderReportedDiagnostics(diagnostics: Collection<ToolingDiagnostic>, logger: Logger, useParsableFormat: Boolean) {
for (diagnostic in diagnostics) { for (diagnostic in diagnostics) {
renderReportedDiagnostic(diagnostic, logger, isVerbose) renderReportedDiagnostic(diagnostic, logger, useParsableFormat)
} }
} }
internal fun renderReportedDiagnostic( internal fun renderReportedDiagnostic(
diagnostic: ToolingDiagnostic, diagnostic: ToolingDiagnostic,
logger: Logger, logger: Logger,
isVerbose: Boolean, useParsableFormat: Boolean,
) { ) {
when (diagnostic.severity) { when (diagnostic.severity) {
WARNING -> logger.warn("w: ${diagnostic.render(isVerbose)}\n") WARNING -> logger.warn("w: ${diagnostic.render(useParsableFormat)}\n")
ERROR -> logger.error("e: ${diagnostic.render(isVerbose)}\n") ERROR -> logger.error("e: ${diagnostic.render(useParsableFormat)}\n")
FATAL -> throw diagnostic.createAnExceptionForFatalDiagnostic(isVerbose) FATAL -> throw diagnostic.createAnExceptionForFatalDiagnostic(useParsableFormat)
} }
} }
internal fun ToolingDiagnostic.createAnExceptionForFatalDiagnostic(isVerbose: Boolean): InvalidUserCodeException = internal fun ToolingDiagnostic.createAnExceptionForFatalDiagnostic(useParsableFormat: Boolean): InvalidUserCodeException =
if (throwable != null) if (throwable != null)
InvalidUserCodeException(render(isVerbose), throwable) InvalidUserCodeException(render(useParsableFormat), throwable)
else else
InvalidUserCodeException(render(isVerbose)) InvalidUserCodeException(render(useParsableFormat))
private fun ToolingDiagnostic.render(isVerbose: Boolean): String = buildString { private fun ToolingDiagnostic.render(useParsableFormat: Boolean): String = buildString {
if (isVerbose) { if (useParsableFormat) {
appendLine(this@render) appendLine(this@render)
append(DIAGNOSTIC_SEPARATOR) append(DIAGNOSTIC_SEPARATOR)
} else { } else {