Fix warnings related to appendln in kotlin-gradle-plugin

`appendln` is deprecated, but its replacement `appendLine` can't be used
yet in kotlin-gradle-plugin because it's compiled with API version 1.3.
This commit is contained in:
Alexander Udalov
2021-04-14 14:07:25 +02:00
committed by TeamCityServer
parent e5128a8772
commit 19a5c2f1c8
11 changed files with 91 additions and 75 deletions
@@ -6,8 +6,8 @@
package org.jetbrains.kotlin.gradle.report
import org.gradle.api.invocation.Gradle
import org.jetbrains.kotlin.gradle.utils.appendLine
import java.io.File
import java.util.*
import kotlin.math.max
class KotlinBuildReporterHandler {
@@ -38,25 +38,25 @@ class KotlinBuildReporterHandler {
}
return buildString {
appendln("Gradle start parameters:")
appendLine("Gradle start parameters:")
startParams.forEach {
appendln(" $it")
appendLine(" $it")
}
if (failure != null) {
appendln("Build failed: ${failure}")
appendLine("Build failed: ${failure}")
}
appendln()
appendLine()
}
}
internal fun taskOverview(kotlinTaskTimeNs: Map<String, Long>, allTasksTimeNs: Long): String {
if (kotlinTaskTimeNs.isEmpty()) return buildString { appendln("No Kotlin task was run") }
if (kotlinTaskTimeNs.isEmpty()) return buildString { appendLine("No Kotlin task was run") }
val sb = StringBuilder()
val kotlinTotalTimeNs = kotlinTaskTimeNs.values.sum()
val ktTaskPercent = (kotlinTotalTimeNs.toDouble() / allTasksTimeNs * 100).asString(1)
sb.appendln("Total time for Kotlin tasks: ${formatTime(kotlinTotalTimeNs)} ($ktTaskPercent % of all tasks time)")
sb.appendLine("Total time for Kotlin tasks: ${formatTime(kotlinTotalTimeNs)} ($ktTaskPercent % of all tasks time)")
val table = TextTable("Time", "% of Kotlin time", "Task")
kotlinTaskTimeNs.entries
@@ -66,7 +66,7 @@ class KotlinBuildReporterHandler {
table.addRow(formatTime(timeNs), "$percent %", taskPath)
}
table.printTo(sb)
sb.appendln()
sb.appendLine()
return sb.toString()
}
@@ -90,7 +90,7 @@ class KotlinBuildReporterHandler {
fun printTo(sb: StringBuilder) {
for (row in rows) {
sb.appendln()
sb.appendLine()
for ((i, col) in row.withIndex()) {
if (i > 0) sb.append("|")
@@ -107,4 +107,4 @@ internal fun formatTime(ns: Long): String {
}
internal fun Double.asString(decPoints: Int): String =
String.format("%.${decPoints}f", this)
String.format("%.${decPoints}f", this)
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.gradle.targets.js.internal
import org.jetbrains.kotlin.gradle.internal.testing.ParsedStackTrace
import org.jetbrains.kotlin.gradle.utils.appendLine
data class NodeJsStackTrace(
val message: String?,
@@ -118,7 +119,7 @@ fun parseNodeJsStackTrace(stackTrace: String): NodeJsStackTrace {
)
} else {
if (firstLines) {
message.appendln(it)
message.appendLine(it)
}
}
}
@@ -137,4 +138,4 @@ private fun filterMethodName(name: String): String =
val suffix = name.substringAfterLast("_")
if (suffix.endsWith("$") || suffix.toIntOrNull() != null) name.substringBeforeLast("_")
else name
} else name
} else name
@@ -35,6 +35,7 @@ import org.jetbrains.kotlin.gradle.targets.js.webpack.WebpackMajorVersion
import org.jetbrains.kotlin.gradle.targets.js.webpack.WebpackMajorVersion.Companion.choose
import org.jetbrains.kotlin.gradle.tasks.KotlinTest
import org.jetbrains.kotlin.gradle.testing.internal.reportsDir
import org.jetbrains.kotlin.gradle.utils.appendLine
import org.jetbrains.kotlin.gradle.utils.isConfigurationCacheAvailable
import org.jetbrains.kotlin.gradle.utils.property
import org.slf4j.Logger
@@ -113,7 +114,7 @@ class KotlinKarma(
// Not all log events goes through this appender
// For example Error in config file
//language=ES6
it.appendln(
it.appendLine(
"""
config.plugins = config.plugins || [];
config.plugins.push('kotlin-test-js-runner/karma-kotlin-reporter.js');
@@ -225,13 +226,13 @@ class KotlinKarma(
addPreprocessor("webpack")
confJsWriters.add {
it.appendln()
it.appendln("// webpack config")
it.appendln("function createWebpackConfig() {")
it.appendLine()
it.appendLine("// webpack config")
it.appendLine("function createWebpackConfig() {")
webpackConfig.appendTo(it)
//language=ES6
it.appendln(
it.appendLine(
"""
// noinspection JSUnnecessarySemicolon
;(function(config) {
@@ -252,11 +253,11 @@ class KotlinKarma(
""".trimIndent()
)
it.appendln(" return config;")
it.appendln("}")
it.appendln()
it.appendln("config.set({webpack: createWebpackConfig()});")
it.appendln()
it.appendLine(" return config;")
it.appendLine("}")
it.appendLine()
it.appendLine("config.set({webpack: createWebpackConfig()});")
it.appendLine()
}
}
@@ -351,7 +352,7 @@ class KotlinKarma(
confJsWriters.add {
//language=ES6
it.appendln(
it.appendLine(
"""
if (!config.plugins) {
config.plugins = config.plugins || [];
@@ -568,11 +569,11 @@ class KotlinKarma(
return
}
appendln()
appendLine()
appendConfigsFromDir(configDirectory)
appendln()
appendLine()
}
}
private val KARMA_MESSAGE = "^.*\\d{2} \\d{2} \\d{4,} \\d{2}:\\d{2}:\\d{2}.\\d{3}:(ERROR|WARN|INFO|DEBUG|LOG) \\[.*]: ([\\w\\W]*)\$"
.toRegex()
.toRegex()
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.gradle.targets.js
import org.jetbrains.kotlin.gradle.utils.appendLine
import java.io.File
fun Appendable.appendConfigsFromDir(confDir: File) {
@@ -15,10 +16,10 @@ fun Appendable.appendConfigsFromDir(confDir: File) {
.filter { it.extension == "js" }
.sortedBy { it.name }
.forEach {
appendln("// ${it.name}")
appendLine("// ${it.name}")
append(it.readText())
appendln()
appendln()
appendLine()
appendLine()
}
}
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackCssMode.EXTRA
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackCssMode.IMPORT
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackCssMode.INLINE
import org.jetbrains.kotlin.gradle.targets.js.webpack.WebpackMajorVersion.Companion.choose
import org.jetbrains.kotlin.gradle.utils.appendLine
import java.io.File
import java.io.Serializable
import java.io.StringWriter
@@ -171,7 +172,7 @@ data class KotlinWebpackConfig(
fun appendTo(target: Appendable) {
with(target) {
//language=JavaScript 1.8
appendln(
appendLine(
"""
let config = {
mode: '${mode.code}',
@@ -202,7 +203,7 @@ data class KotlinWebpackConfig(
if (export) {
//language=JavaScript 1.8
appendln("module.exports = config")
appendLine("module.exports = config")
}
}
}
@@ -213,7 +214,7 @@ data class KotlinWebpackConfig(
val filePath = reportEvaluatedConfigFile!!.canonicalPath.jsQuoted()
//language=JavaScript 1.8
appendln(
appendLine(
"""
// save evaluated config file
;(function(config) {
@@ -230,9 +231,9 @@ data class KotlinWebpackConfig(
private fun Appendable.appendFromConfigDir() {
if (configDirectory == null || !configDirectory!!.isDirectory) return
appendln()
appendLine()
appendConfigsFromDir(configDirectory!!)
appendln()
appendLine()
}
private fun Appendable.appendReport() {
@@ -250,7 +251,7 @@ data class KotlinWebpackConfig(
)
//language=JavaScript 1.8
appendln(
appendLine(
"""
// save webpack-bundle-analyzer report
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
@@ -258,22 +259,22 @@ data class KotlinWebpackConfig(
""".trimIndent()
)
appendln()
appendLine()
}
private fun Appendable.appendDevServer() {
if (devServer == null) return
appendln("// dev server")
appendln("config.devServer = ${json(devServer!!)};")
appendln()
appendLine("// dev server")
appendLine("config.devServer = ${json(devServer!!)};")
appendLine()
}
private fun Appendable.appendSourceMaps() {
if (!sourceMaps) return
//language=JavaScript 1.8
appendln(
appendLine(
"""
// source maps
config.module.rules.push({
@@ -309,7 +310,7 @@ data class KotlinWebpackConfig(
val multiEntryOutput = "${outputFileName!!.removeSuffix(".js")}-[name].js"
//language=JavaScript 1.8
appendln(
appendLine(
"""
// entry
config.entry = {
@@ -336,7 +337,7 @@ data class KotlinWebpackConfig(
if (!cssSupport.enabled || cssSupport.rules.isEmpty())
return
appendln(
appendLine(
"""
// css settings
;(function(config) {
@@ -372,12 +373,12 @@ data class KotlinWebpackConfig(
""".trimMargin()
cssSupport.rules.forEach { rule ->
appendln(
appendLine(
"""
| ;(function(config) {
""".trimMargin()
)
appendln(
appendLine(
"""
| const use = [
| {
@@ -389,9 +390,9 @@ data class KotlinWebpackConfig(
)
when (rule.mode) {
EXTRACT -> appendln(extractedCss)
INLINE -> appendln(inlinedCss)
IMPORT -> appendln(importedCss)
EXTRACT -> appendLine(extractedCss)
INLINE -> appendLine(inlinedCss)
IMPORT -> appendLine(importedCss)
else -> cssError()
}
@@ -407,7 +408,7 @@ data class KotlinWebpackConfig(
} else null
}
appendln(
appendLine(
"""
| config.module.rules.push({
| test: /\.css${'$'}/,
@@ -419,7 +420,7 @@ data class KotlinWebpackConfig(
""".trimMargin()
)
appendln(
appendLine(
"""
| })(config);
@@ -427,7 +428,7 @@ data class KotlinWebpackConfig(
)
}
appendln(
appendLine(
"""
})(config);
@@ -437,7 +438,7 @@ data class KotlinWebpackConfig(
private fun Appendable.appendErrorPlugin() {
//language=ES6
appendln(
appendLine(
"""
// noinspection JSUnnecessarySemicolon
;(function(config) {
@@ -457,7 +458,7 @@ data class KotlinWebpackConfig(
if (!resolveFromModulesFirst || entry == null || entry!!.parent == null) return
//language=JavaScript 1.8
appendln(
appendLine(
"""
// resolve modules
config.resolve.modules.unshift(${entry!!.parent.jsQuoted()})
@@ -470,7 +471,7 @@ data class KotlinWebpackConfig(
if (!progressReporter) return
//language=ES6
appendln(
appendLine(
"""
// Report progress to console
// noinspection JSUnnecessarySemicolon
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.gradle.targets.native
import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeCompilation
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.utils.appendLine
internal object CompilationFreeArgsValidator : AggregateReporter() {
@@ -66,24 +67,24 @@ internal object CompilationFreeArgsValidator : AggregateReporter() {
}
val message = buildString {
appendln()
appendln("The following free compiler arguments must be specified for a binary instead of a compilation:")
appendLine()
appendLine("The following free compiler arguments must be specified for a binary instead of a compilation:")
incorrectArgs.forEach { (project, reports) ->
appendln("* In project '${project.path}':".withIndent(1))
appendLine("* In project '${project.path}':".withIndent(1))
val groupedReports = reports
.groupBy { it.target }
.toSortedMap(compareBy { it.name })
groupedReports.forEach { (target, reports) ->
appendln("* In target '${target.name}':".withIndent(2))
appendLine("* In target '${target.name}':".withIndent(2))
reports.forEach {
appendln(
appendLine(
"* Compilation: '${it.compilation.name}', arguments: [${it.incorrectArgs.joinToString()}]".withIndent(3)
)
}
}
}
appendln()
appendln(
appendLine()
appendLine(
"""
Please move them into final binary declarations. E.g. binaries.executable { freeCompilerArgs += "..." }
See more about final binaries: https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#building-final-native-binaries.
@@ -9,6 +9,7 @@ import org.gradle.api.Project
import org.gradle.api.plugins.ExtraPropertiesExtension
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.utils.appendLine
import org.jetbrains.kotlin.konan.target.HostManager
import org.jetbrains.kotlin.konan.target.KonanTarget
@@ -58,10 +59,10 @@ internal object DisabledNativeTargetsReporter : AggregateReporter() {
.toSortedMap(compareBy { it.path })
project.logger.warn(buildString {
appendln("\n$WARNING_PREFIX${HostManager.host} machine and are disabled:")
appendLine("\n$WARNING_PREFIX${HostManager.host} machine and are disabled:")
disabledTargetGroups.forEach { (targetProject, targetsBySupportedHosts) ->
appendln(
appendLine(
" * In project '${targetProject.path}':"
)
targetsBySupportedHosts.forEach { (supportedHosts, disabledTargets) ->
@@ -72,10 +73,10 @@ internal object DisabledNativeTargetsReporter : AggregateReporter() {
1 -> "a ${supportedHosts.single()} host"
else -> "one of the hosts: ${supportedHosts.joinToString(", ")}"
}
appendln(" (can be built with $supportedHostsString)")
appendLine(" (can be built with $supportedHostsString)")
}
}
appendln("To hide this message, add '$DISABLE_WARNING_PROPERTY_NAME=true' to the Gradle properties.")
appendLine("To hide this message, add '$DISABLE_WARNING_PROPERTY_NAME=true' to the Gradle properties.")
})
}
}
}
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.gradle.targets.native.internal
import org.jetbrains.kotlin.gradle.internal.testing.ParsedStackTrace
import org.jetbrains.kotlin.gradle.utils.appendLine
data class KotlinNativeStackTrace(
val message: String?,
@@ -126,7 +127,7 @@ fun parseKotlinNativeStackTrace(stackTrace: String): KotlinNativeStackTrace {
}
} else {
if (firstLines) {
message.appendln(it)
message.appendLine(it)
}
}
}
@@ -135,4 +136,4 @@ fun parseKotlinNativeStackTrace(stackTrace: String): KotlinNativeStackTrace {
message.toString().trim().let { if (it.isEmpty()) null else it },
if (stack.isEmpty()) null else stack
)
}
}
@@ -12,6 +12,7 @@ import org.gradle.api.tasks.*
import org.jetbrains.kotlin.gradle.plugin.cocoapods.asValidFrameworkName
import org.jetbrains.kotlin.gradle.plugin.mpp.Framework
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.utils.appendLine
import org.jetbrains.kotlin.konan.target.Architecture
import org.jetbrains.kotlin.konan.target.Family
import org.jetbrains.kotlin.konan.target.KonanTarget.*
@@ -234,13 +235,13 @@ open class FatFrameworkTask : DefaultTask() {
headerContents.toList().forEachIndexed { i, (arch, content) ->
val macro = arch.clangMacro
if (i == 0) {
writer.appendln("#if defined($macro)\n")
writer.appendLine("#if defined($macro)\n")
} else {
writer.appendln("#elif defined($macro)\n")
writer.appendLine("#elif defined($macro)\n")
}
writer.appendln(content)
writer.appendLine(content)
}
writer.appendln(
writer.appendLine(
"""
#else
#error Unsupported platform
@@ -16,6 +16,7 @@ import org.gradle.api.tasks.testing.*
import org.jetbrains.kotlin.gradle.internal.testing.KotlinTestRunnerListener
import org.jetbrains.kotlin.gradle.plugin.PropertiesProvider
import org.jetbrains.kotlin.gradle.tasks.KotlinTest
import org.jetbrains.kotlin.gradle.utils.appendLine
import java.io.File
import java.net.URI
@@ -171,7 +172,7 @@ open class KotlinTestReport : TestReport() {
if (taskFailures.isNotEmpty()) {
val allErrors = mutableListOf<Error>()
val msg = buildString {
appendln("Failed to execute all tests:")
appendLine("Failed to execute all tests:")
taskFailures.groupBy { it.first }.forEach { (path, errors) ->
append(path)
append(": ")
@@ -179,7 +180,7 @@ open class KotlinTestReport : TestReport() {
errors.forEach { (_, error) ->
allErrors.add(error)
append(error.message)
if (first) first = false else appendln()
if (first) first = false else appendLine()
}
}
@@ -189,7 +190,7 @@ open class KotlinTestReport : TestReport() {
logger.warn(getFailingTestsMessage())
} else {
allErrors.add(Error(failedTestsMessage))
appendln("Also: $failedTestsMessage")
appendLine("Also: $failedTestsMessage")
}
}
}
@@ -40,4 +40,11 @@ internal fun String.asValidTaskName() = replace(invalidTaskNameCharacters, "_")
private val ANSI_COLOR_REGEX = "\\x1b\\[[0-9;]*m".toRegex()
internal fun String.clearAnsiColor() =
replace(ANSI_COLOR_REGEX, "")
replace(ANSI_COLOR_REGEX, "")
// Copy of stdlib's appendLine which is only available since 1.4. Can be removed as soon as this code is compiled with API >= 1.4.
internal fun Appendable.appendLine(value: Any?): Appendable =
append(value.toString()).appendLine()
internal fun Appendable.appendLine(): Appendable =
append('\n')