Use task's logger where appropriate
KT-28836 Using project's logger prevents messages from showing in task's output (in command-line and build scans)
This commit is contained in:
+1
-1
@@ -16,7 +16,7 @@ internal class GradleCompilerRunnerWithWorkers(
|
|||||||
private val workersExecutor: WorkerExecutor
|
private val workersExecutor: WorkerExecutor
|
||||||
) : GradleCompilerRunner(task) {
|
) : GradleCompilerRunner(task) {
|
||||||
override fun runCompilerAsync(workArgs: GradleKotlinCompilerWorkArguments) {
|
override fun runCompilerAsync(workArgs: GradleKotlinCompilerWorkArguments) {
|
||||||
project.logger.kotlinDebug { "Starting Kotlin compiler work from task '${task.path}'" }
|
task.logger.kotlinDebug { "Starting Kotlin compiler work from task '${task.path}'" }
|
||||||
// todo: write tests with Workers enabled;
|
// todo: write tests with Workers enabled;
|
||||||
workersExecutor.submit(GradleKotlinCompilerWork::class.java) { config ->
|
workersExecutor.submit(GradleKotlinCompilerWork::class.java) { config ->
|
||||||
config.isolationMode = IsolationMode.NONE
|
config.isolationMode = IsolationMode.NONE
|
||||||
|
|||||||
+5
-2
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.cli.common.arguments.K2MetadataCompilerArguments
|
|||||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||||
import org.jetbrains.kotlin.daemon.client.CompileServiceSession
|
import org.jetbrains.kotlin.daemon.client.CompileServiceSession
|
||||||
import org.jetbrains.kotlin.daemon.common.*
|
import org.jetbrains.kotlin.daemon.common.*
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.TaskLoggers
|
||||||
import org.jetbrains.kotlin.gradle.plugin.kotlinDebug
|
import org.jetbrains.kotlin.gradle.plugin.kotlinDebug
|
||||||
import org.jetbrains.kotlin.gradle.tasks.*
|
import org.jetbrains.kotlin.gradle.tasks.*
|
||||||
import org.jetbrains.kotlin.gradle.utils.newTmpFile
|
import org.jetbrains.kotlin.gradle.utils.newTmpFile
|
||||||
@@ -121,7 +122,7 @@ internal open class GradleCompilerRunner(protected val task: Task) {
|
|||||||
buildFile: File? = null
|
buildFile: File? = null
|
||||||
) {
|
) {
|
||||||
if (compilerArgs.version) {
|
if (compilerArgs.version) {
|
||||||
project.logger.lifecycle(
|
task.logger.lifecycle(
|
||||||
"Kotlin version " + loadCompilerVersion(environment.compilerClasspath) +
|
"Kotlin version " + loadCompilerVersion(environment.compilerClasspath) +
|
||||||
" (JRE " + System.getProperty("java.runtime.version") + ")"
|
" (JRE " + System.getProperty("java.runtime.version") + ")"
|
||||||
)
|
)
|
||||||
@@ -139,8 +140,10 @@ internal open class GradleCompilerRunner(protected val task: Task) {
|
|||||||
incrementalCompilationEnvironment = incrementalCompilationEnvironment,
|
incrementalCompilationEnvironment = incrementalCompilationEnvironment,
|
||||||
incrementalModuleInfo = modulesInfo,
|
incrementalModuleInfo = modulesInfo,
|
||||||
buildFile = buildFile,
|
buildFile = buildFile,
|
||||||
localStateDirectories = environment.localStateDirectories
|
localStateDirectories = environment.localStateDirectories,
|
||||||
|
taskPath = task.path
|
||||||
)
|
)
|
||||||
|
TaskLoggers.put(task.path, task.logger)
|
||||||
runCompilerAsync(workArgs)
|
runCompilerAsync(workArgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-2
@@ -56,7 +56,8 @@ internal class GradleKotlinCompilerWorkArguments(
|
|||||||
val incrementalCompilationEnvironment: IncrementalCompilationEnvironment?,
|
val incrementalCompilationEnvironment: IncrementalCompilationEnvironment?,
|
||||||
val incrementalModuleInfo: IncrementalModuleInfo?,
|
val incrementalModuleInfo: IncrementalModuleInfo?,
|
||||||
val buildFile: File?,
|
val buildFile: File?,
|
||||||
val localStateDirectories: List<File>
|
val localStateDirectories: List<File>,
|
||||||
|
val taskPath: String
|
||||||
) : Serializable {
|
) : Serializable {
|
||||||
companion object {
|
companion object {
|
||||||
const val serialVersionUID: Long = 0
|
const val serialVersionUID: Long = 0
|
||||||
@@ -84,9 +85,14 @@ internal class GradleKotlinCompilerWork @Inject constructor(
|
|||||||
private val incrementalModuleInfo = config.incrementalModuleInfo
|
private val incrementalModuleInfo = config.incrementalModuleInfo
|
||||||
private val buildFile = config.buildFile
|
private val buildFile = config.buildFile
|
||||||
private val localStateDirectories = config.localStateDirectories
|
private val localStateDirectories = config.localStateDirectories
|
||||||
|
private val taskPath = config.taskPath
|
||||||
|
|
||||||
private val log: KotlinLogger =
|
private val log: KotlinLogger =
|
||||||
SL4JKotlinLogger(LoggerFactory.getLogger("GradleKotlinCompilerWork"))
|
TaskLoggers.get(taskPath)?.let { GradleKotlinLogger(it) }
|
||||||
|
?: run {
|
||||||
|
System.err.println("Could not get logger for '$taskPath'. Falling back to sl4j logger")
|
||||||
|
SL4JKotlinLogger(LoggerFactory.getLogger("GradleKotlinCompilerWork"))
|
||||||
|
}
|
||||||
private val messageCollector = GradleMessageCollector(log)
|
private val messageCollector = GradleMessageCollector(log)
|
||||||
|
|
||||||
private val isIncremental: Boolean
|
private val isIncremental: Boolean
|
||||||
|
|||||||
+2
@@ -66,6 +66,7 @@ internal class KotlinGradleBuildServices private constructor(gradle: Gradle) : B
|
|||||||
// but it is called before any plugin can attach build listener
|
// but it is called before any plugin can attach build listener
|
||||||
fun buildStarted() {
|
fun buildStarted() {
|
||||||
startMemory = getUsedMemoryKb()
|
startMemory = getUsedMemoryKb()
|
||||||
|
TaskLoggers.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun buildFinished(result: BuildResult) {
|
override fun buildFinished(result: BuildResult) {
|
||||||
@@ -97,6 +98,7 @@ internal class KotlinGradleBuildServices private constructor(gradle: Gradle) : B
|
|||||||
log.lifecycle("[KOTLIN][PERF] Used memory after build: $endMem kb (difference since build start: ${"%+d".format(endMem - startMem)} kb)")
|
log.lifecycle("[KOTLIN][PERF] Used memory after build: $endMem kb (difference since build start: ${"%+d".format(endMem - startMem)} kb)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TaskLoggers.clear()
|
||||||
gradle.removeListener(this)
|
gradle.removeListener(this)
|
||||||
instance = null
|
instance = null
|
||||||
log.kotlinDebug(DISPOSE_MESSAGE)
|
log.kotlinDebug(DISPOSE_MESSAGE)
|
||||||
|
|||||||
+4
-4
@@ -84,11 +84,11 @@ open class KotlinPlatformImplementationPluginBase(platformName: String) : Kotlin
|
|||||||
|
|
||||||
val incrementalMultiplatform = PropertiesProvider(project).incrementalMultiplatform ?: true
|
val incrementalMultiplatform = PropertiesProvider(project).incrementalMultiplatform ?: true
|
||||||
project.afterEvaluate {
|
project.afterEvaluate {
|
||||||
project.tasks.withType(AbstractKotlinCompile::class.java).all {
|
project.tasks.withType(AbstractKotlinCompile::class.java).all { task ->
|
||||||
if (it.incremental && !incrementalMultiplatform) {
|
if (task.incremental && !incrementalMultiplatform) {
|
||||||
project.logger.debug("IC is turned off for task '${it.path}' because multiplatform IC is not enabled")
|
task.logger.debug("IC is turned off for task '${task.path}' because multiplatform IC is not enabled")
|
||||||
}
|
}
|
||||||
it.incremental = it.incremental && incrementalMultiplatform
|
task.incremental = task.incremental && incrementalMultiplatform
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2018 JetBrains s.r.o. 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.plugin
|
||||||
|
|
||||||
|
import org.gradle.api.logging.Logger
|
||||||
|
import java.lang.ref.WeakReference
|
||||||
|
import java.util.HashMap
|
||||||
|
|
||||||
|
// todo: remove when https://github.com/gradle/gradle/issues/2678 is resolved
|
||||||
|
object TaskLoggers {
|
||||||
|
private val taskLoggers = HashMap<String, WeakReference<Logger>>()
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
fun put(path: String, logger: Logger) {
|
||||||
|
taskLoggers[path] = WeakReference(logger)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
fun get(path: String): Logger? =
|
||||||
|
taskLoggers[path]?.get()
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
fun clear() {
|
||||||
|
taskLoggers.clear()
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-3
@@ -91,14 +91,14 @@ open class DiscoverScriptExtensionsTask : DefaultTask() {
|
|||||||
val definitions =
|
val definitions =
|
||||||
ScriptDefinitionsFromClasspathDiscoverySource(
|
ScriptDefinitionsFromClasspathDiscoverySource(
|
||||||
scriptingClasspath.toList(), emptyMap(),
|
scriptingClasspath.toList(), emptyMap(),
|
||||||
GradleMessageCollector(project.logger)
|
GradleMessageCollector(logger)
|
||||||
).definitions
|
).definitions
|
||||||
val extensions = definitions.mapTo(arrayListOf(), KotlinScriptDefinition::fileExtension)
|
val extensions = definitions.mapTo(arrayListOf(), KotlinScriptDefinition::fileExtension)
|
||||||
val kotlinSourceSet = sourceSet.getConvention(KOTLIN_DSL_NAME) as? KotlinSourceSet
|
val kotlinSourceSet = sourceSet.getConvention(KOTLIN_DSL_NAME) as? KotlinSourceSet
|
||||||
if (kotlinSourceSet == null) {
|
if (kotlinSourceSet == null) {
|
||||||
project.logger.warn("kotlin scripting plugin: kotlin source set not found: $project.$sourceSet")
|
logger.warn("kotlin scripting plugin: kotlin source set not found: $project.$sourceSet")
|
||||||
} else if (extensions.isNotEmpty()) {
|
} else if (extensions.isNotEmpty()) {
|
||||||
project.logger.info("kotlin scripting plugin: Add new extensions to the sourceset $project.$sourceSet: $extensions")
|
logger.info("kotlin scripting plugin: Add new extensions to the sourceset $project.$sourceSet: $extensions")
|
||||||
kotlinSourceSet.kotlin.filter.include(extensions.map { "**/*.$it" })
|
kotlinSourceSet.kotlin.filter.include(extensions.map { "**/*.$it" })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -73,7 +73,7 @@ open class KotlinJsDce : AbstractKotlinCompileTool<K2JSDceArguments>(), KotlinJs
|
|||||||
|
|
||||||
val argsArray = serializedCompilerArguments.toTypedArray()
|
val argsArray = serializedCompilerArguments.toTypedArray()
|
||||||
|
|
||||||
val log = GradleKotlinLogger(project.logger)
|
val log = GradleKotlinLogger(logger)
|
||||||
val allArgs = argsArray + outputDirArgs + inputFiles
|
val allArgs = argsArray + outputDirArgs + inputFiles
|
||||||
val exitCode = runToolInSeparateProcess(
|
val exitCode = runToolInSeparateProcess(
|
||||||
allArgs, K2JSDce::class.java.name, computedCompilerClasspath,
|
allArgs, K2JSDce::class.java.name, computedCompilerClasspath,
|
||||||
|
|||||||
+5
-5
@@ -50,7 +50,7 @@ const val USING_JS_INCREMENTAL_COMPILATION_MESSAGE = "Using Kotlin/JS incrementa
|
|||||||
|
|
||||||
abstract class AbstractKotlinCompileTool<T : CommonToolArguments>() : AbstractCompile(), CompilerArgumentAwareWithInput<T> {
|
abstract class AbstractKotlinCompileTool<T : CommonToolArguments>() : AbstractCompile(), CompilerArgumentAwareWithInput<T> {
|
||||||
private fun useCompilerClasspathConfigurationMessage(propertyName: String) {
|
private fun useCompilerClasspathConfigurationMessage(propertyName: String) {
|
||||||
project.logger.kotlinWarn(
|
logger.kotlinWarn(
|
||||||
"'$path.$propertyName' is deprecated and will be removed soon. " +
|
"'$path.$propertyName' is deprecated and will be removed soon. " +
|
||||||
"Use '$COMPILER_CLASSPATH_CONFIGURATION_NAME' " +
|
"Use '$COMPILER_CLASSPATH_CONFIGURATION_NAME' " +
|
||||||
"configuration for customizing compiler classpath."
|
"configuration for customizing compiler classpath."
|
||||||
@@ -94,7 +94,7 @@ abstract class AbstractKotlinCompileTool<T : CommonToolArguments>() : AbstractCo
|
|||||||
try {
|
try {
|
||||||
project.configurations.getByName(COMPILER_CLASSPATH_CONFIGURATION_NAME).resolve().toList()
|
project.configurations.getByName(COMPILER_CLASSPATH_CONFIGURATION_NAME).resolve().toList()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
project.logger.error(
|
logger.error(
|
||||||
"Could not resolve compiler classpath. " +
|
"Could not resolve compiler classpath. " +
|
||||||
"Check if Kotlin Gradle plugin repository is configured in $project."
|
"Check if Kotlin Gradle plugin repository is configured in $project."
|
||||||
)
|
)
|
||||||
@@ -296,7 +296,7 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractKo
|
|||||||
|
|
||||||
logger.kotlinDebug { "args.coroutinesState=${args.coroutinesState}" }
|
logger.kotlinDebug { "args.coroutinesState=${args.coroutinesState}" }
|
||||||
|
|
||||||
if (project.logger.isDebugEnabled) {
|
if (logger.isDebugEnabled) {
|
||||||
args.verbose = true
|
args.verbose = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,7 +428,7 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
|
|||||||
}.firstOrNull() as? AbstractCompile
|
}.firstOrNull() as? AbstractCompile
|
||||||
|
|
||||||
if (illegalTask != null) {
|
if (illegalTask != null) {
|
||||||
project.logger.info(
|
logger.info(
|
||||||
"Kotlin inter-project IC is disabled: " +
|
"Kotlin inter-project IC is disabled: " +
|
||||||
"unknown task '$illegalTask' destination dir ${illegalTask.destinationDir} " +
|
"unknown task '$illegalTask' destination dir ${illegalTask.destinationDir} " +
|
||||||
"intersects with java destination dir $javaOutputDir"
|
"intersects with java destination dir $javaOutputDir"
|
||||||
@@ -577,7 +577,7 @@ private fun Task.getGradleVersion(): ParsedGradleVersion? {
|
|||||||
val gradleVersion = project.gradle.gradleVersion
|
val gradleVersion = project.gradle.gradleVersion
|
||||||
val result = ParsedGradleVersion.parse(gradleVersion)
|
val result = ParsedGradleVersion.parse(gradleVersion)
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
project.logger.kotlinDebug("Could not parse gradle version: $gradleVersion")
|
logger.kotlinDebug("Could not parse gradle version: $gradleVersion")
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user