diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/TeamCityMessageCommonClient.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/TeamCityMessageCommonClient.kt index e43dccccd0e..77fbed26a66 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/TeamCityMessageCommonClient.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/TeamCityMessageCommonClient.kt @@ -13,7 +13,7 @@ import org.gradle.internal.logging.progress.ProgressLogger import org.jetbrains.kotlin.gradle.utils.clearAnsiColor import java.text.ParseException -class TeamCityMessageCommonClient( +open class TeamCityMessageCommonClient( internal val clientType: LogType, internal val log: Logger ) : ServiceMessageParserCallback { @@ -52,7 +52,7 @@ class TeamCityMessageCommonClient( null } - private fun printMessage(text: String, type: LogType?) { + internal open fun printMessage(text: String, type: LogType?) { val value = text.trimEnd() progressLogger?.progress(value) @@ -78,10 +78,10 @@ class TeamCityMessageCommonClient( } override fun regularText(text: String) { - if (clientType == LogType.ERROR || clientType == LogType.WARN) { + if (clientType.isErrorLike()) { printMessage(text, clientType) } else { - printMessage(text, LogType.DEBUG) + printMessage(text, LogType.INFO) } } } \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/TeamCityServiceMessages.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/TeamCityServiceMessages.kt index aa8e5eb3fb8..5fc6a2369fa 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/TeamCityServiceMessages.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/TeamCityServiceMessages.kt @@ -18,6 +18,7 @@ internal fun SlfLogger.processLogMessage( type = type, error = ::error, warn = ::warn, + lifecycle = ::info, info = ::info, debug = ::debug ) @@ -33,6 +34,7 @@ internal fun GradleLogger.processLogMessage( type = type, error = ::error, warn = ::warn, + lifecycle = ::lifecycle, info = ::info, debug = ::debug ) @@ -43,6 +45,7 @@ private fun processLogMessageInternal( type: LogType, error: (text: String) -> Unit, warn: (text: String) -> Unit, + lifecycle: (text: String) -> Unit, info: (text: String) -> Unit, debug: (text: String) -> Unit ) { @@ -54,6 +57,7 @@ private fun processLogMessageInternal( LogType.ERROR -> { error(nonColoredMessage) } + LogType.LIFECYCLE -> lifecycle(nonColoredMessage) LogType.INFO, LogType.LOG -> info(nonColoredMessage) LogType.DEBUG -> debug(nonColoredMessage) } @@ -62,6 +66,7 @@ private fun processLogMessageInternal( enum class LogType(val value: String) { ERROR("error"), WARN("warn"), + LIFECYCLE("lifecycle"), INFO("info"), DEBUG("debug"), LOG("log"); diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/testing/TCServiceMessageOutputStreamHandler.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/testing/TCServiceMessageOutputStreamHandler.kt index ddb54d49d19..118208065d7 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/testing/TCServiceMessageOutputStreamHandler.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/internal/testing/TCServiceMessageOutputStreamHandler.kt @@ -20,7 +20,7 @@ import java.io.OutputStream * Calls [client] for each parsed message and regular text. * * TeamCity server messages should ends with new line. - * Only messages short than [MESSAGE_LIMIT_BYTES] supported. + * Only messages shorter than [MESSAGE_LIMIT_BYTES] supported. */ internal class TCServiceMessageOutputStreamHandler( private val client: ServiceMessageParserCallback, diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/webpack/KotlinWebpackConfig.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/webpack/KotlinWebpackConfig.kt index ee0034ae007..d0d2e77797d 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/webpack/KotlinWebpackConfig.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/webpack/KotlinWebpackConfig.kt @@ -150,7 +150,6 @@ data class KotlinWebpackConfig( appendSourceMaps() appendOptimization() appendDevServer() - appendProgressReporter() rules.forEach { rule -> if (rule.active) { with(rule) { appendToWebpackConfig() } @@ -313,34 +312,6 @@ data class KotlinWebpackConfig( ) } - private fun Appendable.appendProgressReporter() { - if (!progressReporter) return - - //language=ES6 - appendLine( - """ - // Report progress to console - // noinspection JSUnnecessarySemicolon - ;(function(config) { - const webpack = require('webpack'); - const handler = (percentage, message, ...args) => { - const p = percentage * 100; - let msg = `${"$"}{Math.trunc(p / 10)}${"$"}{Math.trunc(p % 10)}% ${"$"}{message} ${"$"}{args.join(' ')}`; - ${ - if (progressReporterPathFilterInput == null) "" else """ - msg = msg.replace(require('path').resolve(__dirname, ${progressReporterPathFilterInput!!.jsQuoted()}), ''); - """.trimIndent() - }; - console.log(msg); - }; - - config.plugins.push(new webpack.ProgressPlugin(handler)) - })(config); - - """.trimIndent() - ) - } - private fun json(obj: Any) = StringWriter().also { GsonBuilder().setPrettyPrinting().create().toJson(obj, it) }.toString() diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/webpack/KotlinWebpackRunner.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/webpack/KotlinWebpackRunner.kt index 757634096ab..21573f1fbf2 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/webpack/KotlinWebpackRunner.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/webpack/KotlinWebpackRunner.kt @@ -50,7 +50,7 @@ internal data class KotlinWebpackRunner( clientType: LogType, progressLogger: ProgressLogger? ): TeamCityMessageCommonClient { - return TeamCityMessageCommonClient(clientType, logger) + return WebpackLogClient(clientType, logger) .apply { if (progressLogger != null) { this.progressLogger = progressLogger diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/webpack/WebpackLogClient.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/webpack/WebpackLogClient.kt new file mode 100644 index 00000000000..cba0cd262c3 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/targets/js/webpack/WebpackLogClient.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2010-2024 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.webpack + +import org.gradle.api.logging.Logger +import org.jetbrains.kotlin.gradle.internal.LogType +import org.jetbrains.kotlin.gradle.internal.TeamCityMessageCommonClient + +class WebpackLogClient( + clientType: LogType, + log: Logger +) : TeamCityMessageCommonClient(clientType, log) { + override fun regularText(text: String) { + if (WEBPACK_INITIAL_REGEX.matches(text)) { + printMessage(text, LogType.LIFECYCLE) + } else { + super.regularText(text) + } + } + + override fun printMessage(text: String, type: LogType?) { + if (WEBPACK_COMPILED_REGEX.matches(text)) { + super.printMessage(text, LogType.LIFECYCLE) + } else { + super.printMessage(text, type) + } + } + + companion object { + internal val WEBPACK_COMPILED_REGEX = "webpack (.+) compiled (.+) in .+\\s".toRegex() + internal val WEBPACK_INITIAL_REGEX = " \\[.+] .+\\s".toRegex() + } +} \ No newline at end of file