Log created error file in debug log
KT-59451 Fixed
This commit is contained in:
committed by
Space Team
parent
496e4dd0e3
commit
f46245621f
+12
-10
@@ -283,21 +283,21 @@ class BuildReportsIT : KGPBaseTest() {
|
||||
}
|
||||
""".trimIndent()
|
||||
)
|
||||
build("compileKotlin") {
|
||||
build("compileKotlin", buildOptions = defaultBuildOptions.copy(logLevel = LogLevel.DEBUG)) {
|
||||
assertTrue { projectPath.resolve(kotlinErrorPath).listDirectoryEntries().isEmpty() }
|
||||
assertOutputDoesNotContain("errors were stored into file")
|
||||
}
|
||||
val kotlinFile = kotlinSourcesDir().resolve("helloWorld.kt")
|
||||
kotlinFile.modify { it.replace("ArrayList", "skjfghsjk") }
|
||||
buildAndFail("compileKotlin") {
|
||||
val buildErrorDir = projectPath.resolve(kotlinErrorPath).toFile()
|
||||
val files = buildErrorDir.listFiles()
|
||||
assertTrue { files?.first()?.exists() ?: false }
|
||||
files?.first()?.bufferedReader().use { reader ->
|
||||
val kotlinVersion = reader?.readLine()
|
||||
buildAndFail("compileKotlin", buildOptions = defaultBuildOptions.copy(logLevel = LogLevel.DEBUG)) {
|
||||
assertOutputContains("errors were stored into file")
|
||||
val file = projectPath.getSingleFileInDir(kotlinErrorPath)
|
||||
file.bufferedReader().use { reader ->
|
||||
val kotlinVersion = reader.readLine()
|
||||
assertTrue("kotlin version should be in the error file") {
|
||||
kotlinVersion != null && kotlinVersion.trim().equals("kotlin version: ${buildOptions.kotlinVersion}")
|
||||
}
|
||||
val errorMessage = reader?.readLine()
|
||||
val errorMessage = reader.readLine()
|
||||
assertTrue("Error message should start with 'error message: ' to parse it on IDEA side") {
|
||||
errorMessage != null && errorMessage.trim().startsWith("error message:")
|
||||
}
|
||||
@@ -314,13 +314,15 @@ class BuildReportsIT : KGPBaseTest() {
|
||||
@GradleTest
|
||||
fun testErrorsFileWithCompilationError(gradleVersion: GradleVersion) {
|
||||
project("simpleProject", gradleVersion) {
|
||||
build("compileKotlin") {
|
||||
build("compileKotlin", buildOptions = defaultBuildOptions.copy(logLevel = LogLevel.DEBUG)) {
|
||||
assertTrue { projectPath.resolve(kotlinErrorPath).listDirectoryEntries().isEmpty() }
|
||||
assertOutputDoesNotContain("errors were stored into file")
|
||||
}
|
||||
val kotlinFile = kotlinSourcesDir().resolve("helloWorld.kt")
|
||||
kotlinFile.modify { it.replace("ArrayList", "skjfghsjk") }
|
||||
buildAndFail("compileKotlin") {
|
||||
buildAndFail("compileKotlin", buildOptions = defaultBuildOptions.copy(logLevel = LogLevel.DEBUG)) {
|
||||
assertTrue { projectPath.resolve(kotlinErrorPath).listDirectoryEntries().isEmpty() }
|
||||
assertOutputDoesNotContain("errors were stored into file")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -130,7 +130,7 @@ internal class GradleKotlinCompilerWork @Inject constructor(
|
||||
metrics.startMeasure(GradleBuildTime.RUN_COMPILATION_IN_WORKER)
|
||||
try {
|
||||
val gradlePrintingMessageCollector = GradlePrintingMessageCollector(log, allWarningsAsErrors)
|
||||
val gradleMessageCollector = GradleErrorMessageCollector(gradlePrintingMessageCollector, kotlinPluginVersion = kotlinPluginVersion)
|
||||
val gradleMessageCollector = GradleErrorMessageCollector(log, gradlePrintingMessageCollector, kotlinPluginVersion = kotlinPluginVersion)
|
||||
val (exitCode, executionStrategy) = compileWithDaemonOrFallbackImpl(gradleMessageCollector)
|
||||
if (incrementalCompilationEnvironment?.disableMultiModuleIC == true) {
|
||||
incrementalCompilationEnvironment.multiModuleICSettings.buildHistoryFile.delete()
|
||||
|
||||
+1
-1
@@ -120,7 +120,7 @@ internal fun runToolInSeparateProcess(
|
||||
compilerClassName,
|
||||
"@${compilerOptions.absolutePath}"
|
||||
)
|
||||
val messageCollector = GradleErrorMessageCollector(createLoggingMessageCollector(logger))
|
||||
val messageCollector = GradleErrorMessageCollector(logger, createLoggingMessageCollector(logger))
|
||||
val process = launchProcessWithFallback(builder, DaemonReportingTargets(messageCollector = messageCollector))
|
||||
|
||||
// important to read inputStream, otherwise the process may hang on some systems
|
||||
|
||||
+11
-1
@@ -5,6 +5,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.logging
|
||||
|
||||
import org.gradle.api.logging.Logger
|
||||
import org.jetbrains.kotlin.buildtools.api.KotlinLogger
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
@@ -12,11 +14,19 @@ import java.io.File
|
||||
import java.io.FileWriter
|
||||
|
||||
class GradleErrorMessageCollector(
|
||||
private val logger: KotlinLogger,
|
||||
private val delegate: MessageCollector? = null,
|
||||
private val acceptableMessageSeverity: List<CompilerMessageSeverity> = listOf(CompilerMessageSeverity.EXCEPTION),
|
||||
private val kotlinPluginVersion: String? = null
|
||||
) : MessageCollector {
|
||||
|
||||
constructor(
|
||||
logger: Logger,
|
||||
delegate: MessageCollector? = null,
|
||||
acceptableMessageSeverity: List<CompilerMessageSeverity> = listOf(CompilerMessageSeverity.EXCEPTION),
|
||||
kotlinPluginVersion: String? = null,
|
||||
) : this(GradleKotlinLogger(logger), delegate, acceptableMessageSeverity, kotlinPluginVersion)
|
||||
|
||||
private val errors = ArrayList<String>()
|
||||
|
||||
override fun clear() {
|
||||
@@ -47,7 +57,6 @@ class GradleErrorMessageCollector(
|
||||
return
|
||||
}
|
||||
file.createNewFile()
|
||||
println("Errors were stored into ${file.absolutePath}")
|
||||
FileWriter(file).use {
|
||||
kotlinPluginVersion?.also { version -> it.append("kotlin version: $version\n") }
|
||||
for (error in errors) {
|
||||
@@ -55,6 +64,7 @@ class GradleErrorMessageCollector(
|
||||
}
|
||||
it.flush()
|
||||
}
|
||||
logger.debug("${errors.count()} errors were stored into file ${file.absolutePath}")
|
||||
clear()
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -318,7 +318,7 @@ abstract class Kotlin2JsCompile @Inject constructor(
|
||||
|
||||
val gradlePrintingMessageCollector = GradlePrintingMessageCollector(logger, args.allWarningsAsErrors)
|
||||
val gradleMessageCollector =
|
||||
GradleErrorMessageCollector(gradlePrintingMessageCollector, kotlinPluginVersion = getKotlinPluginVersion(logger))
|
||||
GradleErrorMessageCollector(logger, gradlePrintingMessageCollector, kotlinPluginVersion = getKotlinPluginVersion(logger))
|
||||
val outputItemCollector = OutputItemsCollectorImpl()
|
||||
val compilerRunner = compilerRunner.get()
|
||||
|
||||
|
||||
+1
-1
@@ -310,7 +310,7 @@ abstract class KotlinCompile @Inject constructor(
|
||||
val gradlePrintingMessageCollector = GradlePrintingMessageCollector(logger, args.allWarningsAsErrors)
|
||||
val gradleMessageCollector =
|
||||
GradleErrorMessageCollector(
|
||||
gradlePrintingMessageCollector, kotlinPluginVersion = getKotlinPluginVersion(logger)
|
||||
logger, gradlePrintingMessageCollector, kotlinPluginVersion = getKotlinPluginVersion(logger)
|
||||
)
|
||||
val outputItemCollector = OutputItemsCollectorImpl()
|
||||
val compilerRunner = compilerRunner.get()
|
||||
|
||||
+2
-1
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.compilerRunner.OutputItemsCollectorImpl
|
||||
import org.jetbrains.kotlin.gradle.dsl.*
|
||||
import org.jetbrains.kotlin.gradle.internal.tasks.allOutputFiles
|
||||
import org.jetbrains.kotlin.gradle.logging.GradleErrorMessageCollector
|
||||
import org.jetbrains.kotlin.gradle.logging.GradleKotlinLogger
|
||||
import org.jetbrains.kotlin.gradle.logging.GradlePrintingMessageCollector
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilerArgumentsProducer.CreateCompilerArgumentsContext.Companion.create
|
||||
@@ -135,7 +136,7 @@ abstract class KotlinCompileCommon @Inject constructor(
|
||||
taskOutputsBackup: TaskOutputsBackup?
|
||||
) {
|
||||
val gradlePrintingMessageCollector = GradlePrintingMessageCollector(logger, args.allWarningsAsErrors)
|
||||
val gradleMessageCollector = GradleErrorMessageCollector(gradlePrintingMessageCollector)
|
||||
val gradleMessageCollector = GradleErrorMessageCollector(logger, gradlePrintingMessageCollector)
|
||||
val outputItemCollector = OutputItemsCollectorImpl()
|
||||
val compilerRunner = compilerRunner.get()
|
||||
val environment = GradleCompilerEnvironment(
|
||||
|
||||
Reference in New Issue
Block a user