diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/TeamCityMessageCommonClient.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/TeamCityMessageCommonClient.kt index 1ef8b70d4e6..e43dccccd0e 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/TeamCityMessageCommonClient.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/TeamCityMessageCommonClient.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.gradle.utils.clearAnsiColor import java.text.ParseException class TeamCityMessageCommonClient( + internal val clientType: LogType, internal val log: Logger ) : ServiceMessageParserCallback { @@ -43,9 +44,12 @@ class TeamCityMessageCommonClient( afterMessage = true } - internal fun testFailedMessage(): String { - return errors - .joinToString("\n") + internal fun testFailedMessage(): String? { + return if (errors.isNotEmpty()) + errors + .joinToString("\n") + else + null } private fun printMessage(text: String, type: LogType?) { @@ -74,6 +78,10 @@ class TeamCityMessageCommonClient( } override fun regularText(text: String) { - printMessage(text, LogType.DEBUG) + if (clientType == LogType.ERROR || clientType == LogType.WARN) { + printMessage(text, clientType) + } else { + printMessage(text, LogType.DEBUG) + } } } \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/exec.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/exec.kt index 5cd9218efee..c2cc1834c84 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/exec.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/internal/exec.kt @@ -71,19 +71,21 @@ internal fun Project.execWithProgress(description: String, readStdErr: Boolean = internal fun Project.execWithErrorLogger( description: String, - body: (ExecAction, ProgressLogger) -> TeamCityMessageCommonClient + body: (ExecAction, ProgressLogger) -> Pair ): ExecResult { this as ProjectInternal val exec = services.get(ExecActionFactory::class.java).newExecAction() return project!!.operation(description) { progress(description) - val client = body(exec, this) + val (standardClient, errorClient) = body(exec, this) exec.isIgnoreExitValue = true val result = exec.execute() if (result.exitValue != 0) { error( - client.testFailedMessage() + errorClient.testFailedMessage() + ?: standardClient.testFailedMessage() + ?: "Error occurred. See log for details." ) } result diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/js/webpack/KotlinWebpackRunner.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/js/webpack/KotlinWebpackRunner.kt index 5ab35d23639..d39cccd7ccb 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/js/webpack/KotlinWebpackRunner.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/js/webpack/KotlinWebpackRunner.kt @@ -9,6 +9,7 @@ import org.gradle.internal.logging.progress.ProgressLogger import org.gradle.process.ExecSpec import org.gradle.process.internal.ExecHandle import org.gradle.process.internal.ExecHandleFactory +import org.jetbrains.kotlin.gradle.internal.LogType import org.jetbrains.kotlin.gradle.internal.TeamCityMessageCommonClient import org.jetbrains.kotlin.gradle.internal.execWithErrorLogger import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessageOutputStreamHandler @@ -25,29 +26,29 @@ internal data class KotlinWebpackRunner( val config: KotlinWebpackConfig ) { fun execute() = npmProject.project.execWithErrorLogger("webpack") { execAction, progressLogger -> - val client = configureClient(progressLogger) - client.apply { - configureExec( - execAction, - client - ) - } + configureExec( + execAction, + progressLogger + ) } fun start(): ExecHandle { val execFactory = execHandleFactory.newExec() configureExec( execFactory, - configureClient(null) + null ) val exec = execFactory.build() exec.start() return exec } - private fun configureClient(progressLogger: ProgressLogger?): TeamCityMessageCommonClient { + private fun configureClient( + clientType: LogType, + progressLogger: ProgressLogger? + ): TeamCityMessageCommonClient { val logger = npmProject.project.logger - return TeamCityMessageCommonClient(logger) + return TeamCityMessageCommonClient(clientType, logger) .apply { if (progressLogger != null) { this.progressLogger = progressLogger @@ -57,21 +58,24 @@ internal data class KotlinWebpackRunner( private fun configureExec( execFactory: ExecSpec, - client: TeamCityMessageCommonClient - ) { + progressLogger: ProgressLogger? + ): Pair { check(config.entry?.isFile == true) { "${this}: Entry file not existed \"${config.entry}\"" } + val standardClient = configureClient(LogType.LOG, progressLogger) execFactory.standardOutput = TCServiceMessageOutputStreamHandler( - client = client, + client = standardClient, onException = { }, - logger = client.log + logger = standardClient.log ) + + val errorClient = configureClient(LogType.ERROR, progressLogger) execFactory.errorOutput = TCServiceMessageOutputStreamHandler( - client = client, + client = errorClient, onException = { }, - logger = client.log + logger = errorClient.log ) config.save(configFile) @@ -89,5 +93,7 @@ internal data class KotlinWebpackRunner( nodeArgs, args ) + + return standardClient to errorClient } } \ No newline at end of file