[Gradle, JS] Add TC client on TC output handler for browser run task

^KT-40178 fixed
This commit is contained in:
Ilya Goncharov
2020-07-10 13:49:41 +03:00
parent 943d012875
commit 797449f7e4
3 changed files with 51 additions and 20 deletions
@@ -14,12 +14,13 @@ import org.jetbrains.kotlin.gradle.utils.clearAnsiColor
import java.text.ParseException import java.text.ParseException
class TeamCityMessageCommonClient( class TeamCityMessageCommonClient(
private val log: Logger, internal val log: Logger
private val progressLogger: ProgressLogger
) : ServiceMessageParserCallback { ) : ServiceMessageParserCallback {
var afterMessage = false var afterMessage = false
var progressLogger: ProgressLogger? = null
private val errors = mutableListOf<String>() private val errors = mutableListOf<String>()
private val stackTraceProcessor = private val stackTraceProcessor =
@@ -49,7 +50,7 @@ class TeamCityMessageCommonClient(
private fun printMessage(text: String, type: LogType?) { private fun printMessage(text: String, type: LogType?) {
val value = text.trimEnd() val value = text.trimEnd()
progressLogger.progress(value) progressLogger?.progress(value)
val actualText = if (afterMessage) val actualText = if (afterMessage)
when { when {
@@ -5,8 +5,10 @@
package org.jetbrains.kotlin.gradle.internal package org.jetbrains.kotlin.gradle.internal
import jetbrains.buildServer.messages.serviceMessages.ServiceMessageParserCallback
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.internal.project.ProjectInternal import org.gradle.api.internal.project.ProjectInternal
import org.gradle.internal.logging.progress.ProgressLogger
import org.gradle.process.ExecResult import org.gradle.process.ExecResult
import org.gradle.process.internal.ExecAction import org.gradle.process.internal.ExecAction
import org.gradle.process.internal.ExecActionFactory import org.gradle.process.internal.ExecActionFactory
@@ -67,24 +69,16 @@ internal fun Project.execWithProgress(description: String, readStdErr: Boolean =
} }
} }
internal fun Project.execWithErrorLogger(description: String, body: (ExecAction) -> Unit): ExecResult { internal fun Project.execWithErrorLogger(
description: String,
body: (ExecAction, ProgressLogger) -> TeamCityMessageCommonClient
): ExecResult {
this as ProjectInternal this as ProjectInternal
val exec = services.get(ExecActionFactory::class.java).newExecAction() val exec = services.get(ExecActionFactory::class.java).newExecAction()
body(exec)
return project!!.operation(description) { return project!!.operation(description) {
progress(description) progress(description)
val client = TeamCityMessageCommonClient(logger, this) val client = body(exec, this)
exec.standardOutput = TCServiceMessageOutputStreamHandler(
client = client,
onException = { },
logger = logger
)
exec.errorOutput = TCServiceMessageOutputStreamHandler(
client = client,
onException = { },
logger = logger
)
exec.isIgnoreExitValue = true exec.isIgnoreExitValue = true
val result = exec.execute() val result = exec.execute()
if (result.exitValue != 0) { if (result.exitValue != 0) {
@@ -5,10 +5,13 @@
package org.jetbrains.kotlin.gradle.targets.js.webpack package org.jetbrains.kotlin.gradle.targets.js.webpack
import org.gradle.internal.logging.progress.ProgressLogger
import org.gradle.process.ExecSpec import org.gradle.process.ExecSpec
import org.gradle.process.internal.ExecHandle import org.gradle.process.internal.ExecHandle
import org.gradle.process.internal.ExecHandleFactory import org.gradle.process.internal.ExecHandleFactory
import org.jetbrains.kotlin.gradle.internal.TeamCityMessageCommonClient
import org.jetbrains.kotlin.gradle.internal.execWithErrorLogger import org.jetbrains.kotlin.gradle.internal.execWithErrorLogger
import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessageOutputStreamHandler
import org.jetbrains.kotlin.gradle.targets.js.npm.NpmProject import org.jetbrains.kotlin.gradle.targets.js.npm.NpmProject
import java.io.File import java.io.File
@@ -21,23 +24,56 @@ internal data class KotlinWebpackRunner(
val nodeArgs: List<String>, val nodeArgs: List<String>,
val config: KotlinWebpackConfig val config: KotlinWebpackConfig
) { ) {
fun execute() = npmProject.project.execWithErrorLogger("webpack") { fun execute() = npmProject.project.execWithErrorLogger("webpack") { execAction, progressLogger ->
configureExec(it) val client = configureClient(progressLogger)
client.apply {
configureExec(
execAction,
client
)
}
} }
fun start(): ExecHandle { fun start(): ExecHandle {
val execFactory = execHandleFactory.newExec() val execFactory = execHandleFactory.newExec()
configureExec(execFactory) configureExec(
execFactory,
configureClient(null)
)
val exec = execFactory.build() val exec = execFactory.build()
exec.start() exec.start()
return exec return exec
} }
private fun configureExec(execFactory: ExecSpec) { private fun configureClient(progressLogger: ProgressLogger?): TeamCityMessageCommonClient {
val logger = npmProject.project.logger
return TeamCityMessageCommonClient(logger)
.apply {
if (progressLogger != null) {
this.progressLogger = progressLogger
}
}
}
private fun configureExec(
execFactory: ExecSpec,
client: TeamCityMessageCommonClient
) {
check(config.entry?.isFile == true) { check(config.entry?.isFile == true) {
"${this}: Entry file not existed \"${config.entry}\"" "${this}: Entry file not existed \"${config.entry}\""
} }
execFactory.standardOutput = TCServiceMessageOutputStreamHandler(
client = client,
onException = { },
logger = client.log
)
execFactory.errorOutput = TCServiceMessageOutputStreamHandler(
client = client,
onException = { },
logger = client.log
)
config.save(configFile) config.save(configFile)
val args = mutableListOf<String>("--config", configFile.absolutePath) val args = mutableListOf<String>("--config", configFile.absolutePath)