Procházet zdrojové kódy

Kotlin 1.5 and dependencies updates (#346)

* Kotlin 1.5 and dependencies updates

* Make MessageScope sealed

* Use Kotlin 1.5.10

* Uses 2.6.4-dev-kt15 in build
Him188 před 4 roky
rodič
revize
19abf48aac

+ 10 - 0
backend/codegen/build.gradle.kts

@@ -1,3 +1,12 @@
+/*
+ * Copyright 2019-2021 Mamoe Technologies and contributors.
+ *
+ *  此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
+ *  Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
+ *
+ *  https://github.com/mamoe/mirai/blob/master/LICENSE
+ */
+
 plugins {
     kotlin("jvm")
     kotlin("plugin.serialization")
@@ -21,4 +30,5 @@ kotlin {
 dependencies {
     api(kotlin("stdlib-jdk8"))
     implementation(kotlin("reflect"))
+    api(`mirai-core-utils`)
 }

+ 6 - 4
backend/codegen/src/MessageScopeCodegen.kt

@@ -1,14 +1,16 @@
 /*
- * Copyright 2019-2020 Mamoe Technologies and contributors.
+ * Copyright 2019-2021 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.
+ *  此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
+ *  Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  *
- * https://github.com/mamoe/mirai/blob/master/LICENSE
+ *  https://github.com/mamoe/mirai/blob/master/LICENSE
  */
 
 package net.mamoe.mirai.console.codegen
 
+import net.mamoe.mirai.utils.capitalize
+
 internal val TypeCandidatesForMessageScope = arrayOf(
     KtType("Contact"),
     KtType("CommandSender"),

+ 5 - 5
backend/codegen/src/old/JSettingCodegen.kt

@@ -1,10 +1,10 @@
 /*
- * Copyright 2019-2020 Mamoe Technologies and contributors.
+ * Copyright 2019-2021 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.
+ *  此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
+ *  Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  *
- * https://github.com/mamoe/mirai/blob/master/LICENSE
+ *  https://github.com/mamoe/mirai/blob/master/LICENSE
  */
 
 @file:Suppress("PRE_RELEASE_CLASS")
@@ -21,7 +21,7 @@ open class JClazz(val primitiveName: String, val packageName: String) {
 }
 
 class JListClazz(item: JClazz) : JClazz("List<${item.packageName}>", "List<${item.packageName}>") {
-    override val funName = item.primitiveName.toLowerCase() + "List"
+    override val funName = item.primitiveName.lowercase() + "List"
 }
 
 class JArrayClazz(item: JClazz) : JClazz(item.primitiveName + "[]", item.primitiveName + "[]")

+ 6 - 6
backend/codegen/src/util.kt

@@ -1,10 +1,10 @@
 /*
- * Copyright 2019-2020 Mamoe Technologies and contributors.
+ * Copyright 2019-2021 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.
+ *  此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
+ *  Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  *
- * https://github.com/mamoe/mirai/blob/master/LICENSE
+ *  https://github.com/mamoe/mirai/blob/master/LICENSE
  */
 
 @file:Suppress("NOTHING_TO_INLINE", "MemberVisibilityCanBePrivate", "unused", "PRE_RELEASE_CLASS")
@@ -44,7 +44,7 @@ sealed class KtType {
      */
     sealed class KtPrimitive(
         override val standardName: String,
-        val jPrimitiveName: String = standardName.toLowerCase(),
+        val jPrimitiveName: String = standardName.lowercase(),
         val jObjectName: String = standardName
     ) : KtType() {
         object KtByte : KtPrimitive("Byte")
@@ -95,7 +95,7 @@ operator fun KtType.plus(type: KtType): List<KtType> {
     return listOf(this, type)
 }
 
-val KtType.lowerCaseName: String get() = this.standardName.toLowerCase()
+val KtType.lowerCaseName: String get() = this.standardName.lowercase()
 
 inline fun kCode(@Language("kt") source: String) = source.trimIndent()
 

+ 2 - 1
backend/mirai-console/src/command/BuiltInCommands.kt

@@ -69,7 +69,7 @@ internal interface BuiltInCommandInternal : Command, BuiltInCommand
  *
  * [查看文档](https://github.com/mamoe/mirai-console/docs/BuiltInCommands.md)
  */
-@Suppress("unused")
+@Suppress("unused", "RESTRICTED_CONSOLE_COMMAND_OWNER")
 public object BuiltInCommands {
     @ConsoleExperimentalApi
     public val parentPermission: Permission by lazy {
@@ -121,6 +121,7 @@ public object BuiltInCommands {
 
         private val closingLock = Mutex()
 
+        @OptIn(DelicateCoroutinesApi::class)
         @Handler
         public suspend fun CommandSender.handle() {
             GlobalScope.launch {

+ 7 - 7
backend/mirai-console/src/command/descriptor/CommandArgumentParserBuiltins.kt

@@ -421,10 +421,10 @@ public class EnumValueArgumentParser<T : Enum<T>>(
     private val delegate: (String) -> T = kotlin.run {
         val enums = type.enumConstants.asSequence()
         // step 1: 分析是否能够忽略大小写
-        if (enums.map { it.name.toLowerCase() }.hasDuplicates()) {
+        if (enums.map { it.name.lowercase() }.hasDuplicates()) {
             ({ java.lang.Enum.valueOf(type, it) })
         } else { // step 2: 分析是否能使用小驼峰命名
-            val lowerCaseEnumDirection = enums.map { it.name.toLowerCase() to it }.toList().toMap()
+            val lowerCaseEnumDirection = enums.map { it.name.lowercase() to it }.toList().toMap()
 
             val camelCase = enums.mapNotNull { elm ->
                 val name = elm.name.split('_')
@@ -433,18 +433,18 @@ public class EnumValueArgumentParser<T : Enum<T>>(
                 } else {
                     buildString {
                         val iterator = name.iterator()
-                        append(iterator.next().toLowerCase())
+                        append(iterator.next().lowercase())
                         for (v in iterator) {
                             if (v.isEmpty()) continue
-                            append(v[0].toUpperCase())
-                            append(v.substring(1, v.length).toLowerCase())
+                            append(v[0].uppercase())
+                            append(v.substring(1, v.length).lowercase())
                         }
                     } to elm
                 }
             }
 
             val camelCaseDirection = if ((
-                    enums.map { it.name.toLowerCase() } + camelCase.map { it.first.toLowerCase() }
+                    enums.map { it.name.lowercase() } + camelCase.map { it.first.lowercase() }
                     ).hasDuplicates()
             ) { // 确认驼峰命名与源没有冲突
                 emptyMap()
@@ -454,7 +454,7 @@ public class EnumValueArgumentParser<T : Enum<T>>(
 
             ({
                 camelCaseDirection[it]
-                    ?: lowerCaseEnumDirection[it.toLowerCase()]
+                    ?: lowerCaseEnumDirection[it.lowercase()]
                     ?: noConstant()
             })
         }

+ 6 - 6
backend/mirai-console/src/internal/command/CommandManagerImpl.kt

@@ -54,9 +54,9 @@ internal object CommandManagerImpl : CommandManager, CoroutineScope by MiraiCons
      */
     override fun matchCommand(commandName: String): Command? {
         if (commandName.startsWith(commandPrefix)) {
-            return requiredPrefixCommandMap[commandName.substringAfter(commandPrefix).toLowerCase()]
+            return requiredPrefixCommandMap[commandName.substringAfter(commandPrefix).lowercase()]
         }
-        return optionalPrefixCommandMap[commandName.toLowerCase()]
+        return optionalPrefixCommandMap[commandName.lowercase()]
     }
     ///// IMPL
 
@@ -90,13 +90,13 @@ internal object CommandManagerImpl : CommandManager, CoroutineScope by MiraiCons
             _registeredCommands.add(command)
             if (command.prefixOptional) {
                 for (name in command.allNames) {
-                    val lowerCaseName = name.toLowerCase()
+                    val lowerCaseName = name.lowercase()
                     optionalPrefixCommandMap[lowerCaseName] = command
                     requiredPrefixCommandMap[lowerCaseName] = command
                 }
             } else {
                 for (name in command.allNames) {
-                    val lowerCaseName = name.toLowerCase()
+                    val lowerCaseName = name.lowercase()
                     optionalPrefixCommandMap.remove(lowerCaseName) // ensure resolution consistency
                     requiredPrefixCommandMap[lowerCaseName] = command
                 }
@@ -111,11 +111,11 @@ internal object CommandManagerImpl : CommandManager, CoroutineScope by MiraiCons
     override fun unregisterCommand(command: Command): Boolean = modifyLock.withLock {
         if (command.prefixOptional) {
             command.allNames.forEach {
-                optionalPrefixCommandMap.remove(it.toLowerCase())
+                optionalPrefixCommandMap.remove(it.lowercase())
             }
         }
         command.allNames.forEach {
-            requiredPrefixCommandMap.remove(it.toLowerCase())
+            requiredPrefixCommandMap.remove(it.lowercase())
         }
         _registeredCommands.remove(command)
     }

+ 5 - 5
backend/mirai-console/src/internal/permission/parseFromStringImpl.kt

@@ -1,10 +1,10 @@
 /*
- * Copyright 2019-2020 Mamoe Technologies and contributors.
+ * Copyright 2019-2021 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.
+ *  此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
+ *  Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  *
- * https://github.com/mamoe/mirai/blob/master/LICENSE
+ *  https://github.com/mamoe/mirai/blob/master/LICENSE
  */
 
 @file:Suppress("unused")
@@ -15,7 +15,7 @@ import net.mamoe.mirai.console.permission.AbstractPermitteeId
 import net.mamoe.mirai.console.permission.AbstractPermitteeId.*
 
 internal fun parseFromStringImpl(string: String): AbstractPermitteeId {
-    val str = string.trim { it.isWhitespace() }.toLowerCase()
+    val str = string.trim { it.isWhitespace() }.lowercase()
     if (str == "*") return AnyContact
     if (str == "console") return Console
     if (str == "client*") return AnyOtherClient

+ 5 - 5
backend/mirai-console/src/internal/util/ByteUtils.kt

@@ -1,10 +1,10 @@
 /*
- * Copyright 2019-2020 Mamoe Technologies and contributors.
+ * Copyright 2019-2021 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.
+ *  此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
+ *  Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  *
- * https://github.com/mamoe/mirai/blob/master/LICENSE
+ *  https://github.com/mamoe/mirai/blob/master/LICENSE
  */
 
 package net.mamoe.mirai.console.internal.util
@@ -44,7 +44,7 @@ internal fun ByteArray.toUHexString(
     return buildString(length * 2) {
         [email protected] { index, it ->
             if (index in offset until lastIndex) {
-                var ret = it.toUByte().toString(16).toUpperCase()
+                var ret = it.toUByte().toString(16).uppercase()
                 if (ret.length == 1) ret = "0$ret"
                 append(ret)
                 if (index < lastIndex - 1) append(separator)

+ 6 - 6
backend/mirai-console/src/permission/PermissionService.kt

@@ -1,10 +1,10 @@
 /*
- * Copyright 2019-2020 Mamoe Technologies and contributors.
+ * Copyright 2019-2021 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.
+ *  此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
+ *  Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  *
- * https://github.com/mamoe/mirai/blob/master/LICENSE
+ *  https://github.com/mamoe/mirai/blob/master/LICENSE
  */
 
 @file:Suppress("NOTHING_TO_INLINE", "unused", "MemberVisibilityCanBePrivate")
@@ -107,8 +107,8 @@ public interface PermissionService<P : Permission> {
         plugin: Plugin,
         @ResolveContext(COMMAND_NAME) permissionName: String,
     ): PermissionId = PermissionId(
-        plugin.description.id.toLowerCase(),
-        permissionName.toLowerCase()
+        plugin.description.id.lowercase(),
+        permissionName.lowercase()
     )
 
     ///////////////////////////////////////////////////////////////////////////

+ 8 - 8
backend/mirai-console/src/plugin/description/PluginDescription.kt

@@ -1,10 +1,10 @@
 /*
- * Copyright 2019-2020 Mamoe Technologies and contributors.
+ * Copyright 2019-2021 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.
+ *  此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
+ *  Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  *
- * https://github.com/mamoe/mirai/blob/master/LICENSE
+ *  https://github.com/mamoe/mirai/blob/master/LICENSE
  */
 
 package net.mamoe.mirai.console.plugin.description
@@ -159,7 +159,7 @@ public interface PluginDescription {
             if (id.isBlank()) throw IllegalPluginDescriptionException("Plugin id cannot be blank")
             if (id.none { it == '.' }) throw IllegalPluginDescriptionException("'$id' is illegal. Plugin id must consist of both domain and name. ")
 
-            val lowercaseId = id.toLowerCase()
+            val lowercaseId = id.lowercase()
 
             if (ID_REGEX.matchEntire(id) == null) {
                 throw IllegalPluginDescriptionException("Plugin does not match regex '${ID_REGEX.pattern}'.")
@@ -178,7 +178,7 @@ public interface PluginDescription {
         @Throws(IllegalPluginDescriptionException::class)
         public fun checkPluginName(name: String) {
             if (name.isBlank()) throw IllegalPluginDescriptionException("Plugin name cannot be blank")
-            val lowercaseName = name.toLowerCase()
+            val lowercaseName = name.lowercase()
             FORBIDDEN_ID_NAMES.firstOrNull { it == lowercaseName }?.let { illegal ->
                 throw IllegalPluginDescriptionException("Plugin name is illegal: '$illegal'.")
             }
@@ -191,8 +191,8 @@ public interface PluginDescription {
          */
         @Throws(IllegalPluginDescriptionException::class)
         public fun checkDependencies(pluginId: String, dependencies: Set<PluginDependency>) {
-            val lowercaseId = pluginId.toLowerCase()
-            val lowercaseDependencies = dependencies.mapTo(LinkedHashSet(dependencies.size)) { it.id.toLowerCase() }
+            val lowercaseId = pluginId.lowercase()
+            val lowercaseDependencies = dependencies.mapTo(LinkedHashSet(dependencies.size)) { it.id.lowercase() }
 
             if (lowercaseDependencies.size != dependencies.size)
                 throw IllegalPluginDescriptionException("Duplicated dependency detected: A plugin cannot depend on different versions of dependencies of the same id")

+ 5 - 5
backend/mirai-console/src/util/MessageScope.kt

@@ -1,10 +1,10 @@
 /*
- * Copyright 2019-2020 Mamoe Technologies and contributors.
+ * Copyright 2019-2021 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.
+ *  此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
+ *  Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  *
- * https://github.com/mamoe/mirai/blob/master/LICENSE
+ *  https://github.com/mamoe/mirai/blob/master/LICENSE
  */
 
 @file:Suppress(
@@ -97,7 +97,7 @@ import kotlin.internal.LowPriorityInOverloadResolution
  * }
  * ```
  */
-public interface MessageScope {
+public sealed interface MessageScope {
     /**
      * 如果此 [MessageScope] 仅包含一个消息对象, 则 [realTarget] 指向这个对象. 否则 [realTarget] 为 `null`.
      *

+ 9 - 9
buildSrc/src/main/kotlin/Versions.kt

@@ -12,26 +12,26 @@
 import org.gradle.api.attributes.Attribute
 
 object Versions {
-    const val core = "2.2.2"  // WARNING: This might not be up-to-date since included in mirai build.
-    const val console = "2.2.2"
+    const val core = "2.6.4-dev-kt15"  // WARNING: This might not be up-to-date since included in mirai build.
+    const val console = "2.6.4-dev-kt15"
     const val consoleGraphical = "0.0.7"
     const val consoleTerminal = console
 
-    const val kotlinCompiler = "1.4.21"
-    const val kotlinStdlib = "1.4.21"
+    const val kotlinCompiler = "1.5.10"
+    const val kotlinStdlib = "1.5.10"
 
     const val kotlinIntellijPlugin = "211-1.4.32-release-IJ6693.72" // keep to newest as kotlinCompiler
     const val intellij = "2021.1" // don't update easily unless you want your disk space -= 500MB
 
 
-    const val coroutines = "1.4.0"
-    const val serialization = "1.0.1"
-    const val ktor = "1.5.0"
-    const val atomicFU = "0.14.4"
+    const val coroutines = "1.5.0"
+    const val atomicFU = "0.16.1"
+    const val serialization = "1.1.0"
+    const val ktor = "1.5.4"
 
     const val androidGradle = "3.6.2"
 
-    const val blockingBridge = "1.6.0"
+    const val blockingBridge = "1.10.3"
 
     const val junit = "5.4.2"
 

+ 5 - 5
frontend/mirai-console-terminal/src/ConsoleTerminalSettings.kt

@@ -1,10 +1,10 @@
 /*
- * Copyright 2019-2020 Mamoe Technologies and contributors.
+ * Copyright 2019-2021 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.
+ *  此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
+ *  Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  *
- * https://github.com/mamoe/mirai/blob/master/LICENSE
+ *  https://github.com/mamoe/mirai/blob/master/LICENSE
  */
 /*
  * @author Karlatemp <[email protected]> <https://github.com/Karlatemp>
@@ -29,7 +29,7 @@ annotation class ConsoleTerminalExperimentalApi
 object ConsoleTerminalSettings {
     @JvmField
     var setupAnsi: Boolean = System.getProperty("os.name")
-        .toLowerCase()
+        .lowercase()
         .contains("windows") // Just for Windows
 
     @JvmField

+ 6 - 6
frontend/mirai-console-terminal/src/noconsole/NoConsole.kt

@@ -1,10 +1,10 @@
 /*
- * Copyright 2019-2020 Mamoe Technologies and contributors.
+ * Copyright 2019-2021 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.
+ *  此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
+ *  Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
  *
- * https://github.com/mamoe/mirai/blob/master/LICENSE
+ *  https://github.com/mamoe/mirai/blob/master/LICENSE
  */
 
 /*
@@ -30,8 +30,8 @@ import java.io.InputStream
 import java.io.OutputStream
 import java.io.PrintWriter
 
-private const val LN_INT = '\n'.toInt()
-private const val LN_BYTE = '\n'.toByte()
+private const val LN_INT = '\n'.code
+private const val LN_BYTE = '\n'.code.toByte()
 
 internal object NoConsoleNonBlockingReader : NonBlockingReader() {
     override fun read(timeout: Long, isPeek: Boolean): Int {

+ 2 - 2
tools/gradle-plugin/src/main/kotlin/VersionConstants.kt

@@ -10,6 +10,6 @@
 package net.mamoe.mirai.console.gradle
 
 internal object VersionConstants {
-    const val CONSOLE_VERSION = "2.6.4" // value is written here automatically during build
-    const val CORE_VERSION = "2.6.4" // value is written here automatically during build
+    const val CONSOLE_VERSION = "2.7-M1-dev-2" // value is written here automatically during build
+    const val CORE_VERSION = "2.7-M1-dev-2" // value is written here automatically during build
 }

+ 7 - 0
tools/intellij-plugin/build.gradle.kts

@@ -60,6 +60,13 @@ fun File.resolveMkdir(relative: String): File {
     return this.resolve(relative).apply { mkdirs() }
 }
 
+kotlin.target.compilations.all {
+    kotlinOptions {
+        apiVersion = "1.4"
+        languageVersion = "1.4"
+    }
+}
+
 tasks.withType<org.jetbrains.intellij.tasks.PatchPluginXmlTask> {
     sinceBuild("201.*")
     untilBuild("215.*")