[Gradle, JS] Add TC client on TC output handler for browser run task
^KT-40178 fixed
This commit is contained in:
+4
-3
@@ -14,12 +14,13 @@ import org.jetbrains.kotlin.gradle.utils.clearAnsiColor
|
||||
import java.text.ParseException
|
||||
|
||||
class TeamCityMessageCommonClient(
|
||||
private val log: Logger,
|
||||
private val progressLogger: ProgressLogger
|
||||
internal val log: Logger
|
||||
) : ServiceMessageParserCallback {
|
||||
|
||||
var afterMessage = false
|
||||
|
||||
var progressLogger: ProgressLogger? = null
|
||||
|
||||
private val errors = mutableListOf<String>()
|
||||
|
||||
private val stackTraceProcessor =
|
||||
@@ -49,7 +50,7 @@ class TeamCityMessageCommonClient(
|
||||
|
||||
private fun printMessage(text: String, type: LogType?) {
|
||||
val value = text.trimEnd()
|
||||
progressLogger.progress(value)
|
||||
progressLogger?.progress(value)
|
||||
|
||||
val actualText = if (afterMessage)
|
||||
when {
|
||||
|
||||
+7
-13
@@ -5,8 +5,10 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.internal
|
||||
|
||||
import jetbrains.buildServer.messages.serviceMessages.ServiceMessageParserCallback
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.internal.project.ProjectInternal
|
||||
import org.gradle.internal.logging.progress.ProgressLogger
|
||||
import org.gradle.process.ExecResult
|
||||
import org.gradle.process.internal.ExecAction
|
||||
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
|
||||
|
||||
val exec = services.get(ExecActionFactory::class.java).newExecAction()
|
||||
body(exec)
|
||||
return project!!.operation(description) {
|
||||
progress(description)
|
||||
val client = TeamCityMessageCommonClient(logger, this)
|
||||
exec.standardOutput = TCServiceMessageOutputStreamHandler(
|
||||
client = client,
|
||||
onException = { },
|
||||
logger = logger
|
||||
)
|
||||
exec.errorOutput = TCServiceMessageOutputStreamHandler(
|
||||
client = client,
|
||||
onException = { },
|
||||
logger = logger
|
||||
)
|
||||
val client = body(exec, this)
|
||||
exec.isIgnoreExitValue = true
|
||||
val result = exec.execute()
|
||||
if (result.exitValue != 0) {
|
||||
|
||||
+40
-4
@@ -5,10 +5,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.targets.js.webpack
|
||||
|
||||
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.TeamCityMessageCommonClient
|
||||
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 java.io.File
|
||||
|
||||
@@ -21,23 +24,56 @@ internal data class KotlinWebpackRunner(
|
||||
val nodeArgs: List<String>,
|
||||
val config: KotlinWebpackConfig
|
||||
) {
|
||||
fun execute() = npmProject.project.execWithErrorLogger("webpack") {
|
||||
configureExec(it)
|
||||
fun execute() = npmProject.project.execWithErrorLogger("webpack") { execAction, progressLogger ->
|
||||
val client = configureClient(progressLogger)
|
||||
client.apply {
|
||||
configureExec(
|
||||
execAction,
|
||||
client
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun start(): ExecHandle {
|
||||
val execFactory = execHandleFactory.newExec()
|
||||
configureExec(execFactory)
|
||||
configureExec(
|
||||
execFactory,
|
||||
configureClient(null)
|
||||
)
|
||||
val exec = execFactory.build()
|
||||
exec.start()
|
||||
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) {
|
||||
"${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)
|
||||
|
||||
val args = mutableListOf<String>("--config", configFile.absolutePath)
|
||||
|
||||
Reference in New Issue
Block a user