[Gradle, JS] Beautiful log for webpack
#KT-38286 fixed
This commit is contained in:
+34
-2
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* that can be found in the license/LICENSE.txt file.
|
* 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.internal
|
package org.jetbrains.kotlin.gradle.internal
|
||||||
@@ -10,6 +10,8 @@ import org.gradle.api.internal.project.ProjectInternal
|
|||||||
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
|
||||||
|
import org.jetbrains.kotlin.gradle.internal.testing.TCServiceMessageOutputStreamHandler
|
||||||
|
import org.jetbrains.kotlin.gradle.targets.js.TeamCityMessageCommonClient
|
||||||
import java.io.ByteArrayOutputStream
|
import java.io.ByteArrayOutputStream
|
||||||
import java.io.PipedInputStream
|
import java.io.PipedInputStream
|
||||||
import java.io.PipedOutputStream
|
import java.io.PipedOutputStream
|
||||||
@@ -65,3 +67,33 @@ internal fun Project.execWithProgress(description: String, readStdErr: Boolean =
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal fun Project.execWithErrorLogger(description: String, body: (ExecAction) -> Unit): ExecResult {
|
||||||
|
this as ProjectInternal
|
||||||
|
|
||||||
|
val exec = services.get(ExecActionFactory::class.java).newExecAction()
|
||||||
|
body(exec)
|
||||||
|
return project!!.operation(description) {
|
||||||
|
progress(description)
|
||||||
|
exec.standardOutput = TCServiceMessageOutputStreamHandler(
|
||||||
|
client = TeamCityMessageCommonClient(logger, this),
|
||||||
|
onException = { },
|
||||||
|
logger = logger
|
||||||
|
)
|
||||||
|
exec.errorOutput = TCServiceMessageOutputStreamHandler(
|
||||||
|
client = TeamCityMessageCommonClient(logger, this),
|
||||||
|
onException = { },
|
||||||
|
logger = logger
|
||||||
|
)
|
||||||
|
exec.isIgnoreExitValue = true
|
||||||
|
val result = exec.execute()
|
||||||
|
if (result.exitValue != 0) {
|
||||||
|
error(
|
||||||
|
"""
|
||||||
|
Process '$description' returns ${result.exitValue}
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
|
}
|
||||||
+39
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 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
|
||||||
|
|
||||||
|
import jetbrains.buildServer.messages.serviceMessages.Message
|
||||||
|
import jetbrains.buildServer.messages.serviceMessages.ServiceMessage
|
||||||
|
import jetbrains.buildServer.messages.serviceMessages.ServiceMessageParserCallback
|
||||||
|
import org.gradle.api.logging.Logger
|
||||||
|
import org.gradle.internal.logging.progress.ProgressLogger
|
||||||
|
import java.text.ParseException
|
||||||
|
|
||||||
|
class TeamCityMessageCommonClient(
|
||||||
|
private val log: Logger,
|
||||||
|
private val progressLogger: ProgressLogger
|
||||||
|
) : ServiceMessageParserCallback {
|
||||||
|
override fun parseException(e: ParseException, text: String) {
|
||||||
|
log.error("Failed to parse test process messages: \"$text\"", e)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun serviceMessage(message: ServiceMessage) {
|
||||||
|
when (message) {
|
||||||
|
is Message -> printMessage(message.text, message.attributes["type"])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun printMessage(text: String, type: String?) {
|
||||||
|
val value = text.trimEnd()
|
||||||
|
progressLogger.progress(value)
|
||||||
|
|
||||||
|
type?.let { log.processLogMessage(value, it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun regularText(text: String) {
|
||||||
|
printMessage(text, null)
|
||||||
|
}
|
||||||
|
}
|
||||||
+17
-2
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@file:Suppress("NodeJsCodingAssistanceForCoreModules", "JSUnresolvedFunction")
|
@file:Suppress("NodeJsCodingAssistanceForCoreModules", "JSUnresolvedFunction")
|
||||||
@@ -41,6 +41,7 @@ data class KotlinWebpackConfig(
|
|||||||
) {
|
) {
|
||||||
fun getRequiredDependencies(versions: NpmVersions) =
|
fun getRequiredDependencies(versions: NpmVersions) =
|
||||||
mutableListOf<RequiredKotlinJsDependency>().also {
|
mutableListOf<RequiredKotlinJsDependency>().also {
|
||||||
|
it.add(versions.kotlinJsTestRunner)
|
||||||
it.add(versions.webpack)
|
it.add(versions.webpack)
|
||||||
it.add(versions.webpackCli)
|
it.add(versions.webpackCli)
|
||||||
|
|
||||||
@@ -131,6 +132,7 @@ data class KotlinWebpackConfig(
|
|||||||
appendReport()
|
appendReport()
|
||||||
appendProgressReporter()
|
appendProgressReporter()
|
||||||
appendCssSettings()
|
appendCssSettings()
|
||||||
|
appendErrorPlugin()
|
||||||
appendFromConfigDir()
|
appendFromConfigDir()
|
||||||
appendEvaluatedFileReport()
|
appendEvaluatedFileReport()
|
||||||
|
|
||||||
@@ -357,6 +359,19 @@ data class KotlinWebpackConfig(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun Appendable.appendErrorPlugin() {
|
||||||
|
//language=ES6
|
||||||
|
appendln(
|
||||||
|
"""
|
||||||
|
// noinspection JSUnnecessarySemicolon
|
||||||
|
;(function(config) {
|
||||||
|
const tcErrorPlugin = require('kotlin-test-js-runner/tc-log-error-webpack');
|
||||||
|
config.plugins.push(new tcErrorPlugin(tcErrorPlugin))
|
||||||
|
})(config);
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun Appendable.appendResolveModules() {
|
private fun Appendable.appendResolveModules() {
|
||||||
if (!resolveFromModulesFirst || entry == null || entry.parent == null) return
|
if (!resolveFromModulesFirst || entry == null || entry.parent == null) return
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* that can be found in the license/LICENSE.txt file.
|
* 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
|
package org.jetbrains.kotlin.gradle.targets.js.webpack
|
||||||
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.gradle.targets.js.webpack
|
|||||||
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.execWithProgress
|
import org.jetbrains.kotlin.gradle.internal.execWithErrorLogger
|
||||||
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
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ internal data class KotlinWebpackRunner(
|
|||||||
val tool: String,
|
val tool: String,
|
||||||
val config: KotlinWebpackConfig
|
val config: KotlinWebpackConfig
|
||||||
) {
|
) {
|
||||||
fun execute() = npmProject.project.execWithProgress("webpack") {
|
fun execute() = npmProject.project.execWithErrorLogger("webpack") {
|
||||||
configureExec(it)
|
configureExec(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user