From 96017ae862eadffd5fe846db4242fabd313ccab7 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Sat, 24 Oct 2020 19:34:16 +0800 Subject: [PATCH 001/133] MiraiConsoleLoggerController --- .../console/MiraiConsoleImplementation.kt | 10 +-- .../MiraiConsoleImplementationBridge.kt | 21 ++++++- .../internal/data/builtins/LoggerConfig.kt | 50 +++++++++++++++ .../console/logging/MiraiConsoleLogger.kt | 47 ++++++++++++++ .../logging/MiraiConsoleLoggerController.kt | 26 ++++++++ ...MiraiConsoleLoggerControllerForFrontend.kt | 39 ++++++++++++ ...iraiConsoleLoggerControllerPlatformBase.kt | 36 +++++++++++ .../logging/MiraiConsoleLoggerUnused.kt | 61 +++++++++++++++++++ .../console/logging/MiraiDelegateLogger.kt | 24 ++++++++ .../mamoe/mirai/console/TestMiraiConosle.kt | 12 ++-- .../MiraiConsoleImplementationTerminal.kt | 7 ++- 11 files changed, 316 insertions(+), 17 deletions(-) create mode 100644 backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/LoggerConfig.kt create mode 100644 backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLogger.kt create mode 100644 backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerController.kt create mode 100644 backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerControllerForFrontend.kt create mode 100644 backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerControllerPlatformBase.kt create mode 100644 backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerUnused.kt create mode 100644 backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiDelegateLogger.kt diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt index a1fd6347a..55281c8df 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt @@ -18,13 +18,13 @@ import net.mamoe.mirai.console.MiraiConsoleImplementation.Companion.start import net.mamoe.mirai.console.command.ConsoleCommandSender import net.mamoe.mirai.console.data.PluginDataStorage import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge +import net.mamoe.mirai.console.logging.MiraiConsoleLoggerController import net.mamoe.mirai.console.plugin.jvm.JvmPluginLoader import net.mamoe.mirai.console.plugin.loader.PluginLoader import net.mamoe.mirai.console.util.ConsoleInput import net.mamoe.mirai.message.data.Message import net.mamoe.mirai.utils.BotConfiguration import net.mamoe.mirai.utils.LoginSolver -import net.mamoe.mirai.utils.MiraiLogger import java.nio.file.Path import java.util.* import java.util.concurrent.locks.ReentrantLock @@ -161,13 +161,7 @@ public interface MiraiConsoleImplementation : CoroutineScope { */ public fun createLoginSolver(requesterBot: Long, configuration: BotConfiguration): LoginSolver - /** - * 创建一个 [MiraiLogger]. - * - * **注意**: [MiraiConsole] 会将 [net.mamoe.mirai.utils.DefaultLogger] 设置为 `MiraiConsole::createLogger`. - * 因此不要在 [createLogger] 中调用 [net.mamoe.mirai.utils.DefaultLogger] - */ - public fun createLogger(identity: String?): MiraiLogger + public val loggerController: MiraiConsoleLoggerController public companion object { internal lateinit var instance: MiraiConsoleImplementation diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt index 175af2331..c67694f6d 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt @@ -31,12 +31,17 @@ import net.mamoe.mirai.console.extensions.SingletonExtensionSelector import net.mamoe.mirai.console.internal.command.CommandManagerImpl import net.mamoe.mirai.console.internal.data.builtins.AutoLoginConfig import net.mamoe.mirai.console.internal.data.builtins.ConsoleDataScope +import net.mamoe.mirai.console.internal.data.builtins.LoggerConfig import net.mamoe.mirai.console.internal.data.castOrNull import net.mamoe.mirai.console.internal.extension.BuiltInSingletonExtensionSelector import net.mamoe.mirai.console.internal.extension.GlobalComponentStorage import net.mamoe.mirai.console.internal.permission.BuiltInPermissionService import net.mamoe.mirai.console.internal.plugin.PluginManagerImpl import net.mamoe.mirai.console.internal.util.autoHexToBytes +import net.mamoe.mirai.console.logging.MiraiConsoleLoggerController +import net.mamoe.mirai.console.logging.MiraiConsoleLoggerControllerForFrontend +import net.mamoe.mirai.console.logging.MiraiConsoleLoggerUnused +import net.mamoe.mirai.console.logging.MiraiDelegateLogger import net.mamoe.mirai.console.permission.PermissionService import net.mamoe.mirai.console.permission.PermissionService.Companion.grantPermission import net.mamoe.mirai.console.permission.RootPermission @@ -82,6 +87,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI override val dataStorageForBuiltIns: PluginDataStorage by instance::dataStorageForBuiltIns override val configStorageForBuiltIns: PluginDataStorage by instance::configStorageForBuiltIns override val consoleInput: ConsoleInput by instance::consoleInput + override val loggerController: MiraiConsoleLoggerController by instance::loggerController override fun createLoginSolver(requesterBot: Long, configuration: BotConfiguration): LoginSolver = instance.createLoginSolver(requesterBot, configuration) @@ -90,10 +96,22 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI DefaultLogger = this::createLogger } - override fun createLogger(identity: String?): MiraiLogger = instance.createLogger(identity) + + override fun createLogger(identity: String?): MiraiLogger { + val controller = loggerController + val logger = MiraiConsoleLoggerUnused(controller, identity) + val delegate = MiraiDelegateLogger(logger) + logger.delegateLogger = delegate + return delegate + } @Suppress("RemoveRedundantBackticks") internal fun doStart() { + phase `setup logger controller`@{ + if (loggerController is MiraiConsoleLoggerControllerForFrontend) { + ConsoleDataScope.addAndReloadConfig(LoggerConfig) + } + } phase `greeting`@{ val buildDateFormatted = buildDate.atZone(ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) @@ -102,7 +120,6 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI mainLogger.info { "Backend: version $version, built on $buildDateFormatted." } mainLogger.info { frontEndDescription.render() } } - phase `check coroutineContext`@{ if (coroutineContext[Job] == null) { throw MalformedMiraiConsoleImplementationError("The coroutineContext given to MiraiConsole must have a Job in it.") diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/LoggerConfig.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/LoggerConfig.kt new file mode 100644 index 000000000..da403aa53 --- /dev/null +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/LoggerConfig.kt @@ -0,0 +1,50 @@ +/* + * Copyright 2019-2020 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + * + */ + +package net.mamoe.mirai.console.internal.data.builtins + +import net.mamoe.mirai.console.data.AutoSavePluginConfig +import net.mamoe.mirai.console.data.value +import net.mamoe.mirai.utils.SimpleLogger +import java.util.* + +internal object LoggerConfig : AutoSavePluginConfig("Logger") { + val defaultPriority by value(LogPriority.INFO) + val loggers: Map by value( + mapOf("example.logger" to LogPriority.NONE) + ) + + enum class LogPriority { + ALL(null), + VERBOSE, + DEBUG, + INFO, + WARNING, + ERROR, + NONE(null); + + var mapped: SimpleLogger.LogPriority? = null + + // resolve NullPointerException + private object Holder { + @JvmField + val mapping = EnumMap(SimpleLogger.LogPriority::class.java) + } + companion object { + fun by(priority: SimpleLogger.LogPriority): LogPriority = Holder.mapping[priority]!! + } + constructor(void: Nothing?) + constructor() { + mapped = SimpleLogger.LogPriority.valueOf(name) + Holder.mapping[mapped] = this + } + + } +} diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLogger.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLogger.kt new file mode 100644 index 000000000..2c2bcf531 --- /dev/null +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLogger.kt @@ -0,0 +1,47 @@ +/* + * Copyright 2019-2020 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + * + */ + +package net.mamoe.mirai.console.logging + +import net.mamoe.mirai.utils.MiraiLogger +import net.mamoe.mirai.utils.MiraiLoggerPlatformBase +import net.mamoe.mirai.utils.SimpleLogger + +internal class MiraiConsoleLogger( + private val controller: MiraiConsoleLoggerController, + val logger: MiraiLogger +) : MiraiLoggerPlatformBase() { + override val identity: String? get() = logger.identity + override val isEnabled: Boolean get() = logger.isEnabled + override fun info0(message: String?, e: Throwable?) { + if (controller.shouldLog(identity, SimpleLogger.LogPriority.INFO)) + logger.info(message, e) + } + + override fun warning0(message: String?, e: Throwable?) { + if (controller.shouldLog(identity, SimpleLogger.LogPriority.WARNING)) + logger.warning(message, e) + } + + override fun debug0(message: String?, e: Throwable?) { + if (controller.shouldLog(identity, SimpleLogger.LogPriority.DEBUG)) + logger.debug(message, e) + } + + override fun error0(message: String?, e: Throwable?) { + if (controller.shouldLog(identity, SimpleLogger.LogPriority.ERROR)) + logger.error(message, e) + } + + override fun verbose0(message: String?, e: Throwable?) { + if (controller.shouldLog(identity, SimpleLogger.LogPriority.VERBOSE)) + logger.verbose(message, e) + } +} diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerController.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerController.kt new file mode 100644 index 000000000..1c5126d1d --- /dev/null +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerController.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2019-2020 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + * + */ + +package net.mamoe.mirai.console.logging + +import net.mamoe.mirai.console.ConsoleFrontEndImplementation +import net.mamoe.mirai.console.util.ConsoleExperimentalApi +import net.mamoe.mirai.utils.MiraiLogger +import net.mamoe.mirai.utils.SimpleLogger +import java.util.concurrent.atomic.AtomicReference + +@ConsoleExperimentalApi +@ConsoleFrontEndImplementation +public interface MiraiConsoleLoggerController { + public fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean + public val cacheLoggers: Boolean + public fun newLoggerImpl(identity: String?): MiraiLogger + public fun allocateLoggerRegistration(identity: String?): AtomicReference +} diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerControllerForFrontend.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerControllerForFrontend.kt new file mode 100644 index 000000000..58ee58c7e --- /dev/null +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerControllerForFrontend.kt @@ -0,0 +1,39 @@ +/* + * Copyright 2019-2020 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + * + */ + +package net.mamoe.mirai.console.logging + +import net.mamoe.mirai.console.ConsoleFrontEndImplementation +import net.mamoe.mirai.console.internal.data.builtins.ConsoleDataScope +import net.mamoe.mirai.console.internal.data.builtins.LoggerConfig +import net.mamoe.mirai.console.util.ConsoleInternalApi +import net.mamoe.mirai.utils.SimpleLogger + +@ConsoleFrontEndImplementation +@ConsoleInternalApi +public abstract class MiraiConsoleLoggerControllerForFrontend : MiraiConsoleLoggerControllerPlatformBase() { + + private fun shouldLog( + priority: LoggerConfig.LogPriority, + settings: LoggerConfig.LogPriority + ): Boolean = settings <= priority + + private fun shouldLog(identity: String?, priority: LoggerConfig.LogPriority): Boolean { + return if (identity == null) { + shouldLog(priority, LoggerConfig.defaultPriority) + } else { + shouldLog(priority, LoggerConfig.loggers[identity] ?: LoggerConfig.defaultPriority) + } + } + + override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = + shouldLog(identity, LoggerConfig.LogPriority.by(priority)) + +} \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerControllerPlatformBase.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerControllerPlatformBase.kt new file mode 100644 index 000000000..660f03f1e --- /dev/null +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerControllerPlatformBase.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2019-2020 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + * + */ + +package net.mamoe.mirai.console.logging + +import net.mamoe.mirai.console.ConsoleFrontEndImplementation +import net.mamoe.mirai.console.util.ConsoleExperimentalApi +import net.mamoe.mirai.utils.SimpleLogger +import java.util.concurrent.ConcurrentHashMap +import java.util.concurrent.atomic.AtomicReference + +@Suppress("MemberVisibilityCanBePrivate") +@ConsoleExperimentalApi +@ConsoleFrontEndImplementation +public abstract class MiraiConsoleLoggerControllerPlatformBase : MiraiConsoleLoggerController { + + override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = true + + override val cacheLoggers: Boolean + get() = true + + protected val registrations: ConcurrentHashMap> = ConcurrentHashMap() + + protected object NilIdentityPlaceholder + + override fun allocateLoggerRegistration(identity: String?): AtomicReference = + registrations.computeIfAbsent(identity ?: NilIdentityPlaceholder) { AtomicReference() } + +} \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerUnused.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerUnused.kt new file mode 100644 index 000000000..0a7671001 --- /dev/null +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerUnused.kt @@ -0,0 +1,61 @@ +/* + * Copyright 2019-2020 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + * + */ + +package net.mamoe.mirai.console.logging + +import net.mamoe.mirai.utils.MiraiLogger +import net.mamoe.mirai.utils.MiraiLoggerPlatformBase + +internal class MiraiConsoleLoggerUnused( + val controller: MiraiConsoleLoggerController, + override val identity: String? +) : MiraiLoggerPlatformBase() { + internal object InitializeLock + + internal lateinit var delegateLogger: MiraiDelegateLogger + private val logger: MiraiLogger by lazy { + val logger = if (controller.cacheLoggers) { + val reference = controller.allocateLoggerRegistration(identity) + if (reference.compareAndSet(null, InitializeLock)) { + val logger = MiraiConsoleLogger(controller, controller.newLoggerImpl(identity)) + reference.set(logger) + logger + } else { + // initialized/initializing + val logger: MiraiLogger + while (true) { + val status = reference.get() + if (status is MiraiLogger) { + logger = status + break + } + } + logger + } + } else { + MiraiConsoleLogger(controller, controller.newLoggerImpl(identity)) + } + delegateLogger.logger = logger + logger + } + override val isEnabled: Boolean + get() = super.isEnabled + + override fun debug0(message: String?, e: Throwable?) = logger.debug(message, e) + + override fun error0(message: String?, e: Throwable?) = logger.error(message, e) + + override fun info0(message: String?, e: Throwable?) = logger.info(message, e) + + override fun verbose0(message: String?, e: Throwable?) = logger.verbose(message, e) + + override fun warning0(message: String?, e: Throwable?) = logger.warning(message, e) + +} \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiDelegateLogger.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiDelegateLogger.kt new file mode 100644 index 000000000..5f61088f7 --- /dev/null +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiDelegateLogger.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2019-2020 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + * + */ + +package net.mamoe.mirai.console.logging + +import net.mamoe.mirai.utils.MiraiLogger +import net.mamoe.mirai.utils.MiraiLoggerPlatformBase + +internal class MiraiDelegateLogger(var logger: MiraiLogger) : MiraiLoggerPlatformBase() { + override val identity: String? get() = logger.identity + override val isEnabled: Boolean get() = logger.isEnabled + override fun debug0(message: String?, e: Throwable?) = logger.debug(message, e) + override fun error0(message: String?, e: Throwable?) = logger.error(message, e) + override fun info0(message: String?, e: Throwable?) = logger.info(message, e) + override fun verbose0(message: String?, e: Throwable?) = logger.verbose(message, e) + override fun warning0(message: String?, e: Throwable?) = logger.warning(message, e) +} diff --git a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt b/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt index 969f03425..d3ae59a88 100644 --- a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt +++ b/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt @@ -14,6 +14,8 @@ import net.mamoe.mirai.console.MiraiConsoleImplementation.Companion.start import net.mamoe.mirai.console.command.CommandManager import net.mamoe.mirai.console.data.MemoryPluginDataStorage import net.mamoe.mirai.console.data.PluginDataStorage +import net.mamoe.mirai.console.logging.MiraiConsoleLoggerController +import net.mamoe.mirai.console.logging.MiraiConsoleLoggerControllerPlatformBase import net.mamoe.mirai.console.plugin.jvm.JvmPluginLoader import net.mamoe.mirai.console.plugin.loader.PluginLoader import net.mamoe.mirai.console.util.ConsoleExperimentalApi @@ -21,10 +23,7 @@ import net.mamoe.mirai.console.util.ConsoleInput import net.mamoe.mirai.console.util.ConsoleInternalApi import net.mamoe.mirai.console.util.SemVersion import net.mamoe.mirai.message.data.Message -import net.mamoe.mirai.utils.BotConfiguration -import net.mamoe.mirai.utils.LoginSolver -import net.mamoe.mirai.utils.MiraiLogger -import net.mamoe.mirai.utils.PlatformLogger +import net.mamoe.mirai.utils.* import java.nio.file.Path import kotlin.coroutines.Continuation import kotlin.coroutines.CoroutineContext @@ -73,8 +72,9 @@ fun initTestEnvironment() { override fun createLoginSolver(requesterBot: Long, configuration: BotConfiguration): LoginSolver = LoginSolver.Default - override fun createLogger(identity: String?): MiraiLogger { - return PlatformLogger(identity) + override val loggerController: MiraiConsoleLoggerController = object:MiraiConsoleLoggerControllerPlatformBase(){ + override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = true + override fun newLoggerImpl(identity: String?): MiraiLogger = PlatformLogger(identity) } override val coroutineContext: CoroutineContext = SupervisorJob() + CoroutineExceptionHandler { _, throwable -> diff --git a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt b/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt index 1cd89f853..f20566a43 100644 --- a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt +++ b/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt @@ -33,6 +33,8 @@ import net.mamoe.mirai.console.MiraiConsoleFrontEndDescription import net.mamoe.mirai.console.MiraiConsoleImplementation import net.mamoe.mirai.console.data.MultiFilePluginDataStorage import net.mamoe.mirai.console.data.PluginDataStorage +import net.mamoe.mirai.console.logging.MiraiConsoleLoggerController +import net.mamoe.mirai.console.logging.MiraiConsoleLoggerControllerForFrontend import net.mamoe.mirai.console.plugin.jvm.JvmPluginLoader import net.mamoe.mirai.console.plugin.loader.PluginLoader import net.mamoe.mirai.console.terminal.ConsoleInputImpl.requestInput @@ -81,7 +83,9 @@ class MiraiConsoleImplementationTerminal return DefaultLoginSolver(input = { requestInput("LOGIN> ") }) } - override fun createLogger(identity: String?): MiraiLogger = LoggerCreator(identity) + override val loggerController: MiraiConsoleLoggerController = object : MiraiConsoleLoggerControllerForFrontend() { + override fun newLoggerImpl(identity: String?): MiraiLogger = LoggerCreator(identity) + } init { with(rootPath.toFile()) { @@ -151,6 +155,7 @@ val terminal: Terminal = run { private object ConsoleFrontEndDescImpl : MiraiConsoleFrontEndDescription { override val name: String get() = "Terminal" override val vendor: String get() = "Mamoe Technologies" + // net.mamoe.mirai.console.internal.MiraiConsoleBuildConstants.version // is console's version not frontend's version override val version: SemVersion = SemVersion(net.mamoe.mirai.console.internal.MiraiConsoleBuildConstants.versionConst) From d477b79e65c7a168342956fe83b81ba9efab06d5 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Sat, 24 Oct 2020 19:51:00 +0800 Subject: [PATCH 002/133] KDoc for MiraiConsoleLoggerController --- .../console/MiraiConsoleImplementation.kt | 6 ++++ .../logging/MiraiConsoleLoggerController.kt | 28 +++++++++++++++++-- ...iraiConsoleLoggerControllerPlatformBase.kt | 7 ++--- .../logging/MiraiConsoleLoggerUnused.kt | 6 ++-- .../mamoe/mirai/console/TestMiraiConosle.kt | 2 +- .../MiraiConsoleImplementationTerminal.kt | 2 +- 6 files changed, 39 insertions(+), 12 deletions(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt index 55281c8df..74dfe8501 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt @@ -19,6 +19,7 @@ import net.mamoe.mirai.console.command.ConsoleCommandSender import net.mamoe.mirai.console.data.PluginDataStorage import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge import net.mamoe.mirai.console.logging.MiraiConsoleLoggerController +import net.mamoe.mirai.console.logging.MiraiConsoleLoggerControllerForFrontend import net.mamoe.mirai.console.plugin.jvm.JvmPluginLoader import net.mamoe.mirai.console.plugin.loader.PluginLoader import net.mamoe.mirai.console.util.ConsoleInput @@ -161,6 +162,11 @@ public interface MiraiConsoleImplementation : CoroutineScope { */ public fun createLoginSolver(requesterBot: Long, configuration: BotConfiguration): LoginSolver + /** + * 日志控制器 + * + * @see [MiraiConsoleLoggerControllerForFrontend] + */ public val loggerController: MiraiConsoleLoggerController public companion object { diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerController.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerController.kt index 1c5126d1d..ff864aa20 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerController.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerController.kt @@ -16,11 +16,35 @@ import net.mamoe.mirai.utils.MiraiLogger import net.mamoe.mirai.utils.SimpleLogger import java.util.concurrent.atomic.AtomicReference +/** + * 日志控制系统 + * + * @see [MiraiConsoleLoggerControllerPlatformBase] + * @see [MiraiConsoleLoggerControllerForFrontend] + */ @ConsoleExperimentalApi @ConsoleFrontEndImplementation public interface MiraiConsoleLoggerController { + /** 是否应该记录该等级的日志 */ public fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean + /** 是否应该对 [newLogger] 的结果进行缓存 */ public val cacheLoggers: Boolean - public fun newLoggerImpl(identity: String?): MiraiLogger - public fun allocateLoggerRegistration(identity: String?): AtomicReference + /** + * 创建一个新的 [MiraiLogger] + * + * 实现细节: + * - 应当直接创建一个新的 [MiraiLogger], 且不进行任何持久性操作, + * 例如 放置到字段, 放入任意集合 等 + * - 即不需要在此方法中把 [MiraiLogger] 放入任意缓存 + */ + public fun newLogger(identity: String?): MiraiLogger + /** + * 获取对应的 Registration + * + * 实现细节: + * - 如果 [identity] 存在对应 Registration, 直接返回先前的 Registration + * - [identity] 不存在对应 Registration时, 创建新的 Registration 并存储起来 + * - 注意并发性 + */ + public fun getLoggerRegistration(identity: String?): AtomicReference } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerControllerPlatformBase.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerControllerPlatformBase.kt index 660f03f1e..f7753e0ee 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerControllerPlatformBase.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerControllerPlatformBase.kt @@ -22,15 +22,12 @@ import java.util.concurrent.atomic.AtomicReference public abstract class MiraiConsoleLoggerControllerPlatformBase : MiraiConsoleLoggerController { override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = true - - override val cacheLoggers: Boolean - get() = true - + override val cacheLoggers: Boolean get() = true protected val registrations: ConcurrentHashMap> = ConcurrentHashMap() protected object NilIdentityPlaceholder - override fun allocateLoggerRegistration(identity: String?): AtomicReference = + override fun getLoggerRegistration(identity: String?): AtomicReference = registrations.computeIfAbsent(identity ?: NilIdentityPlaceholder) { AtomicReference() } } \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerUnused.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerUnused.kt index 0a7671001..064819304 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerUnused.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerUnused.kt @@ -22,9 +22,9 @@ internal class MiraiConsoleLoggerUnused( internal lateinit var delegateLogger: MiraiDelegateLogger private val logger: MiraiLogger by lazy { val logger = if (controller.cacheLoggers) { - val reference = controller.allocateLoggerRegistration(identity) + val reference = controller.getLoggerRegistration(identity) if (reference.compareAndSet(null, InitializeLock)) { - val logger = MiraiConsoleLogger(controller, controller.newLoggerImpl(identity)) + val logger = MiraiConsoleLogger(controller, controller.newLogger(identity)) reference.set(logger) logger } else { @@ -40,7 +40,7 @@ internal class MiraiConsoleLoggerUnused( logger } } else { - MiraiConsoleLogger(controller, controller.newLoggerImpl(identity)) + MiraiConsoleLogger(controller, controller.newLogger(identity)) } delegateLogger.logger = logger logger diff --git a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt b/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt index d3ae59a88..9499e373e 100644 --- a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt +++ b/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt @@ -74,7 +74,7 @@ fun initTestEnvironment() { override val loggerController: MiraiConsoleLoggerController = object:MiraiConsoleLoggerControllerPlatformBase(){ override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = true - override fun newLoggerImpl(identity: String?): MiraiLogger = PlatformLogger(identity) + override fun newLogger(identity: String?): MiraiLogger = PlatformLogger(identity) } override val coroutineContext: CoroutineContext = SupervisorJob() + CoroutineExceptionHandler { _, throwable -> diff --git a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt b/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt index f20566a43..6d756f13e 100644 --- a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt +++ b/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt @@ -84,7 +84,7 @@ class MiraiConsoleImplementationTerminal } override val loggerController: MiraiConsoleLoggerController = object : MiraiConsoleLoggerControllerForFrontend() { - override fun newLoggerImpl(identity: String?): MiraiLogger = LoggerCreator(identity) + override fun newLogger(identity: String?): MiraiLogger = LoggerCreator(identity) } init { From e9de080a962d60e82e98c2d6499a046ed0ad663e Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Sat, 24 Oct 2020 19:54:40 +0800 Subject: [PATCH 003/133] Update KDoc for MiraiConsoleLoggerController --- .../mirai/console/logging/MiraiConsoleLoggerController.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerController.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerController.kt index ff864aa20..463ec0276 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerController.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerController.kt @@ -11,6 +11,7 @@ package net.mamoe.mirai.console.logging import net.mamoe.mirai.console.ConsoleFrontEndImplementation +import net.mamoe.mirai.console.MiraiConsole import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.utils.MiraiLogger import net.mamoe.mirai.utils.SimpleLogger @@ -36,6 +37,10 @@ public interface MiraiConsoleLoggerController { * - 应当直接创建一个新的 [MiraiLogger], 且不进行任何持久性操作, * 例如 放置到字段, 放入任意集合 等 * - 即不需要在此方法中把 [MiraiLogger] 放入任意缓存 + * + * * **注意**: [MiraiConsole] 会将 [net.mamoe.mirai.utils.DefaultLogger] 设置为 `MiraiConsole::createLogger`. + * `MiraiConsole::createLogger` 会使用 [MiraiConsoleLoggerController.newLogger] + * 因此不要在 [newLogger] 中调用 [net.mamoe.mirai.utils.DefaultLogger] */ public fun newLogger(identity: String?): MiraiLogger /** From 1d88a9d9428485281f0b040574c9e3af387afb06 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Sat, 24 Oct 2020 19:58:29 +0800 Subject: [PATCH 004/133] Fix MiraiConsoleLoggerUnused.isEnabled --- .../console/internal/MiraiConsoleImplementationBridge.kt | 2 ++ .../mirai/console/logging/MiraiConsoleLoggerUnused.kt | 7 +------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt index c67694f6d..628d06c2d 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt @@ -112,6 +112,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI ConsoleDataScope.addAndReloadConfig(LoggerConfig) } } + phase `greeting`@{ val buildDateFormatted = buildDate.atZone(ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) @@ -120,6 +121,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI mainLogger.info { "Backend: version $version, built on $buildDateFormatted." } mainLogger.info { frontEndDescription.render() } } + phase `check coroutineContext`@{ if (coroutineContext[Job] == null) { throw MalformedMiraiConsoleImplementationError("The coroutineContext given to MiraiConsole must have a Job in it.") diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerUnused.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerUnused.kt index 064819304..3fc98e568 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerUnused.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerUnused.kt @@ -45,17 +45,12 @@ internal class MiraiConsoleLoggerUnused( delegateLogger.logger = logger logger } - override val isEnabled: Boolean - get() = super.isEnabled + override val isEnabled: Boolean get() = logger.isEnabled override fun debug0(message: String?, e: Throwable?) = logger.debug(message, e) - override fun error0(message: String?, e: Throwable?) = logger.error(message, e) - override fun info0(message: String?, e: Throwable?) = logger.info(message, e) - override fun verbose0(message: String?, e: Throwable?) = logger.verbose(message, e) - override fun warning0(message: String?, e: Throwable?) = logger.warning(message, e) } \ No newline at end of file From cef1326432e1684133efd4ea75efff8bfddc8a50 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Sun, 25 Oct 2020 23:00:59 +0800 Subject: [PATCH 005/133] Rename MiraiConsoleLoggerController to LoggerController --- .../net/mamoe/mirai/console/MiraiConsoleImplementation.kt | 8 ++++---- .../console/internal/MiraiConsoleImplementationBridge.kt | 8 ++++---- ...iraiConsoleLoggerController.kt => LoggerController.kt} | 8 ++++---- ...ollerForFrontend.kt => LoggerControllerForFrontend.kt} | 3 +-- ...lerPlatformBase.kt => LoggerControllerPlatformBase.kt} | 2 +- .../net/mamoe/mirai/console/logging/MiraiConsoleLogger.kt | 2 +- .../mirai/console/logging/MiraiConsoleLoggerUnused.kt | 2 +- .../kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt | 6 +++--- .../terminal/MiraiConsoleImplementationTerminal.kt | 6 +++--- 9 files changed, 22 insertions(+), 23 deletions(-) rename backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/{MiraiConsoleLoggerController.kt => LoggerController.kt} (89%) rename backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/{MiraiConsoleLoggerControllerForFrontend.kt => LoggerControllerForFrontend.kt} (88%) rename backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/{MiraiConsoleLoggerControllerPlatformBase.kt => LoggerControllerPlatformBase.kt} (93%) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt index 74dfe8501..9fcc73a41 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt @@ -18,8 +18,8 @@ import net.mamoe.mirai.console.MiraiConsoleImplementation.Companion.start import net.mamoe.mirai.console.command.ConsoleCommandSender import net.mamoe.mirai.console.data.PluginDataStorage import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge -import net.mamoe.mirai.console.logging.MiraiConsoleLoggerController -import net.mamoe.mirai.console.logging.MiraiConsoleLoggerControllerForFrontend +import net.mamoe.mirai.console.logging.LoggerController +import net.mamoe.mirai.console.logging.LoggerControllerForFrontend import net.mamoe.mirai.console.plugin.jvm.JvmPluginLoader import net.mamoe.mirai.console.plugin.loader.PluginLoader import net.mamoe.mirai.console.util.ConsoleInput @@ -165,9 +165,9 @@ public interface MiraiConsoleImplementation : CoroutineScope { /** * 日志控制器 * - * @see [MiraiConsoleLoggerControllerForFrontend] + * @see [LoggerControllerForFrontend] */ - public val loggerController: MiraiConsoleLoggerController + public val loggerController: LoggerController public companion object { internal lateinit var instance: MiraiConsoleImplementation diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt index 628d06c2d..d4ea82228 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt @@ -38,8 +38,8 @@ import net.mamoe.mirai.console.internal.extension.GlobalComponentStorage import net.mamoe.mirai.console.internal.permission.BuiltInPermissionService import net.mamoe.mirai.console.internal.plugin.PluginManagerImpl import net.mamoe.mirai.console.internal.util.autoHexToBytes -import net.mamoe.mirai.console.logging.MiraiConsoleLoggerController -import net.mamoe.mirai.console.logging.MiraiConsoleLoggerControllerForFrontend +import net.mamoe.mirai.console.logging.LoggerController +import net.mamoe.mirai.console.logging.LoggerControllerForFrontend import net.mamoe.mirai.console.logging.MiraiConsoleLoggerUnused import net.mamoe.mirai.console.logging.MiraiDelegateLogger import net.mamoe.mirai.console.permission.PermissionService @@ -87,7 +87,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI override val dataStorageForBuiltIns: PluginDataStorage by instance::dataStorageForBuiltIns override val configStorageForBuiltIns: PluginDataStorage by instance::configStorageForBuiltIns override val consoleInput: ConsoleInput by instance::consoleInput - override val loggerController: MiraiConsoleLoggerController by instance::loggerController + override val loggerController: LoggerController by instance::loggerController override fun createLoginSolver(requesterBot: Long, configuration: BotConfiguration): LoginSolver = instance.createLoginSolver(requesterBot, configuration) @@ -108,7 +108,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI @Suppress("RemoveRedundantBackticks") internal fun doStart() { phase `setup logger controller`@{ - if (loggerController is MiraiConsoleLoggerControllerForFrontend) { + if (loggerController is LoggerControllerForFrontend) { ConsoleDataScope.addAndReloadConfig(LoggerConfig) } } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerController.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerController.kt similarity index 89% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerController.kt rename to backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerController.kt index 463ec0276..1eaecff5c 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerController.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerController.kt @@ -20,12 +20,12 @@ import java.util.concurrent.atomic.AtomicReference /** * 日志控制系统 * - * @see [MiraiConsoleLoggerControllerPlatformBase] - * @see [MiraiConsoleLoggerControllerForFrontend] + * @see [LoggerControllerPlatformBase] + * @see [LoggerControllerForFrontend] */ @ConsoleExperimentalApi @ConsoleFrontEndImplementation -public interface MiraiConsoleLoggerController { +public interface LoggerController { /** 是否应该记录该等级的日志 */ public fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean /** 是否应该对 [newLogger] 的结果进行缓存 */ @@ -39,7 +39,7 @@ public interface MiraiConsoleLoggerController { * - 即不需要在此方法中把 [MiraiLogger] 放入任意缓存 * * * **注意**: [MiraiConsole] 会将 [net.mamoe.mirai.utils.DefaultLogger] 设置为 `MiraiConsole::createLogger`. - * `MiraiConsole::createLogger` 会使用 [MiraiConsoleLoggerController.newLogger] + * `MiraiConsole::createLogger` 会使用 [LoggerController.newLogger] * 因此不要在 [newLogger] 中调用 [net.mamoe.mirai.utils.DefaultLogger] */ public fun newLogger(identity: String?): MiraiLogger diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerControllerForFrontend.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerControllerForFrontend.kt similarity index 88% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerControllerForFrontend.kt rename to backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerControllerForFrontend.kt index 58ee58c7e..89bd913ba 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerControllerForFrontend.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerControllerForFrontend.kt @@ -11,14 +11,13 @@ package net.mamoe.mirai.console.logging import net.mamoe.mirai.console.ConsoleFrontEndImplementation -import net.mamoe.mirai.console.internal.data.builtins.ConsoleDataScope import net.mamoe.mirai.console.internal.data.builtins.LoggerConfig import net.mamoe.mirai.console.util.ConsoleInternalApi import net.mamoe.mirai.utils.SimpleLogger @ConsoleFrontEndImplementation @ConsoleInternalApi -public abstract class MiraiConsoleLoggerControllerForFrontend : MiraiConsoleLoggerControllerPlatformBase() { +public abstract class LoggerControllerForFrontend : LoggerControllerPlatformBase() { private fun shouldLog( priority: LoggerConfig.LogPriority, diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerControllerPlatformBase.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerControllerPlatformBase.kt similarity index 93% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerControllerPlatformBase.kt rename to backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerControllerPlatformBase.kt index f7753e0ee..a77b0860c 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerControllerPlatformBase.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerControllerPlatformBase.kt @@ -19,7 +19,7 @@ import java.util.concurrent.atomic.AtomicReference @Suppress("MemberVisibilityCanBePrivate") @ConsoleExperimentalApi @ConsoleFrontEndImplementation -public abstract class MiraiConsoleLoggerControllerPlatformBase : MiraiConsoleLoggerController { +public abstract class LoggerControllerPlatformBase : LoggerController { override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = true override val cacheLoggers: Boolean get() = true diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLogger.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLogger.kt index 2c2bcf531..de35aeac4 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLogger.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLogger.kt @@ -15,7 +15,7 @@ import net.mamoe.mirai.utils.MiraiLoggerPlatformBase import net.mamoe.mirai.utils.SimpleLogger internal class MiraiConsoleLogger( - private val controller: MiraiConsoleLoggerController, + private val controller: LoggerController, val logger: MiraiLogger ) : MiraiLoggerPlatformBase() { override val identity: String? get() = logger.identity diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerUnused.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerUnused.kt index 3fc98e568..d2caa896e 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerUnused.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerUnused.kt @@ -14,7 +14,7 @@ import net.mamoe.mirai.utils.MiraiLogger import net.mamoe.mirai.utils.MiraiLoggerPlatformBase internal class MiraiConsoleLoggerUnused( - val controller: MiraiConsoleLoggerController, + val controller: LoggerController, override val identity: String? ) : MiraiLoggerPlatformBase() { internal object InitializeLock diff --git a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt b/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt index 9499e373e..9af2aa7e2 100644 --- a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt +++ b/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt @@ -14,8 +14,8 @@ import net.mamoe.mirai.console.MiraiConsoleImplementation.Companion.start import net.mamoe.mirai.console.command.CommandManager import net.mamoe.mirai.console.data.MemoryPluginDataStorage import net.mamoe.mirai.console.data.PluginDataStorage -import net.mamoe.mirai.console.logging.MiraiConsoleLoggerController -import net.mamoe.mirai.console.logging.MiraiConsoleLoggerControllerPlatformBase +import net.mamoe.mirai.console.logging.LoggerController +import net.mamoe.mirai.console.logging.LoggerControllerPlatformBase import net.mamoe.mirai.console.plugin.jvm.JvmPluginLoader import net.mamoe.mirai.console.plugin.loader.PluginLoader import net.mamoe.mirai.console.util.ConsoleExperimentalApi @@ -72,7 +72,7 @@ fun initTestEnvironment() { override fun createLoginSolver(requesterBot: Long, configuration: BotConfiguration): LoginSolver = LoginSolver.Default - override val loggerController: MiraiConsoleLoggerController = object:MiraiConsoleLoggerControllerPlatformBase(){ + override val loggerController: LoggerController = object:LoggerControllerPlatformBase(){ override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = true override fun newLogger(identity: String?): MiraiLogger = PlatformLogger(identity) } diff --git a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt b/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt index 6d756f13e..642e12e45 100644 --- a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt +++ b/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt @@ -33,8 +33,8 @@ import net.mamoe.mirai.console.MiraiConsoleFrontEndDescription import net.mamoe.mirai.console.MiraiConsoleImplementation import net.mamoe.mirai.console.data.MultiFilePluginDataStorage import net.mamoe.mirai.console.data.PluginDataStorage -import net.mamoe.mirai.console.logging.MiraiConsoleLoggerController -import net.mamoe.mirai.console.logging.MiraiConsoleLoggerControllerForFrontend +import net.mamoe.mirai.console.logging.LoggerController +import net.mamoe.mirai.console.logging.LoggerControllerForFrontend import net.mamoe.mirai.console.plugin.jvm.JvmPluginLoader import net.mamoe.mirai.console.plugin.loader.PluginLoader import net.mamoe.mirai.console.terminal.ConsoleInputImpl.requestInput @@ -83,7 +83,7 @@ class MiraiConsoleImplementationTerminal return DefaultLoginSolver(input = { requestInput("LOGIN> ") }) } - override val loggerController: MiraiConsoleLoggerController = object : MiraiConsoleLoggerControllerForFrontend() { + override val loggerController: LoggerController = object : LoggerControllerForFrontend() { override fun newLogger(identity: String?): MiraiLogger = LoggerCreator(identity) } From 9f88293691193b2bbce6b344cded8b520d621091 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Sun, 25 Oct 2020 23:16:58 +0800 Subject: [PATCH 006/133] Review LoggerController - Delete logger cache - Move MiraiConsoleLogger to internal package --- .../MiraiConsoleImplementationBridge.kt | 11 +--- .../internal/data/builtins/LoggerConfig.kt | 8 +++ .../logging/MiraiConsoleLogger.kt | 3 +- .../mirai/console/logging/LoggerController.kt | 11 ---- .../logging/LoggerControllerPlatformBase.kt | 8 +-- .../logging/MiraiConsoleLoggerUnused.kt | 56 ------------------- .../console/logging/MiraiDelegateLogger.kt | 24 -------- .../mamoe/mirai/console/TestMiraiConosle.kt | 2 +- 8 files changed, 15 insertions(+), 108 deletions(-) rename backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/{ => internal}/logging/MiraiConsoleLogger.kt (94%) delete mode 100644 backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerUnused.kt delete mode 100644 backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiDelegateLogger.kt diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt index d4ea82228..b414d596d 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt @@ -38,10 +38,8 @@ import net.mamoe.mirai.console.internal.extension.GlobalComponentStorage import net.mamoe.mirai.console.internal.permission.BuiltInPermissionService import net.mamoe.mirai.console.internal.plugin.PluginManagerImpl import net.mamoe.mirai.console.internal.util.autoHexToBytes -import net.mamoe.mirai.console.logging.LoggerController -import net.mamoe.mirai.console.logging.LoggerControllerForFrontend -import net.mamoe.mirai.console.logging.MiraiConsoleLoggerUnused -import net.mamoe.mirai.console.logging.MiraiDelegateLogger +import net.mamoe.mirai.console.logging.* +import net.mamoe.mirai.console.internal.logging.MiraiConsoleLogger import net.mamoe.mirai.console.permission.PermissionService import net.mamoe.mirai.console.permission.PermissionService.Companion.grantPermission import net.mamoe.mirai.console.permission.RootPermission @@ -99,10 +97,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI override fun createLogger(identity: String?): MiraiLogger { val controller = loggerController - val logger = MiraiConsoleLoggerUnused(controller, identity) - val delegate = MiraiDelegateLogger(logger) - logger.delegateLogger = delegate - return delegate + return MiraiConsoleLogger(controller, controller.newLogger(identity)) } @Suppress("RemoveRedundantBackticks") diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/LoggerConfig.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/LoggerConfig.kt index da403aa53..a7fc11db2 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/LoggerConfig.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/LoggerConfig.kt @@ -11,12 +11,20 @@ package net.mamoe.mirai.console.internal.data.builtins import net.mamoe.mirai.console.data.AutoSavePluginConfig +import net.mamoe.mirai.console.data.ValueDescription import net.mamoe.mirai.console.data.value import net.mamoe.mirai.utils.SimpleLogger import java.util.* internal object LoggerConfig : AutoSavePluginConfig("Logger") { + @ValueDescription(""" + 日志输出等级 可选值: ALL, VERBOSE, DEBUG, INFO, WARNING, ERROR, NONE + """) val defaultPriority by value(LogPriority.INFO) + + @ValueDescription(""" + 特定日志记录器输出等级 + """) val loggers: Map by value( mapOf("example.logger" to LogPriority.NONE) ) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLogger.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/MiraiConsoleLogger.kt similarity index 94% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLogger.kt rename to backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/MiraiConsoleLogger.kt index de35aeac4..48b829ee9 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLogger.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/MiraiConsoleLogger.kt @@ -8,8 +8,9 @@ * */ -package net.mamoe.mirai.console.logging +package net.mamoe.mirai.console.internal.logging +import net.mamoe.mirai.console.logging.LoggerController import net.mamoe.mirai.utils.MiraiLogger import net.mamoe.mirai.utils.MiraiLoggerPlatformBase import net.mamoe.mirai.utils.SimpleLogger diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerController.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerController.kt index 1eaecff5c..75b280e89 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerController.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerController.kt @@ -28,8 +28,6 @@ import java.util.concurrent.atomic.AtomicReference public interface LoggerController { /** 是否应该记录该等级的日志 */ public fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean - /** 是否应该对 [newLogger] 的结果进行缓存 */ - public val cacheLoggers: Boolean /** * 创建一个新的 [MiraiLogger] * @@ -43,13 +41,4 @@ public interface LoggerController { * 因此不要在 [newLogger] 中调用 [net.mamoe.mirai.utils.DefaultLogger] */ public fun newLogger(identity: String?): MiraiLogger - /** - * 获取对应的 Registration - * - * 实现细节: - * - 如果 [identity] 存在对应 Registration, 直接返回先前的 Registration - * - [identity] 不存在对应 Registration时, 创建新的 Registration 并存储起来 - * - 注意并发性 - */ - public fun getLoggerRegistration(identity: String?): AtomicReference } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerControllerPlatformBase.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerControllerPlatformBase.kt index a77b0860c..2be82ab8a 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerControllerPlatformBase.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerControllerPlatformBase.kt @@ -12,6 +12,7 @@ package net.mamoe.mirai.console.logging import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.util.ConsoleExperimentalApi +import net.mamoe.mirai.utils.MiraiLogger import net.mamoe.mirai.utils.SimpleLogger import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.atomic.AtomicReference @@ -22,12 +23,5 @@ import java.util.concurrent.atomic.AtomicReference public abstract class LoggerControllerPlatformBase : LoggerController { override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = true - override val cacheLoggers: Boolean get() = true - protected val registrations: ConcurrentHashMap> = ConcurrentHashMap() - - protected object NilIdentityPlaceholder - - override fun getLoggerRegistration(identity: String?): AtomicReference = - registrations.computeIfAbsent(identity ?: NilIdentityPlaceholder) { AtomicReference() } } \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerUnused.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerUnused.kt deleted file mode 100644 index d2caa896e..000000000 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiConsoleLoggerUnused.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2019-2020 Mamoe Technologies and contributors. - * - * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link. - * - * https://github.com/mamoe/mirai/blob/master/LICENSE - * - */ - -package net.mamoe.mirai.console.logging - -import net.mamoe.mirai.utils.MiraiLogger -import net.mamoe.mirai.utils.MiraiLoggerPlatformBase - -internal class MiraiConsoleLoggerUnused( - val controller: LoggerController, - override val identity: String? -) : MiraiLoggerPlatformBase() { - internal object InitializeLock - - internal lateinit var delegateLogger: MiraiDelegateLogger - private val logger: MiraiLogger by lazy { - val logger = if (controller.cacheLoggers) { - val reference = controller.getLoggerRegistration(identity) - if (reference.compareAndSet(null, InitializeLock)) { - val logger = MiraiConsoleLogger(controller, controller.newLogger(identity)) - reference.set(logger) - logger - } else { - // initialized/initializing - val logger: MiraiLogger - while (true) { - val status = reference.get() - if (status is MiraiLogger) { - logger = status - break - } - } - logger - } - } else { - MiraiConsoleLogger(controller, controller.newLogger(identity)) - } - delegateLogger.logger = logger - logger - } - override val isEnabled: Boolean get() = logger.isEnabled - - override fun debug0(message: String?, e: Throwable?) = logger.debug(message, e) - override fun error0(message: String?, e: Throwable?) = logger.error(message, e) - override fun info0(message: String?, e: Throwable?) = logger.info(message, e) - override fun verbose0(message: String?, e: Throwable?) = logger.verbose(message, e) - override fun warning0(message: String?, e: Throwable?) = logger.warning(message, e) - -} \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiDelegateLogger.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiDelegateLogger.kt deleted file mode 100644 index 5f61088f7..000000000 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/MiraiDelegateLogger.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2019-2020 Mamoe Technologies and contributors. - * - * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link. - * - * https://github.com/mamoe/mirai/blob/master/LICENSE - * - */ - -package net.mamoe.mirai.console.logging - -import net.mamoe.mirai.utils.MiraiLogger -import net.mamoe.mirai.utils.MiraiLoggerPlatformBase - -internal class MiraiDelegateLogger(var logger: MiraiLogger) : MiraiLoggerPlatformBase() { - override val identity: String? get() = logger.identity - override val isEnabled: Boolean get() = logger.isEnabled - override fun debug0(message: String?, e: Throwable?) = logger.debug(message, e) - override fun error0(message: String?, e: Throwable?) = logger.error(message, e) - override fun info0(message: String?, e: Throwable?) = logger.info(message, e) - override fun verbose0(message: String?, e: Throwable?) = logger.verbose(message, e) - override fun warning0(message: String?, e: Throwable?) = logger.warning(message, e) -} diff --git a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt b/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt index 9af2aa7e2..ce6708193 100644 --- a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt +++ b/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt @@ -72,7 +72,7 @@ fun initTestEnvironment() { override fun createLoginSolver(requesterBot: Long, configuration: BotConfiguration): LoginSolver = LoginSolver.Default - override val loggerController: LoggerController = object:LoggerControllerPlatformBase(){ + override val loggerController: LoggerController = object : LoggerControllerPlatformBase() { override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = true override fun newLogger(identity: String?): MiraiLogger = PlatformLogger(identity) } From 0a76a4b71a18e36586e41bcd121b053510165748 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Mon, 26 Oct 2020 12:35:29 +0800 Subject: [PATCH 007/133] Review LoggerController - Delete LoggerControllerPlatformBase - Rename LoggerControllerForFrontend to LoggerControllerImpl --- .../console/MiraiConsoleImplementation.kt | 4 +-- .../MiraiConsoleImplementationBridge.kt | 7 ++--- .../logging/LoggerControllerImpl.kt} | 5 ++-- .../mirai/console/logging/LoggerController.kt | 6 ++--- .../logging/LoggerControllerPlatformBase.kt | 27 ------------------- .../mamoe/mirai/console/TestMiraiConosle.kt | 3 +-- .../MiraiConsoleImplementationTerminal.kt | 4 +-- 7 files changed, 15 insertions(+), 41 deletions(-) rename backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/{logging/LoggerControllerForFrontend.kt => internal/logging/LoggerControllerImpl.kt} (88%) delete mode 100644 backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerControllerPlatformBase.kt diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt index 9916f025c..3bee16ef3 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt @@ -19,7 +19,7 @@ import net.mamoe.mirai.console.command.ConsoleCommandSender import net.mamoe.mirai.console.data.PluginDataStorage import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge import net.mamoe.mirai.console.logging.LoggerController -import net.mamoe.mirai.console.logging.LoggerControllerForFrontend +import net.mamoe.mirai.console.internal.logging.LoggerControllerImpl import net.mamoe.mirai.console.plugin.jvm.JvmPluginLoader import net.mamoe.mirai.console.plugin.loader.PluginLoader import net.mamoe.mirai.console.util.ConsoleInput @@ -166,7 +166,7 @@ public interface MiraiConsoleImplementation : CoroutineScope { /** * 日志控制器 * - * @see [LoggerControllerForFrontend] + * @see [LoggerControllerImpl] */ public val loggerController: LoggerController diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt index 90024c888..00074b41f 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt @@ -35,11 +35,12 @@ import net.mamoe.mirai.console.internal.data.builtins.LoggerConfig import net.mamoe.mirai.console.internal.data.castOrNull import net.mamoe.mirai.console.internal.extension.BuiltInSingletonExtensionSelector import net.mamoe.mirai.console.internal.extension.GlobalComponentStorage +import net.mamoe.mirai.console.internal.logging.LoggerControllerImpl +import net.mamoe.mirai.console.internal.logging.MiraiConsoleLogger import net.mamoe.mirai.console.internal.permission.BuiltInPermissionService import net.mamoe.mirai.console.internal.plugin.PluginManagerImpl import net.mamoe.mirai.console.internal.util.autoHexToBytes -import net.mamoe.mirai.console.logging.* -import net.mamoe.mirai.console.internal.logging.MiraiConsoleLogger +import net.mamoe.mirai.console.logging.LoggerController import net.mamoe.mirai.console.permission.PermissionService import net.mamoe.mirai.console.permission.PermissionService.Companion.permit import net.mamoe.mirai.console.permission.RootPermission @@ -103,7 +104,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI @Suppress("RemoveRedundantBackticks") internal fun doStart() { phase `setup logger controller`@{ - if (loggerController is LoggerControllerForFrontend) { + if (loggerController is LoggerControllerImpl) { ConsoleDataScope.addAndReloadConfig(LoggerConfig) } } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerControllerForFrontend.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerImpl.kt similarity index 88% rename from backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerControllerForFrontend.kt rename to backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerImpl.kt index 89bd913ba..925813cde 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerControllerForFrontend.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerImpl.kt @@ -8,16 +8,17 @@ * */ -package net.mamoe.mirai.console.logging +package net.mamoe.mirai.console.internal.logging import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.internal.data.builtins.LoggerConfig +import net.mamoe.mirai.console.logging.LoggerController import net.mamoe.mirai.console.util.ConsoleInternalApi import net.mamoe.mirai.utils.SimpleLogger @ConsoleFrontEndImplementation @ConsoleInternalApi -public abstract class LoggerControllerForFrontend : LoggerControllerPlatformBase() { +public abstract class LoggerControllerImpl : LoggerController { private fun shouldLog( priority: LoggerConfig.LogPriority, diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerController.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerController.kt index 75b280e89..ba120cb72 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerController.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerController.kt @@ -12,22 +12,22 @@ package net.mamoe.mirai.console.logging import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.MiraiConsole +import net.mamoe.mirai.console.internal.logging.LoggerControllerImpl import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.utils.MiraiLogger import net.mamoe.mirai.utils.SimpleLogger -import java.util.concurrent.atomic.AtomicReference /** * 日志控制系统 * - * @see [LoggerControllerPlatformBase] - * @see [LoggerControllerForFrontend] + * @see [LoggerControllerImpl] */ @ConsoleExperimentalApi @ConsoleFrontEndImplementation public interface LoggerController { /** 是否应该记录该等级的日志 */ public fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean + /** * 创建一个新的 [MiraiLogger] * diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerControllerPlatformBase.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerControllerPlatformBase.kt deleted file mode 100644 index 2be82ab8a..000000000 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerControllerPlatformBase.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2019-2020 Mamoe Technologies and contributors. - * - * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link. - * - * https://github.com/mamoe/mirai/blob/master/LICENSE - * - */ - -package net.mamoe.mirai.console.logging - -import net.mamoe.mirai.console.ConsoleFrontEndImplementation -import net.mamoe.mirai.console.util.ConsoleExperimentalApi -import net.mamoe.mirai.utils.MiraiLogger -import net.mamoe.mirai.utils.SimpleLogger -import java.util.concurrent.ConcurrentHashMap -import java.util.concurrent.atomic.AtomicReference - -@Suppress("MemberVisibilityCanBePrivate") -@ConsoleExperimentalApi -@ConsoleFrontEndImplementation -public abstract class LoggerControllerPlatformBase : LoggerController { - - override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = true - -} \ No newline at end of file diff --git a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt b/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt index ca770aeb5..fd436a4b3 100644 --- a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt +++ b/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt @@ -15,7 +15,6 @@ import net.mamoe.mirai.console.command.CommandManager import net.mamoe.mirai.console.data.MemoryPluginDataStorage import net.mamoe.mirai.console.data.PluginDataStorage import net.mamoe.mirai.console.logging.LoggerController -import net.mamoe.mirai.console.logging.LoggerControllerPlatformBase import net.mamoe.mirai.console.plugin.jvm.JvmPluginLoader import net.mamoe.mirai.console.plugin.loader.PluginLoader import net.mamoe.mirai.console.util.ConsoleExperimentalApi @@ -72,7 +71,7 @@ fun initTestEnvironment() { override fun createLoginSolver(requesterBot: Long, configuration: BotConfiguration): LoginSolver = LoginSolver.Default - override val loggerController: LoggerController = object : LoggerControllerPlatformBase() { + override val loggerController: LoggerController = object : LoggerController { override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = true override fun newLogger(identity: String?): MiraiLogger = PlatformLogger(identity) } diff --git a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt b/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt index 642e12e45..5917c096e 100644 --- a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt +++ b/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt @@ -34,7 +34,7 @@ import net.mamoe.mirai.console.MiraiConsoleImplementation import net.mamoe.mirai.console.data.MultiFilePluginDataStorage import net.mamoe.mirai.console.data.PluginDataStorage import net.mamoe.mirai.console.logging.LoggerController -import net.mamoe.mirai.console.logging.LoggerControllerForFrontend +import net.mamoe.mirai.console.internal.logging.LoggerControllerImpl import net.mamoe.mirai.console.plugin.jvm.JvmPluginLoader import net.mamoe.mirai.console.plugin.loader.PluginLoader import net.mamoe.mirai.console.terminal.ConsoleInputImpl.requestInput @@ -83,7 +83,7 @@ class MiraiConsoleImplementationTerminal return DefaultLoginSolver(input = { requestInput("LOGIN> ") }) } - override val loggerController: LoggerController = object : LoggerControllerForFrontend() { + override val loggerController: LoggerController = object : LoggerControllerImpl() { override fun newLogger(identity: String?): MiraiLogger = LoggerCreator(identity) } From 544e11747c49d3175109ea2644eba947e0e6fc83 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Mon, 26 Oct 2020 23:20:10 +0800 Subject: [PATCH 008/133] Redesign LoggerController --- .../console/MiraiConsoleImplementation.kt | 8 ++-- .../mirai/console/data/AutoSavePluginData.kt | 15 ++++++- .../extensions/LoggerControllerProvider.kt | 35 +++++++++++++++ .../MiraiConsoleImplementationBridge.kt | 26 +++++++---- .../data/builtins/ConsoleDataScope.kt | 10 +++-- .../internal/data/builtins/LoggerConfig.kt | 29 +----------- .../logging/LoggerControllerDelegate.kt | 21 +++++++++ .../internal/logging/LoggerControllerImpl.kt | 11 ++--- .../logging/LoggerControllerTrusted.kt | 18 ++++++++ .../mirai/console/logging/LogPriority.kt | 44 +++++++++++++++++++ .../mirai/console/logging/LoggerController.kt | 17 ------- .../mamoe/mirai/console/TestMiraiConosle.kt | 5 +-- .../MiraiConsoleImplementationTerminal.kt | 4 +- 13 files changed, 171 insertions(+), 72 deletions(-) create mode 100644 backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/LoggerControllerProvider.kt create mode 100644 backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerDelegate.kt create mode 100644 backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerTrusted.kt create mode 100644 backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LogPriority.kt diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt index 3bee16ef3..01d0b7b63 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt @@ -26,6 +26,7 @@ import net.mamoe.mirai.console.util.ConsoleInput import net.mamoe.mirai.message.data.Message import net.mamoe.mirai.utils.BotConfiguration import net.mamoe.mirai.utils.LoginSolver +import net.mamoe.mirai.utils.MiraiLogger import java.nio.file.Path import java.util.* import java.util.concurrent.locks.ReentrantLock @@ -164,11 +165,12 @@ public interface MiraiConsoleImplementation : CoroutineScope { public fun createLoginSolver(requesterBot: Long, configuration: BotConfiguration): LoginSolver /** - * 日志控制器 + * 创建一个 [MiraiLogger]. * - * @see [LoggerControllerImpl] + * **注意**: [MiraiConsole] 会将 [net.mamoe.mirai.utils.DefaultLogger] 设置为 `MiraiConsole::createLogger`. + * 因此不要在 [createLogger] 中调用 [net.mamoe.mirai.utils.DefaultLogger] */ - public val loggerController: LoggerController + public fun createLogger(identity: String?): MiraiLogger public companion object { internal lateinit var instance: MiraiConsoleImplementation diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AutoSavePluginData.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AutoSavePluginData.kt index f081af4d2..58fbbd195 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AutoSavePluginData.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AutoSavePluginData.kt @@ -36,6 +36,8 @@ public open class AutoSavePluginData private constructor( private lateinit var owner_: AutoSavePluginDataHolder private val autoSaveIntervalMillis_: LongRange get() = owner_.autoSaveIntervalMillis private lateinit var storage_: PluginDataStorage + private var authSaveJob: Job? = null + private var completionHandle: DisposableHandle? = null public final override val saveName: String get() = _saveName @@ -54,18 +56,27 @@ public open class AutoSavePluginData private constructor( ?: throw IllegalArgumentException("Cannot find a serial name for ${this::class}") } + @ConsoleExperimentalApi + public fun destroy() { + completionHandle?.dispose() + authSaveJob?.cancel() + completionHandle = null + authSaveJob = null + } + @ConsoleExperimentalApi override fun onInit(owner: PluginDataHolder, storage: PluginDataStorage) { check(owner is AutoSavePluginDataHolder) { "owner must be AutoSavePluginDataHolder for AutoSavePluginData" } if (this::storage_.isInitialized) { check(storage == this.storage_) { "AutoSavePluginData is already initialized with one storage and cannot be reinitialized with another." } + destroy() // Destroy old jobs } this.storage_ = storage this.owner_ = owner - owner_.coroutineContext[Job]?.invokeOnCompletion { + completionHandle = owner_.coroutineContext[Job]?.invokeOnCompletion { kotlin.runCatching { doSave() }.onFailure { e -> @@ -80,7 +91,7 @@ public open class AutoSavePluginData private constructor( } if (shouldPerformAutoSaveWheneverChanged()) { - owner_.launch(CoroutineName("AutoSavePluginData.timedAutoSave: ${this::class.qualifiedNameOrTip}")) { + authSaveJob = owner_.launch(CoroutineName("AutoSavePluginData.timedAutoSave: ${this::class.qualifiedNameOrTip}")) { while (isActive) { try { delay(autoSaveIntervalMillis_.last) // 定时自动保存一次, 用于 kts 序列化的对象 diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/LoggerControllerProvider.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/LoggerControllerProvider.kt new file mode 100644 index 000000000..ebe84d036 --- /dev/null +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/LoggerControllerProvider.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2019-2020 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + * + */ + +package net.mamoe.mirai.console.extensions + +import net.mamoe.mirai.console.extension.AbstractSingletonExtensionPoint +import net.mamoe.mirai.console.extension.SingletonExtension +import net.mamoe.mirai.console.internal.logging.LoggerControllerImpl +import net.mamoe.mirai.console.logging.LoggerController +import net.mamoe.mirai.console.permission.PermissionService + +public interface LoggerControllerProvider : SingletonExtension { + public companion object ExtensionPoint : + AbstractSingletonExtensionPoint(LoggerControllerProvider::class, LoggerControllerImpl) + +} + +/** + * @see LoggerControllerProvider + */ +public class LoggerControllerProviderImpl(override val instance: LoggerController) : LoggerControllerProvider + +/** + * @see LoggerControllerProvider + */ +public class LoggerControllerProviderLazy(initializer: () -> LoggerController) : LoggerControllerProvider { + override val instance: LoggerController by lazy(initializer) +} diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt index 00074b41f..cdde2d2f6 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt @@ -25,6 +25,7 @@ import net.mamoe.mirai.console.command.BuiltInCommands import net.mamoe.mirai.console.command.CommandManager import net.mamoe.mirai.console.command.ConsoleCommandSender import net.mamoe.mirai.console.data.PluginDataStorage +import net.mamoe.mirai.console.extensions.LoggerControllerProvider import net.mamoe.mirai.console.extensions.PermissionServiceProvider import net.mamoe.mirai.console.extensions.PostStartupExtension import net.mamoe.mirai.console.extensions.SingletonExtensionSelector @@ -35,12 +36,13 @@ import net.mamoe.mirai.console.internal.data.builtins.LoggerConfig import net.mamoe.mirai.console.internal.data.castOrNull import net.mamoe.mirai.console.internal.extension.BuiltInSingletonExtensionSelector import net.mamoe.mirai.console.internal.extension.GlobalComponentStorage +import net.mamoe.mirai.console.internal.logging.LoggerControllerDelegate import net.mamoe.mirai.console.internal.logging.LoggerControllerImpl +import net.mamoe.mirai.console.internal.logging.LoggerControllerTrusted import net.mamoe.mirai.console.internal.logging.MiraiConsoleLogger import net.mamoe.mirai.console.internal.permission.BuiltInPermissionService import net.mamoe.mirai.console.internal.plugin.PluginManagerImpl import net.mamoe.mirai.console.internal.util.autoHexToBytes -import net.mamoe.mirai.console.logging.LoggerController import net.mamoe.mirai.console.permission.PermissionService import net.mamoe.mirai.console.permission.PermissionService.Companion.permit import net.mamoe.mirai.console.permission.RootPermission @@ -86,8 +88,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI override val dataStorageForBuiltIns: PluginDataStorage by instance::dataStorageForBuiltIns override val configStorageForBuiltIns: PluginDataStorage by instance::configStorageForBuiltIns override val consoleInput: ConsoleInput by instance::consoleInput - override val loggerController: LoggerController by instance::loggerController - + private val loggerController = LoggerControllerDelegate(LoggerControllerTrusted) override fun createLoginSolver(requesterBot: Long, configuration: BotConfiguration): LoginSolver = instance.createLoginSolver(requesterBot, configuration) @@ -98,15 +99,16 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI override fun createLogger(identity: String?): MiraiLogger { val controller = loggerController - return MiraiConsoleLogger(controller, controller.newLogger(identity)) + return MiraiConsoleLogger(controller, instance.createLogger(identity)) } @Suppress("RemoveRedundantBackticks") internal fun doStart() { - phase `setup logger controller`@{ - if (loggerController is LoggerControllerImpl) { - ConsoleDataScope.addAndReloadConfig(LoggerConfig) - } + + phase `pre setup logger controller`@{ + loggerController.delegate = LoggerControllerImpl + // Relaod LoggerConfig first. + ConsoleDataScope.addAndReloadConfig(LoggerConfig) } phase `greeting`@{ @@ -175,6 +177,14 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI } } + phase `setup logger controller`@{ + val selected = LoggerControllerProvider.selectedInstance + if (selected !== LoggerControllerImpl) { + ConsoleDataScope.dropConfig(LoggerConfig) + loggerController.delegate = selected + } + } + phase `load PermissionService`@{ mainLogger.verbose { "Loading PermissionService..." } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/ConsoleDataScope.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/ConsoleDataScope.kt index 98b8077bd..95c0d9a8f 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/ConsoleDataScope.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/ConsoleDataScope.kt @@ -11,10 +11,7 @@ package net.mamoe.mirai.console.internal.data.builtins import kotlinx.coroutines.CoroutineScope import net.mamoe.mirai.console.MiraiConsole -import net.mamoe.mirai.console.data.AutoSavePluginDataHolder -import net.mamoe.mirai.console.data.PluginConfig -import net.mamoe.mirai.console.data.PluginData -import net.mamoe.mirai.console.data.PluginDataStorage +import net.mamoe.mirai.console.data.* import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge import net.mamoe.mirai.console.util.CoroutineScopeUtils.childScope import net.mamoe.mirai.utils.minutesToMillis @@ -29,6 +26,11 @@ internal object ConsoleDataScope : CoroutineScope by MiraiConsole.childScope("Co ConsoleBuiltInPluginConfigStorage.load(ConsoleBuiltInPluginConfigHolder, config) } + fun dropConfig(config: PluginConfig) { + configs.remove(config) + (config as? AutoSavePluginConfig)?.destroy() + } + fun reloadAll() { data.forEach { dt -> ConsoleBuiltInPluginDataStorage.load(ConsoleBuiltInPluginDataHolder, dt) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/LoggerConfig.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/LoggerConfig.kt index a7fc11db2..394bc1d78 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/LoggerConfig.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/LoggerConfig.kt @@ -13,8 +13,7 @@ package net.mamoe.mirai.console.internal.data.builtins import net.mamoe.mirai.console.data.AutoSavePluginConfig import net.mamoe.mirai.console.data.ValueDescription import net.mamoe.mirai.console.data.value -import net.mamoe.mirai.utils.SimpleLogger -import java.util.* +import net.mamoe.mirai.console.logging.LogPriority internal object LoggerConfig : AutoSavePluginConfig("Logger") { @ValueDescription(""" @@ -29,30 +28,4 @@ internal object LoggerConfig : AutoSavePluginConfig("Logger") { mapOf("example.logger" to LogPriority.NONE) ) - enum class LogPriority { - ALL(null), - VERBOSE, - DEBUG, - INFO, - WARNING, - ERROR, - NONE(null); - - var mapped: SimpleLogger.LogPriority? = null - - // resolve NullPointerException - private object Holder { - @JvmField - val mapping = EnumMap(SimpleLogger.LogPriority::class.java) - } - companion object { - fun by(priority: SimpleLogger.LogPriority): LogPriority = Holder.mapping[priority]!! - } - constructor(void: Nothing?) - constructor() { - mapped = SimpleLogger.LogPriority.valueOf(name) - Holder.mapping[mapped] = this - } - - } } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerDelegate.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerDelegate.kt new file mode 100644 index 000000000..c10c32f2a --- /dev/null +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerDelegate.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2019-2020 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + * + */ + +package net.mamoe.mirai.console.internal.logging + +import net.mamoe.mirai.console.logging.LoggerController +import net.mamoe.mirai.utils.SimpleLogger + +internal class LoggerControllerDelegate( + @Volatile + var delegate: LoggerController +) : LoggerController { + override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = delegate.shouldLog(identity, priority) +} \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerImpl.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerImpl.kt index 925813cde..5984d5f03 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerImpl.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerImpl.kt @@ -12,20 +12,21 @@ package net.mamoe.mirai.console.internal.logging import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.internal.data.builtins.LoggerConfig +import net.mamoe.mirai.console.logging.LogPriority import net.mamoe.mirai.console.logging.LoggerController import net.mamoe.mirai.console.util.ConsoleInternalApi import net.mamoe.mirai.utils.SimpleLogger @ConsoleFrontEndImplementation @ConsoleInternalApi -public abstract class LoggerControllerImpl : LoggerController { +internal object LoggerControllerImpl : LoggerController { private fun shouldLog( - priority: LoggerConfig.LogPriority, - settings: LoggerConfig.LogPriority + priority: LogPriority, + settings: LogPriority ): Boolean = settings <= priority - private fun shouldLog(identity: String?, priority: LoggerConfig.LogPriority): Boolean { + private fun shouldLog(identity: String?, priority: LogPriority): Boolean { return if (identity == null) { shouldLog(priority, LoggerConfig.defaultPriority) } else { @@ -34,6 +35,6 @@ public abstract class LoggerControllerImpl : LoggerController { } override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = - shouldLog(identity, LoggerConfig.LogPriority.by(priority)) + shouldLog(identity, LogPriority.by(priority)) } \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerTrusted.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerTrusted.kt new file mode 100644 index 000000000..eb2e16381 --- /dev/null +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerTrusted.kt @@ -0,0 +1,18 @@ +/* + * Copyright 2019-2020 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + * + */ + +package net.mamoe.mirai.console.internal.logging + +import net.mamoe.mirai.console.logging.LoggerController +import net.mamoe.mirai.utils.SimpleLogger + +internal object LoggerControllerTrusted: LoggerController { + override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = true +} diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LogPriority.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LogPriority.kt new file mode 100644 index 000000000..957e42206 --- /dev/null +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LogPriority.kt @@ -0,0 +1,44 @@ +/* + * Copyright 2019-2020 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + * + */ + +package net.mamoe.mirai.console.logging + +import net.mamoe.mirai.utils.SimpleLogger +import java.util.* + +public enum class LogPriority { + ALL(null), + VERBOSE, + DEBUG, + INFO, + WARNING, + ERROR, + NONE(null); + + private var mapped: SimpleLogger.LogPriority? = null + + public companion object { + private val mapping = EnumMap(SimpleLogger.LogPriority::class.java) + + public fun by(priority: SimpleLogger.LogPriority): LogPriority = mapping[priority]!! + + init { + values().forEach { priority -> + mapping[priority.mapped ?: return@forEach] = priority + } + } + } + + constructor(void: Nothing?) + constructor() { + mapped = SimpleLogger.LogPriority.valueOf(name) + } + +} \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerController.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerController.kt index ba120cb72..d4124e2fb 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerController.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/logging/LoggerController.kt @@ -10,11 +10,8 @@ package net.mamoe.mirai.console.logging -import net.mamoe.mirai.console.ConsoleFrontEndImplementation -import net.mamoe.mirai.console.MiraiConsole import net.mamoe.mirai.console.internal.logging.LoggerControllerImpl import net.mamoe.mirai.console.util.ConsoleExperimentalApi -import net.mamoe.mirai.utils.MiraiLogger import net.mamoe.mirai.utils.SimpleLogger /** @@ -23,22 +20,8 @@ import net.mamoe.mirai.utils.SimpleLogger * @see [LoggerControllerImpl] */ @ConsoleExperimentalApi -@ConsoleFrontEndImplementation public interface LoggerController { /** 是否应该记录该等级的日志 */ public fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean - /** - * 创建一个新的 [MiraiLogger] - * - * 实现细节: - * - 应当直接创建一个新的 [MiraiLogger], 且不进行任何持久性操作, - * 例如 放置到字段, 放入任意集合 等 - * - 即不需要在此方法中把 [MiraiLogger] 放入任意缓存 - * - * * **注意**: [MiraiConsole] 会将 [net.mamoe.mirai.utils.DefaultLogger] 设置为 `MiraiConsole::createLogger`. - * `MiraiConsole::createLogger` 会使用 [LoggerController.newLogger] - * 因此不要在 [newLogger] 中调用 [net.mamoe.mirai.utils.DefaultLogger] - */ - public fun newLogger(identity: String?): MiraiLogger } diff --git a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt b/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt index fd436a4b3..d5186fabe 100644 --- a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt +++ b/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/TestMiraiConosle.kt @@ -71,9 +71,8 @@ fun initTestEnvironment() { override fun createLoginSolver(requesterBot: Long, configuration: BotConfiguration): LoginSolver = LoginSolver.Default - override val loggerController: LoggerController = object : LoggerController { - override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = true - override fun newLogger(identity: String?): MiraiLogger = PlatformLogger(identity) + override fun createLogger(identity: String?): MiraiLogger { + return PlatformLogger(identity) } override val coroutineContext: CoroutineContext = SupervisorJob() + CoroutineExceptionHandler { _, throwable -> diff --git a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt b/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt index 5917c096e..43252bf18 100644 --- a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt +++ b/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt @@ -83,8 +83,8 @@ class MiraiConsoleImplementationTerminal return DefaultLoginSolver(input = { requestInput("LOGIN> ") }) } - override val loggerController: LoggerController = object : LoggerControllerImpl() { - override fun newLogger(identity: String?): MiraiLogger = LoggerCreator(identity) + override fun createLogger(identity: String?): MiraiLogger { + return LoggerCreator(identity) } init { From abb55ac619b815deb4a0db1fc285d223e8c4bed9 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Mon, 26 Oct 2020 23:30:35 +0800 Subject: [PATCH 009/133] Allow FrontEnd to implement LoggerController --- .../console/MiraiConsoleImplementation.kt | 5 +++++ .../extensions/LoggerControllerProvider.kt | 3 ++- .../MiraiConsoleImplementationBridge.kt | 15 +++++++++------ .../logging/LoggerControllerTrusted.kt | 18 ------------------ 4 files changed, 16 insertions(+), 25 deletions(-) delete mode 100644 backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerTrusted.kt diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt index 01d0b7b63..a6583fa45 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt @@ -172,6 +172,11 @@ public interface MiraiConsoleImplementation : CoroutineScope { */ public fun createLogger(identity: String?): MiraiLogger + /** + * 前端预先定义的 [LoggerController], 以允许前端使用自己的配置系统 + */ + public val loggerController: LoggerController get() = LoggerControllerImpl + public companion object { internal lateinit var instance: MiraiConsoleImplementation private val initLock = ReentrantLock() diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/LoggerControllerProvider.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/LoggerControllerProvider.kt index ebe84d036..43204c465 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/LoggerControllerProvider.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/LoggerControllerProvider.kt @@ -12,13 +12,14 @@ package net.mamoe.mirai.console.extensions import net.mamoe.mirai.console.extension.AbstractSingletonExtensionPoint import net.mamoe.mirai.console.extension.SingletonExtension +import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge import net.mamoe.mirai.console.internal.logging.LoggerControllerImpl import net.mamoe.mirai.console.logging.LoggerController import net.mamoe.mirai.console.permission.PermissionService public interface LoggerControllerProvider : SingletonExtension { public companion object ExtensionPoint : - AbstractSingletonExtensionPoint(LoggerControllerProvider::class, LoggerControllerImpl) + AbstractSingletonExtensionPoint(LoggerControllerProvider::class, MiraiConsoleImplementationBridge.frontendLoggerController) } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt index cdde2d2f6..f43ec85ca 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt @@ -38,7 +38,6 @@ import net.mamoe.mirai.console.internal.extension.BuiltInSingletonExtensionSelec import net.mamoe.mirai.console.internal.extension.GlobalComponentStorage import net.mamoe.mirai.console.internal.logging.LoggerControllerDelegate import net.mamoe.mirai.console.internal.logging.LoggerControllerImpl -import net.mamoe.mirai.console.internal.logging.LoggerControllerTrusted import net.mamoe.mirai.console.internal.logging.MiraiConsoleLogger import net.mamoe.mirai.console.internal.permission.BuiltInPermissionService import net.mamoe.mirai.console.internal.plugin.PluginManagerImpl @@ -88,10 +87,12 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI override val dataStorageForBuiltIns: PluginDataStorage by instance::dataStorageForBuiltIns override val configStorageForBuiltIns: PluginDataStorage by instance::configStorageForBuiltIns override val consoleInput: ConsoleInput by instance::consoleInput - private val loggerController = LoggerControllerDelegate(LoggerControllerTrusted) override fun createLoginSolver(requesterBot: Long, configuration: BotConfiguration): LoginSolver = instance.createLoginSolver(requesterBot, configuration) + internal val frontendLoggerController = instance.loggerController + override val loggerController: LoggerControllerDelegate = LoggerControllerDelegate(frontendLoggerController) + init { DefaultLogger = this::createLogger } @@ -106,9 +107,11 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI internal fun doStart() { phase `pre setup logger controller`@{ - loggerController.delegate = LoggerControllerImpl - // Relaod LoggerConfig first. - ConsoleDataScope.addAndReloadConfig(LoggerConfig) + loggerController.delegate = frontendLoggerController + if (frontendLoggerController === LoggerControllerImpl) { + // Relaod LoggerConfig first. + ConsoleDataScope.addAndReloadConfig(LoggerConfig) + } } phase `greeting`@{ @@ -179,7 +182,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI phase `setup logger controller`@{ val selected = LoggerControllerProvider.selectedInstance - if (selected !== LoggerControllerImpl) { + if (selected !== frontendLoggerController) { ConsoleDataScope.dropConfig(LoggerConfig) loggerController.delegate = selected } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerTrusted.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerTrusted.kt deleted file mode 100644 index eb2e16381..000000000 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerTrusted.kt +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright 2019-2020 Mamoe Technologies and contributors. - * - * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link. - * - * https://github.com/mamoe/mirai/blob/master/LICENSE - * - */ - -package net.mamoe.mirai.console.internal.logging - -import net.mamoe.mirai.console.logging.LoggerController -import net.mamoe.mirai.utils.SimpleLogger - -internal object LoggerControllerTrusted: LoggerController { - override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = true -} From 97ca3d38f2c4a718a538f57bd763420ca9236b32 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Mon, 26 Oct 2020 23:37:34 +0800 Subject: [PATCH 010/133] inline createLogger --- .../console/terminal/MiraiConsoleImplementationTerminal.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt b/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt index 43252bf18..f86949c16 100644 --- a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt +++ b/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleImplementationTerminal.kt @@ -83,9 +83,7 @@ class MiraiConsoleImplementationTerminal return DefaultLoginSolver(input = { requestInput("LOGIN> ") }) } - override fun createLogger(identity: String?): MiraiLogger { - return LoggerCreator(identity) - } + override fun createLogger(identity: String?): MiraiLogger = LoggerCreator(identity) init { with(rootPath.toFile()) { From 73463554b8ce2eeeb366f29bed2b6d735b51a6bd Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Wed, 28 Oct 2020 18:09:03 +0800 Subject: [PATCH 011/133] delete LoggerControllerProvider --- .../mirai/console/data/AutoSavePluginData.kt | 15 ++------ .../extensions/LoggerControllerProvider.kt | 36 ------------------- .../MiraiConsoleImplementationBridge.kt | 20 +++-------- .../logging/LoggerControllerDelegate.kt | 21 ----------- 4 files changed, 7 insertions(+), 85 deletions(-) delete mode 100644 backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/LoggerControllerProvider.kt delete mode 100644 backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerDelegate.kt diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AutoSavePluginData.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AutoSavePluginData.kt index 58fbbd195..f081af4d2 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AutoSavePluginData.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AutoSavePluginData.kt @@ -36,8 +36,6 @@ public open class AutoSavePluginData private constructor( private lateinit var owner_: AutoSavePluginDataHolder private val autoSaveIntervalMillis_: LongRange get() = owner_.autoSaveIntervalMillis private lateinit var storage_: PluginDataStorage - private var authSaveJob: Job? = null - private var completionHandle: DisposableHandle? = null public final override val saveName: String get() = _saveName @@ -56,27 +54,18 @@ public open class AutoSavePluginData private constructor( ?: throw IllegalArgumentException("Cannot find a serial name for ${this::class}") } - @ConsoleExperimentalApi - public fun destroy() { - completionHandle?.dispose() - authSaveJob?.cancel() - completionHandle = null - authSaveJob = null - } - @ConsoleExperimentalApi override fun onInit(owner: PluginDataHolder, storage: PluginDataStorage) { check(owner is AutoSavePluginDataHolder) { "owner must be AutoSavePluginDataHolder for AutoSavePluginData" } if (this::storage_.isInitialized) { check(storage == this.storage_) { "AutoSavePluginData is already initialized with one storage and cannot be reinitialized with another." } - destroy() // Destroy old jobs } this.storage_ = storage this.owner_ = owner - completionHandle = owner_.coroutineContext[Job]?.invokeOnCompletion { + owner_.coroutineContext[Job]?.invokeOnCompletion { kotlin.runCatching { doSave() }.onFailure { e -> @@ -91,7 +80,7 @@ public open class AutoSavePluginData private constructor( } if (shouldPerformAutoSaveWheneverChanged()) { - authSaveJob = owner_.launch(CoroutineName("AutoSavePluginData.timedAutoSave: ${this::class.qualifiedNameOrTip}")) { + owner_.launch(CoroutineName("AutoSavePluginData.timedAutoSave: ${this::class.qualifiedNameOrTip}")) { while (isActive) { try { delay(autoSaveIntervalMillis_.last) // 定时自动保存一次, 用于 kts 序列化的对象 diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/LoggerControllerProvider.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/LoggerControllerProvider.kt deleted file mode 100644 index 43204c465..000000000 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/extensions/LoggerControllerProvider.kt +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2019-2020 Mamoe Technologies and contributors. - * - * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link. - * - * https://github.com/mamoe/mirai/blob/master/LICENSE - * - */ - -package net.mamoe.mirai.console.extensions - -import net.mamoe.mirai.console.extension.AbstractSingletonExtensionPoint -import net.mamoe.mirai.console.extension.SingletonExtension -import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge -import net.mamoe.mirai.console.internal.logging.LoggerControllerImpl -import net.mamoe.mirai.console.logging.LoggerController -import net.mamoe.mirai.console.permission.PermissionService - -public interface LoggerControllerProvider : SingletonExtension { - public companion object ExtensionPoint : - AbstractSingletonExtensionPoint(LoggerControllerProvider::class, MiraiConsoleImplementationBridge.frontendLoggerController) - -} - -/** - * @see LoggerControllerProvider - */ -public class LoggerControllerProviderImpl(override val instance: LoggerController) : LoggerControllerProvider - -/** - * @see LoggerControllerProvider - */ -public class LoggerControllerProviderLazy(initializer: () -> LoggerController) : LoggerControllerProvider { - override val instance: LoggerController by lazy(initializer) -} diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt index f43ec85ca..2389a8c36 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleImplementationBridge.kt @@ -25,7 +25,6 @@ import net.mamoe.mirai.console.command.BuiltInCommands import net.mamoe.mirai.console.command.CommandManager import net.mamoe.mirai.console.command.ConsoleCommandSender import net.mamoe.mirai.console.data.PluginDataStorage -import net.mamoe.mirai.console.extensions.LoggerControllerProvider import net.mamoe.mirai.console.extensions.PermissionServiceProvider import net.mamoe.mirai.console.extensions.PostStartupExtension import net.mamoe.mirai.console.extensions.SingletonExtensionSelector @@ -36,12 +35,12 @@ import net.mamoe.mirai.console.internal.data.builtins.LoggerConfig import net.mamoe.mirai.console.internal.data.castOrNull import net.mamoe.mirai.console.internal.extension.BuiltInSingletonExtensionSelector import net.mamoe.mirai.console.internal.extension.GlobalComponentStorage -import net.mamoe.mirai.console.internal.logging.LoggerControllerDelegate import net.mamoe.mirai.console.internal.logging.LoggerControllerImpl import net.mamoe.mirai.console.internal.logging.MiraiConsoleLogger import net.mamoe.mirai.console.internal.permission.BuiltInPermissionService import net.mamoe.mirai.console.internal.plugin.PluginManagerImpl import net.mamoe.mirai.console.internal.util.autoHexToBytes +import net.mamoe.mirai.console.logging.LoggerController import net.mamoe.mirai.console.permission.PermissionService import net.mamoe.mirai.console.permission.PermissionService.Companion.permit import net.mamoe.mirai.console.permission.RootPermission @@ -90,8 +89,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI override fun createLoginSolver(requesterBot: Long, configuration: BotConfiguration): LoginSolver = instance.createLoginSolver(requesterBot, configuration) - internal val frontendLoggerController = instance.loggerController - override val loggerController: LoggerControllerDelegate = LoggerControllerDelegate(frontendLoggerController) + override val loggerController: LoggerController by instance::loggerController init { DefaultLogger = this::createLogger @@ -106,10 +104,9 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI @Suppress("RemoveRedundantBackticks") internal fun doStart() { - phase `pre setup logger controller`@{ - loggerController.delegate = frontendLoggerController - if (frontendLoggerController === LoggerControllerImpl) { - // Relaod LoggerConfig first. + phase `setup logger controller`@{ + if (loggerController === LoggerControllerImpl) { + // Relaod LoggerConfig. ConsoleDataScope.addAndReloadConfig(LoggerConfig) } } @@ -180,13 +177,6 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI } } - phase `setup logger controller`@{ - val selected = LoggerControllerProvider.selectedInstance - if (selected !== frontendLoggerController) { - ConsoleDataScope.dropConfig(LoggerConfig) - loggerController.delegate = selected - } - } phase `load PermissionService`@{ mainLogger.verbose { "Loading PermissionService..." } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerDelegate.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerDelegate.kt deleted file mode 100644 index c10c32f2a..000000000 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/logging/LoggerControllerDelegate.kt +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2019-2020 Mamoe Technologies and contributors. - * - * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link. - * - * https://github.com/mamoe/mirai/blob/master/LICENSE - * - */ - -package net.mamoe.mirai.console.internal.logging - -import net.mamoe.mirai.console.logging.LoggerController -import net.mamoe.mirai.utils.SimpleLogger - -internal class LoggerControllerDelegate( - @Volatile - var delegate: LoggerController -) : LoggerController { - override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = delegate.shouldLog(identity, priority) -} \ No newline at end of file From 6d15c3b3015c1a02ef643de32f7a14e5959e2c04 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Wed, 28 Oct 2020 18:11:00 +0800 Subject: [PATCH 012/133] delete dropConfig --- .../mirai/console/internal/data/builtins/ConsoleDataScope.kt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/ConsoleDataScope.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/ConsoleDataScope.kt index 95c0d9a8f..ab5c122c6 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/ConsoleDataScope.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/builtins/ConsoleDataScope.kt @@ -26,11 +26,6 @@ internal object ConsoleDataScope : CoroutineScope by MiraiConsole.childScope("Co ConsoleBuiltInPluginConfigStorage.load(ConsoleBuiltInPluginConfigHolder, config) } - fun dropConfig(config: PluginConfig) { - configs.remove(config) - (config as? AutoSavePluginConfig)?.destroy() - } - fun reloadAll() { data.forEach { dt -> ConsoleBuiltInPluginDataStorage.load(ConsoleBuiltInPluginDataHolder, dt) From ada3c8f37593fb21f1cc2cb9f40c91890112234d Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Fri, 30 Oct 2020 18:14:09 +0800 Subject: [PATCH 013/133] AbstractLoggerController --- .../internal/data/builtins/LoggerConfig.kt | 3 +-- .../internal/logging/LoggerControllerImpl.kt | 26 +++++-------------- .../internal/logging/MiraiConsoleLogger.kt | 3 +-- .../src/logging/AbstractLoggerController.kt | 26 +++++++++++++++++++ .../mirai-console/src/logging/LogPriority.kt | 5 ++-- .../src/logging/LoggerController.kt | 3 +-- 6 files changed, 38 insertions(+), 28 deletions(-) create mode 100644 backend/mirai-console/src/logging/AbstractLoggerController.kt diff --git a/backend/mirai-console/src/internal/data/builtins/LoggerConfig.kt b/backend/mirai-console/src/internal/data/builtins/LoggerConfig.kt index 394bc1d78..adaa2fa5e 100644 --- a/backend/mirai-console/src/internal/data/builtins/LoggerConfig.kt +++ b/backend/mirai-console/src/internal/data/builtins/LoggerConfig.kt @@ -2,10 +2,9 @@ * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found through the following link. * * https://github.com/mamoe/mirai/blob/master/LICENSE - * */ package net.mamoe.mirai.console.internal.data.builtins diff --git a/backend/mirai-console/src/internal/logging/LoggerControllerImpl.kt b/backend/mirai-console/src/internal/logging/LoggerControllerImpl.kt index 5984d5f03..f828f5e86 100644 --- a/backend/mirai-console/src/internal/logging/LoggerControllerImpl.kt +++ b/backend/mirai-console/src/internal/logging/LoggerControllerImpl.kt @@ -2,39 +2,27 @@ * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found through the following link. * * https://github.com/mamoe/mirai/blob/master/LICENSE - * */ package net.mamoe.mirai.console.internal.logging import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.internal.data.builtins.LoggerConfig +import net.mamoe.mirai.console.logging.AbstractLoggerController import net.mamoe.mirai.console.logging.LogPriority -import net.mamoe.mirai.console.logging.LoggerController import net.mamoe.mirai.console.util.ConsoleInternalApi -import net.mamoe.mirai.utils.SimpleLogger @ConsoleFrontEndImplementation @ConsoleInternalApi -internal object LoggerControllerImpl : LoggerController { +internal object LoggerControllerImpl : AbstractLoggerController() { - private fun shouldLog( - priority: LogPriority, - settings: LogPriority - ): Boolean = settings <= priority - - private fun shouldLog(identity: String?, priority: LogPriority): Boolean { - return if (identity == null) { - shouldLog(priority, LoggerConfig.defaultPriority) - } else { - shouldLog(priority, LoggerConfig.loggers[identity] ?: LoggerConfig.defaultPriority) - } + override fun getPriority(identity: String?): LogPriority = if (identity == null) { + LoggerConfig.defaultPriority + } else { + LoggerConfig.loggers[identity] ?: LoggerConfig.defaultPriority } - override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = - shouldLog(identity, LogPriority.by(priority)) - } \ No newline at end of file diff --git a/backend/mirai-console/src/internal/logging/MiraiConsoleLogger.kt b/backend/mirai-console/src/internal/logging/MiraiConsoleLogger.kt index 48b829ee9..6d4fa04a5 100644 --- a/backend/mirai-console/src/internal/logging/MiraiConsoleLogger.kt +++ b/backend/mirai-console/src/internal/logging/MiraiConsoleLogger.kt @@ -2,10 +2,9 @@ * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found through the following link. * * https://github.com/mamoe/mirai/blob/master/LICENSE - * */ package net.mamoe.mirai.console.internal.logging diff --git a/backend/mirai-console/src/logging/AbstractLoggerController.kt b/backend/mirai-console/src/logging/AbstractLoggerController.kt new file mode 100644 index 000000000..6198f1109 --- /dev/null +++ b/backend/mirai-console/src/logging/AbstractLoggerController.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2019-2020 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + */ + +package net.mamoe.mirai.console.logging + +import net.mamoe.mirai.utils.SimpleLogger + +public abstract class AbstractLoggerController : LoggerController { + + protected open fun shouldLog( + priority: LogPriority, + settings: LogPriority + ): Boolean = settings <= priority + + protected abstract fun getPriority(identity: String?): LogPriority + + override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = + shouldLog(LogPriority.by(priority), getPriority(identity)) + +} diff --git a/backend/mirai-console/src/logging/LogPriority.kt b/backend/mirai-console/src/logging/LogPriority.kt index 957e42206..c6ad127af 100644 --- a/backend/mirai-console/src/logging/LogPriority.kt +++ b/backend/mirai-console/src/logging/LogPriority.kt @@ -2,10 +2,9 @@ * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found through the following link. * * https://github.com/mamoe/mirai/blob/master/LICENSE - * */ package net.mamoe.mirai.console.logging @@ -41,4 +40,4 @@ public enum class LogPriority { mapped = SimpleLogger.LogPriority.valueOf(name) } -} \ No newline at end of file +} diff --git a/backend/mirai-console/src/logging/LoggerController.kt b/backend/mirai-console/src/logging/LoggerController.kt index d4124e2fb..59b60457b 100644 --- a/backend/mirai-console/src/logging/LoggerController.kt +++ b/backend/mirai-console/src/logging/LoggerController.kt @@ -2,10 +2,9 @@ * Copyright 2019-2020 Mamoe Technologies and contributors. * * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found through the following link. * * https://github.com/mamoe/mirai/blob/master/LICENSE - * */ package net.mamoe.mirai.console.logging From 7f35409b50695857a56dd7b25e85c40ce8b001f7 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Fri, 30 Oct 2020 18:25:55 +0800 Subject: [PATCH 014/133] Typo --- .../src/internal/MiraiConsoleImplementationBridge.kt | 2 +- .../src/MiraiConsoleImplementationTerminal.kt | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt b/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt index 4db45a43f..7ce79204e 100644 --- a/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt +++ b/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt @@ -106,7 +106,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI phase `setup logger controller`@{ if (loggerController === LoggerControllerImpl) { - // Relaod LoggerConfig. + // Reload LoggerConfig. ConsoleDataScope.addAndReloadConfig(LoggerConfig) } } diff --git a/frontend/mirai-console-terminal/src/MiraiConsoleImplementationTerminal.kt b/frontend/mirai-console-terminal/src/MiraiConsoleImplementationTerminal.kt index dbcb26a82..9cd5a3ead 100644 --- a/frontend/mirai-console-terminal/src/MiraiConsoleImplementationTerminal.kt +++ b/frontend/mirai-console-terminal/src/MiraiConsoleImplementationTerminal.kt @@ -32,8 +32,6 @@ import net.mamoe.mirai.console.MiraiConsoleFrontEndDescription import net.mamoe.mirai.console.MiraiConsoleImplementation import net.mamoe.mirai.console.data.MultiFilePluginDataStorage import net.mamoe.mirai.console.data.PluginDataStorage -import net.mamoe.mirai.console.logging.LoggerController -import net.mamoe.mirai.console.internal.logging.LoggerControllerImpl import net.mamoe.mirai.console.plugin.jvm.JvmPluginLoader import net.mamoe.mirai.console.plugin.loader.PluginLoader import net.mamoe.mirai.console.terminal.ConsoleInputImpl.requestInput From 4f3c9bd8d9f595c3ef6007455b8f4e01c3131114 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 8 Nov 2020 09:33:05 +0800 Subject: [PATCH 015/133] Kotlin compiler 1.4.20-RC and Kotlin Jvm Blocking Bridge 1.4.0 --- buildSrc/src/main/kotlin/Versions.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 09016f70a..f5e3de2b7 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -13,8 +13,8 @@ object Versions { const val consoleGraphical = "0.0.7" const val consoleTerminal = console - const val kotlinCompiler = "1.4.10" - const val kotlinStdlib = kotlinCompiler + const val kotlinCompiler = "1.4.20-RC" + const val kotlinStdlib = "1.4.10" const val coroutines = "1.3.9" const val collectionsImmutable = "0.3.2" @@ -26,6 +26,6 @@ object Versions { const val bintray = "1.8.5" - const val blockingBridge = "1.1.0" + const val blockingBridge = "1.4.0" const val yamlkt = "0.5.3" } \ No newline at end of file From 65a65ffb0342c7d62728a978b419e52c2f3389ae Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 8 Nov 2020 09:38:19 +0800 Subject: [PATCH 016/133] Fix cast in findBackingFieldValue --- backend/mirai-console/src/data/AbstractPluginData.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/mirai-console/src/data/AbstractPluginData.kt b/backend/mirai-console/src/data/AbstractPluginData.kt index 6bbc507a4..a6f3ed4d1 100644 --- a/backend/mirai-console/src/data/AbstractPluginData.kt +++ b/backend/mirai-console/src/data/AbstractPluginData.kt @@ -161,7 +161,7 @@ public fun AbstractPluginData.findBackingFieldValue(property: KProperty): @ConsoleExperimentalApi public fun AbstractPluginData.findBackingFieldValue(propertyValueName: String): Value? { @Suppress("UNCHECKED_CAST") - return this.valueNodes.find { it.valueName == propertyValueName }?.value as Value + return this.valueNodes.find { it.valueName == propertyValueName }?.value as Value? } /** From e5a7df46de8cef106f5838057dbc4c8fb1a197c6 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 8 Nov 2020 09:52:29 +0800 Subject: [PATCH 017/133] Code cleanup --- backend/codegen/src/Codegen.kt | 8 ++-- backend/codegen/src/MessageScopeCodegen.kt | 6 +-- backend/codegen/src/old/JSettingCodegen.kt | 2 +- .../src/old/SettingValueUseSiteCodegen.kt | 4 +- backend/codegen/src/old/ValueImplCodegen.kt | 4 ++ backend/codegen/src/util.kt | 6 +-- .../src/MiraiConsoleFrontEndDescription.kt | 4 ++ .../src/data/AutoSavePluginData.kt | 1 + .../src/internal/data/collectionUtil.kt | 13 ++--- .../src/internal/data/reflectionUtils.kt | 2 + .../src/internal/data/serializerHelper.kt | 2 + .../src/internal/data/valueFromKTypeImpl.kt | 2 +- .../permission/parseFromStringImpl.kt | 4 +- .../src/internal/util/PluginServiceHelper.kt | 7 +-- .../src/permission/PermissionId.kt | 19 ++------ .../src/plugin/jvm/ExportManager.kt | 1 + .../mirai-console/src/util/MessageScope.kt | 4 +- .../mirai-console/src/util/MessageUtils.kt | 2 + .../mirai-console/src/util/retryCatching.kt | 2 +- .../mirai-console/test/data/SettingTest.kt | 1 + buildSrc/src/main/kotlin/PublishingHelpers.kt | 47 ++----------------- buildSrc/src/main/kotlin/Versions.kt | 17 +++---- docs/Commands.md | 2 +- docs/Preparations.md | 2 +- .../src/resolve/resolveTypes.kt | 4 +- tools/compiler-common/src/utilCommon.kt | 2 + tools/gradle-plugin/README.md | 4 +- .../intellij-plugin/src/QuickFixRegistrar.kt | 1 + .../src/diagnostics/diagnosticsUtil.kt | 6 +-- .../CommandDeclarationLineMarkerProvider.kt | 2 +- .../marker/PluginMainLineMarkerProvider.kt | 2 +- .../src/resolve/resolveIdea.kt | 4 +- 32 files changed, 76 insertions(+), 111 deletions(-) diff --git a/backend/codegen/src/Codegen.kt b/backend/codegen/src/Codegen.kt index bfc674cc4..18b376c2c 100644 --- a/backend/codegen/src/Codegen.kt +++ b/backend/codegen/src/Codegen.kt @@ -7,7 +7,7 @@ * https://github.com/mamoe/mirai/blob/master/LICENSE */ -@file:Suppress("FunctionName", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "PRE_RELEASE_CLASS") +@file:Suppress("FunctionName", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "PRE_RELEASE_CLASS", "unused") package net.mamoe.mirai.console.codegen @@ -59,9 +59,9 @@ class CodegenScope : MutableList by mutableListOf() { @CodegenDsl operator fun Codegen.invoke(ktTypes: Collection) { - add(Replacer { - it + buildString { - ktTypes.forEach { applyTo(this, it) } + add(Replacer { str -> + str + buildString { + ktTypes.forEach { ktType -> applyTo(this, ktType) } } }) } diff --git a/backend/codegen/src/MessageScopeCodegen.kt b/backend/codegen/src/MessageScopeCodegen.kt index e6b1c6b87..b444f9586 100644 --- a/backend/codegen/src/MessageScopeCodegen.kt +++ b/backend/codegen/src/MessageScopeCodegen.kt @@ -26,10 +26,6 @@ internal fun Array.arrangements(): List> { return result } -internal fun Array.distinctArrangements(): List> { - return this.arrangements().distinctBy { it.first.toString().hashCode() + it.second.toString().hashCode() } -} - internal object MessageScopeCodegen { object IterableMessageScopeBuildersCodegen : RegionCodegen("MessageScope.kt"), DefaultInvoke { @JvmStatic @@ -181,7 +177,7 @@ internal object MessageScopeCodegen { ReplaceWith( "this.asMessageScope()(action)", "net.mamoe.mirai.console.util.asMessageScope", - "net.mamoe.mirai.console.util.invoke" + "net.mamoe.mirai.console.util.invoke", ) ) public inline fun ${a}.scopeWith(action: MessageScope.() -> R): R = asMessageScope()(action) diff --git a/backend/codegen/src/old/JSettingCodegen.kt b/backend/codegen/src/old/JSettingCodegen.kt index 312703014..db9a50905 100644 --- a/backend/codegen/src/old/JSettingCodegen.kt +++ b/backend/codegen/src/old/JSettingCodegen.kt @@ -20,7 +20,7 @@ open class JClazz(val primitiveName: String, val packageName: String) { open val funName: String = "value" } -class JListClazz(val item: JClazz) : JClazz("List<${item.packageName}>", "List<${item.packageName}>") { +class JListClazz(item: JClazz) : JClazz("List<${item.packageName}>", "List<${item.packageName}>") { override val funName = item.primitiveName.toLowerCase() + "List" } diff --git a/backend/codegen/src/old/SettingValueUseSiteCodegen.kt b/backend/codegen/src/old/SettingValueUseSiteCodegen.kt index 9d2f20fb8..4b917092a 100644 --- a/backend/codegen/src/old/SettingValueUseSiteCodegen.kt +++ b/backend/codegen/src/old/SettingValueUseSiteCodegen.kt @@ -57,6 +57,7 @@ import kotlin.internal.LowPriorityInOverloadResolution """.trimIndent() fun genAllValueUseSite(): String = buildString { + @Suppress("SpellCheckingInspection") fun appendln(@Language("kt") code: String) { this.appendLine(code.trimIndent()) } @@ -112,6 +113,7 @@ fun genAllValueUseSite(): String = buildString { // SPECIAL appendLine() + @Suppress("unused", "SpellCheckingInspection", "KDocUnresolvedReference") appendln( """ fun PluginData.value(default: T): Value { @@ -153,7 +155,7 @@ fun genAllValueUseSite(): String = buildString { ""${'"'} 这种只保存引用的 Value 可能会导致意料之外的结果, 在使用时须保持谨慎. 对值的改变不会触发自动保存, 也不会同步到 UI 中. 在 UI 中只能编辑序列化之后的值. - ""${'"'}, level = RequiresOptIn.Level.WARNING + ""${'"'}, level = RequiresOptIn.Level.WARNING, ) @Retention(AnnotationRetention.BINARY) @Target(AnnotationTarget.FUNCTION) diff --git a/backend/codegen/src/old/ValueImplCodegen.kt b/backend/codegen/src/old/ValueImplCodegen.kt index 47e42a836..10485d8d2 100644 --- a/backend/codegen/src/old/ValueImplCodegen.kt +++ b/backend/codegen/src/old/ValueImplCodegen.kt @@ -52,6 +52,7 @@ import kotlinx.serialization.builtins.* import net.mamoe.mirai.console.data.* """.trimIndent() +@Suppress("SpellCheckingInspection") fun genAllValueImpl(): String = buildString { fun appendln(@Language("kt") code: String) { this.appendLine(code.trimIndent()) @@ -118,6 +119,7 @@ fun genAllValueImpl(): String = buildString { for (collectionName in listOf("List", "Set")) { for (number in NUMBERS + OTHER_PRIMITIVES) { + @Suppress("unused") appendln( """ @JvmName("valueImplMutable${number}${collectionName}") @@ -164,6 +166,7 @@ fun genAllValueImpl(): String = buildString { appendLine() + @Suppress("unused") appendln( """ internal fun PluginData.valueImpl(default: T): Value { @@ -230,6 +233,7 @@ fun genPrimitiveValueImpl( """.trimIndent() + "\n" +@Suppress("SpellCheckingInspection") fun genCollectionValueImpl( collectionName: String, kotlinTypeName: String, diff --git a/backend/codegen/src/util.kt b/backend/codegen/src/util.kt index 735215346..441df612f 100644 --- a/backend/codegen/src/util.kt +++ b/backend/codegen/src/util.kt @@ -107,10 +107,8 @@ fun codegen(targetFile: String, block: CodegenScope.() -> Unit) { println("Codegen target: ${it.absolutePath}") }.apply { writeText( - CodegenScope().apply(block).also { list -> - list.forEach { - println("Applying replacement: $it") - } + CodegenScope().apply(block).onEach { + println("Applying replacement: $it") }.applyTo(readText()) ) } diff --git a/backend/mirai-console/src/MiraiConsoleFrontEndDescription.kt b/backend/mirai-console/src/MiraiConsoleFrontEndDescription.kt index 4c4de4b32..a09d08b5d 100644 --- a/backend/mirai-console/src/MiraiConsoleFrontEndDescription.kt +++ b/backend/mirai-console/src/MiraiConsoleFrontEndDescription.kt @@ -7,9 +7,12 @@ * https://github.com/mamoe/mirai/blob/master/LICENSE */ +@file:Suppress("unused") + package net.mamoe.mirai.console import net.mamoe.mirai.console.util.SemVersion +import net.mamoe.mirai.utils.MiraiExperimentalAPI /** @@ -38,6 +41,7 @@ public interface MiraiConsoleFrontEndDescription { * * 返回 `null` 表示禁止 [MiraiConsole] 后端检查版本兼容性. */ + @MiraiExperimentalAPI public val compatibleBackendVersion: SemVersion? get() = null /** diff --git a/backend/mirai-console/src/data/AutoSavePluginData.kt b/backend/mirai-console/src/data/AutoSavePluginData.kt index 1d21c29c3..ff281c02f 100644 --- a/backend/mirai-console/src/data/AutoSavePluginData.kt +++ b/backend/mirai-console/src/data/AutoSavePluginData.kt @@ -170,4 +170,5 @@ internal inline fun MiraiLogger.runCatchingLog(message: (Throwable) -> Strin }.getOrNull() } +@Suppress("SpellCheckingInspection") private const val MAGIC_NUMBER_CFST_INIT: Long = Long.MAX_VALUE diff --git a/backend/mirai-console/src/internal/data/collectionUtil.kt b/backend/mirai-console/src/internal/data/collectionUtil.kt index 255bd9931..ff392ff76 100644 --- a/backend/mirai-console/src/internal/data/collectionUtil.kt +++ b/backend/mirai-console/src/internal/data/collectionUtil.kt @@ -11,11 +11,6 @@ package net.mamoe.mirai.console.internal.data -import kotlinx.serialization.InternalSerializationApi -import kotlinx.serialization.serializer -import net.mamoe.yamlkt.Yaml -import kotlin.reflect.KClass - // TODO: 2020/6/24 优化性能: 引入一个 comparator 之类来替代将 Int 包装为 Value 后进行 containsKey 比较的方法 @@ -245,6 +240,8 @@ internal inline fun MutableSet.shadowMap( } } +/* + internal inline fun dynamicList(crossinline supplier: () -> List): List { return object : List { override val size: Int get() = supplier().size @@ -304,7 +301,6 @@ internal inline fun dynamicMutableList(crossinline supplier: () -> MutableLi } } - internal inline fun dynamicMutableSet(crossinline supplier: () -> MutableSet): MutableSet { return object : MutableSet { override val size: Int get() = supplier().size @@ -322,7 +318,7 @@ internal inline fun dynamicMutableSet(crossinline supplier: () -> MutableSet override fun hashCode(): Int = supplier().hashCode() } } - +*/ @Suppress("UNCHECKED_CAST", "USELESS_CAST") // type inference bug internal inline fun MutableMap.observable(crossinline onChanged: () -> Unit): MutableMap { return object : MutableMap, Map by (this as Map) { @@ -472,7 +468,7 @@ internal inline fun MutableSet.observable(crossinline onChanged: () -> Un } } - +/* @OptIn(InternalSerializationApi::class) internal fun Any.smartCastPrimitive(clazz: KClass): R { kotlin.runCatching { @@ -482,3 +478,4 @@ internal fun Any.smartCastPrimitive(clazz: KClass): R { } } +*/ \ No newline at end of file diff --git a/backend/mirai-console/src/internal/data/reflectionUtils.kt b/backend/mirai-console/src/internal/data/reflectionUtils.kt index d14c3b12e..5cb7cd62a 100644 --- a/backend/mirai-console/src/internal/data/reflectionUtils.kt +++ b/backend/mirai-console/src/internal/data/reflectionUtils.kt @@ -7,6 +7,8 @@ * https://github.com/mamoe/mirai/blob/master/LICENSE */ +@file:Suppress("unused") + package net.mamoe.mirai.console.internal.data import net.mamoe.mirai.console.data.PluginData diff --git a/backend/mirai-console/src/internal/data/serializerHelper.kt b/backend/mirai-console/src/internal/data/serializerHelper.kt index b5a2a0938..f9e5b837f 100644 --- a/backend/mirai-console/src/internal/data/serializerHelper.kt +++ b/backend/mirai-console/src/internal/data/serializerHelper.kt @@ -7,6 +7,8 @@ * https://github.com/mamoe/mirai/blob/master/LICENSE */ +@file:Suppress("unused") + package net.mamoe.mirai.console.internal.data import kotlinx.serialization.ExperimentalSerializationApi diff --git a/backend/mirai-console/src/internal/data/valueFromKTypeImpl.kt b/backend/mirai-console/src/internal/data/valueFromKTypeImpl.kt index 1d63acce7..17b7ba3eb 100644 --- a/backend/mirai-console/src/internal/data/valueFromKTypeImpl.kt +++ b/backend/mirai-console/src/internal/data/valueFromKTypeImpl.kt @@ -102,7 +102,7 @@ internal fun PluginData.valueFromKTypeImpl(type: KType): SerializerAwareValue<*> } } -internal fun KClass<*>.createInstanceSmart(): Any? { +internal fun KClass<*>.createInstanceSmart(): Any { return when (this) { Byte::class -> 0.toByte() Short::class -> 0.toShort() diff --git a/backend/mirai-console/src/internal/permission/parseFromStringImpl.kt b/backend/mirai-console/src/internal/permission/parseFromStringImpl.kt index e1267706c..fd1fb8a2e 100644 --- a/backend/mirai-console/src/internal/permission/parseFromStringImpl.kt +++ b/backend/mirai-console/src/internal/permission/parseFromStringImpl.kt @@ -39,7 +39,7 @@ internal fun parseFromStringImpl(string: String): AbstractPermitteeId { val arg = str.substring(1) if (arg == "*") return AnyContact } - 'm' -> kotlin.run { + 'm' -> run { val arg = str.substring(1) if (arg == "*") return AnyMemberFromAnyGroup else { @@ -56,7 +56,7 @@ internal fun parseFromStringImpl(string: String): AbstractPermitteeId { } } } - 't' -> kotlin.run { + 't' -> run { val arg = str.substring(1) if (arg == "*") return AnyTempFromAnyGroup else { diff --git a/backend/mirai-console/src/internal/util/PluginServiceHelper.kt b/backend/mirai-console/src/internal/util/PluginServiceHelper.kt index d64a7ddc5..86dc84dab 100644 --- a/backend/mirai-console/src/internal/util/PluginServiceHelper.kt +++ b/backend/mirai-console/src/internal/util/PluginServiceHelper.kt @@ -7,6 +7,8 @@ * https://github.com/mamoe/mirai/blob/master/LICENSE */ +@file:Suppress("unused") + package net.mamoe.mirai.console.internal.util import net.mamoe.mirai.console.internal.data.cast @@ -18,7 +20,6 @@ import java.util.* import kotlin.reflect.KClass import java.lang.reflect.Member as JReflectionMember -@Suppress("unused") internal class ServiceList( internal val classLoader: ClassLoader, internal val delegate: List @@ -38,8 +39,8 @@ internal object PluginServiceHelper { return delegate.mapNotNull { classLoader.loadService(it) } } - fun ClassLoader.loadService( - classname: String + private fun ClassLoader.loadService( + classname: String, ): T? { @Suppress("UNCHECKED_CAST") return kotlin.runCatching { diff --git a/backend/mirai-console/src/permission/PermissionId.kt b/backend/mirai-console/src/permission/PermissionId.kt index 65411c3eb..bd99d5d22 100644 --- a/backend/mirai-console/src/permission/PermissionId.kt +++ b/backend/mirai-console/src/permission/PermissionId.kt @@ -31,19 +31,8 @@ public data class PermissionId( @ResolveContext(PERMISSION_NAME) public val name: String, ) { init { - require(namespace.none { it.isWhitespace() }) { - "' ' is not allowed in namespace" - } - require(name.none { it.isWhitespace() }) { - "' ' is not allowed in name" - } - - require(!namespace.contains(':')) { - "':' is not allowed in namespace" - } - require(!name.contains(':')) { - "':' is not allowed in name" - } + checkPermissionIdName(name) + checkPermissionIdName(namespace) } public object PermissionIdAsStringSerializer : KSerializer by String.serializer().map( @@ -79,7 +68,7 @@ public data class PermissionId( public fun checkPermissionIdName(@ResolveContext(PERMISSION_NAME) name: String) { when { name.isBlank() -> throw IllegalArgumentException("PermissionId.name should not be blank.") - name.any { it.isWhitespace() } -> throw IllegalArgumentException("Spaces are not yet allowed in PermissionId.name.") + name.any(Char::isWhitespace) -> throw IllegalArgumentException("Spaces are not yet allowed in PermissionId.name.") name.contains(':') -> throw IllegalArgumentException("':' is forbidden in PermissionId.name.") } } @@ -92,7 +81,7 @@ public data class PermissionId( public fun checkPermissionIdNamespace(@ResolveContext(PERMISSION_NAME) namespace: String) { when { namespace.isBlank() -> throw IllegalArgumentException("PermissionId.namespace should not be blank.") - namespace.any { it.isWhitespace() } -> throw IllegalArgumentException("Spaces are not yet allowed in PermissionId.namespace.") + namespace.any(Char::isWhitespace) -> throw IllegalArgumentException("Spaces are not yet allowed in PermissionId.namespace.") namespace.contains(':') -> throw IllegalArgumentException("':' is forbidden in PermissionId.namespace.") } } diff --git a/backend/mirai-console/src/plugin/jvm/ExportManager.kt b/backend/mirai-console/src/plugin/jvm/ExportManager.kt index c9bac5cde..844c41338 100644 --- a/backend/mirai-console/src/plugin/jvm/ExportManager.kt +++ b/backend/mirai-console/src/plugin/jvm/ExportManager.kt @@ -76,6 +76,7 @@ import net.mamoe.mirai.console.util.ConsoleExperimentalApi * } * ``` * + * @see StandardExportManagers */ @ConsoleExperimentalApi public interface ExportManager { diff --git a/backend/mirai-console/src/util/MessageScope.kt b/backend/mirai-console/src/util/MessageScope.kt index 023642dcb..1b39f9c9f 100644 --- a/backend/mirai-console/src/util/MessageScope.kt +++ b/backend/mirai-console/src/util/MessageScope.kt @@ -555,7 +555,7 @@ private class CombinedScope( private class CommandSenderAsMessageScope( private val sender: CommandSender, ) : MessageScope { - override val realTarget: Any? + override val realTarget: Any get() = sender.user ?: sender // ConsoleCommandSender override suspend fun sendMessage(message: Message) { @@ -570,7 +570,7 @@ private class CommandSenderAsMessageScope( private class ContactAsMessageScope( private val sender: Contact, ) : MessageScope { - override val realTarget: Any? + override val realTarget: Any get() = sender override suspend fun sendMessage(message: Message) { diff --git a/backend/mirai-console/src/util/MessageUtils.kt b/backend/mirai-console/src/util/MessageUtils.kt index 117b7307f..383b4e57a 100644 --- a/backend/mirai-console/src/util/MessageUtils.kt +++ b/backend/mirai-console/src/util/MessageUtils.kt @@ -7,6 +7,8 @@ * https://github.com/mamoe/mirai/blob/master/LICENSE */ +@file:Suppress("unused") + package net.mamoe.mirai.console.util import net.mamoe.mirai.message.data.MessageChain diff --git a/backend/mirai-console/src/util/retryCatching.kt b/backend/mirai-console/src/util/retryCatching.kt index 88b951706..fa6859b05 100644 --- a/backend/mirai-console/src/util/retryCatching.kt +++ b/backend/mirai-console/src/util/retryCatching.kt @@ -7,7 +7,7 @@ * https://github.com/mamoe/mirai/blob/master/LICENSE */ -@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "RESULT_CLASS_IN_RETURN_TYPE") +@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE", "RESULT_CLASS_IN_RETURN_TYPE", "unused") @file:JvmMultifileClass @file:JvmName("ConsoleUtils") diff --git a/backend/mirai-console/test/data/SettingTest.kt b/backend/mirai-console/test/data/SettingTest.kt index e50cb7e11..3b1fe1f92 100644 --- a/backend/mirai-console/test/data/SettingTest.kt +++ b/backend/mirai-console/test/data/SettingTest.kt @@ -23,6 +23,7 @@ internal class PluginDataTest { val map2: MutableMap> by value() } + @Suppress("unused") private val jsonPrettyPrint = Json { prettyPrint = true } private val json = Json {} diff --git a/buildSrc/src/main/kotlin/PublishingHelpers.kt b/buildSrc/src/main/kotlin/PublishingHelpers.kt index a48ca62d0..8b695c9ef 100644 --- a/buildSrc/src/main/kotlin/PublishingHelpers.kt +++ b/buildSrc/src/main/kotlin/PublishingHelpers.kt @@ -16,9 +16,6 @@ import org.gradle.api.tasks.TaskContainer import org.gradle.api.tasks.bundling.Jar import org.gradle.kotlin.dsl.* import upload.Bintray -import java.io.InputStream -import java.io.OutputStream -import java.security.MessageDigest import java.util.* import kotlin.reflect.KProperty @@ -35,7 +32,7 @@ import kotlin.reflect.KProperty * Configures the [bintray][com.jfrog.bintray.gradle.BintrayExtension] extension. */ @PublishedApi -internal fun org.gradle.api.Project.`bintray`(configure: com.jfrog.bintray.gradle.BintrayExtension.() -> Unit): Unit = +internal fun Project.`bintray`(configure: com.jfrog.bintray.gradle.BintrayExtension.() -> Unit): Unit = (this as org.gradle.api.plugins.ExtensionAware).extensions.configure("bintray", configure) @PublishedApi @@ -47,7 +44,7 @@ internal operator fun RegisteringDomainObjectDelegateProviderWithType ) @PublishedApi -internal val org.gradle.api.Project.`sourceSets`: org.gradle.api.tasks.SourceSetContainer +internal val Project.`sourceSets`: org.gradle.api.tasks.SourceSetContainer get() = (this as org.gradle.api.plugins.ExtensionAware).extensions.getByName("sourceSets") as org.gradle.api.tasks.SourceSetContainer @@ -59,48 +56,10 @@ internal operator fun ExistingDomainObjectDelegate.getValue(receiver: * Configures the [publishing][org.gradle.api.publish.PublishingExtension] extension. */ @PublishedApi -internal fun org.gradle.api.Project.`publishing`(configure: org.gradle.api.publish.PublishingExtension.() -> Unit): Unit = +internal fun Project.`publishing`(configure: org.gradle.api.publish.PublishingExtension.() -> Unit): Unit = (this as org.gradle.api.plugins.ExtensionAware).extensions.configure("publishing", configure) -fun InputStream.md5(): ByteArray { - val digest = MessageDigest.getInstance("md5") - digest.reset() - use { input -> - object : OutputStream() { - override fun write(b: Int) { - digest.update(b.toByte()) - } - }.use { output -> - input.copyTo(output) - } - } - return digest.digest() -} - -@OptIn(ExperimentalUnsignedTypes::class) -@JvmOverloads -fun ByteArray.toUHexString( - separator: String = " ", - offset: Int = 0, - length: Int = this.size - offset -): String { - if (length == 0) { - return "" - } - val lastIndex = offset + length - return buildString(length * 2) { - this@toUHexString.forEachIndexed { index, it -> - if (index in offset until lastIndex) { - var ret = it.toUByte().toString(16).toUpperCase() - if (ret.length == 1) ret = "0$ret" - append(ret) - if (index < lastIndex - 1) append(separator) - } - } - } -} - inline fun Project.setupPublishing( artifactId: String, bintrayRepo: String = "mirai", diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index f5e3de2b7..91701e16c 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -1,11 +1,13 @@ /* - * Copyright 2019-2020 Mamoe Technologies and contributors. - * - * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found through the following link. - * - * https://github.com/mamoe/mirai/blob/master/LICENSE - */ +* Copyright 2019-2020 Mamoe Technologies and contributors. +* +* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. +* Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found through the following link. +* +* https://github.com/mamoe/mirai/blob/master/LICENSE +*/ + +@file:Suppress("MemberVisibilityCanBePrivate") object Versions { const val core = "1.3.2" @@ -17,7 +19,6 @@ object Versions { const val kotlinStdlib = "1.4.10" const val coroutines = "1.3.9" - const val collectionsImmutable = "0.3.2" const val serialization = "1.0.0-RC" const val ktor = "1.4.1" const val atomicFU = "0.14.4" diff --git a/docs/Commands.md b/docs/Commands.md index 0fad7bcf8..621d994e9 100644 --- a/docs/Commands.md +++ b/docs/Commands.md @@ -127,7 +127,7 @@ Mirai Console 内建 [`SimpleCommand`] 与 [`CompositeCommand`] 拥有 [`Command object MySimpleCommand : SimpleCommand( MyPluginMain, "tell", "私聊", description = "Tell somebody privately", - usage = "/tell " // usage 如不设置则自动根据带有 @Handler 的方法生成 + usage = "/tell ", // usage 如不设置则自动根据带有 @Handler 的方法生成 ) { @Handler // 标记这是指令处理器 // 函数名随意 suspend fun CommandSender.handle(target: User, message: String) { // 这两个参数会被作为指令参数要求 diff --git a/docs/Preparations.md b/docs/Preparations.md index 24dd2d120..bd31bd42f 100644 --- a/docs/Preparations.md +++ b/docs/Preparations.md @@ -43,7 +43,7 @@ - Java 中的「方法」在 Kotlin 中均被称为「函数」。 - Kotlin 默认的访问权限是 `public`。如 Kotlin `class Test` 相当于 Java 的 `public class Test {}` -- Kotlin 的函数定义 `fun test(int: Int): String` 相当于 Java 的方法定义 `public String test(int int)` +- Kotlin 的函数定义 `fun test(int: Int): String` 相当于 Java 的方法定义 `public String test(int integer)` ### 在 Java 使用 Mirai Console 中的 Kotlin `suspend` 函数 diff --git a/tools/compiler-common/src/resolve/resolveTypes.kt b/tools/compiler-common/src/resolve/resolveTypes.kt index 9687dc4b9..080f61ed4 100644 --- a/tools/compiler-common/src/resolve/resolveTypes.kt +++ b/tools/compiler-common/src/resolve/resolveTypes.kt @@ -7,6 +7,8 @@ * https://github.com/mamoe/mirai/blob/master/LICENSE */ +@file:Suppress("unused") + package net.mamoe.mirai.console.compiler.common.resolve import net.mamoe.mirai.console.compiler.common.castOrNull @@ -70,7 +72,7 @@ enum class ResolveContextKind { ; companion object { - fun valueOfOrNull(string: String): ResolveContextKind? = values().find { it.name == string } + fun valueOfOrNull(string: String) = values().find { it.name == string } } } diff --git a/tools/compiler-common/src/utilCommon.kt b/tools/compiler-common/src/utilCommon.kt index 6ee261353..8a6e62fb5 100644 --- a/tools/compiler-common/src/utilCommon.kt +++ b/tools/compiler-common/src/utilCommon.kt @@ -7,6 +7,8 @@ * https://github.com/mamoe/mirai/blob/master/LICENSE */ +@file:Suppress("unused") + package net.mamoe.mirai.console.compiler.common import org.jetbrains.kotlin.name.FqName diff --git a/tools/gradle-plugin/README.md b/tools/gradle-plugin/README.md index 679bb73d7..493d793dd 100644 --- a/tools/gradle-plugin/README.md +++ b/tools/gradle-plugin/README.md @@ -4,7 +4,7 @@ Mirai Console Gradle 插件。 ## 使用 -参考 [ConfiguringProjects](../../docs/ConfiguringProjects.md#gradle)[ +参考 [ConfiguringProjects](../../docs/ConfiguringProjects.md) ## 功能 @@ -34,7 +34,7 @@ mirai { // this: MiraiConsoleExtension } ``` -DSL 详见 [MiraiConsoleExtension](src/main/kotlin/net/mamoe/mirai/console/gradle/MiraiConsoleExtension.kt)。 +DSL 详见 [MiraiConsoleExtension](src/MiraiConsoleExtension.kt)。 #### 排除依赖 diff --git a/tools/intellij-plugin/src/QuickFixRegistrar.kt b/tools/intellij-plugin/src/QuickFixRegistrar.kt index e13b263ba..6e0bcccdc 100644 --- a/tools/intellij-plugin/src/QuickFixRegistrar.kt +++ b/tools/intellij-plugin/src/QuickFixRegistrar.kt @@ -23,6 +23,7 @@ class QuickFixRegistrar : QuickFixContributor { quickFixes.register(this, *factory) } + @Suppress("unused") fun DiagnosticFactory<*>.registerActions(vararg action: IntentionAction) { quickFixes.register(this, *action) } diff --git a/tools/intellij-plugin/src/diagnostics/diagnosticsUtil.kt b/tools/intellij-plugin/src/diagnostics/diagnosticsUtil.kt index 066a3985b..ac09c62f8 100644 --- a/tools/intellij-plugin/src/diagnostics/diagnosticsUtil.kt +++ b/tools/intellij-plugin/src/diagnostics/diagnosticsUtil.kt @@ -9,7 +9,7 @@ package net.mamoe.mirai.console.intellij.diagnostics -import net.mamoe.mirai.console.intellij.resolve.getResolvedCallOrResolveToCall +import net.mamoe.mirai.console.intellij.resolve.getResolvedCall import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.psi.KtElement @@ -22,8 +22,8 @@ fun DeclarationCheckerContext.report(diagnostic: Diagnostic) { val DeclarationCheckerContext.bindingContext get() = this.trace.bindingContext -fun KtElement?.getResolvedCallOrResolveToCall( +fun KtElement?.getResolvedCall( context: DeclarationCheckerContext, ): ResolvedCall? { - return this.getResolvedCallOrResolveToCall(context.bindingContext) + return this.getResolvedCall(context.bindingContext) } \ No newline at end of file diff --git a/tools/intellij-plugin/src/line/marker/CommandDeclarationLineMarkerProvider.kt b/tools/intellij-plugin/src/line/marker/CommandDeclarationLineMarkerProvider.kt index d2f6c4c8f..fbde5b3fe 100644 --- a/tools/intellij-plugin/src/line/marker/CommandDeclarationLineMarkerProvider.kt +++ b/tools/intellij-plugin/src/line/marker/CommandDeclarationLineMarkerProvider.kt @@ -41,7 +41,7 @@ class CommandDeclarationLineMarkerProvider : LineMarkerProvider { null, GutterIconRenderer.Alignment.RIGHT ) { - override fun createGutterRenderer(): GutterIconRenderer? { + override fun createGutterRenderer(): GutterIconRenderer { return object : LineMarkerInfo.LineMarkerGutterIconRenderer(this) { override fun getClickAction(): AnAction? = null } diff --git a/tools/intellij-plugin/src/line/marker/PluginMainLineMarkerProvider.kt b/tools/intellij-plugin/src/line/marker/PluginMainLineMarkerProvider.kt index eba297dc1..cbd077d2e 100644 --- a/tools/intellij-plugin/src/line/marker/PluginMainLineMarkerProvider.kt +++ b/tools/intellij-plugin/src/line/marker/PluginMainLineMarkerProvider.kt @@ -52,7 +52,7 @@ class PluginMainLineMarkerProvider : LineMarkerProvider { null, GutterIconRenderer.Alignment.CENTER ) { - override fun createGutterRenderer(): GutterIconRenderer? { + override fun createGutterRenderer(): GutterIconRenderer { return object : LineMarkerInfo.LineMarkerGutterIconRenderer(this) { override fun getClickAction(): AnAction? = null } diff --git a/tools/intellij-plugin/src/resolve/resolveIdea.kt b/tools/intellij-plugin/src/resolve/resolveIdea.kt index dfcd8389b..9afd5bc70 100644 --- a/tools/intellij-plugin/src/resolve/resolveIdea.kt +++ b/tools/intellij-plugin/src/resolve/resolveIdea.kt @@ -88,7 +88,7 @@ fun KtAnnotated.hasAnnotation(fqName: FqName): Boolean = fun KtDeclaration.resolveAllCalls(bindingContext: BindingContext): Sequence> { return allChildrenWithSelf .filterIsInstance() - .mapNotNull { it.calleeExpression?.getResolvedCallOrResolveToCall(bindingContext) } + .mapNotNull { it.calleeExpression?.getResolvedCall(bindingContext) } } fun KtDeclaration.resolveAllCallsWithElement(bindingContext: BindingContext): Sequence, KtCallExpression>> { @@ -122,7 +122,7 @@ val PsiElement.allChildrenFlat: Sequence inline fun PsiElement.findChild(): E? = this.children.find { it is E } as E? -fun KtElement?.getResolvedCallOrResolveToCall( +fun KtElement?.getResolvedCall( context: BindingContext, ): ResolvedCall? { return this?.getCall(context)?.getResolvedCall(context) From d3451573498fe6c2c2d6506f679755abe6732fac Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Sun, 8 Nov 2020 10:22:08 +0800 Subject: [PATCH 018/133] @ConsoleExperimentalApi --- backend/mirai-console/src/logging/AbstractLoggerController.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/mirai-console/src/logging/AbstractLoggerController.kt b/backend/mirai-console/src/logging/AbstractLoggerController.kt index 6198f1109..19dc9b7f6 100644 --- a/backend/mirai-console/src/logging/AbstractLoggerController.kt +++ b/backend/mirai-console/src/logging/AbstractLoggerController.kt @@ -9,8 +9,10 @@ package net.mamoe.mirai.console.logging +import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.utils.SimpleLogger +@ConsoleExperimentalApi public abstract class AbstractLoggerController : LoggerController { protected open fun shouldLog( From 3a5fa11554cb8f631d22bac640bee3e99cdb9a14 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Sun, 8 Nov 2020 10:49:57 +0800 Subject: [PATCH 019/133] Move LogPriority into AbstractLoggerController --- .../internal/data/builtins/LoggerConfig.kt | 8 ++-- .../internal/logging/LoggerControllerImpl.kt | 1 - .../src/logging/AbstractLoggerController.kt | 34 +++++++++++++++ .../mirai-console/src/logging/LogPriority.kt | 43 ------------------- 4 files changed, 38 insertions(+), 48 deletions(-) delete mode 100644 backend/mirai-console/src/logging/LogPriority.kt diff --git a/backend/mirai-console/src/internal/data/builtins/LoggerConfig.kt b/backend/mirai-console/src/internal/data/builtins/LoggerConfig.kt index adaa2fa5e..f860e104a 100644 --- a/backend/mirai-console/src/internal/data/builtins/LoggerConfig.kt +++ b/backend/mirai-console/src/internal/data/builtins/LoggerConfig.kt @@ -12,19 +12,19 @@ package net.mamoe.mirai.console.internal.data.builtins import net.mamoe.mirai.console.data.AutoSavePluginConfig import net.mamoe.mirai.console.data.ValueDescription import net.mamoe.mirai.console.data.value -import net.mamoe.mirai.console.logging.LogPriority +import net.mamoe.mirai.console.logging.AbstractLoggerController internal object LoggerConfig : AutoSavePluginConfig("Logger") { @ValueDescription(""" 日志输出等级 可选值: ALL, VERBOSE, DEBUG, INFO, WARNING, ERROR, NONE """) - val defaultPriority by value(LogPriority.INFO) + val defaultPriority by value(AbstractLoggerController.LogPriority.INFO) @ValueDescription(""" 特定日志记录器输出等级 """) - val loggers: Map by value( - mapOf("example.logger" to LogPriority.NONE) + val loggers: Map by value( + mapOf("example.logger" to AbstractLoggerController.LogPriority.NONE) ) } diff --git a/backend/mirai-console/src/internal/logging/LoggerControllerImpl.kt b/backend/mirai-console/src/internal/logging/LoggerControllerImpl.kt index f828f5e86..c65a23237 100644 --- a/backend/mirai-console/src/internal/logging/LoggerControllerImpl.kt +++ b/backend/mirai-console/src/internal/logging/LoggerControllerImpl.kt @@ -12,7 +12,6 @@ package net.mamoe.mirai.console.internal.logging import net.mamoe.mirai.console.ConsoleFrontEndImplementation import net.mamoe.mirai.console.internal.data.builtins.LoggerConfig import net.mamoe.mirai.console.logging.AbstractLoggerController -import net.mamoe.mirai.console.logging.LogPriority import net.mamoe.mirai.console.util.ConsoleInternalApi @ConsoleFrontEndImplementation diff --git a/backend/mirai-console/src/logging/AbstractLoggerController.kt b/backend/mirai-console/src/logging/AbstractLoggerController.kt index 19dc9b7f6..3d4725990 100644 --- a/backend/mirai-console/src/logging/AbstractLoggerController.kt +++ b/backend/mirai-console/src/logging/AbstractLoggerController.kt @@ -11,6 +11,7 @@ package net.mamoe.mirai.console.logging import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.utils.SimpleLogger +import java.util.* @ConsoleExperimentalApi public abstract class AbstractLoggerController : LoggerController { @@ -25,4 +26,37 @@ public abstract class AbstractLoggerController : LoggerController { override fun shouldLog(identity: String?, priority: SimpleLogger.LogPriority): Boolean = shouldLog(LogPriority.by(priority), getPriority(identity)) + @Suppress("unused") + @ConsoleExperimentalApi + public enum class LogPriority { + ALL(null), + VERBOSE, + DEBUG, + INFO, + WARNING, + ERROR, + NONE(null); + + private var mapped: SimpleLogger.LogPriority? = null + + public companion object { + private val mapping = EnumMap(SimpleLogger.LogPriority::class.java) + + public fun by(priority: SimpleLogger.LogPriority): LogPriority = mapping[priority]!! + + init { + values().forEach { priority -> + mapping[priority.mapped ?: return@forEach] = priority + } + } + } + + @Suppress("UNUSED_PARAMETER") + constructor(void: Nothing?) + constructor() { + mapped = SimpleLogger.LogPriority.valueOf(name) + } + + } + } diff --git a/backend/mirai-console/src/logging/LogPriority.kt b/backend/mirai-console/src/logging/LogPriority.kt deleted file mode 100644 index c6ad127af..000000000 --- a/backend/mirai-console/src/logging/LogPriority.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2019-2020 Mamoe Technologies and contributors. - * - * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. - * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found through the following link. - * - * https://github.com/mamoe/mirai/blob/master/LICENSE - */ - -package net.mamoe.mirai.console.logging - -import net.mamoe.mirai.utils.SimpleLogger -import java.util.* - -public enum class LogPriority { - ALL(null), - VERBOSE, - DEBUG, - INFO, - WARNING, - ERROR, - NONE(null); - - private var mapped: SimpleLogger.LogPriority? = null - - public companion object { - private val mapping = EnumMap(SimpleLogger.LogPriority::class.java) - - public fun by(priority: SimpleLogger.LogPriority): LogPriority = mapping[priority]!! - - init { - values().forEach { priority -> - mapping[priority.mapped ?: return@forEach] = priority - } - } - } - - constructor(void: Nothing?) - constructor() { - mapped = SimpleLogger.LogPriority.valueOf(name) - } - -} From e1c1e2871332e9b7dfec89d7b5dd0cef459a314a Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 8 Nov 2020 11:10:46 +0800 Subject: [PATCH 020/133] Update dependencies --- backend/mirai-console/build.gradle.kts | 1 + buildSrc/src/main/kotlin/Versions.kt | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/backend/mirai-console/build.gradle.kts b/backend/mirai-console/build.gradle.kts index 4795a996c..74ff2294a 100644 --- a/backend/mirai-console/build.gradle.kts +++ b/backend/mirai-console/build.gradle.kts @@ -63,6 +63,7 @@ dependencies { compileAndTestRuntime("org.jetbrains.kotlinx:atomicfu:${Versions.atomicFU}") compileAndTestRuntime(kotlinx("coroutines-core", Versions.coroutines)) compileAndTestRuntime(kotlinx("serialization-core", Versions.serialization)) + compileAndTestRuntime(kotlinx("serialization-json", Versions.serialization)) compileAndTestRuntime(kotlin("reflect")) smartImplementation("net.mamoe.yamlkt:yamlkt:${Versions.yamlkt}") diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 91701e16c..8768d6a80 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -10,7 +10,7 @@ @file:Suppress("MemberVisibilityCanBePrivate") object Versions { - const val core = "1.3.2" + const val core = "1.3.3" const val console = "1.0-RC-1" const val consoleGraphical = "0.0.7" const val consoleTerminal = console @@ -18,8 +18,8 @@ object Versions { const val kotlinCompiler = "1.4.20-RC" const val kotlinStdlib = "1.4.10" - const val coroutines = "1.3.9" - const val serialization = "1.0.0-RC" + const val coroutines = "1.4.0" + const val serialization = "1.0.1" const val ktor = "1.4.1" const val atomicFU = "0.14.4" @@ -28,5 +28,5 @@ object Versions { const val bintray = "1.8.5" const val blockingBridge = "1.4.0" - const val yamlkt = "0.5.3" + const val yamlkt = "0.7.0" } \ No newline at end of file From 34a892e4d7576f17e5acaa9023879f94cffc0308 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 8 Nov 2020 12:13:39 +0800 Subject: [PATCH 021/133] Update Permissions.md --- docs/Permissions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Permissions.md b/docs/Permissions.md index 9cb6b0fcd..46003e4d2 100644 --- a/docs/Permissions.md +++ b/docs/Permissions.md @@ -40,7 +40,7 @@ data class PermissionId( [`PermissionId`] 是 [`Permission`] 的唯一标识符。知道 [`PermissionId`] 就可以获取到对应的 [`Permission`]。 -字符串表示为 "$namespace:$name",如 "console:command.stop", "*:*" +字符串表示为 "$namespace:$name",如 "console:command.stop", "\*:\*" #### 命名空间 From 539b397be08160233e5c3e22cd8fb0bb97050b6f Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 8 Nov 2020 12:16:26 +0800 Subject: [PATCH 022/133] Update Permissions.md --- docs/Permissions.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/docs/Permissions.md b/docs/Permissions.md index 46003e4d2..170dfe3a9 100644 --- a/docs/Permissions.md +++ b/docs/Permissions.md @@ -68,7 +68,7 @@ data class PermissionId( #### 根权限 -[`RootPermission`] 是所有权限的父权限。其 ID 为 "*:*" +[`RootPermission`] 是所有权限的父权限。其 ID 为 "\*:\*" ## 被许可人 @@ -121,14 +121,14 @@ interface PermitteeId { | 精确临时会话 | t123456.789 | 群 123456 内的成员 789. 必须通过临时会话 | | 精确群成员 | m123456.789 | 群 123456 内的成员 789. 同时包含临时会话. | | 精确用户 | u123456 | 同时包含群成员, 好友, 临时会话 | -| 任意群 | g* | | -| 任意群的任意群员 | m* | | -| 精确群的任意群员 | m123456.* | 群 123456 内的任意成员. 同时包含临时会话. | -| 任意群的任意临时会话 | t* | 必须通过临时会话 | -| 精确群的任意临时会话 | t123456.* | 群 123456 内的任意成员. 必须通过临时会话 | -| 任意好友 | f* | | -| 任意用户 | u* | 任何人在任何环境 | -| 任意对象 | * | 即任何人, 任何群, 控制台 | +| 任意群 | g\* | g 意为 group | +| 任意群的任意群员 | m\* | m 意为 member | +| 精确群的任意群员 | m123456.\* | 群 123456 内的任意成员. 同时包含临时会话. | +| 任意群的任意临时会话 | t\* | t 意为 temp. 必须通过临时会话 | +| 精确群的任意临时会话 | t123456.\* | 群 123456 内的任意成员. 必须通过临时会话 | +| 任意好友 | f\* | f 意为 friend | +| 任意用户 | u\* | u 意为 user. 任何人在任何环境 | +| 任意对象 | \* | 即任何人, 任何群, 控制台 | ### 获取被许可人 @@ -164,8 +164,9 @@ fun Permission.testPermission(PermitteeId): Boolean ### 使用内置权限服务指令 -**根指令**: "/permission", "/perm", "/权限" +**指令**: "/permission", "/perm", "/权限" +使用指令而不带参数可以获取如下用法: ``` /permission cancel <被许可人 ID> <权限 ID> 取消授权一个权限 /permission cancelall <被许可人 ID> <权限 ID> 取消授权一个权限及其所有子权限 From 7182a500f9cdad17c075db53f9939aaff06790bd Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 8 Nov 2020 23:41:17 +0800 Subject: [PATCH 023/133] Update dependencies --- buildSrc/src/main/kotlin/Versions.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 8768d6a80..485edeac1 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -27,6 +27,6 @@ object Versions { const val bintray = "1.8.5" - const val blockingBridge = "1.4.0" - const val yamlkt = "0.7.0" + const val blockingBridge = "1.4.1" + const val yamlkt = "0.7.1" } \ No newline at end of file From 289a82189b46b76ec5d66943ce5f7b2c8f794329 Mon Sep 17 00:00:00 2001 From: Him188 Date: Mon, 9 Nov 2020 09:02:16 +0800 Subject: [PATCH 024/133] Fix tests --- buildSrc/src/main/kotlin/dependencyExtensions.kt | 2 +- tools/gradle-plugin/src/VersionConstants.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/buildSrc/src/main/kotlin/dependencyExtensions.kt b/buildSrc/src/main/kotlin/dependencyExtensions.kt index 761651eb4..d3563a573 100644 --- a/buildSrc/src/main/kotlin/dependencyExtensions.kt +++ b/buildSrc/src/main/kotlin/dependencyExtensions.kt @@ -21,7 +21,7 @@ fun DependencyHandlerScope.ktor(id: String, version: String = Versions.ktor) = " @Suppress("unused") fun DependencyHandler.compileAndTestRuntime(any: Any) { add("compileOnly", any) - add("testRuntimeOnly", any) + add("testImplementation", any) } fun DependencyHandler.smartApi( diff --git a/tools/gradle-plugin/src/VersionConstants.kt b/tools/gradle-plugin/src/VersionConstants.kt index 2ed00f770..feb3369c6 100644 --- a/tools/gradle-plugin/src/VersionConstants.kt +++ b/tools/gradle-plugin/src/VersionConstants.kt @@ -11,5 +11,5 @@ package net.mamoe.mirai.console.gradle internal object VersionConstants { const val CONSOLE_VERSION = "1.0-RC-1" // value is written here automatically during build - const val CORE_VERSION = "1.3.2" // value is written here automatically during build + const val CORE_VERSION = "1.3.3" // value is written here automatically during build } \ No newline at end of file From de9159948bd93556df1aef622961b0dd82b55532 Mon Sep 17 00:00:00 2001 From: Him188 Date: Mon, 9 Nov 2020 09:14:31 +0800 Subject: [PATCH 025/133] Create TagRelease.yml --- .github/workflows/TagRelease.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/TagRelease.yml diff --git a/.github/workflows/TagRelease.yml b/.github/workflows/TagRelease.yml new file mode 100644 index 000000000..0e8c32947 --- /dev/null +++ b/.github/workflows/TagRelease.yml @@ -0,0 +1,30 @@ +# This is a basic workflow to help you get started with Actions + +name: TagRelease + +# Controls when the action will run. Triggers the workflow on push or pull request +# events but only for the master branch +on: + push: + # Sequence of patterns matched against refs/tags + tags: + - '*-dev*' # Push events to matching v*, i.e. v1.0, v20.15.10 + +jobs: + build: + name: Create Release + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token + with: + tag_name: ${{ github.ref }} + release_name: ${{ github.ref }} + body: "" + draft: false + prerelease: true From 9066c9a1174de97701081047597203d7d8ed43f7 Mon Sep 17 00:00:00 2001 From: Him188 Date: Mon, 9 Nov 2020 09:16:14 +0800 Subject: [PATCH 026/133] 1.0-RC2-dev-1 --- buildSrc/src/main/kotlin/Versions.kt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 485edeac1..e49db4a6c 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -1,17 +1,17 @@ /* -* Copyright 2019-2020 Mamoe Technologies and contributors. -* -* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. -* Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found through the following link. -* -* https://github.com/mamoe/mirai/blob/master/LICENSE -*/ + * Copyright 2019-2020 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + */ @file:Suppress("MemberVisibilityCanBePrivate") object Versions { const val core = "1.3.3" - const val console = "1.0-RC-1" + const val console = "1.0-RC2-dev-1" const val consoleGraphical = "0.0.7" const val consoleTerminal = console From 1a5355db89630a88a79d7367a4b2dc376fab9889 Mon Sep 17 00:00:00 2001 From: Him188 Date: Mon, 9 Nov 2020 09:53:47 +0800 Subject: [PATCH 027/133] CommandConfig, support custom commandPrefix, close #131 --- .../MiraiConsoleImplementationBridge.kt | 2 ++ .../internal/command/CommandManagerImpl.kt | 2 +- .../src/internal/command/CommnadConfig.kt | 30 +++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 backend/mirai-console/src/internal/command/CommnadConfig.kt diff --git a/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt b/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt index 7ce79204e..11e148b50 100644 --- a/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt +++ b/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt @@ -28,6 +28,7 @@ import net.mamoe.mirai.console.data.PluginDataStorage import net.mamoe.mirai.console.extensions.PermissionServiceProvider import net.mamoe.mirai.console.extensions.PostStartupExtension import net.mamoe.mirai.console.extensions.SingletonExtensionSelector +import net.mamoe.mirai.console.internal.command.CommandConfig import net.mamoe.mirai.console.internal.command.CommandManagerImpl import net.mamoe.mirai.console.internal.data.builtins.AutoLoginConfig import net.mamoe.mirai.console.internal.data.builtins.ConsoleDataScope @@ -139,6 +140,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI phase `load configurations`@{ mainLogger.verbose { "Loading configurations..." } + ConsoleDataScope.addAndReloadConfig(CommandConfig) ConsoleDataScope.reloadAll() } diff --git a/backend/mirai-console/src/internal/command/CommandManagerImpl.kt b/backend/mirai-console/src/internal/command/CommandManagerImpl.kt index 82e472477..9b6f3ecd5 100644 --- a/backend/mirai-console/src/internal/command/CommandManagerImpl.kt +++ b/backend/mirai-console/src/internal/command/CommandManagerImpl.kt @@ -103,7 +103,7 @@ internal object CommandManagerImpl : CommandManager, CoroutineScope by MiraiCons override fun getRegisteredCommands(owner: CommandOwner): List = _registeredCommands.filter { it.owner == owner } override val allRegisteredCommands: List get() = _registeredCommands.toList() // copy - override val commandPrefix: String get() = "/" + override val commandPrefix: String get() = CommandConfig.commandPrefix override fun unregisterAllCommands(owner: CommandOwner) { for (registeredCommand in getRegisteredCommands(owner)) { unregisterCommand(registeredCommand) diff --git a/backend/mirai-console/src/internal/command/CommnadConfig.kt b/backend/mirai-console/src/internal/command/CommnadConfig.kt new file mode 100644 index 000000000..6e0a571d6 --- /dev/null +++ b/backend/mirai-console/src/internal/command/CommnadConfig.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2019-2020 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + */ + +package net.mamoe.mirai.console.internal.command + +import net.mamoe.mirai.console.data.AutoSavePluginConfig +import net.mamoe.mirai.console.data.ValueDescription +import net.mamoe.mirai.console.data.ValueName +import net.mamoe.mirai.console.data.value + +@ValueDescription(""" + 内置指令系统配置 +""") +internal object CommandConfig : AutoSavePluginConfig("Command") { + override fun shouldPerformAutoSaveWheneverChanged(): Boolean { + return false + } + + @ValueDescription(""" + 指令前缀, 默认 "/" + """) + @ValueName("commandPrefix") + val commandPrefix: String by value("/") +} \ No newline at end of file From 8b6e2a1d9cd4737a58e2e53a962c113c217c1dc9 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Mon, 9 Nov 2020 13:16:44 +0800 Subject: [PATCH 028/133] Update AbstractCommandValueParameter.render style --- backend/mirai-console/src/internal/command/CommandReflector.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/mirai-console/src/internal/command/CommandReflector.kt b/backend/mirai-console/src/internal/command/CommandReflector.kt index 1bf73d773..867c50ec3 100644 --- a/backend/mirai-console/src/internal/command/CommandReflector.kt +++ b/backend/mirai-console/src/internal/command/CommandReflector.kt @@ -174,7 +174,8 @@ internal class CommandReflector( is AbstractCommandValueParameter.Extended, is AbstractCommandValueParameter.UserDefinedType<*>, -> { - "<${this.name ?: this.type.classifierAsKClass().simpleName}>" + val nameToRender = this.name ?: this.type.classifierAsKClass().simpleName + if (isOptional) "[$nameToRender]" else "<$nameToRender>" } is AbstractCommandValueParameter.StringConstant -> { this.expectingValue From d54f4cd0d909d9f669a06b271dc4226e12684924 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Mon, 9 Nov 2020 13:33:05 +0800 Subject: [PATCH 029/133] console.debug logger --- .../mirai-console/src/data/AutoSavePluginData.kt | 2 +- .../internal/MiraiConsoleImplementationBridge.kt | 1 + .../src/internal/command/CommandManagerImpl.kt | 6 +++++- .../src/internal/data/builtins/LoggerConfig.kt | 5 ++++- .../src/internal/logging/LoggerControllerImpl.kt | 13 ++++++++----- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/backend/mirai-console/src/data/AutoSavePluginData.kt b/backend/mirai-console/src/data/AutoSavePluginData.kt index ff281c02f..36a1071c9 100644 --- a/backend/mirai-console/src/data/AutoSavePluginData.kt +++ b/backend/mirai-console/src/data/AutoSavePluginData.kt @@ -146,7 +146,7 @@ public open class AutoSavePluginData private constructor( } internal val debuggingLogger1 by lazy { - DefaultLogger("debug").withSwitch(false) + DefaultLogger("console.debug").withSwitch(false) } @Suppress("RESULT_CLASS_IN_RETURN_TYPE") diff --git a/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt b/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt index 11e148b50..b86024a88 100644 --- a/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt +++ b/backend/mirai-console/src/internal/MiraiConsoleImplementationBridge.kt @@ -109,6 +109,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI if (loggerController === LoggerControllerImpl) { // Reload LoggerConfig. ConsoleDataScope.addAndReloadConfig(LoggerConfig) + LoggerControllerImpl.initialized = true } } diff --git a/backend/mirai-console/src/internal/command/CommandManagerImpl.kt b/backend/mirai-console/src/internal/command/CommandManagerImpl.kt index 9b6f3ecd5..8640664f1 100644 --- a/backend/mirai-console/src/internal/command/CommandManagerImpl.kt +++ b/backend/mirai-console/src/internal/command/CommandManagerImpl.kt @@ -20,6 +20,7 @@ import net.mamoe.mirai.console.command.CommandSender.Companion.toCommandSender import net.mamoe.mirai.console.command.descriptor.ExperimentalCommandDescriptors import net.mamoe.mirai.console.command.parse.CommandCallParser.Companion.parseCommandCall import net.mamoe.mirai.console.command.resolve.CommandCallResolver.Companion.resolve +import net.mamoe.mirai.console.internal.MiraiConsoleImplementationBridge import net.mamoe.mirai.console.permission.PermissionService.Companion.testPermission import net.mamoe.mirai.console.util.CoroutineScopeUtils.childScope import net.mamoe.mirai.event.Listener @@ -30,6 +31,7 @@ import net.mamoe.mirai.message.data.Message import net.mamoe.mirai.message.data.asMessageChain import net.mamoe.mirai.message.data.content import net.mamoe.mirai.utils.MiraiLogger +import net.mamoe.mirai.utils.SimpleLogger import java.util.concurrent.locks.ReentrantLock @OptIn(ExperimentalCommandDescriptors::class) @@ -75,7 +77,9 @@ internal object CommandManagerImpl : CommandManager, CoroutineScope by MiraiCons when (val result = executeCommand(sender, message)) { is CommandExecuteResult.PermissionDenied -> { if (!result.command.prefixOptional || message.content.startsWith(CommandManager.commandPrefix)) { - sender.sendMessage("权限不足") + if (MiraiConsoleImplementationBridge.loggerController.shouldLog("console.debug", SimpleLogger.LogPriority.DEBUG)) { + sender.sendMessage("权限不足") + } intercept() } } diff --git a/backend/mirai-console/src/internal/data/builtins/LoggerConfig.kt b/backend/mirai-console/src/internal/data/builtins/LoggerConfig.kt index f860e104a..49375d866 100644 --- a/backend/mirai-console/src/internal/data/builtins/LoggerConfig.kt +++ b/backend/mirai-console/src/internal/data/builtins/LoggerConfig.kt @@ -24,7 +24,10 @@ internal object LoggerConfig : AutoSavePluginConfig("Logger") { 特定日志记录器输出等级 """) val loggers: Map by value( - mapOf("example.logger" to AbstractLoggerController.LogPriority.NONE) + mapOf( + "example.logger" to AbstractLoggerController.LogPriority.NONE, + "console.debug" to AbstractLoggerController.LogPriority.NONE, + ) ) } diff --git a/backend/mirai-console/src/internal/logging/LoggerControllerImpl.kt b/backend/mirai-console/src/internal/logging/LoggerControllerImpl.kt index c65a23237..836583e7e 100644 --- a/backend/mirai-console/src/internal/logging/LoggerControllerImpl.kt +++ b/backend/mirai-console/src/internal/logging/LoggerControllerImpl.kt @@ -17,11 +17,14 @@ import net.mamoe.mirai.console.util.ConsoleInternalApi @ConsoleFrontEndImplementation @ConsoleInternalApi internal object LoggerControllerImpl : AbstractLoggerController() { + internal var initialized = false - override fun getPriority(identity: String?): LogPriority = if (identity == null) { - LoggerConfig.defaultPriority - } else { - LoggerConfig.loggers[identity] ?: LoggerConfig.defaultPriority + override fun getPriority(identity: String?): LogPriority { + if (!initialized) return LogPriority.NONE + return if (identity == null) { + LoggerConfig.defaultPriority + } else { + LoggerConfig.loggers[identity] ?: LoggerConfig.defaultPriority + } } - } \ No newline at end of file From 64e535d28224bc3eaa50a5a55dff66b2318515c2 Mon Sep 17 00:00:00 2001 From: Him188 Date: Mon, 9 Nov 2020 14:37:10 +0800 Subject: [PATCH 030/133] Move JvmPluginDescription.invoke to top-level --- .../src/plugin/jvm/JvmPluginDescription.kt | 89 ++++++++++++------- 1 file changed, 58 insertions(+), 31 deletions(-) diff --git a/backend/mirai-console/src/plugin/jvm/JvmPluginDescription.kt b/backend/mirai-console/src/plugin/jvm/JvmPluginDescription.kt index d4bb97196..04f84543d 100644 --- a/backend/mirai-console/src/plugin/jvm/JvmPluginDescription.kt +++ b/backend/mirai-console/src/plugin/jvm/JvmPluginDescription.kt @@ -29,52 +29,79 @@ import net.mamoe.mirai.console.util.SemVersion */ public interface JvmPluginDescription : PluginDescription { public companion object { - /** - * 构建 [JvmPluginDescription] - * @see JvmPluginDescriptionBuilder - */ + @Suppress("UNUSED_PARAMETER") + @Deprecated( + "Use top-level function instead", + ReplaceWith("JvmPluginDescription(id, version, block)", "net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription"), + DeprecationLevel.ERROR + ) @JvmName("create") - @JvmSynthetic - public inline operator fun invoke( - /** - * @see [PluginDescription.id] - */ + public inline fun invoke( @ResolveContext(PLUGIN_ID) id: String, - /** - * @see [PluginDescription.version] - */ @ResolveContext(SEMANTIC_VERSION) version: String, - /** - * @see [PluginDescription.name] - */ @ResolveContext(PLUGIN_NAME) name: String = id, block: JvmPluginDescriptionBuilder.() -> Unit = {}, - ): JvmPluginDescription = JvmPluginDescriptionBuilder(id, version).apply { name(name) }.apply(block).build() + ): JvmPluginDescription = error("Shouldn't be called") - /** - * 构建 [JvmPluginDescription] - * @see JvmPluginDescriptionBuilder - */ + @Suppress("UNUSED_PARAMETER") + @Deprecated( + "Use top-level function instead", + ReplaceWith("JvmPluginDescription(id, version, block)", "net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription"), + DeprecationLevel.ERROR + ) @JvmName("create") @JvmSynthetic - public inline operator fun invoke( - /** - * @see [PluginDescription.id] - */ + public inline fun invoke( @ResolveContext(PLUGIN_ID) id: String, - /** - * @see [PluginDescription.version] - */ version: SemVersion, - /** - * @see [PluginDescription.name] - */ @ResolveContext(PLUGIN_NAME) name: String = id, block: JvmPluginDescriptionBuilder.() -> Unit = {}, - ): JvmPluginDescription = JvmPluginDescriptionBuilder(id, version).apply { name(name) }.apply(block).build() + ): JvmPluginDescription = error("Shouldn't be called") } } +/** + * 构建 [JvmPluginDescription] + * @see JvmPluginDescriptionBuilder + */ +@JvmSynthetic +public inline fun JvmPluginDescription( + /** + * @see [PluginDescription.id] + */ + @ResolveContext(PLUGIN_ID) id: String, + /** + * @see [PluginDescription.version] + */ + @ResolveContext(SEMANTIC_VERSION) version: String, + /** + * @see [PluginDescription.name] + */ + @ResolveContext(PLUGIN_NAME) name: String = id, + block: JvmPluginDescriptionBuilder.() -> Unit = {}, +): JvmPluginDescription = JvmPluginDescriptionBuilder(id, version).apply { name(name) }.apply(block).build() + +/** + * 构建 [JvmPluginDescription] + * @see JvmPluginDescriptionBuilder + */ +@JvmSynthetic +public inline fun JvmPluginDescription( + /** + * @see [PluginDescription.id] + */ + @ResolveContext(PLUGIN_ID) id: String, + /** + * @see [PluginDescription.version] + */ + version: SemVersion, + /** + * @see [PluginDescription.name] + */ + @ResolveContext(PLUGIN_NAME) name: String = id, + block: JvmPluginDescriptionBuilder.() -> Unit = {}, +): JvmPluginDescription = JvmPluginDescriptionBuilder(id, version).apply { name(name) }.apply(block).build() + /** * [JvmPluginDescription] 构建器. * From 0fb7d498986047343a62bdba981915a610896a0d Mon Sep 17 00:00:00 2001 From: Him188 Date: Mon, 9 Nov 2020 15:31:41 +0800 Subject: [PATCH 031/133] Make PluginDependency serializable --- .../plugin/description/PluginDependency.kt | 56 ++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/backend/mirai-console/src/plugin/description/PluginDependency.kt b/backend/mirai-console/src/plugin/description/PluginDependency.kt index ea45ea173..b5f4669cd 100644 --- a/backend/mirai-console/src/plugin/description/PluginDependency.kt +++ b/backend/mirai-console/src/plugin/description/PluginDependency.kt @@ -11,8 +11,12 @@ package net.mamoe.mirai.console.plugin.description +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.builtins.serializer import net.mamoe.mirai.console.compiler.common.ResolveContext import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.PLUGIN_ID +import net.mamoe.mirai.console.internal.data.map import net.mamoe.mirai.console.util.SemVersion /** @@ -20,7 +24,8 @@ import net.mamoe.mirai.console.util.SemVersion * * @see PluginDescription.dependencies */ -public data class PluginDependency @JvmOverloads constructor( +@Serializable(with = PluginDependency.PluginDependencyAsStringSerializer::class) +public class PluginDependency @JvmOverloads constructor( /** * 依赖插件 ID, [PluginDescription.id] */ @@ -55,4 +60,53 @@ public data class PluginDependency @JvmOverloads constructor( ) : this( id, null, isOptional ) + + public override fun toString(): String = buildString { + append(id) + versionRequirement?.rule?.let(::append) + if (isOptional) { + append('?') + } + } + + public override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false + + other as PluginDependency + + if (id != other.id) return false + if (versionRequirement?.rule != other.versionRequirement?.rule) return false + if (isOptional != other.isOptional) return false + + return true + } + + public override fun hashCode(): Int { + var result = id.hashCode() + result = 31 * result + (versionRequirement?.rule?.hashCode() ?: 0) + result = 31 * result + isOptional.hashCode() + return result + } + + public companion object { + /** + * 解析 "$id:$versionRequirement?" + */ + @JvmStatic + @Throws(IllegalArgumentException::class) + public fun parseFromString(string: String): PluginDependency { + require(string.isNotEmpty()) { "string is empty." } + val optional = string.endsWith('?') + val (id, version) = string.removeSuffix("?").let { + it.substringBeforeLast(':') to it.substringAfterLast(':', "") + } + return PluginDependency(id, SemVersion.parseRangeRequirement(version), optional) + } + } + + public object PluginDependencyAsStringSerializer : KSerializer by String.serializer().map( + serializer = { it.toString() }, + deserializer = { parseFromString(it) } + ) } \ No newline at end of file From fd438c2e4cbc33748996cbd31ab5d9162f7c6ce2 Mon Sep 17 00:00:00 2001 From: Him188 Date: Mon, 9 Nov 2020 15:36:44 +0800 Subject: [PATCH 032/133] Support loading plugin description from resources --- .../src/plugin/jvm/JvmPluginDescription.kt | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/backend/mirai-console/src/plugin/jvm/JvmPluginDescription.kt b/backend/mirai-console/src/plugin/jvm/JvmPluginDescription.kt index 04f84543d..7aa466b3b 100644 --- a/backend/mirai-console/src/plugin/jvm/JvmPluginDescription.kt +++ b/backend/mirai-console/src/plugin/jvm/JvmPluginDescription.kt @@ -11,11 +11,15 @@ package net.mamoe.mirai.console.plugin.jvm +import kotlinx.serialization.Serializable import net.mamoe.mirai.console.compiler.common.ResolveContext import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.* import net.mamoe.mirai.console.plugin.description.PluginDependency import net.mamoe.mirai.console.plugin.description.PluginDescription import net.mamoe.mirai.console.util.SemVersion +import net.mamoe.yamlkt.Yaml +import sun.reflect.CallerSensitive +import sun.reflect.Reflection /** * JVM 插件的描述. 通常作为 `plugin.yml` @@ -57,6 +61,18 @@ public interface JvmPluginDescription : PluginDescription { @ResolveContext(PLUGIN_NAME) name: String = id, block: JvmPluginDescriptionBuilder.() -> Unit = {}, ): JvmPluginDescription = error("Shouldn't be called") + + @JvmStatic + @CallerSensitive + public fun loadFromResource(filename: String = "config.yaml"): JvmPluginDescription { + val callerClass = Reflection.getCallerClass() + val stream = callerClass.getResourceAsStream(filename) ?: callerClass.classLoader.getResourceAsStream(filename) + ?: error("Cannot find plugin description resource") + + val bytes = stream.use { it.readBytes() } + + return Yaml.default.decodeFromString(SimpleJvmPluginDescription.serializer(), String(bytes)) + } } } @@ -121,7 +137,7 @@ public inline fun JvmPluginDescription( * .build(); * ``` * - * @see [JvmPluginDescription.invoke] + * @see [JvmPluginDescription] */ public class JvmPluginDescriptionBuilder( @ResolveContext(PLUGIN_ID) private var id: String, @@ -219,7 +235,7 @@ public class JvmPluginDescriptionBuilder( public fun build(): JvmPluginDescription = @Suppress("DEPRECATION_ERROR") - SimpleJvmPluginDescription(name, version, id, author, info, dependencies) + SimpleJvmPluginDescription(id, name, version, author, info, dependencies) /** * 标注一个 [JvmPluginDescription] DSL @@ -235,11 +251,12 @@ public class JvmPluginDescriptionBuilder( * * @see JvmPluginDescription */ +@Serializable internal data class SimpleJvmPluginDescription @JvmOverloads constructor( - override val name: String, + override val id: String, + override val name: String = id, override val version: SemVersion, - override val id: String = name, override val author: String = "", override val info: String = "", override val dependencies: Set = setOf(), @@ -248,13 +265,13 @@ internal data class SimpleJvmPluginDescription @Suppress("DEPRECATION_ERROR") @JvmOverloads constructor( - name: String, + id: String, + name: String = id, version: String, - id: String = name, author: String = "", info: String = "", dependencies: Set = setOf(), - ) : this(name, SemVersion(version), id, author, info, dependencies) + ) : this(id, name, SemVersion(version), author, info, dependencies) init { PluginDescription.checkPluginDescription(this) From 85600d35b015cc1361fec311cc1c9fed15625af8 Mon Sep 17 00:00:00 2001 From: Him188 Date: Mon, 9 Nov 2020 15:46:05 +0800 Subject: [PATCH 033/133] Fix build --- .../src/internal/plugin/PluginManagerImpl.kt | 6 ++-- .../plugin/description/PluginDependency.kt | 28 +++---------------- .../src/plugin/jvm/JvmPluginDescription.kt | 18 ++---------- tools/gradle-plugin/src/VersionConstants.kt | 2 +- 4 files changed, 10 insertions(+), 44 deletions(-) diff --git a/backend/mirai-console/src/internal/plugin/PluginManagerImpl.kt b/backend/mirai-console/src/internal/plugin/PluginManagerImpl.kt index e93fdb365..70bbdd4c5 100644 --- a/backend/mirai-console/src/internal/plugin/PluginManagerImpl.kt +++ b/backend/mirai-console/src/internal/plugin/PluginManagerImpl.kt @@ -28,7 +28,7 @@ import net.mamoe.mirai.console.plugin.loader.PluginLoadException import net.mamoe.mirai.console.plugin.loader.PluginLoader import net.mamoe.mirai.console.plugin.name import net.mamoe.mirai.console.util.CoroutineScopeUtils.childScope -import net.mamoe.mirai.console.util.SemVersion.Companion.contains +import net.mamoe.mirai.console.util.SemVersion import net.mamoe.mirai.utils.info import java.io.File import java.nio.file.Path @@ -248,8 +248,8 @@ internal fun List.findDependency(dependency: PluginDependency } internal fun PluginDescription.checkSatisfies(dependency: PluginDependency, plugin: PluginDescription) { - val requirement = dependency.versionRequirement - if (requirement != null && this.version !in requirement) { + val requirement = dependency.versionRequirement ?: return + if (SemVersion.parseRangeRequirement(requirement).test(this.version)) { throw PluginLoadException("Plugin '${plugin.id}' ('${plugin.id}') requires '${dependency.id}' with version $requirement while the resolved is ${this.version}") } } diff --git a/backend/mirai-console/src/plugin/description/PluginDependency.kt b/backend/mirai-console/src/plugin/description/PluginDependency.kt index b5f4669cd..ff53a02aa 100644 --- a/backend/mirai-console/src/plugin/description/PluginDependency.kt +++ b/backend/mirai-console/src/plugin/description/PluginDependency.kt @@ -25,7 +25,7 @@ import net.mamoe.mirai.console.util.SemVersion * @see PluginDescription.dependencies */ @Serializable(with = PluginDependency.PluginDependencyAsStringSerializer::class) -public class PluginDependency @JvmOverloads constructor( +public data class PluginDependency @JvmOverloads constructor( /** * 依赖插件 ID, [PluginDescription.id] */ @@ -37,7 +37,7 @@ public class PluginDependency @JvmOverloads constructor( * * @see SemVersion.Requirement */ - public val versionRequirement: SemVersion.Requirement? = null, + public val versionRequirement: String? = null, /** * 若为 `false`, 插件在找不到此依赖时也能正常加载. */ @@ -63,32 +63,12 @@ public class PluginDependency @JvmOverloads constructor( public override fun toString(): String = buildString { append(id) - versionRequirement?.rule?.let(::append) + versionRequirement?.let(::append) if (isOptional) { append('?') } } - public override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false - - other as PluginDependency - - if (id != other.id) return false - if (versionRequirement?.rule != other.versionRequirement?.rule) return false - if (isOptional != other.isOptional) return false - - return true - } - - public override fun hashCode(): Int { - var result = id.hashCode() - result = 31 * result + (versionRequirement?.rule?.hashCode() ?: 0) - result = 31 * result + isOptional.hashCode() - return result - } - public companion object { /** * 解析 "$id:$versionRequirement?" @@ -101,7 +81,7 @@ public class PluginDependency @JvmOverloads constructor( val (id, version) = string.removeSuffix("?").let { it.substringBeforeLast(':') to it.substringAfterLast(':', "") } - return PluginDependency(id, SemVersion.parseRangeRequirement(version), optional) + return PluginDependency(id, version, optional) } } diff --git a/backend/mirai-console/src/plugin/jvm/JvmPluginDescription.kt b/backend/mirai-console/src/plugin/jvm/JvmPluginDescription.kt index 7aa466b3b..ee17ceef4 100644 --- a/backend/mirai-console/src/plugin/jvm/JvmPluginDescription.kt +++ b/backend/mirai-console/src/plugin/jvm/JvmPluginDescription.kt @@ -191,20 +191,6 @@ public class JvmPluginDescriptionBuilder( } } - /** - * isOptional = false - * - * @see PluginDependency - */ - @ILoveKuriyamaMiraiForever - public fun dependsOn( - @ResolveContext(PLUGIN_ID) pluginId: String, - versionRequirement: SemVersion.Requirement, - isOptional: Boolean = false, - ): JvmPluginDescriptionBuilder = apply { - this.dependencies.add(PluginDependency(pluginId, versionRequirement, isOptional)) - } - /** * @see PluginDependency */ @@ -214,7 +200,7 @@ public class JvmPluginDescriptionBuilder( @ResolveContext(VERSION_REQUIREMENT) versionRequirement: String, isOptional: Boolean = false, ): JvmPluginDescriptionBuilder = apply { - this.dependencies.add(PluginDependency(pluginId, SemVersion.parseRangeRequirement(versionRequirement), isOptional)) + this.dependencies.add(PluginDependency(pluginId, versionRequirement, isOptional)) } /** @@ -255,7 +241,7 @@ public class JvmPluginDescriptionBuilder( internal data class SimpleJvmPluginDescription @JvmOverloads constructor( override val id: String, - override val name: String = id, + override val name: String, override val version: SemVersion, override val author: String = "", override val info: String = "", diff --git a/tools/gradle-plugin/src/VersionConstants.kt b/tools/gradle-plugin/src/VersionConstants.kt index feb3369c6..1f9ccb633 100644 --- a/tools/gradle-plugin/src/VersionConstants.kt +++ b/tools/gradle-plugin/src/VersionConstants.kt @@ -10,6 +10,6 @@ package net.mamoe.mirai.console.gradle internal object VersionConstants { - const val CONSOLE_VERSION = "1.0-RC-1" // value is written here automatically during build + const val CONSOLE_VERSION = "1.0-RC2-dev-1" // value is written here automatically during build const val CORE_VERSION = "1.3.3" // value is written here automatically during build } \ No newline at end of file From ce678a75b73449d0c85a9a1fb92d5555fa6c947f Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Mon, 9 Nov 2020 23:19:42 +0800 Subject: [PATCH 034/133] Make SemVersion.Requirement data class --- .../internal/util/semver/RangeTokenReader.kt | 6 ++-- .../util/semver/RequirementInternal.kt | 16 ++++++++++ .../util/semver/SemVersionInternal.kt | 30 ++++++++----------- backend/mirai-console/src/util/SemVersion.kt | 30 +++++++++++++++++-- .../mirai-console/test/util/TestSemVersion.kt | 5 ++-- 5 files changed, 61 insertions(+), 26 deletions(-) create mode 100644 backend/mirai-console/src/internal/util/semver/RequirementInternal.kt diff --git a/backend/mirai-console/src/internal/util/semver/RangeTokenReader.kt b/backend/mirai-console/src/internal/util/semver/RangeTokenReader.kt index 5f761cb6e..17064132b 100644 --- a/backend/mirai-console/src/internal/util/semver/RangeTokenReader.kt +++ b/backend/mirai-console/src/internal/util/semver/RangeTokenReader.kt @@ -189,7 +189,7 @@ internal object RangeTokenReader { } } - fun parse(source: String, token: Token): SemVersion.Requirement { + fun parse(source: String, token: Token): RequirementInternal { return when (token) { is Token.Group -> { if (token.values.size == 1) { @@ -206,7 +206,7 @@ internal object RangeTokenReader { }.map { parse(source, it) }.toList() when (logic.first()) { TokenType.OR -> { - return object : SemVersion.Requirement { + return object : RequirementInternal { override fun test(version: SemVersion): Boolean { rules.forEach { if (it.test(version)) return true } return false @@ -214,7 +214,7 @@ internal object RangeTokenReader { } } TokenType.AND -> { - return object : SemVersion.Requirement { + return object : RequirementInternal { override fun test(version: SemVersion): Boolean { rules.forEach { if (!it.test(version)) return false } return true diff --git a/backend/mirai-console/src/internal/util/semver/RequirementInternal.kt b/backend/mirai-console/src/internal/util/semver/RequirementInternal.kt new file mode 100644 index 000000000..903f19eea --- /dev/null +++ b/backend/mirai-console/src/internal/util/semver/RequirementInternal.kt @@ -0,0 +1,16 @@ +/* + * Copyright 2019-2020 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + */ + +package net.mamoe.mirai.console.internal.util.semver + +import net.mamoe.mirai.console.util.SemVersion + +internal interface RequirementInternal { + fun test(version: SemVersion): Boolean +} diff --git a/backend/mirai-console/src/internal/util/semver/SemVersionInternal.kt b/backend/mirai-console/src/internal/util/semver/SemVersionInternal.kt index 1c5e013af..1d9c1af03 100644 --- a/backend/mirai-console/src/internal/util/semver/SemVersionInternal.kt +++ b/backend/mirai-console/src/internal/util/semver/SemVersionInternal.kt @@ -75,11 +75,11 @@ internal object SemVersionInternal { } @JvmStatic - internal fun parseRule(rule: String): SemVersion.Requirement { + internal fun parseRule(rule: String): RequirementInternal { val trimmed = rule.trim() if (directVersion.matches(trimmed)) { val parsed = SemVersion.invoke(trimmed) - return object : SemVersion.Requirement { + return object : RequirementInternal { override fun test(version: SemVersion): Boolean = version.compareTo(parsed) == 0 } } @@ -89,7 +89,7 @@ internal object SemVersionInternal { .replace("x", ".+") + "$" ).toRegex() - return object : SemVersion.Requirement { + return object : RequirementInternal { override fun test(version: SemVersion): Boolean = regex.matches(version.toString()) } } @@ -120,7 +120,7 @@ internal object SemVersionInternal { '(', ')' -> ({ it < end }) else -> throw AssertionError() } - return object : SemVersion.Requirement { + return object : RequirementInternal { override fun test(version: SemVersion): Boolean = a(version) && b(version) } } @@ -129,32 +129,32 @@ internal object SemVersionInternal { val version1 = SemVersion.invoke(result.groupValues[8]) return when (operator) { ">=" -> { - object : SemVersion.Requirement { + object : RequirementInternal { override fun test(version: SemVersion): Boolean = version >= version1 } } ">" -> { - object : SemVersion.Requirement { + object : RequirementInternal { override fun test(version: SemVersion): Boolean = version > version1 } } "<=" -> { - object : SemVersion.Requirement { + object : RequirementInternal { override fun test(version: SemVersion): Boolean = version <= version1 } } "<" -> { - object : SemVersion.Requirement { + object : RequirementInternal { override fun test(version: SemVersion): Boolean = version < version1 } } "=" -> { - object : SemVersion.Requirement { + object : RequirementInternal { override fun test(version: SemVersion): Boolean = version.compareTo(version1) == 0 } } "!=" -> { - object : SemVersion.Requirement { + object : RequirementInternal { override fun test(version: SemVersion): Boolean = version.compareTo(version1) != 0 } } @@ -164,15 +164,9 @@ internal object SemVersionInternal { throw IllegalArgumentException("Cannot parse $rule") } - private fun SemVersion.Requirement.withRule(rule: String): SemVersion.Requirement { - return object : SemVersion.Requirement { - override fun test(version: SemVersion): Boolean = this@withRule.test(version) - override fun toString(): String = rule - } - } @JvmStatic - fun parseRangeRequirement(requirement: String): SemVersion.Requirement { + fun parseRangeRequirement(requirement: String): RequirementInternal { if (requirement.isBlank()) { throw IllegalArgumentException("Invalid requirement: Empty requirement rule.") } @@ -180,7 +174,7 @@ internal object SemVersionInternal { val collected = RangeTokenReader.collect(requirement, tokens.iterator(), true) RangeTokenReader.check(requirement, collected.iterator(), null) return kotlin.runCatching { - RangeTokenReader.parse(requirement, RangeTokenReader.Token.Group(collected, 0)).withRule(requirement) + RangeTokenReader.parse(requirement, RangeTokenReader.Token.Group(collected, 0)) }.onFailure { error -> throw IllegalArgumentException("Exception in parsing $requirement\n\n" + buildString { collected.forEach { dump("", it) } diff --git a/backend/mirai-console/src/util/SemVersion.kt b/backend/mirai-console/src/util/SemVersion.kt index 47c207fa8..f350c0f58 100644 --- a/backend/mirai-console/src/util/SemVersion.kt +++ b/backend/mirai-console/src/util/SemVersion.kt @@ -81,9 +81,33 @@ internal constructor( * 一条依赖规则 * @see [parseRangeRequirement] */ - public interface Requirement { + @Serializable(Requirement.RequirementAsStringSerializer::class) + public data class Requirement internal constructor( + /** + * 规则的字符串表示方式 + * + * @see [SemVersion.parseRangeRequirement] + */ + val rule: String + ) { + @Transient + private val impl = SemVersionInternal.parseRangeRequirement(rule) + /** 在 [version] 满足此要求时返回 true */ - public fun test(version: SemVersion): Boolean + public fun test(version: SemVersion): Boolean { + return impl.test(version) + } + + public object RequirementAsStringSerializer : KSerializer by String.serializer().map( + serializer = { it.rule }, + deserializer = { parseRangeRequirement(it) } + ) + + public companion object { + @JvmSynthetic + public operator fun invoke(@ResolveContext(VERSION_REQUIREMENT) requirement: String): Requirement = + parseRangeRequirement(requirement) + } } public object SemVersionAsStringSerializer : KSerializer by String.serializer().map( @@ -149,7 +173,7 @@ internal constructor( @JvmStatic @Throws(IllegalArgumentException::class) public fun parseRangeRequirement(@ResolveContext(VERSION_REQUIREMENT) requirement: String): Requirement = - SemVersionInternal.parseRangeRequirement(requirement) + Requirement(requirement) /** @see [Requirement.test] */ @JvmStatic diff --git a/backend/mirai-console/test/util/TestSemVersion.kt b/backend/mirai-console/test/util/TestSemVersion.kt index 60881b310..3021de67b 100644 --- a/backend/mirai-console/test/util/TestSemVersion.kt +++ b/backend/mirai-console/test/util/TestSemVersion.kt @@ -16,6 +16,7 @@ package net.mamoe.mirai.console.util import net.mamoe.mirai.console.util.SemVersion.Companion.test import org.junit.jupiter.api.Test +import kotlin.test.assertFails internal class TestSemVersion { @Test @@ -50,9 +51,9 @@ internal class TestSemVersion { } fun assertInvalid(requirement: String) { - kotlin.runCatching { + assertFails(requirement) { SemVersion.parseRangeRequirement(requirement) - }.onSuccess { assert(false) { requirement } } + } } fun SemVersion.Requirement.assertFalse(version: String): SemVersion.Requirement { From f51003ad580ce56c1c5792c60cde62ed8d77ad5f Mon Sep 17 00:00:00 2001 From: Him188 Date: Tue, 10 Nov 2020 08:55:54 +0800 Subject: [PATCH 035/133] Add test raw command --- .../src/command/CommandManager.kt | 6 +++--- .../mirai-console/test/command/TestCommand.kt | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/backend/mirai-console/src/command/CommandManager.kt b/backend/mirai-console/src/command/CommandManager.kt index ee2871993..f265483b6 100644 --- a/backend/mirai-console/src/command/CommandManager.kt +++ b/backend/mirai-console/src/command/CommandManager.kt @@ -240,9 +240,9 @@ public suspend inline fun CommandSender.executeCommand( @JvmSynthetic public suspend inline fun Command.execute( sender: CommandSender, - arguments: Message = EmptyMessageChain, + vararg arguments: Message = emptyArray(), checkPermission: Boolean = true, -): CommandExecuteResult = CommandManager.executeCommand(sender, this, arguments, checkPermission) +): CommandExecuteResult = CommandManager.executeCommand(sender, this, arguments.asMessageChain(), checkPermission) /** * 执行一个确切的指令 @@ -255,4 +255,4 @@ public suspend inline fun Command.execute( sender: CommandSender, arguments: String = "", checkPermission: Boolean = true, -): CommandExecuteResult = execute(sender, PlainText(arguments), checkPermission) +): CommandExecuteResult = execute(sender, PlainText(arguments), checkPermission = checkPermission) diff --git a/backend/mirai-console/test/command/TestCommand.kt b/backend/mirai-console/test/command/TestCommand.kt index 3a89ca769..82d7e524a 100644 --- a/backend/mirai-console/test/command/TestCommand.kt +++ b/backend/mirai-console/test/command/TestCommand.kt @@ -48,6 +48,15 @@ object TestCompositeCommand : CompositeCommand( } } +object TestRawCommand : RawCommand( + ConsoleCommandOwner, + "testRaw" +) { + override suspend fun CommandSender.onCommand(args: MessageChain) { + Testing.ok(args) + } +} + object TestSimpleCommand : RawCommand(owner, "testSimple", "tsS") { override suspend fun CommandSender.onCommand(args: MessageChain) { @@ -104,6 +113,17 @@ internal class TestCommand { } } + @Test + fun `test raw command`() = runBlocking { + TestRawCommand.withRegistration { + val result = withTesting { + assertSuccess(TestRawCommand.execute(sender, PlainText("a1"), PlainText("a2"), PlainText("a3"))) + } + assertEquals(3, result.size) + assertEquals("a1, a2, a3", result.joinToString()) + } + } + @Test fun `test flattenCommandArgs`() { val result = arrayOf("test", image).flattenCommandComponents().toTypedArray() From e3aceec0b4175ef0b47ed9579fe7a31f2d89ef92 Mon Sep 17 00:00:00 2001 From: Him188 Date: Tue, 10 Nov 2020 08:57:25 +0800 Subject: [PATCH 036/133] Use super.description for JCompositeCommand.description --- backend/mirai-console/src/command/java/JCompositeCommand.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/mirai-console/src/command/java/JCompositeCommand.kt b/backend/mirai-console/src/command/java/JCompositeCommand.kt index aecefc529..aba439d1c 100644 --- a/backend/mirai-console/src/command/java/JCompositeCommand.kt +++ b/backend/mirai-console/src/command/java/JCompositeCommand.kt @@ -77,7 +77,7 @@ public abstract class JCompositeCommand parentPermission: Permission = owner.parentPermission, ) : CompositeCommand(owner, primaryName, secondaryNames = secondaryNames, parentPermission = parentPermission) { /** 指令描述, 用于显示在 [BuiltInCommands.HelpCommand] */ - public final override var description: String = "" + public final override var description: String = super.description protected set public final override var permission: Permission = super.permission From ea4bdddf836b94a0402351087ceccc69ba97972b Mon Sep 17 00:00:00 2001 From: Him188 Date: Tue, 10 Nov 2020 08:58:14 +0800 Subject: [PATCH 037/133] 1.0-RC2-dev-3 --- buildSrc/src/main/kotlin/Versions.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index e49db4a6c..49eec70f7 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -11,7 +11,7 @@ object Versions { const val core = "1.3.3" - const val console = "1.0-RC2-dev-1" + const val console = "1.0-RC2-dev-3" const val consoleGraphical = "0.0.7" const val consoleTerminal = console From 724d8940f8651410e14184f2046f6fbfa6bd7563 Mon Sep 17 00:00:00 2001 From: Him188 Date: Tue, 10 Nov 2020 09:06:27 +0800 Subject: [PATCH 038/133] Update publisher --- .../{gradle-build.yml => Gradle CI.yml} | 0 .github/workflows/Publishing.yml | 4 ++ .github/workflows/TagRelease.yml | 2 +- .github/workflows/cui.yml | 48 ------------------- .github/workflows/shadow.yml | 48 ------------------- buildSrc/src/main/kotlin/PublishingHelpers.kt | 4 ++ 6 files changed, 9 insertions(+), 97 deletions(-) rename .github/workflows/{gradle-build.yml => Gradle CI.yml} (100%) delete mode 100644 .github/workflows/cui.yml delete mode 100644 .github/workflows/shadow.yml diff --git a/.github/workflows/gradle-build.yml b/.github/workflows/Gradle CI.yml similarity index 100% rename from .github/workflows/gradle-build.yml rename to .github/workflows/Gradle CI.yml diff --git a/.github/workflows/Publishing.yml b/.github/workflows/Publishing.yml index 12a8e5450..dc365bd7f 100644 --- a/.github/workflows/Publishing.yml +++ b/.github/workflows/Publishing.yml @@ -5,6 +5,10 @@ name: Bintray Publish # Controls when the action will run. Triggers the workflow on push or pull request # events but only for the master branch on: + push: + # Sequence of patterns matched against refs/tags + tags: + - '*-dev*' release: types: - created diff --git a/.github/workflows/TagRelease.yml b/.github/workflows/TagRelease.yml index 0e8c32947..feb32bf72 100644 --- a/.github/workflows/TagRelease.yml +++ b/.github/workflows/TagRelease.yml @@ -8,7 +8,7 @@ on: push: # Sequence of patterns matched against refs/tags tags: - - '*-dev*' # Push events to matching v*, i.e. v1.0, v20.15.10 + - '*-dev*' jobs: build: diff --git a/.github/workflows/cui.yml b/.github/workflows/cui.yml deleted file mode 100644 index eee6c4ecb..000000000 --- a/.github/workflows/cui.yml +++ /dev/null @@ -1,48 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: CuiCloud Publish - -# Controls when the action will run. Triggers the workflow on push or pull request -# events but only for the master branch -on: - release: - types: - - created - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - name: Gradle clean - run: ./gradlew clean - - name: Gradle build - run: ./gradlew build # if test's failed, don't publish - - name: Gradle :mirai-console:cuiCloudUpload - run: ./gradlew :mirai-console:cuiCloudUpload -Dcui_cloud_key=${{ secrets.CUI_CLOUD_KEY }} -Pcui_cloud_key=${{ secrets.CUI_CLOUD_KEY }} -Dcui_cloud_url=${{ secrets.CUI_CLOUD_URL }} -Pcui_cloud_url=${{ secrets.CUI_CLOUD_URL }} - - name: Gradle :mirai-console-graphical:cuiCloudUpload - run: ./gradlew :mirai-console-graphical:cuiCloudUpload -Dcui_cloud_key=${{ secrets.CUI_CLOUD_KEY }} -Pcui_cloud_key=${{ secrets.CUI_CLOUD_KEY }} -Dcui_cloud_url=${{ secrets.CUI_CLOUD_URL }} -Pcui_cloud_url=${{ secrets.CUI_CLOUD_URL }} - - -# - name: Upload artifact -# uses: actions/upload-artifact@v1.0.0 -# with: -# # Artifact name -# name: mirai-core -# # Directory containing files to upload -# path: "mirai-core/build/libs/mirai-core-*-all.jar" -# - name: Upload artifact -# uses: actions/upload-artifact@v1.0.0 -# with: -# # Artifact name -# name: mirai-core-qqandroid-all -# # Directory containing files to upload -# path: "mirai-core-qqandroid/build/libs/mirai-core-qqandroid-*-all.jar" diff --git a/.github/workflows/shadow.yml b/.github/workflows/shadow.yml deleted file mode 100644 index 4b52408e7..000000000 --- a/.github/workflows/shadow.yml +++ /dev/null @@ -1,48 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: mirai-repo Publish - -# Controls when the action will run. Triggers the workflow on push or pull request -# events but only for the master branch -on: - release: - types: - - created - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - name: Gradle clean - run: ./gradlew clean - - name: Gradle build - run: ./gradlew build # if test's failed, don't publish - - name: Gradle :mirai-console:githubUpload - run: ./gradlew :mirai-console:githubUpload -Dgithub_token=${{ secrets.MAMOE_TOKEN }} -Pgithub_token=${{ secrets.MAMOE_TOKEN }} - - name: Gradle :mirai-console-terminal:githubUpload - run: ./gradlew :mirai-console-terminal:githubUpload -Dgithub_token=${{ secrets.MAMOE_TOKEN }} -Pgithub_token=${{ secrets.MAMOE_TOKEN }} - - -# - name: Upload artifact -# uses: actions/upload-artifact@v1.0.0 -# with: -# # Artifact name -# name: mirai-core -# # Directory containing files to upload -# path: "mirai-core/build/libs/mirai-core-*-all.jar" -# - name: Upload artifact -# uses: actions/upload-artifact@v1.0.0 -# with: -# # Artifact name -# name: mirai-core-qqandroid-all -# # Directory containing files to upload -# path: "mirai-core-qqandroid/build/libs/mirai-core-qqandroid-*-all.jar" diff --git a/buildSrc/src/main/kotlin/PublishingHelpers.kt b/buildSrc/src/main/kotlin/PublishingHelpers.kt index 8b695c9ef..65414a697 100644 --- a/buildSrc/src/main/kotlin/PublishingHelpers.kt +++ b/buildSrc/src/main/kotlin/PublishingHelpers.kt @@ -84,6 +84,10 @@ inline fun Project.setupPublishing( user = Bintray.getUser(project) key = Bintray.getKey(project) + + publish = true + override = true + setPublications("mavenJava") setConfigurations("archives") From 8cd4d1cca2710e7c2c71adae708a54aceeb94858 Mon Sep 17 00:00:00 2001 From: Him188 Date: Tue, 10 Nov 2020 10:48:32 +0800 Subject: [PATCH 039/133] Update kotlin idea dependency --- tools/compiler-common/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/compiler-common/build.gradle.kts b/tools/compiler-common/build.gradle.kts index e733d5e55..fafaf57f1 100644 --- a/tools/compiler-common/build.gradle.kts +++ b/tools/compiler-common/build.gradle.kts @@ -56,7 +56,7 @@ dependencies { api(kotlinx("coroutines-jdk8", Versions.coroutines)) compileOnly("org.jetbrains.kotlin:kotlin-compiler:${Versions.kotlinCompiler}") - compileOnly("org.jetbrains.kotlin:kotlin-compiler:${Versions.kotlinCompiler}") + testRuntimeOnly("org.jetbrains.kotlin:kotlin-compiler:${Versions.kotlinCompiler}") testApi(kotlin("test")) testApi(kotlin("test-junit5")) From fb0b54f42e81f47a16751797893da39016192016 Mon Sep 17 00:00:00 2001 From: Him188 Date: Tue, 10 Nov 2020 10:49:08 +0800 Subject: [PATCH 040/133] Update kotlin idea dependency --- tools/intellij-plugin/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/intellij-plugin/build.gradle.kts b/tools/intellij-plugin/build.gradle.kts index 2c02d5f7c..2b71cfb01 100644 --- a/tools/intellij-plugin/build.gradle.kts +++ b/tools/intellij-plugin/build.gradle.kts @@ -33,7 +33,7 @@ intellij { updateSinceUntilBuild = false setPlugins( - "org.jetbrains.kotlin:1.4.10-release-IJ2020.2-1@staging", + "org.jetbrains.kotlin:1.4.20-RC-IJ2020.2-1@eap", "java" ) } From 233ff9bee3e62f7666c513dfe8730a0b65770990 Mon Sep 17 00:00:00 2001 From: Him188 Date: Tue, 10 Nov 2020 10:49:48 +0800 Subject: [PATCH 041/133] Fix MiraiConsoleErrors --- .../src/diagnostics/MiraiConsoleErrors.kt | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/tools/compiler-common/src/diagnostics/MiraiConsoleErrors.kt b/tools/compiler-common/src/diagnostics/MiraiConsoleErrors.kt index 03d21ea9e..4b604bcf8 100644 --- a/tools/compiler-common/src/diagnostics/MiraiConsoleErrors.kt +++ b/tools/compiler-common/src/diagnostics/MiraiConsoleErrors.kt @@ -14,45 +14,44 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticFactory1.create import org.jetbrains.kotlin.diagnostics.DiagnosticFactory2.create import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.diagnostics.Severity.ERROR +import org.jetbrains.kotlin.psi.KtCallExpression import org.jetbrains.kotlin.psi.KtNamedDeclaration object MiraiConsoleErrors { - @JvmStatic + @JvmField val ILLEGAL_PLUGIN_DESCRIPTION = create(ERROR) - @JvmStatic - val NOT_CONSTRUCTABLE_TYPE = create(ERROR) + @JvmField + val NOT_CONSTRUCTABLE_TYPE = create(ERROR) - @JvmStatic + @JvmField val UNSERIALIZABLE_TYPE = create(ERROR) - @JvmStatic + @JvmField val ILLEGAL_COMMAND_NAME = create(ERROR) - @JvmStatic + @JvmField val ILLEGAL_PERMISSION_NAME = create(ERROR) - @JvmStatic + @JvmField val ILLEGAL_PERMISSION_ID = create(ERROR) - @JvmStatic + @JvmField val ILLEGAL_PERMISSION_NAMESPACE = create(ERROR) - @JvmStatic + @JvmField val ILLEGAL_COMMAND_REGISTER_USE = create(ERROR) - @JvmStatic + @JvmField val ILLEGAL_PERMISSION_REGISTER_USE = create(ERROR) @Suppress("ObjectPropertyName", "unused") - @JvmStatic + @JvmField @Deprecated("", level = DeprecationLevel.ERROR) - val _init: Any = object : Any() { - init { - Errors.Initializer.initializeFactoryNamesAndDefaultErrorMessages( - MiraiConsoleErrors::class.java, - MiraiConsoleErrorsRendering - ) - } + val _init: Any = run { + Errors.Initializer.initializeFactoryNamesAndDefaultErrorMessages( + MiraiConsoleErrors::class.java, + MiraiConsoleErrorsRendering + ) } } \ No newline at end of file From c077719c1be535c205c226c70841068093311f44 Mon Sep 17 00:00:00 2001 From: Him188 Date: Tue, 10 Nov 2020 10:50:48 +0800 Subject: [PATCH 042/133] Report NOT_CONSTRUCTABLE_TYPE on type argument --- .../kotlin/org/example/myplugin/MyPluginMain.kt | 2 +- .../kotlin/org/example/myplugin/MySimpleCommand.kt | 5 ++++- .../src/diagnostics/PluginDataValuesChecker.kt | 4 +++- .../src/diagnostics/diagnosticsUtil.kt | 14 +++++++++++++- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/tools/intellij-plugin/run/projects/test-project/src/main/kotlin/org/example/myplugin/MyPluginMain.kt b/tools/intellij-plugin/run/projects/test-project/src/main/kotlin/org/example/myplugin/MyPluginMain.kt index 8856e0d1b..e59e512e3 100644 --- a/tools/intellij-plugin/run/projects/test-project/src/main/kotlin/org/example/myplugin/MyPluginMain.kt +++ b/tools/intellij-plugin/run/projects/test-project/src/main/kotlin/org/example/myplugin/MyPluginMain.kt @@ -30,8 +30,8 @@ object MyPluginMain : KotlinPlugin( } } + object DataTest : AutoSavePluginConfig("data") { - val p by value() val pp by value() } diff --git a/tools/intellij-plugin/run/projects/test-project/src/main/kotlin/org/example/myplugin/MySimpleCommand.kt b/tools/intellij-plugin/run/projects/test-project/src/main/kotlin/org/example/myplugin/MySimpleCommand.kt index 30699c49a..4e100351f 100644 --- a/tools/intellij-plugin/run/projects/test-project/src/main/kotlin/org/example/myplugin/MySimpleCommand.kt +++ b/tools/intellij-plugin/run/projects/test-project/src/main/kotlin/org/example/myplugin/MySimpleCommand.kt @@ -1,7 +1,10 @@ package org.example.myplugin +import kotlinx.serialization.Serializable import net.mamoe.mirai.console.command.CommandSender import net.mamoe.mirai.console.command.SimpleCommand +import net.mamoe.mirai.console.data.AutoSavePluginConfig +import net.mamoe.mirai.console.data.value object MySimpleCommand000 : SimpleCommand( MyPluginMain, "foo", @@ -11,4 +14,4 @@ object MySimpleCommand000 : SimpleCommand( suspend fun CommandSender.handle(int: Int, str: String) { } -} +} \ No newline at end of file diff --git a/tools/intellij-plugin/src/diagnostics/PluginDataValuesChecker.kt b/tools/intellij-plugin/src/diagnostics/PluginDataValuesChecker.kt index 79b584b3f..274d7ea9c 100644 --- a/tools/intellij-plugin/src/diagnostics/PluginDataValuesChecker.kt +++ b/tools/intellij-plugin/src/diagnostics/PluginDataValuesChecker.kt @@ -43,13 +43,15 @@ class PluginDataValuesChecker : DeclarationChecker { val classDescriptor = type.constructor.declarationDescriptor?.castOrNull() val inspectionTarget: PsiElement by lazy { - callExpr.typeArguments.find { it.references.firstOrNull()?.canonicalText == type.fqName?.toString() } ?: callExpr + val fqName = type.fqName ?: return@lazy callExpr + callExpr.typeArguments.find { it.typeReference?.isReferencing(fqName) == true } ?: callExpr } if (classDescriptor == null || !classDescriptor.hasNoArgConstructor() ) return@forEach context.report(MiraiConsoleErrors.NOT_CONSTRUCTABLE_TYPE.on( inspectionTarget, + callExpr, type.fqName?.asString().toString()) ) diff --git a/tools/intellij-plugin/src/diagnostics/diagnosticsUtil.kt b/tools/intellij-plugin/src/diagnostics/diagnosticsUtil.kt index ac09c62f8..9b615da46 100644 --- a/tools/intellij-plugin/src/diagnostics/diagnosticsUtil.kt +++ b/tools/intellij-plugin/src/diagnostics/diagnosticsUtil.kt @@ -9,10 +9,16 @@ package net.mamoe.mirai.console.intellij.diagnostics +import net.mamoe.mirai.console.compiler.common.castOrNull import net.mamoe.mirai.console.intellij.resolve.getResolvedCall import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.diagnostics.Diagnostic +import org.jetbrains.kotlin.idea.refactoring.fqName.getKotlinFqName +import org.jetbrains.kotlin.idea.references.mainReference +import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.psi.KtElement +import org.jetbrains.kotlin.psi.KtTypeReference +import org.jetbrains.kotlin.psi.KtUserType import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.checkers.DeclarationCheckerContext @@ -26,4 +32,10 @@ fun KtElement?.getResolvedCall( context: DeclarationCheckerContext, ): ResolvedCall? { return this.getResolvedCall(context.bindingContext) -} \ No newline at end of file +} + +fun KtTypeReference.isReferencing(fqName: FqName): Boolean { + return resolveReferencedType()?.getKotlinFqName() == fqName +} + +fun KtTypeReference.resolveReferencedType() = this.typeElement.castOrNull()?.referenceExpression?.mainReference?.resolve() \ No newline at end of file From e37ac17b8238cf016c2e97cab71b7f1003514cf5 Mon Sep 17 00:00:00 2001 From: Him188 Date: Tue, 10 Nov 2020 11:38:24 +0800 Subject: [PATCH 043/133] Support ProvideDefaultValueFix for NOT_CONSTRUCTABLE_TYPE --- .../src/diagnostics/MiraiConsoleErrors.kt | 3 +- .../MiraiConsoleErrorsRendering.kt | 3 +- tools/gradle-plugin/src/VersionConstants.kt | 2 +- .../org/example/myplugin/MyPluginMain.kt | 13 ---- .../org/example/myplugin/MySimpleCommand.kt | 16 ++++- .../intellij-plugin/src/QuickFixRegistrar.kt | 2 + .../diagnostics/PluginDataValuesChecker.kt | 9 ++- .../src/diagnostics/diagnosticsUtil.kt | 4 +- .../diagnostics/fix/ProvideDefaultValueFix.kt | 71 +++++++++++++++++++ 9 files changed, 100 insertions(+), 23 deletions(-) create mode 100644 tools/intellij-plugin/src/diagnostics/fix/ProvideDefaultValueFix.kt diff --git a/tools/compiler-common/src/diagnostics/MiraiConsoleErrors.kt b/tools/compiler-common/src/diagnostics/MiraiConsoleErrors.kt index 4b604bcf8..7f2544a39 100644 --- a/tools/compiler-common/src/diagnostics/MiraiConsoleErrors.kt +++ b/tools/compiler-common/src/diagnostics/MiraiConsoleErrors.kt @@ -16,13 +16,14 @@ import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.diagnostics.Severity.ERROR import org.jetbrains.kotlin.psi.KtCallExpression import org.jetbrains.kotlin.psi.KtNamedDeclaration +import org.jetbrains.kotlin.psi.KtTypeProjection object MiraiConsoleErrors { @JvmField val ILLEGAL_PLUGIN_DESCRIPTION = create(ERROR) @JvmField - val NOT_CONSTRUCTABLE_TYPE = create(ERROR) + val NOT_CONSTRUCTABLE_TYPE = create(ERROR) @JvmField val UNSERIALIZABLE_TYPE = create(ERROR) diff --git a/tools/compiler-common/src/diagnostics/MiraiConsoleErrorsRendering.kt b/tools/compiler-common/src/diagnostics/MiraiConsoleErrorsRendering.kt index 734a3a02a..effb040ff 100644 --- a/tools/compiler-common/src/diagnostics/MiraiConsoleErrorsRendering.kt +++ b/tools/compiler-common/src/diagnostics/MiraiConsoleErrorsRendering.kt @@ -32,7 +32,8 @@ object MiraiConsoleErrorsRendering : DefaultErrorMessages.Extension { put( NOT_CONSTRUCTABLE_TYPE, - "类型 ''{0}'' 无法通过反射直接构造, 需要提供默认值.", + "类型 ''{1}'' 无法通过反射直接构造, 需要提供默认值.", + Renderers.EMPTY, Renderers.STRING, ) diff --git a/tools/gradle-plugin/src/VersionConstants.kt b/tools/gradle-plugin/src/VersionConstants.kt index 1f9ccb633..3c742ce5a 100644 --- a/tools/gradle-plugin/src/VersionConstants.kt +++ b/tools/gradle-plugin/src/VersionConstants.kt @@ -10,6 +10,6 @@ package net.mamoe.mirai.console.gradle internal object VersionConstants { - const val CONSOLE_VERSION = "1.0-RC2-dev-1" // value is written here automatically during build + const val CONSOLE_VERSION = "1.0-RC2-dev-3" // value is written here automatically during build const val CORE_VERSION = "1.3.3" // value is written here automatically during build } \ No newline at end of file diff --git a/tools/intellij-plugin/run/projects/test-project/src/main/kotlin/org/example/myplugin/MyPluginMain.kt b/tools/intellij-plugin/run/projects/test-project/src/main/kotlin/org/example/myplugin/MyPluginMain.kt index e59e512e3..9e148c27d 100644 --- a/tools/intellij-plugin/run/projects/test-project/src/main/kotlin/org/example/myplugin/MyPluginMain.kt +++ b/tools/intellij-plugin/run/projects/test-project/src/main/kotlin/org/example/myplugin/MyPluginMain.kt @@ -31,17 +31,4 @@ object MyPluginMain : KotlinPlugin( } -object DataTest : AutoSavePluginConfig("data") { - val pp by value() -} - -@Serializable -data class HasDefaultValue( - val x: Int = 0, -) - -data class NoDefaultValue( - val y: Int, -) - val y = "傻逼 yellow" \ No newline at end of file diff --git a/tools/intellij-plugin/run/projects/test-project/src/main/kotlin/org/example/myplugin/MySimpleCommand.kt b/tools/intellij-plugin/run/projects/test-project/src/main/kotlin/org/example/myplugin/MySimpleCommand.kt index 4e100351f..85199308a 100644 --- a/tools/intellij-plugin/run/projects/test-project/src/main/kotlin/org/example/myplugin/MySimpleCommand.kt +++ b/tools/intellij-plugin/run/projects/test-project/src/main/kotlin/org/example/myplugin/MySimpleCommand.kt @@ -14,4 +14,18 @@ object MySimpleCommand000 : SimpleCommand( suspend fun CommandSender.handle(int: Int, str: String) { } -} \ No newline at end of file +} + +object DataTest : AutoSavePluginConfig("data") { + val pp by value(NoDefaultValue(1)) +} + +@Serializable +data class HasDefaultValue( + val x: Int = 0, +) + +@Serializable +data class NoDefaultValue( + val y: Int, +) diff --git a/tools/intellij-plugin/src/QuickFixRegistrar.kt b/tools/intellij-plugin/src/QuickFixRegistrar.kt index 6e0bcccdc..e860ec0a0 100644 --- a/tools/intellij-plugin/src/QuickFixRegistrar.kt +++ b/tools/intellij-plugin/src/QuickFixRegistrar.kt @@ -12,6 +12,7 @@ package net.mamoe.mirai.console.intellij import com.intellij.codeInsight.intention.IntentionAction import net.mamoe.mirai.console.compiler.common.diagnostics.MiraiConsoleErrors import net.mamoe.mirai.console.intellij.diagnostics.fix.AddSerializerFix +import net.mamoe.mirai.console.intellij.diagnostics.fix.ProvideDefaultValueFix import org.jetbrains.kotlin.diagnostics.DiagnosticFactory import org.jetbrains.kotlin.idea.quickfix.KotlinIntentionActionsFactory import org.jetbrains.kotlin.idea.quickfix.QuickFixContributor @@ -29,5 +30,6 @@ class QuickFixRegistrar : QuickFixContributor { } MiraiConsoleErrors.UNSERIALIZABLE_TYPE.registerFactory(AddSerializerFix) + MiraiConsoleErrors.NOT_CONSTRUCTABLE_TYPE.registerFactory(ProvideDefaultValueFix) } } diff --git a/tools/intellij-plugin/src/diagnostics/PluginDataValuesChecker.kt b/tools/intellij-plugin/src/diagnostics/PluginDataValuesChecker.kt index 274d7ea9c..7eb1c0f6b 100644 --- a/tools/intellij-plugin/src/diagnostics/PluginDataValuesChecker.kt +++ b/tools/intellij-plugin/src/diagnostics/PluginDataValuesChecker.kt @@ -9,7 +9,6 @@ package net.mamoe.mirai.console.intellij.diagnostics -import com.intellij.psi.PsiElement import net.mamoe.mirai.console.compiler.common.SERIALIZABLE_FQ_NAME import net.mamoe.mirai.console.compiler.common.castOrNull import net.mamoe.mirai.console.compiler.common.diagnostics.MiraiConsoleErrors @@ -42,10 +41,10 @@ class PluginDataValuesChecker : DeclarationChecker { val (_, type) = e val classDescriptor = type.constructor.declarationDescriptor?.castOrNull() - val inspectionTarget: PsiElement by lazy { - val fqName = type.fqName ?: return@lazy callExpr - callExpr.typeArguments.find { it.typeReference?.isReferencing(fqName) == true } ?: callExpr - } + val inspectionTarget = kotlin.run { + val fqName = type.fqName ?: return@run null + callExpr.typeArguments.find { it.typeReference?.isReferencing(fqName) == true } + } ?: return@forEach if (classDescriptor == null || !classDescriptor.hasNoArgConstructor() diff --git a/tools/intellij-plugin/src/diagnostics/diagnosticsUtil.kt b/tools/intellij-plugin/src/diagnostics/diagnosticsUtil.kt index 9b615da46..86481de29 100644 --- a/tools/intellij-plugin/src/diagnostics/diagnosticsUtil.kt +++ b/tools/intellij-plugin/src/diagnostics/diagnosticsUtil.kt @@ -38,4 +38,6 @@ fun KtTypeReference.isReferencing(fqName: FqName): Boolean { return resolveReferencedType()?.getKotlinFqName() == fqName } -fun KtTypeReference.resolveReferencedType() = this.typeElement.castOrNull()?.referenceExpression?.mainReference?.resolve() \ No newline at end of file +val KtTypeReference.referencedUserType: KtUserType? get() = this.typeElement.castOrNull() + +fun KtTypeReference.resolveReferencedType() = referencedUserType?.referenceExpression?.mainReference?.resolve() \ No newline at end of file diff --git a/tools/intellij-plugin/src/diagnostics/fix/ProvideDefaultValueFix.kt b/tools/intellij-plugin/src/diagnostics/fix/ProvideDefaultValueFix.kt new file mode 100644 index 000000000..8ac8b20cb --- /dev/null +++ b/tools/intellij-plugin/src/diagnostics/fix/ProvideDefaultValueFix.kt @@ -0,0 +1,71 @@ +/* + * Copyright 2019-2020 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + */ + +package net.mamoe.mirai.console.intellij.diagnostics.fix + +import com.intellij.codeInsight.intention.IntentionAction +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.project.Project +import com.intellij.psi.PsiFile +import com.intellij.psi.SmartPointerManager +import com.intellij.psi.SmartPsiElementPointer +import net.mamoe.mirai.console.compiler.common.castOrNull +import net.mamoe.mirai.console.compiler.common.diagnostics.MiraiConsoleErrors +import net.mamoe.mirai.console.intellij.resolve.findChild +import org.jetbrains.kotlin.diagnostics.Diagnostic +import org.jetbrains.kotlin.diagnostics.DiagnosticWithParameters2 +import org.jetbrains.kotlin.idea.core.moveCaret +import org.jetbrains.kotlin.idea.inspections.KotlinUniversalQuickFix +import org.jetbrains.kotlin.idea.quickfix.KotlinCrossLanguageQuickFixAction +import org.jetbrains.kotlin.idea.quickfix.KotlinSingleIntentionActionFactory +import org.jetbrains.kotlin.idea.util.application.executeWriteCommand +import org.jetbrains.kotlin.psi.* +import org.jetbrains.kotlin.psi.psiUtil.endOffset + +/** + * @see MiraiConsoleErrors.NOT_CONSTRUCTABLE_TYPE + */ +class ProvideDefaultValueFix( + element: KtCallExpression, + private val typeProjection: SmartPsiElementPointer, +) : KotlinCrossLanguageQuickFixAction(element), KotlinUniversalQuickFix { + + override fun getFamilyName(): String = "Mirai Console" + override fun getText(): String = "添加默认值" + + override fun invokeImpl(project: Project, editor: Editor?, file: PsiFile) { + val element = element ?: return + if (file !is KtFile) return + + + /* + val refereeFqName = element.resolve()?.getKotlinFqName() ?: return + val referee = file.resolveImportReference(refereeFqName).singleOrNull { it is ClassDescriptor } ?: return + ImportInsertHelper.getInstance(project).importDescriptor(file, referee) + */ + + val typeName = typeProjection.element?.typeReference?.typeElement?.castOrNull()?.referencedName ?: return + val argumentList = element.findChild() ?: return + val offset = argumentList.leftParenthesis?.endOffset ?: return + + project.executeWriteCommand(name) { + argumentList.addArgument(KtPsiFactory(project).createArgument("$typeName()")) + editor?.moveCaret(offset + typeName.length + 1) + } + } + + companion object : KotlinSingleIntentionActionFactory() { + override fun createAction(diagnostic: Diagnostic): IntentionAction? { + val diagnostic1 = diagnostic.castOrNull>() ?: return null + return ProvideDefaultValueFix(diagnostic1.a, SmartPointerManager.createPointer(diagnostic1.psiElement)) + } + + override fun isApplicableForCodeFragment(): Boolean = false + } +} From 0c3a4c735d4392ea3310a2bd46d97a07126aa92b Mon Sep 17 00:00:00 2001 From: Him188 Date: Tue, 10 Nov 2020 13:59:41 +0800 Subject: [PATCH 044/133] Support PluginMainServiceNotConfiguredInspection and ConfigurePluginMainServiceFix --- .../src/resolve/resolveTypes.kt | 3 +- .../resources/META-INF/plugin.xml | 6 ++ .../InspectionGadgetsBundle.properties | 9 +++ .../messages/InspectionsBundle.properties | 9 +++ .../org/example/myplugin/MyPluginMain.kt | 3 - ...luginMainServiceNotConfiguredInspection.kt | 77 +++++++++++++++++++ .../src/diagnostics/diagnosticsUtil.kt | 20 ++++- .../fix/ConfigurePluginMainServiceFix.kt | 44 +++++++++++ .../marker/PluginMainLineMarkerProvider.kt | 17 +--- .../src/resolve/resolveIdea.kt | 9 ++- 10 files changed, 172 insertions(+), 25 deletions(-) create mode 100644 tools/intellij-plugin/resources/messages/InspectionGadgetsBundle.properties create mode 100644 tools/intellij-plugin/resources/messages/InspectionsBundle.properties create mode 100644 tools/intellij-plugin/src/diagnostics/PluginMainServiceNotConfiguredInspection.kt create mode 100644 tools/intellij-plugin/src/diagnostics/fix/ConfigurePluginMainServiceFix.kt diff --git a/tools/compiler-common/src/resolve/resolveTypes.kt b/tools/compiler-common/src/resolve/resolveTypes.kt index 080f61ed4..c8d5bce00 100644 --- a/tools/compiler-common/src/resolve/resolveTypes.kt +++ b/tools/compiler-common/src/resolve/resolveTypes.kt @@ -19,10 +19,11 @@ import org.jetbrains.kotlin.resolve.constants.ArrayValue import org.jetbrains.kotlin.resolve.constants.EnumValue /////////////////////////////////////////////////////////////////////////// -// Serializer +// OTHERS /////////////////////////////////////////////////////////////////////////// val SERIALIZABLE_FQ_NAME = FqName("kotlinx.serialization.Serializable") +val AUTO_SERVICE = FqName("com.google.auto.service.AutoService") /////////////////////////////////////////////////////////////////////////// diff --git a/tools/intellij-plugin/resources/META-INF/plugin.xml b/tools/intellij-plugin/resources/META-INF/plugin.xml index 3dbd79325..4e7a1187d 100644 --- a/tools/intellij-plugin/resources/META-INF/plugin.xml +++ b/tools/intellij-plugin/resources/META-INF/plugin.xml @@ -32,6 +32,12 @@ + +