KT-54492 Add kotlin plugin version into error file
This commit is contained in:
committed by
Space Team
parent
871fd09e3f
commit
e1e07d2094
+17
-4
@@ -169,6 +169,8 @@ class BuildReportsIT : KGPBaseTest() {
|
||||
}
|
||||
}
|
||||
|
||||
private val kotlinErrorPath = ".gradle/kotlin/errors"
|
||||
|
||||
@DisplayName("Error file is created")
|
||||
@GradleTest
|
||||
fun testErrorsFileSmokeTest(gradleVersion: GradleVersion) {
|
||||
@@ -183,14 +185,25 @@ class BuildReportsIT : KGPBaseTest() {
|
||||
}
|
||||
""".trimIndent())
|
||||
build("compileKotlin") {
|
||||
assertTrue { projectPath.resolve(".gradle/build_errors").listDirectoryEntries().isEmpty() }
|
||||
assertTrue { projectPath.resolve(kotlinErrorPath).listDirectoryEntries().isEmpty() }
|
||||
}
|
||||
val kotlinFile = kotlinSourcesDir().resolve("helloWorld.kt")
|
||||
kotlinFile.modify { it.replace("ArrayList","skjfghsjk") }
|
||||
buildAndFail("compileKotlin") {
|
||||
val buildErrorDir = projectPath.resolve(".gradle/build_errors").toFile()
|
||||
val buildErrorDir = projectPath.resolve(kotlinErrorPath).toFile()
|
||||
val files = buildErrorDir.listFiles()
|
||||
assertTrue { files?.first()?.exists() ?: false }
|
||||
files?.first()?.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()
|
||||
assertTrue("Error message should start with 'error message: ' to parse it on IDEA side") {
|
||||
errorMessage != null && errorMessage.trim().startsWith("error message:")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -200,12 +213,12 @@ class BuildReportsIT : KGPBaseTest() {
|
||||
fun testErrorsFileWithCompilationError(gradleVersion: GradleVersion) {
|
||||
project("simpleProject", gradleVersion) {
|
||||
build("compileKotlin") {
|
||||
assertTrue { projectPath.resolve(".gradle/build_errors").listDirectoryEntries().isEmpty() }
|
||||
assertTrue { projectPath.resolve(kotlinErrorPath).listDirectoryEntries().isEmpty() }
|
||||
}
|
||||
val kotlinFile = kotlinSourcesDir().resolve("helloWorld.kt")
|
||||
kotlinFile.modify { it.replace("ArrayList","skjfghsjk") }
|
||||
buildAndFail("compileKotlin") {
|
||||
assertTrue { projectPath.resolve(".gradle/build_errors").listDirectoryEntries().isEmpty() }
|
||||
assertTrue { projectPath.resolve(kotlinErrorPath).listDirectoryEntries().isEmpty() }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
|
||||
import org.jetbrains.kotlin.gradle.logging.kotlinDebug
|
||||
import org.jetbrains.kotlin.gradle.logging.kotlinInfo
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
|
||||
import org.jetbrains.kotlin.gradle.plugin.internal.JavaSourceSetsAccessor
|
||||
import org.jetbrains.kotlin.gradle.plugin.internal.state.TaskLoggers
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinWithJavaTarget
|
||||
@@ -204,7 +205,8 @@ internal open class GradleCompilerRunner(
|
||||
kotlinScriptExtensions = environment.kotlinScriptExtensions,
|
||||
allWarningsAsErrors = compilerArgs.allWarningsAsErrors,
|
||||
compilerExecutionSettings = compilerExecutionSettings,
|
||||
errorsFile = errorsFile
|
||||
errorsFile = errorsFile,
|
||||
kotlinPluginVersion = getKotlinPluginVersion(loggerProvider)
|
||||
)
|
||||
TaskLoggers.put(pathProvider, loggerProvider)
|
||||
return runCompilerAsync(
|
||||
|
||||
+3
-1
@@ -68,6 +68,7 @@ internal class GradleKotlinCompilerWorkArguments(
|
||||
val allWarningsAsErrors: Boolean,
|
||||
val compilerExecutionSettings: CompilerExecutionSettings,
|
||||
val errorsFile: File?,
|
||||
val kotlinPluginVersion: String,
|
||||
) : Serializable {
|
||||
companion object {
|
||||
const val serialVersionUID: Long = 1
|
||||
@@ -104,6 +105,7 @@ internal class GradleKotlinCompilerWork @Inject constructor(
|
||||
private var icLogLines: List<String> = emptyList()
|
||||
private val compilerExecutionSettings = config.compilerExecutionSettings
|
||||
private val errorsFile = config.errorsFile
|
||||
private val kotlinPluginVersion = config.kotlinPluginVersion
|
||||
|
||||
private val log: KotlinLogger =
|
||||
TaskLoggers.get(taskPath)?.let { GradleKotlinLogger(it).apply { debug("Using '$taskPath' logger") } }
|
||||
@@ -124,7 +126,7 @@ internal class GradleKotlinCompilerWork @Inject constructor(
|
||||
override fun run() {
|
||||
try {
|
||||
val gradlePrintingMessageCollector = GradlePrintingMessageCollector(log, allWarningsAsErrors)
|
||||
val gradleMessageCollector = GradleErrorMessageCollector(gradlePrintingMessageCollector)
|
||||
val gradleMessageCollector = GradleErrorMessageCollector(gradlePrintingMessageCollector, kotlinPluginVersion = kotlinPluginVersion)
|
||||
val (exitCode, executionStrategy) = compileWithDaemonOrFallbackImpl(gradleMessageCollector)
|
||||
if (incrementalCompilationEnvironment?.disableMultiModuleIC == true) {
|
||||
incrementalCompilationEnvironment.multiModuleICSettings.buildHistoryFile.delete()
|
||||
|
||||
+3
-1
@@ -13,7 +13,8 @@ import java.io.FileWriter
|
||||
|
||||
class GradleErrorMessageCollector(
|
||||
private val delegate: MessageCollector? = null,
|
||||
private val acceptableMessageSeverity: List<CompilerMessageSeverity> = listOf(CompilerMessageSeverity.EXCEPTION)
|
||||
private val acceptableMessageSeverity: List<CompilerMessageSeverity> = listOf(CompilerMessageSeverity.EXCEPTION),
|
||||
private val kotlinPluginVersion: String? = null
|
||||
) : MessageCollector {
|
||||
|
||||
private val errors = ArrayList<String>()
|
||||
@@ -48,6 +49,7 @@ class GradleErrorMessageCollector(
|
||||
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) {
|
||||
it.append("error message: $error\n\n")
|
||||
}
|
||||
|
||||
+3
-3
@@ -238,7 +238,7 @@ abstract class GradleCompileTaskProvider @Inject constructor(
|
||||
@get:Internal
|
||||
val errorsFile: Provider<File?> = objectFactory
|
||||
.property(
|
||||
gradle.rootProject.rootDir.resolve(".gradle/build_errors/").also { it.mkdirs() }
|
||||
gradle.rootProject.rootDir.resolve(".gradle/kotlin/errors/").also { it.mkdirs() }
|
||||
.resolve("errors-${System.currentTimeMillis()}.log"))
|
||||
}
|
||||
|
||||
@@ -734,7 +734,7 @@ abstract class KotlinCompile @Inject constructor(
|
||||
|
||||
val scriptSources = scriptSources.asFileTree.files
|
||||
val gradlePrintingMessageCollector = GradlePrintingMessageCollector(logger, args.allWarningsAsErrors,)
|
||||
val gradleMessageCollector = GradleErrorMessageCollector(gradlePrintingMessageCollector)
|
||||
val gradleMessageCollector = GradleErrorMessageCollector(gradlePrintingMessageCollector, kotlinPluginVersion = getKotlinPluginVersion(logger))
|
||||
val outputItemCollector = OutputItemsCollectorImpl()
|
||||
val compilerRunner = compilerRunner.get()
|
||||
|
||||
@@ -1160,7 +1160,7 @@ abstract class Kotlin2JsCompile @Inject constructor(
|
||||
logger.kotlinDebug("compiling with args ${ArgumentUtils.convertArgumentsToStringList(args)}")
|
||||
|
||||
val gradlePrintingMessageCollector = GradlePrintingMessageCollector(logger, args.allWarningsAsErrors)
|
||||
val gradleMessageCollector = GradleErrorMessageCollector(gradlePrintingMessageCollector)
|
||||
val gradleMessageCollector = GradleErrorMessageCollector(gradlePrintingMessageCollector, kotlinPluginVersion = getKotlinPluginVersion(logger))
|
||||
val outputItemCollector = OutputItemsCollectorImpl()
|
||||
val compilerRunner = compilerRunner.get()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user