[Gradle] Unify a bit logic of retrieving task loggers
This commit is contained in:
committed by
Space Team
parent
b1ec2eb18a
commit
1556925358
+2
-12
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
|
||||
import org.jetbrains.kotlin.gradle.logging.*
|
||||
import org.jetbrains.kotlin.gradle.plugin.internal.state.TaskExecutionResults
|
||||
import org.jetbrains.kotlin.gradle.plugin.internal.state.TaskLoggers
|
||||
import org.jetbrains.kotlin.gradle.plugin.internal.state.getTaskLogger
|
||||
import org.jetbrains.kotlin.gradle.report.*
|
||||
import org.jetbrains.kotlin.gradle.tasks.*
|
||||
import org.jetbrains.kotlin.gradle.utils.stackTraceAsString
|
||||
@@ -109,18 +110,7 @@ internal class GradleKotlinCompilerWork @Inject constructor(
|
||||
private val kotlinPluginVersion = config.kotlinPluginVersion
|
||||
private val kotlinLanguageVersion = config.kotlinLanguageVersion
|
||||
|
||||
private val log: KotlinLogger =
|
||||
TaskLoggers.get(taskPath)?.let { GradleKotlinLogger(it).apply { debug("Using '$taskPath' logger") } }
|
||||
?: run {
|
||||
val logger = LoggerFactory.getLogger("GradleKotlinCompilerWork")
|
||||
val kotlinLogger = if (logger is Logger) {
|
||||
GradleKotlinLogger(logger)
|
||||
} else SL4JKotlinLogger(logger)
|
||||
|
||||
kotlinLogger.apply {
|
||||
debug("Could not get logger for '$taskPath'. Falling back to sl4j logger")
|
||||
}
|
||||
}
|
||||
private val log: KotlinLogger = getTaskLogger(taskPath, null, "GradleKotlinCompilerWork")
|
||||
|
||||
private val isIncremental: Boolean
|
||||
get() = incrementalCompilationEnvironment != null
|
||||
|
||||
+2
-13
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.gradle.logging.SL4JKotlinLogger
|
||||
import org.jetbrains.kotlin.gradle.plugin.BuildFinishedListenerService
|
||||
import org.jetbrains.kotlin.gradle.plugin.internal.BuildIdService
|
||||
import org.jetbrains.kotlin.gradle.plugin.internal.state.TaskLoggers
|
||||
import org.jetbrains.kotlin.gradle.plugin.internal.state.getTaskLogger
|
||||
import org.jetbrains.kotlin.gradle.tasks.*
|
||||
import org.jetbrains.kotlin.gradle.tasks.FailedCompilationException
|
||||
import org.jetbrains.kotlin.gradle.tasks.TaskOutputsBackup
|
||||
@@ -58,19 +59,7 @@ internal abstract class BuildToolsApiCompilationWork @Inject constructor(
|
||||
private val taskPath
|
||||
get() = workArguments.taskPath
|
||||
|
||||
private val log: KotlinLogger by lazy(LazyThreadSafetyMode.NONE) {
|
||||
TaskLoggers.get(taskPath)?.let { GradleKotlinLogger(it, LOGGER_PREFIX).apply { debug("Using '$taskPath' logger") } }
|
||||
?: run {
|
||||
val logger = LoggerFactory.getLogger("GradleKotlinCompilerWork")
|
||||
val kotlinLogger = if (logger is org.gradle.api.logging.Logger) {
|
||||
GradleKotlinLogger(logger, LOGGER_PREFIX)
|
||||
} else SL4JKotlinLogger(logger, LOGGER_PREFIX)
|
||||
|
||||
kotlinLogger.apply {
|
||||
debug("Could not get logger for '$taskPath'. Falling back to sl4j logger")
|
||||
}
|
||||
}
|
||||
}
|
||||
private val log: KotlinLogger = getTaskLogger(taskPath, LOGGER_PREFIX, BuildToolsApiCompilationWork::class.java.simpleName)
|
||||
|
||||
private fun performCompilation(): CompilationResult {
|
||||
val executionStrategy = workArguments.compilerExecutionSettings.strategy
|
||||
|
||||
+17
-1
@@ -6,6 +6,9 @@
|
||||
package org.jetbrains.kotlin.gradle.plugin.internal.state
|
||||
|
||||
import org.gradle.api.logging.Logger
|
||||
import org.jetbrains.kotlin.gradle.logging.GradleKotlinLogger
|
||||
import org.jetbrains.kotlin.gradle.logging.SL4JKotlinLogger
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.lang.ref.WeakReference
|
||||
import java.util.HashMap
|
||||
|
||||
@@ -26,4 +29,17 @@ internal object TaskLoggers {
|
||||
fun clear() {
|
||||
taskLoggers.clear()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal fun getTaskLogger(taskPath: String, prefix: String?, fallbackLoggerName: String) =
|
||||
TaskLoggers.get(taskPath)?.let { GradleKotlinLogger(it, prefix).apply { debug("Using '$taskPath' logger") } }
|
||||
?: run {
|
||||
val logger = LoggerFactory.getLogger(fallbackLoggerName)
|
||||
val kotlinLogger = if (logger is Logger) {
|
||||
GradleKotlinLogger(logger, prefix)
|
||||
} else SL4JKotlinLogger(logger, prefix)
|
||||
|
||||
kotlinLogger.apply {
|
||||
debug("Could not get logger for '$taskPath'. Falling back to sl4j logger")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user