[Gradle, JS]Process error output and rethrow errors and warns to console
^KT-43869 fixed
This commit is contained in:
+12
-4
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.gradle.utils.clearAnsiColor
|
|||||||
import java.text.ParseException
|
import java.text.ParseException
|
||||||
|
|
||||||
class TeamCityMessageCommonClient(
|
class TeamCityMessageCommonClient(
|
||||||
|
internal val clientType: LogType,
|
||||||
internal val log: Logger
|
internal val log: Logger
|
||||||
) : ServiceMessageParserCallback {
|
) : ServiceMessageParserCallback {
|
||||||
|
|
||||||
@@ -43,9 +44,12 @@ class TeamCityMessageCommonClient(
|
|||||||
afterMessage = true
|
afterMessage = true
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun testFailedMessage(): String {
|
internal fun testFailedMessage(): String? {
|
||||||
return errors
|
return if (errors.isNotEmpty())
|
||||||
.joinToString("\n")
|
errors
|
||||||
|
.joinToString("\n")
|
||||||
|
else
|
||||||
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun printMessage(text: String, type: LogType?) {
|
private fun printMessage(text: String, type: LogType?) {
|
||||||
@@ -74,6 +78,10 @@ class TeamCityMessageCommonClient(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun regularText(text: String) {
|
override fun regularText(text: String) {
|
||||||
printMessage(text, LogType.DEBUG)
|
if (clientType == LogType.ERROR || clientType == LogType.WARN) {
|
||||||
|
printMessage(text, clientType)
|
||||||
|
} else {
|
||||||
|
printMessage(text, LogType.DEBUG)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+5
-3
@@ -71,19 +71,21 @@ internal fun Project.execWithProgress(description: String, readStdErr: Boolean =
|
|||||||
|
|
||||||
internal fun Project.execWithErrorLogger(
|
internal fun Project.execWithErrorLogger(
|
||||||
description: String,
|
description: String,
|
||||||
body: (ExecAction, ProgressLogger) -> TeamCityMessageCommonClient
|
body: (ExecAction, ProgressLogger) -> Pair<TeamCityMessageCommonClient, TeamCityMessageCommonClient>
|
||||||
): ExecResult {
|
): ExecResult {
|
||||||
this as ProjectInternal
|
this as ProjectInternal
|
||||||
|
|
||||||
val exec = services.get(ExecActionFactory::class.java).newExecAction()
|
val exec = services.get(ExecActionFactory::class.java).newExecAction()
|
||||||
return project!!.operation(description) {
|
return project!!.operation(description) {
|
||||||
progress(description)
|
progress(description)
|
||||||
val client = body(exec, this)
|
val (standardClient, errorClient) = body(exec, this)
|
||||||
exec.isIgnoreExitValue = true
|
exec.isIgnoreExitValue = true
|
||||||
val result = exec.execute()
|
val result = exec.execute()
|
||||||
if (result.exitValue != 0) {
|
if (result.exitValue != 0) {
|
||||||
error(
|
error(
|
||||||
client.testFailedMessage()
|
errorClient.testFailedMessage()
|
||||||
|
?: standardClient.testFailedMessage()
|
||||||
|
?: "Error occurred. See log for details."
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
|
|||||||
+22
-16
@@ -9,6 +9,7 @@ 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.LogType
|
||||||
import org.jetbrains.kotlin.gradle.internal.TeamCityMessageCommonClient
|
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.internal.testing.TCServiceMessageOutputStreamHandler
|
||||||
@@ -25,29 +26,29 @@ internal data class KotlinWebpackRunner(
|
|||||||
val config: KotlinWebpackConfig
|
val config: KotlinWebpackConfig
|
||||||
) {
|
) {
|
||||||
fun execute() = npmProject.project.execWithErrorLogger("webpack") { execAction, progressLogger ->
|
fun execute() = npmProject.project.execWithErrorLogger("webpack") { execAction, progressLogger ->
|
||||||
val client = configureClient(progressLogger)
|
configureExec(
|
||||||
client.apply {
|
execAction,
|
||||||
configureExec(
|
progressLogger
|
||||||
execAction,
|
)
|
||||||
client
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun start(): ExecHandle {
|
fun start(): ExecHandle {
|
||||||
val execFactory = execHandleFactory.newExec()
|
val execFactory = execHandleFactory.newExec()
|
||||||
configureExec(
|
configureExec(
|
||||||
execFactory,
|
execFactory,
|
||||||
configureClient(null)
|
null
|
||||||
)
|
)
|
||||||
val exec = execFactory.build()
|
val exec = execFactory.build()
|
||||||
exec.start()
|
exec.start()
|
||||||
return exec
|
return exec
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun configureClient(progressLogger: ProgressLogger?): TeamCityMessageCommonClient {
|
private fun configureClient(
|
||||||
|
clientType: LogType,
|
||||||
|
progressLogger: ProgressLogger?
|
||||||
|
): TeamCityMessageCommonClient {
|
||||||
val logger = npmProject.project.logger
|
val logger = npmProject.project.logger
|
||||||
return TeamCityMessageCommonClient(logger)
|
return TeamCityMessageCommonClient(clientType, logger)
|
||||||
.apply {
|
.apply {
|
||||||
if (progressLogger != null) {
|
if (progressLogger != null) {
|
||||||
this.progressLogger = progressLogger
|
this.progressLogger = progressLogger
|
||||||
@@ -57,21 +58,24 @@ internal data class KotlinWebpackRunner(
|
|||||||
|
|
||||||
private fun configureExec(
|
private fun configureExec(
|
||||||
execFactory: ExecSpec,
|
execFactory: ExecSpec,
|
||||||
client: TeamCityMessageCommonClient
|
progressLogger: ProgressLogger?
|
||||||
) {
|
): Pair<TeamCityMessageCommonClient, 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}\""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val standardClient = configureClient(LogType.LOG, progressLogger)
|
||||||
execFactory.standardOutput = TCServiceMessageOutputStreamHandler(
|
execFactory.standardOutput = TCServiceMessageOutputStreamHandler(
|
||||||
client = client,
|
client = standardClient,
|
||||||
onException = { },
|
onException = { },
|
||||||
logger = client.log
|
logger = standardClient.log
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val errorClient = configureClient(LogType.ERROR, progressLogger)
|
||||||
execFactory.errorOutput = TCServiceMessageOutputStreamHandler(
|
execFactory.errorOutput = TCServiceMessageOutputStreamHandler(
|
||||||
client = client,
|
client = errorClient,
|
||||||
onException = { },
|
onException = { },
|
||||||
logger = client.log
|
logger = errorClient.log
|
||||||
)
|
)
|
||||||
|
|
||||||
config.save(configFile)
|
config.save(configFile)
|
||||||
@@ -89,5 +93,7 @@ internal data class KotlinWebpackRunner(
|
|||||||
nodeArgs,
|
nodeArgs,
|
||||||
args
|
args
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return standardClient to errorClient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user