Warn in Gradle log when incremental compilation fails
When incremental compilation fails, we currently log it at the `debug` level (and fall back to non-incremental compilation). This commit will change it to `warning` so that we can get more user reports, which will allow us to fix the root cause. Also make sure the warning includes a stack trace. Additionally, let ReportSeverity.fromCode() return a non-null value or throw an exception otherwise as that case is not expected. ^KT-52839 In Progress
This commit is contained in:
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.daemon.report
|
||||
|
||||
import org.jetbrains.kotlin.build.report.debug
|
||||
import org.jetbrains.kotlin.build.report.info
|
||||
import org.jetbrains.kotlin.build.report.warn
|
||||
import org.jetbrains.kotlin.daemon.testfixtures.FakeCompilationResults
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class BuildReportICReporterTest {
|
||||
|
||||
@Test
|
||||
fun testVerboseMode() {
|
||||
val compilationResults = FakeCompilationResults()
|
||||
val reporter = BuildReportICReporter(compilationResults, File("unusedRootDir"), isVerbose = true)
|
||||
reporter.warn { WARNING_MESSAGE }
|
||||
reporter.info { INFO_MESSAGE }
|
||||
reporter.debug { DEBUG_MESSAGE }
|
||||
reporter.flush()
|
||||
|
||||
assertEquals(
|
||||
expected = listOf(WARNING_MESSAGE, INFO_MESSAGE, DEBUG_MESSAGE),
|
||||
actual = compilationResults.results.single() as List<*>
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNonVerboseMode() {
|
||||
val compilationResults = FakeCompilationResults()
|
||||
val reporter = BuildReportICReporter(compilationResults, File("unusedRootDir"), isVerbose = false)
|
||||
reporter.warn { WARNING_MESSAGE }
|
||||
reporter.info { INFO_MESSAGE }
|
||||
reporter.debug { DEBUG_MESSAGE }
|
||||
reporter.flush()
|
||||
|
||||
assertEquals(
|
||||
expected = listOf(WARNING_MESSAGE, INFO_MESSAGE),
|
||||
actual = compilationResults.results.single() as List<*>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
internal const val WARNING_MESSAGE = "Warning message"
|
||||
internal const val INFO_MESSAGE = "Info message"
|
||||
internal const val DEBUG_MESSAGE = "Debug message"
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.daemon.report
|
||||
|
||||
import org.jetbrains.kotlin.build.report.ICReporter
|
||||
import org.jetbrains.kotlin.build.report.debug
|
||||
import org.jetbrains.kotlin.build.report.info
|
||||
import org.jetbrains.kotlin.build.report.warn
|
||||
import org.jetbrains.kotlin.daemon.common.ReportCategory
|
||||
import org.jetbrains.kotlin.daemon.common.ReportSeverity
|
||||
import org.jetbrains.kotlin.daemon.testfixtures.FakeCompilerServicesFacadeBase
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class DebugMessagesICReporterTest {
|
||||
|
||||
@Test
|
||||
fun testWarningLevel() {
|
||||
val compilerServices = FakeCompilerServicesFacadeBase()
|
||||
val reporter = DebugMessagesICReporter(compilerServices, File("unusedRootDir"), ICReporter.ReportSeverity.WARNING)
|
||||
reporter.warn { WARNING_MESSAGE }
|
||||
reporter.info { INFO_MESSAGE }
|
||||
reporter.debug { DEBUG_MESSAGE }
|
||||
|
||||
assertEquals(
|
||||
expected = mapOf(
|
||||
WARNING_MESSAGE to Pair(ReportCategory.IC_MESSAGE, ReportSeverity.WARNING),
|
||||
),
|
||||
actual = compilerServices.messages
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testInfoLevel() {
|
||||
val compilerServices = FakeCompilerServicesFacadeBase()
|
||||
val reporter = DebugMessagesICReporter(compilerServices, File("unusedRootDir"), ICReporter.ReportSeverity.INFO)
|
||||
reporter.warn { WARNING_MESSAGE }
|
||||
reporter.info { INFO_MESSAGE }
|
||||
reporter.debug { DEBUG_MESSAGE }
|
||||
|
||||
assertEquals(
|
||||
expected = mapOf(
|
||||
WARNING_MESSAGE to Pair(ReportCategory.IC_MESSAGE, ReportSeverity.WARNING),
|
||||
INFO_MESSAGE to Pair(ReportCategory.IC_MESSAGE, ReportSeverity.INFO),
|
||||
),
|
||||
actual = compilerServices.messages
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDebugLevel() {
|
||||
val compilerServices = FakeCompilerServicesFacadeBase()
|
||||
val reporter = DebugMessagesICReporter(compilerServices, File("unusedRootDir"), ICReporter.ReportSeverity.DEBUG)
|
||||
reporter.warn { WARNING_MESSAGE }
|
||||
reporter.info { INFO_MESSAGE }
|
||||
reporter.debug { DEBUG_MESSAGE }
|
||||
|
||||
assertEquals(
|
||||
mapOf(
|
||||
WARNING_MESSAGE to Pair(ReportCategory.IC_MESSAGE, ReportSeverity.WARNING),
|
||||
INFO_MESSAGE to Pair(ReportCategory.IC_MESSAGE, ReportSeverity.INFO),
|
||||
DEBUG_MESSAGE to Pair(ReportCategory.IC_MESSAGE, ReportSeverity.DEBUG)
|
||||
),
|
||||
actual = compilerServices.messages
|
||||
)
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.daemon.testfixtures
|
||||
|
||||
import org.jetbrains.kotlin.daemon.common.CompilationResults
|
||||
import java.io.Serializable
|
||||
|
||||
class FakeCompilationResults : CompilationResults {
|
||||
|
||||
val results: List<Serializable>
|
||||
get() = resultList.toList()
|
||||
|
||||
private val resultList = mutableListOf<Serializable>()
|
||||
|
||||
override fun add(compilationResultCategory: Int, value: Serializable) {
|
||||
resultList.add(value)
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.daemon.testfixtures
|
||||
|
||||
import org.jetbrains.kotlin.daemon.common.CompilerServicesFacadeBase
|
||||
import org.jetbrains.kotlin.daemon.common.ReportCategory
|
||||
import org.jetbrains.kotlin.daemon.common.ReportSeverity
|
||||
import java.io.Serializable
|
||||
|
||||
class FakeCompilerServicesFacadeBase : CompilerServicesFacadeBase {
|
||||
|
||||
val messages: Map<String, Pair<ReportCategory, ReportSeverity>>
|
||||
get() = messageMap.toMap()
|
||||
|
||||
private val messageMap = mutableMapOf<String, Pair<ReportCategory, ReportSeverity>>()
|
||||
|
||||
override fun report(category: Int, severity: Int, message: String?, attachment: Serializable?) {
|
||||
messageMap[message!!] = ReportCategory.fromCode(category)!! to ReportSeverity.fromCode(severity)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user