[Gradle, JS] Stack trace processor

#KT-38109 fixed
#KT-38286 fixed
This commit is contained in:
Ilya Goncharov
2020-04-14 19:45:49 +03:00
parent 3c033c168c
commit 480a9c16fb
2 changed files with 27 additions and 11 deletions
@@ -0,0 +1,19 @@
/*
* Copyright 2010-2020 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.targets.js
internal class TeamCityMessageStackTraceProcessor {
private var firstLine: String? = null
fun process(text: String, firstLineAction: (String?) -> Unit) {
firstLine = if (text.trim().startsWith("at ")) {
firstLineAction(firstLine)
null
} else {
text
}
}
}
@@ -425,7 +425,7 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) :
private val failedBrowsers: MutableList<String> = mutableListOf()
private var previousLine: String = ""
private var stackTraceProcessor = TeamCityMessageStackTraceProcessor()
override fun printNonTestOutput(text: String, type: String?) {
val value = text.trimEnd()
@@ -436,19 +436,16 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) :
private fun parseConsole(text: String, type: String?) {
val actualType = if (text.trim().startsWith("at ")) {
parseConsole(previousLine, ERROR)
previousLine = ""
ERROR
} else {
previousLine = text
type
var actualType = type
stackTraceProcessor.process(text) { line ->
actualType = ERROR
line?.let { parseConsole(it, actualType) }
}
val launcherMessage = KARMA_LAUNCHER_MESSAGE.matchEntire(text)
val launcherMessage = KARMA_MESSAGE.matchEntire(text)
val actualText = if (launcherMessage != null) {
val (message) = launcherMessage.destructured
val (_, message) = launcherMessage.destructured
when (actualType?.toLowerCase()) {
WARN, ERROR -> {
processFailedBrowsers(text)
@@ -542,5 +539,5 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) :
}
}
private val KARMA_LAUNCHER_MESSAGE = "^.*\\[launcher]: ([\\w\\W]*)\$"
private val KARMA_MESSAGE = "^.*\\d{2} \\d{2} \\d{4,} \\d{2}:\\d{2}:\\d{2}.\\d{3}:(ERROR|WARN|INFO|DEBUG|LOG) \\[.*]: ([\\w\\W]*)\$"
.toRegex()