From ef4d259f601ac9669513a32a192945f445cbc93d Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 20 Sep 2020 13:55:00 +0800 Subject: [PATCH 01/23] Document improvements --- .../mamoe/mirai/console/util/SemVersion.kt | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt index 783becc0c..f07b8d5b9 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt @@ -12,6 +12,8 @@ * @author Karlatemp */ +@file:Suppress("unused") + package net.mamoe.mirai.console.util import kotlinx.serialization.KSerializer @@ -21,20 +23,14 @@ import kotlinx.serialization.builtins.serializer import net.mamoe.mirai.console.internal.data.map import net.mamoe.mirai.console.internal.util.SemVersionInternal import net.mamoe.mirai.console.util.SemVersion.Companion.equals +import net.mamoe.mirai.console.util.SemVersion.RangeRequirement /** - * 语义化版本支持 + * [语义化版本](https://semver.org/lang/zh-CN/) 支持 * - * 在阅读此文件前, 请先阅读 https://semver.org/lang/zh-CN/ - * 该文档说明了语义化版本是什么, 此文件不再过多描述 + * 解析示例: * - * ---- - * - * 这是一个例子 `1.0.0-M4+c25733b8` - * - * 将会解析出三个内容, mainVersion(核心版本号), identifier(先行版本号) 和 metadata(元数据). - * - * 对这个例子进行解析会得到 + * `1.0.0-M4+c25733b8` 将会解析出三个内容, mainVersion (核心版本号), [identifier] (先行版本号) 和 [metadata] (元数据). * ``` * SemVersion( * mainVersion = IntArray [1, 0, 0], @@ -43,9 +39,10 @@ import net.mamoe.mirai.console.util.SemVersion.Companion.equals * ) * ``` * 其中 identifier 和 metadata 都是可选的. - * 对于核心版本号, 此实现稍微比 semver 宽松一些, 允许 x.y 的存在. - * 但是不允许 0.0.0.0 之类的存在 * + * 对于核心版本号, 此实现稍微比 semver 宽松一些, 允许 x.y 的存在. + * + * @see RangeRequirement */ @Serializable(with = SemVersion.SemVersionAsStringSerializer::class) public data class SemVersion internal constructor( @@ -83,7 +80,7 @@ public data class SemVersion internal constructor( * 解析一个版本号, 将会返回一个 [SemVersion], * 如果发生解析错误将会抛出一个 [IllegalArgumentException] 或者 [NumberFormatException] * - * 对于版本号的组成, 我们有以下规定: + * 对于版本号的组成, 有以下规定: * - 必须包含主版本号和次版本号 * - 存在 先行版本号 的时候 先行版本号 不能为空 * - 存在 元数据 的时候 元数据 不能为空 @@ -104,7 +101,7 @@ public data class SemVersion internal constructor( if (!SEM_VERSION_REGEX.matches(version)) { throw IllegalArgumentException("`$version` not a valid version") } - var mainVersionEnd: Int = 0 + var mainVersionEnd = 0 kotlin.run { val iterator = version.iterator() while (iterator.hasNext()) { @@ -154,7 +151,7 @@ public data class SemVersion internal constructor( * - `< 1.0.0-RC` 要求 1.0.0-RC 之前的版本, 不能是 1.0.0-RC * - `<= 1.0.0-RC` 要求 1.0.0-RC 或之前的版本, 可以是 1.0.0-RC * - * 对于多个规则, 也允许使用 `||` 拼接在一起. + * 对于多个规则, 也允许使用 `||` 拼接. * 例如: * - `1.x || 2.x || 3.0.0` * - `<= 0.5.3 || >= 1.0.0` From 798425e6e8b0f89b374dcda238893f6cb70878f4 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Sun, 20 Sep 2020 13:55:44 +0800 Subject: [PATCH 02/23] Rename SemVersion.RangeRequirement.check to test --- .../console/internal/util/SemVersionInternal.kt | 6 +++--- .../net/mamoe/mirai/console/util/SemVersion.kt | 12 ++++++------ .../net/mamoe/mirai/console/util/TestSemVersion.kt | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/SemVersionInternal.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/SemVersionInternal.kt index f880a8ecd..718a12d09 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/SemVersionInternal.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/SemVersionInternal.kt @@ -91,8 +91,8 @@ internal object SemVersionInternal { private fun SemVersion.RangeRequirement.withRule(rule: String): SemVersion.RangeRequirement { return object : SemVersion.RangeRequirement { - override fun check(version: SemVersion): Boolean { - return this@withRule.check(version) + override fun test(version: SemVersion): Boolean { + return this@withRule.test(version) } override fun toString(): String { @@ -112,7 +112,7 @@ internal object SemVersionInternal { if (checks.size == 1) return checks[0] SemVersion.RangeRequirement { checks.forEach { rule -> - if (rule.check(it)) return@RangeRequirement true + if (rule.test(it)) return@RangeRequirement true } return@RangeRequirement false }.withRule(requirement) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt index 783becc0c..713e9dee4 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt @@ -62,7 +62,7 @@ public data class SemVersion internal constructor( */ public fun interface RangeRequirement { /** 在 [version] 满足此要求时返回 true */ - public fun check(version: SemVersion): Boolean + public fun test(version: SemVersion): Boolean } public object SemVersionAsStringSerializer : KSerializer by String.serializer().map( @@ -169,25 +169,25 @@ public data class SemVersion internal constructor( return SemVersionInternal.parseRangeRequirement(requirement) } - /** @see [RangeRequirement.check] */ + /** @see [RangeRequirement.test] */ @JvmStatic - public fun RangeRequirement.check(version: String): Boolean = check(parse(version)) + public fun RangeRequirement.test(version: String): Boolean = test(parse(version)) /** * 当满足 [requirement] 时返回 true, 否则返回 false */ @JvmStatic - public fun SemVersion.satisfies(requirement: RangeRequirement): Boolean = requirement.check(this) + public fun SemVersion.satisfies(requirement: RangeRequirement): Boolean = requirement.test(this) /** for Kotlin only */ @JvmStatic @JvmSynthetic - public operator fun RangeRequirement.contains(version: SemVersion): Boolean = check(version) + public operator fun RangeRequirement.contains(version: SemVersion): Boolean = test(version) /** for Kotlin only */ @JvmStatic @JvmSynthetic - public operator fun RangeRequirement.contains(version: String): Boolean = check(version) + public operator fun RangeRequirement.contains(version: String): Boolean = test(version) } @Transient diff --git a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/util/TestSemVersion.kt b/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/util/TestSemVersion.kt index 56d34ab71..b76d610e1 100644 --- a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/util/TestSemVersion.kt +++ b/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/util/TestSemVersion.kt @@ -14,7 +14,7 @@ package net.mamoe.mirai.console.util -import net.mamoe.mirai.console.util.SemVersion.Companion.check +import net.mamoe.mirai.console.util.SemVersion.Companion.test import org.junit.jupiter.api.Test internal class TestSemVersion { @@ -44,12 +44,12 @@ internal class TestSemVersion { @Test internal fun testRequirement() { fun SemVersion.RangeRequirement.assert(version: String): SemVersion.RangeRequirement { - assert(check(version)) { version } + assert(test(version)) { version } return this } fun SemVersion.RangeRequirement.assertFalse(version: String): SemVersion.RangeRequirement { - assert(!check(version)) { version } + assert(!test(version)) { version } return this } SemVersion.parseRangeRequirement("1.0") From 7a533d4667dd0a0b5babf1debf7e2f37c9537bf0 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 20 Sep 2020 13:56:12 +0800 Subject: [PATCH 03/23] Use lazy for SemVersion.toString --- .../mamoe/mirai/console/util/SemVersion.kt | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt index f07b8d5b9..939fe7ea6 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt @@ -188,23 +188,22 @@ public data class SemVersion internal constructor( } @Transient - private var toString: String? = null // For cache. - override fun toString(): String { - return toString ?: kotlin.run { - buildString { - mainVersion.joinTo(this, ".") - identifier?.let { identifier -> - append('-') - append(identifier) - } - metadata?.let { metadata -> - append('+') - append(metadata) - } - }.also { toString = it } + private val toString: String by lazy(LazyThreadSafetyMode.NONE) { + buildString { + mainVersion.joinTo(this, ".") + identifier?.let { identifier -> + append('-') + append(identifier) + } + metadata?.let { metadata -> + append('+') + append(metadata) + } } } + override fun toString(): String = toString + /** * 将 [SemVersion] 转为 Kotlin data class 风格的 [String] */ From 9c2a0abda55f856d2d34e18157404b60e2850984 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 20 Sep 2020 14:09:48 +0800 Subject: [PATCH 04/23] Move implementations to SemVersionInternal --- .../internal/util/SemVersionInternal.kt | 49 +++++++++++++++++ .../mamoe/mirai/console/util/SemVersion.kt | 52 +------------------ 2 files changed, 51 insertions(+), 50 deletions(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/SemVersionInternal.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/SemVersionInternal.kt index f880a8ecd..6d2da7ae5 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/SemVersionInternal.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/SemVersionInternal.kt @@ -32,6 +32,55 @@ internal object SemVersionInternal { } } + private val SEM_VERSION_REGEX = + """^(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$""".toRegex() + + /** 解析核心版本号, eg: `1.0.0` -> IntArray[1, 0, 0] */ + @JvmStatic + private fun String.parseMainVersion(): IntArray = + split('.').map { it.toInt() }.toIntArray() + + + fun parse(version: String): SemVersion { + if (!SEM_VERSION_REGEX.matches(version)) { + throw IllegalArgumentException("`$version` not a valid version") + } + var mainVersionEnd = 0 + kotlin.run { + val iterator = version.iterator() + while (iterator.hasNext()) { + val next = iterator.next() + if (next == '-' || next == '+') { + break + } + mainVersionEnd++ + } + } + var identifier: String? = null + var metadata: String? = null + if (mainVersionEnd != version.length) { + when (version[mainVersionEnd]) { + '-' -> { + val metadataSplitter = version.indexOf('+', startIndex = mainVersionEnd) + if (metadataSplitter == -1) { + identifier = version.substring(mainVersionEnd + 1) + } else { + identifier = version.substring(mainVersionEnd + 1, metadataSplitter) + metadata = version.substring(metadataSplitter + 1) + } + } + '+' -> { + metadata = version.substring(mainVersionEnd + 1) + } + } + } + return SemVersion( + mainVersion = version.substring(0, mainVersionEnd).parseMainVersion(), + identifier = identifier, + metadata = metadata + ) + } + @JvmStatic private fun String.parseRule(): SemVersion.RangeRequirement { val trimmed = trim() diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt index 939fe7ea6..cc75c416e 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt @@ -68,14 +68,6 @@ public data class SemVersion internal constructor( ) public companion object { - private val SEM_VERSION_REGEX = - """^(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$""".toRegex() - - /** 解析核心版本号, eg: `1.0.0` -> IntArray[1, 0, 0] */ - @JvmStatic - private fun String.parseMainVersion(): IntArray = - split('.').map { it.toInt() }.toIntArray() - /** * 解析一个版本号, 将会返回一个 [SemVersion], * 如果发生解析错误将会抛出一个 [IllegalArgumentException] 或者 [NumberFormatException] @@ -97,45 +89,7 @@ public data class SemVersion internal constructor( */ @Throws(IllegalArgumentException::class, NumberFormatException::class) @JvmStatic - public fun parse(version: String): SemVersion { - if (!SEM_VERSION_REGEX.matches(version)) { - throw IllegalArgumentException("`$version` not a valid version") - } - var mainVersionEnd = 0 - kotlin.run { - val iterator = version.iterator() - while (iterator.hasNext()) { - val next = iterator.next() - if (next == '-' || next == '+') { - break - } - mainVersionEnd++ - } - } - var identifier: String? = null - var metadata: String? = null - if (mainVersionEnd != version.length) { - when (version[mainVersionEnd]) { - '-' -> { - val metadataSplitter = version.indexOf('+', startIndex = mainVersionEnd) - if (metadataSplitter == -1) { - identifier = version.substring(mainVersionEnd + 1) - } else { - identifier = version.substring(mainVersionEnd + 1, metadataSplitter) - metadata = version.substring(metadataSplitter + 1) - } - } - '+' -> { - metadata = version.substring(mainVersionEnd + 1) - } - } - } - return SemVersion( - mainVersion = version.substring(0, mainVersionEnd).parseMainVersion(), - identifier = identifier, - metadata = metadata - ) - } + public fun parse(version: String): SemVersion = SemVersionInternal.parse(version) /** * 解析一条依赖需求描述, 在无法解析的时候抛出 [IllegalArgumentException] @@ -162,9 +116,7 @@ public data class SemVersion internal constructor( */ @Throws(IllegalArgumentException::class) @JvmStatic - public fun parseRangeRequirement(requirement: String): RangeRequirement { - return SemVersionInternal.parseRangeRequirement(requirement) - } + public fun parseRangeRequirement(requirement: String): RangeRequirement = SemVersionInternal.parseRangeRequirement(requirement) /** @see [RangeRequirement.check] */ @JvmStatic From 44598aa1fae78aa6acbd55ed54d36fb0c969dae9 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Sun, 20 Sep 2020 14:10:08 +0800 Subject: [PATCH 05/23] Convert receiver to parameter --- .../mirai/console/internal/util/SemVersionInternal.kt | 10 +++++----- .../kotlin/net/mamoe/mirai/console/util/SemVersion.kt | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/SemVersionInternal.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/SemVersionInternal.kt index 718a12d09..02b365999 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/SemVersionInternal.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/SemVersionInternal.kt @@ -120,23 +120,23 @@ internal object SemVersionInternal { } @JvmStatic - fun SemVersion.compareInternal(other: SemVersion): Int { + fun compareInternal(source: SemVersion, other: SemVersion): Int { // ignored metadata in comparing // If $this equals $other (without metadata), // return same. - if (other.mainVersion.contentEquals(mainVersion) && identifier == other.identifier) { + if (other.mainVersion.contentEquals(source.mainVersion) && source.identifier == other.identifier) { return 0 } fun IntArray.getSafe(index: Int) = getOrElse(index) { 0 } // Compare main-version - for (index in 0 until (max(mainVersion.size, other.mainVersion.size))) { - val result = mainVersion.getSafe(index).compareTo(other.mainVersion.getSafe(index)) + for (index in 0 until (max(source.mainVersion.size, other.mainVersion.size))) { + val result = source.mainVersion.getSafe(index).compareTo(other.mainVersion.getSafe(index)) if (result != 0) return result } // If main-versions are same. - var identifier0 = identifier + var identifier0 = source.identifier var identifier1 = other.identifier // If anyone doesn't have the identifier... if (identifier0 == null || identifier1 == null) { diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt index 77cd0746a..2610cfb6e 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt @@ -233,6 +233,6 @@ public data class SemVersion internal constructor( * if it's greater than [other]. */ public override operator fun compareTo(other: SemVersion): Int { - return SemVersionInternal.run { compareInternal(other) } + return SemVersionInternal.run { compareInternal(this@SemVersion, other) } } } From 30a10f56d0cdbcbb9d9e49ba286a629e3a310be2 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 20 Sep 2020 14:25:54 +0800 Subject: [PATCH 06/23] Update docs --- backend/codegen/README.md | 6 +++++ ...ngCodegen.kt => ValuePluginDataCodegen.kt} | 0 backend/mirai-console/README.md | 3 +++ backend/mirai-console/build.gradle.kts | 1 - docs/Contributing.md | 23 +++++++++++++++++++ 5 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 backend/codegen/README.md rename backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/{ValueSettingCodegen.kt => ValuePluginDataCodegen.kt} (100%) create mode 100644 backend/mirai-console/README.md diff --git a/backend/codegen/README.md b/backend/codegen/README.md new file mode 100644 index 000000000..013c05c7b --- /dev/null +++ b/backend/codegen/README.md @@ -0,0 +1,6 @@ +# Mirai Console - Backend.codegen + +后端代码生成模块,用于最小化重复代码的人工成本。 + +- `MessageScope` 代码生成: [MessageScopeCodegen.kt: Line 33](src/main/kotlin/net/mamoe/mirai/console/codegen/MessageScopeCodegen.kt#L33) +- `Value` 和 `PluginData` 相关代码生成: [ValueSettingCodegen.kt: Line 18](src/main/kotlin/net/mamoe/mirai/console/codegen/ValuePluginDataCodegen.kt#L18) diff --git a/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/ValueSettingCodegen.kt b/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/ValuePluginDataCodegen.kt similarity index 100% rename from backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/ValueSettingCodegen.kt rename to backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/ValuePluginDataCodegen.kt diff --git a/backend/mirai-console/README.md b/backend/mirai-console/README.md new file mode 100644 index 000000000..451b5aaee --- /dev/null +++ b/backend/mirai-console/README.md @@ -0,0 +1,3 @@ +# Mirai Console - Backend + +Mirai Console 后端模块. 发布为 `net.mamoe:mirai-console`. \ No newline at end of file diff --git a/backend/mirai-console/build.gradle.kts b/backend/mirai-console/build.gradle.kts index 745d77d1a..d520dd69e 100644 --- a/backend/mirai-console/build.gradle.kts +++ b/backend/mirai-console/build.gradle.kts @@ -69,7 +69,6 @@ dependencies { smartApi(kotlinx("coroutines-jdk8", Versions.coroutines)) smartApi("net.mamoe.yamlkt:yamlkt:${Versions.yamlkt}") - smartApi("com.vdurmont:semver4j:3.1.0") testApi("net.mamoe:mirai-core-qqandroid:${Versions.core}") testApi(kotlin("stdlib-jdk8")) diff --git a/docs/Contributing.md b/docs/Contributing.md index d90a8dd4c..a562a15d4 100644 --- a/docs/Contributing.md +++ b/docs/Contributing.md @@ -1,2 +1,25 @@ # Mirai Console - Contributing +感谢你来到这里,感谢你对 Mirai Console 做的一切贡献。 + +## 开发 Mirai Console + +### 模块 + +Mirai Console 项目由四个模块组成:后端,前端,Gradle 插件,Intellij 插件。 + +``` +/ +|--- backend 后端 +| |--- codegen 后端代码生成工具 +| `--- mirai-console 后端主模块, 发布为 net.mamoe:mirai-console +|--- buildSrc 项目构建 +|--- frontend 前端 +| `--- mirai-console-terminal 终端前端,发布为 net.mamoe:mirai-console-terminal +`--- tools 开发工具 + |--- compiler-common 编译器通用模块 + |--- gradle-plugin Gradle 插件,发布为 net.mamoe.mirai-console + `--- intellij-plugin IntelliJ 平台 IDE 插件,发布为 Mirai Console +``` + +请前往各模块内的 README.md 查看详细说明。 \ No newline at end of file From 6912982949765dcbfaaac3fcba4d36506ac6ac30 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 20 Sep 2020 14:31:27 +0800 Subject: [PATCH 07/23] Fix docs --- .../net/mamoe/mirai/console/plugin/jvm/JvmPluginLoader.kt | 2 +- .../net/mamoe/mirai/console/plugin/loader/PluginLoader.kt | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginLoader.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginLoader.kt index 66986ee9e..30b4e7f34 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginLoader.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginLoader.kt @@ -15,7 +15,7 @@ import net.mamoe.mirai.console.internal.plugin.BuiltInJvmPluginLoaderImpl import net.mamoe.mirai.console.plugin.loader.FilePluginLoader /** - * 内建的 Jar (JVM) 插件加载器 + * JVM 插件加载器 */ public interface JvmPluginLoader : CoroutineScope, FilePluginLoader { /** diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/loader/PluginLoader.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/loader/PluginLoader.kt index 04cae8515..280ce144b 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/loader/PluginLoader.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/loader/PluginLoader.kt @@ -61,10 +61,9 @@ public interface PluginLoader

{ * @throws PluginLoadException 在加载插件遇到意料之中的错误时抛出 (如无法读取插件信息等). * * @see PluginDescription 插件描述 - * @see getPluginDescription 无 receiver, 接受参数的版本. */ @Throws(PluginLoadException::class) - public fun getPluginDescription(plugin: P): D // Java signature: `public D getDescription(P)` + public fun getPluginDescription(plugin: P): D /** * 主动加载一个插件 (实例), 但不 [启用][enable] 它. 返回加载成功的主类实例 From a6411005f59f0b76d7bab789d5050669f85b1fe3 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 20 Sep 2020 15:25:27 +0800 Subject: [PATCH 08/23] Update docs --- docs/Contributing.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/Contributing.md b/docs/Contributing.md index a562a15d4..f4e4befbb 100644 --- a/docs/Contributing.md +++ b/docs/Contributing.md @@ -22,4 +22,11 @@ Mirai Console 项目由四个模块组成:后端,前端,Gradle 插件,In `--- intellij-plugin IntelliJ 平台 IDE 插件,发布为 Mirai Console ``` -请前往各模块内的 README.md 查看详细说明。 \ No newline at end of file +请前往各模块内的 README.md 查看详细说明。 + +### 构建 +```shell script +gradlew build +``` + +首次加载和构建 mirai-console 项目可能要花费数小时时间。 \ No newline at end of file From eb7cd3811db83f9aae48083738eaa4ef2a3e7e93 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Sun, 20 Sep 2020 18:01:02 +0800 Subject: [PATCH 09/23] Deploy SemVersion --- backend/mirai-console/build.gradle.kts | 4 +- .../net/mamoe/mirai/console/MiraiConsole.kt | 4 +- .../MiraiConsoleFrontEndDescription.kt | 7 +- .../internal/MiraiConsoleBuildConstants.kt | 6 +- .../MiraiConsoleImplementationBridge.kt | 4 +- .../internal/plugin/PluginManagerImpl.kt | 1 + .../net/mamoe/mirai/console/plugin/Plugin.kt | 4 +- .../plugin/description/PluginDependency.kt | 4 +- .../plugin/description/PluginDescription.kt | 4 +- .../plugin/description/VersionRequirement.kt | 242 ------------------ .../plugin/jvm/JvmPluginDescription.kt | 34 ++- .../mamoe/mirai/console/util/SemVersion.kt | 3 +- .../util/SemVersionRangeRequirementBuilder.kt | 90 +++++++ .../mamoe/mirai/console/TestMiraiConosle.kt | 6 +- .../MiraiConsoleImplementationTerminal.kt | 8 +- 15 files changed, 133 insertions(+), 288 deletions(-) delete mode 100644 backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/VersionRequirement.kt create mode 100644 backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersionRangeRequirementBuilder.kt diff --git a/backend/mirai-console/build.gradle.kts b/backend/mirai-console/build.gradle.kts index d520dd69e..6aad5bba4 100644 --- a/backend/mirai-console/build.gradle.kts +++ b/backend/mirai-console/build.gradle.kts @@ -101,8 +101,8 @@ tasks { })""" } .replace( - Regex("""val version: Semver = Semver\(".*", Semver.SemverType.LOOSE\)""") - ) { """val version: Semver = Semver("${project.version}", Semver.SemverType.LOOSE)""" } + Regex("""val version: SemVersion = SemVersion.parse\(".*"\)""") + ) { """val version: SemVersion = SemVersion.parse("${project.version}")""" } ) } } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt index 15f4b9a01..42106685e 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsole.kt @@ -12,7 +12,6 @@ package net.mamoe.mirai.console -import com.vdurmont.semver4j.Semver import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job import net.mamoe.mirai.Bot @@ -29,6 +28,7 @@ import net.mamoe.mirai.console.plugin.loader.PluginLoader import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.console.util.ConsoleInternalApi import net.mamoe.mirai.console.util.CoroutineScopeUtils.childScopeContext +import net.mamoe.mirai.console.util.SemVersion import net.mamoe.mirai.utils.BotConfiguration import net.mamoe.mirai.utils.MiraiLogger import java.io.File @@ -79,7 +79,7 @@ public interface MiraiConsole : CoroutineScope { /** * 此 Console 后端版本号 */ - public val version: Semver + public val version: SemVersion @ConsoleExperimentalApi diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleFrontEndDescription.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleFrontEndDescription.kt index 21c1f8103..6b7426d4d 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleFrontEndDescription.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleFrontEndDescription.kt @@ -9,7 +9,8 @@ package net.mamoe.mirai.console -import com.vdurmont.semver4j.Semver +import net.mamoe.mirai.console.util.SemVersion + /** * 有关前端实现的信息 @@ -28,7 +29,7 @@ public interface MiraiConsoleFrontEndDescription { /** * 此前端实现的名称 */ - public val version: Semver + public val version: SemVersion /** * 兼容的 [MiraiConsole] 后端版本号 @@ -37,7 +38,7 @@ public interface MiraiConsoleFrontEndDescription { * * 返回 `null` 表示禁止 [MiraiConsole] 后端检查版本兼容性. */ - public val compatibleBackendVersion: Semver? get() = null + public val compatibleBackendVersion: SemVersion? get() = null /** * 返回显示在 [MiraiConsole] 启动时的信息 diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleBuildConstants.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleBuildConstants.kt index 19dd40076..f1889aeab 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleBuildConstants.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleBuildConstants.kt @@ -9,13 +9,13 @@ package net.mamoe.mirai.console.internal -import com.vdurmont.semver4j.Semver +import net.mamoe.mirai.console.util.SemVersion import java.time.Instant internal object MiraiConsoleBuildConstants { // auto-filled on build (task :mirai-console:fillBuildConstants) @JvmStatic - val buildDate: Instant = Instant.ofEpochSecond(1600522812) + val buildDate: Instant = Instant.ofEpochSecond(1600596035) @JvmStatic - val version: Semver = Semver("1.0-RC-dev-28", Semver.SemverType.LOOSE) + val version: SemVersion = SemVersion.parse("1.0-RC-dev-28") } 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 0751b2432..175af2331 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 @@ -11,7 +11,6 @@ package net.mamoe.mirai.console.internal -import com.vdurmont.semver4j.Semver import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job @@ -47,6 +46,7 @@ import net.mamoe.mirai.console.plugin.jvm.AbstractJvmPlugin import net.mamoe.mirai.console.plugin.loader.PluginLoader import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.console.util.ConsoleInput +import net.mamoe.mirai.console.util.SemVersion import net.mamoe.mirai.utils.* import java.nio.file.Path import java.time.Instant @@ -66,7 +66,7 @@ internal object MiraiConsoleImplementationBridge : CoroutineScope, MiraiConsoleI private val instance: MiraiConsoleImplementation by MiraiConsoleImplementation.Companion::instance override val buildDate: Instant by MiraiConsoleBuildConstants::buildDate - override val version: Semver by MiraiConsoleBuildConstants::version + override val version: SemVersion by MiraiConsoleBuildConstants::version override val rootPath: Path by instance::rootPath override val frontEndDescription: MiraiConsoleFrontEndDescription by instance::frontEndDescription diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/PluginManagerImpl.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/PluginManagerImpl.kt index f53ebac6f..2f15ba42a 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/PluginManagerImpl.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/PluginManagerImpl.kt @@ -27,6 +27,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.utils.info import java.io.File import java.nio.file.Path diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/Plugin.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/Plugin.kt index 55a00f667..8db84c890 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/Plugin.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/Plugin.kt @@ -11,7 +11,6 @@ package net.mamoe.mirai.console.plugin -import com.vdurmont.semver4j.Semver import net.mamoe.mirai.console.command.CommandOwner import net.mamoe.mirai.console.plugin.PluginManager.INSTANCE.disable import net.mamoe.mirai.console.plugin.PluginManager.INSTANCE.enable @@ -20,6 +19,7 @@ import net.mamoe.mirai.console.plugin.description.PluginDependency import net.mamoe.mirai.console.plugin.description.PluginDescription import net.mamoe.mirai.console.plugin.jvm.JvmPlugin import net.mamoe.mirai.console.plugin.loader.PluginLoader +import net.mamoe.mirai.console.util.SemVersion /** * 表示一个 mirai-console 插件. @@ -62,7 +62,7 @@ public inline val Plugin.name: String get() = this.description.name /** * 获取 [PluginDescription.version] */ -public inline val Plugin.version: Semver get() = this.description.version +public inline val Plugin.version: SemVersion get() = this.description.version /** * 获取 [PluginDescription.info] diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDependency.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDependency.kt index 49bfad6ff..d22883093 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDependency.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDependency.kt @@ -11,6 +11,8 @@ package net.mamoe.mirai.console.plugin.description +import net.mamoe.mirai.console.util.SemVersion + /** * 插件的一个依赖的信息. * @@ -29,7 +31,7 @@ public data class PluginDependency @JvmOverloads constructor( * ### 示例 * `Requirement.buildIvy("[1.0, 2.0)")` */ - public val versionRequirement: VersionRequirement? = null, + public val versionRequirement: SemVersion.RangeRequirement? = null, /** * 若为 `false`, 插件在找不到此依赖时也能正常加载. */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDescription.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDescription.kt index 85c199628..ca9267495 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDescription.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDescription.kt @@ -9,10 +9,10 @@ package net.mamoe.mirai.console.plugin.description -import com.vdurmont.semver4j.Semver import net.mamoe.mirai.console.compiler.common.ResolveContext import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.* import net.mamoe.mirai.console.plugin.Plugin +import net.mamoe.mirai.console.util.SemVersion /** @@ -93,7 +93,7 @@ public interface PluginDescription { * @see Semver 语义化版本. 允许 [宽松][Semver.SemverType.LOOSE] 类型版本. */ @ResolveContext(PLUGIN_VERSION) - public val version: Semver + public val version: SemVersion /** * 插件信息, 允许为空 diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/VersionRequirement.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/VersionRequirement.kt deleted file mode 100644 index e3a3e6680..000000000 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/VersionRequirement.kt +++ /dev/null @@ -1,242 +0,0 @@ -package net.mamoe.mirai.console.plugin.description - -import com.vdurmont.semver4j.Requirement -import com.vdurmont.semver4j.Semver - -public sealed class VersionRequirement { - public abstract operator fun contains(version: Semver): Boolean - public fun contains(version: String): Boolean = contains(Semver(version, Semver.SemverType.LOOSE)) - - public class Exact - @Deprecated("Semver 将会在 1.0-RC 被替换为 Console 自己实现的版本。请临时使用 String。", level = DeprecationLevel.ERROR) - constructor( - version: Semver, - ) : VersionRequirement() { - @Deprecated("Semver 将会在 1.0-RC 被替换为 Console 自己实现的版本。请临时使用 String。", level = DeprecationLevel.ERROR) - public val version: Semver = version.toStrict() - - @Suppress("DEPRECATION_ERROR") - public constructor(version: String) : this(Semver(version, Semver.SemverType.LOOSE)) - - @Suppress("DEPRECATION_ERROR") - override fun contains(version: Semver): Boolean = this.version.isEquivalentTo(version.toStrict()) - } - - public data class MatchesNpmPattern( - val pattern: String, - ) : VersionRequirement() { - private val requirement = Requirement.buildNPM(pattern) - override fun contains(version: Semver): Boolean = requirement.isSatisfiedBy(version.toStrict()) - } - - public data class MatchesIvyPattern( - val pattern: String, - ) : VersionRequirement() { - private val requirement = Requirement.buildIvy(pattern) - override fun contains(version: Semver): Boolean = requirement.isSatisfiedBy(version.toStrict()) - } - - - public data class MatchesCocoapodsPattern( - val pattern: String, - ) : VersionRequirement() { - private val requirement = Requirement.buildCocoapods(pattern) - override fun contains(version: Semver): Boolean = requirement.isSatisfiedBy(version.toStrict()) - } - - public abstract class Custom : VersionRequirement() - - @Suppress("MemberVisibilityCanBePrivate") - public class InRange( - begin: Semver, - public val beginInclusive: Boolean, - end: Semver, - public val endInclusive: Boolean, - ) : VersionRequirement() { - public val end: Semver = end.toStrict() - public val begin: Semver = begin.toStrict() - - public constructor( - begin: String, - beginInclusive: Boolean, - end: Semver, - endInclusive: Boolean, - ) : this(Semver(begin, Semver.SemverType.LOOSE), beginInclusive, end, endInclusive) - - public constructor( - begin: String, - beginInclusive: Boolean, - end: String, - endInclusive: Boolean, - ) : this(Semver(begin, Semver.SemverType.LOOSE), - beginInclusive, - Semver(end, Semver.SemverType.LOOSE), - endInclusive) - - public constructor( - begin: Semver, - beginInclusive: Boolean, - end: String, - endInclusive: Boolean, - ) : this(begin, beginInclusive, Semver(end, Semver.SemverType.LOOSE), endInclusive) - - override fun contains(version: Semver): Boolean { - val strict = version.toStrict() - return if (beginInclusive) { - strict.isGreaterThanOrEqualTo(begin) - } else { - strict.isGreaterThan(begin) - } && if (endInclusive) { - strict.isLowerThanOrEqualTo(end) - } else { - strict.isLowerThan(end) - } - } - - override fun toString(): String { - return buildString { - append(if (beginInclusive) "[" else "(") - append(begin) - append(",") - append(end) - append(if (endInclusive) "]" else ")") - } - } - } - - - @Suppress("unused", "DeprecatedCallableAddReplaceWith") - public class Builder { - @Suppress("DEPRECATION_ERROR") - @Deprecated("Semver 将会在 1.0-RC 被替换为 Console 自己实现的版本。请临时使用 String。", level = DeprecationLevel.ERROR) - @ILoveKafuuChinoForever - public fun exact(version: Semver): VersionRequirement = Exact(version) - - @ILoveKafuuChinoForever - public fun exact(version: String): VersionRequirement = Exact(version) - - @Deprecated("Semver 将会在 1.0-RC 被替换为 Console 自己实现的版本。请临时使用 String。", level = DeprecationLevel.ERROR) - @ILoveKafuuChinoForever - public fun custom(checker: (version: Semver) -> Boolean): VersionRequirement { - return object : Custom() { - override fun contains(version: Semver): Boolean = checker(version) - } - } - - /** - * @see Semver.SemverType.NPM - */ - @ILoveKafuuChinoForever - public fun npmPattern(versionPattern: String): VersionRequirement { - return MatchesNpmPattern(versionPattern) - } - - /** - * @see Semver.SemverType.IVY - */ - @ILoveKafuuChinoForever - public fun ivyPattern(versionPattern: String): VersionRequirement { - return MatchesIvyPattern(versionPattern) - } - - /** - * @see Semver.SemverType.COCOAPODS - */ - @ILoveKafuuChinoForever - public fun cocoapodsPattern(versionPattern: String): VersionRequirement { - return MatchesCocoapodsPattern(versionPattern) - } - - @Deprecated("Semver 将会在 1.0-RC 被替换为 Console 自己实现的版本。请临时使用 String。", level = DeprecationLevel.ERROR) - @ILoveKafuuChinoForever - public fun range( - begin: Semver, - beginInclusive: Boolean, - end: Semver, - endInclusive: Boolean, - ): VersionRequirement = InRange(begin, beginInclusive, end, endInclusive) - - @Deprecated("Semver 将会在 1.0-RC 被替换为 Console 自己实现的版本。请临时使用 String。", level = DeprecationLevel.ERROR) - @ILoveKafuuChinoForever - public fun range( - begin: String, - beginInclusive: Boolean, - end: Semver, - endInclusive: Boolean, - ): VersionRequirement = InRange(begin, beginInclusive, end, endInclusive) - - @Deprecated("Semver 将会在 1.0-RC 被替换为 Console 自己实现的版本。请临时使用 String。", level = DeprecationLevel.ERROR) - @ILoveKafuuChinoForever - public fun range( - begin: Semver, - beginInclusive: Boolean, - end: String, - endInclusive: Boolean, - ): VersionRequirement = InRange(begin, beginInclusive, end, endInclusive) - - @ILoveKafuuChinoForever - public fun range( - begin: String, - beginInclusive: Boolean, - end: String, - endInclusive: Boolean, - ): VersionRequirement = InRange(begin, beginInclusive, end, endInclusive) - - - @Deprecated("Semver 将会在 1.0-RC 被替换为 Console 自己实现的版本。请临时使用 String。", level = DeprecationLevel.ERROR) - @ILoveKafuuChinoForever - public operator fun Semver.rangeTo(endInclusive: Semver): VersionRequirement { - return InRange(this, true, endInclusive, true) - } - - @ILoveKafuuChinoForever - public operator fun Semver.rangeTo(endInclusive: String): VersionRequirement { - return InRange(this, true, Semver(endInclusive, Semver.SemverType.LOOSE), true) - } - - @ILoveKafuuChinoForever - public operator fun String.rangeTo(endInclusive: String): VersionRequirement { - return InRange(Semver(this, Semver.SemverType.LOOSE), - true, - Semver(endInclusive, Semver.SemverType.LOOSE), - true) - } - - @Deprecated("Semver 将会在 1.0-RC 被替换为 Console 自己实现的版本。请临时使用 String。", level = DeprecationLevel.ERROR) - @ILoveKafuuChinoForever - public operator fun String.rangeTo(endInclusive: Semver): VersionRequirement { - return InRange(Semver(this, Semver.SemverType.LOOSE), true, endInclusive, true) - } - - - @Deprecated("Semver 将会在 1.0-RC 被替换为 Console 自己实现的版本。请临时使用 String。", level = DeprecationLevel.ERROR) - @ILoveKafuuChinoForever - public infix fun Semver.until(endExclusive: Semver): VersionRequirement { - return InRange(this, true, endExclusive, false) - } - - @ILoveKafuuChinoForever - public infix fun Semver.until(endExclusive: String): VersionRequirement { - return InRange(this, true, Semver(endExclusive, Semver.SemverType.LOOSE), false) - } - - @ILoveKafuuChinoForever - public infix fun String.until(endExclusive: String): VersionRequirement { - return InRange(Semver(this, Semver.SemverType.LOOSE), - true, - Semver(endExclusive, Semver.SemverType.LOOSE), - false) - } - - @Deprecated("Semver 将会在 1.0-RC 被替换为 Console 自己实现的版本。请临时使用 String。", level = DeprecationLevel.ERROR) - @ILoveKafuuChinoForever - public infix fun String.until(endExclusive: Semver): VersionRequirement { - return InRange(Semver(this, Semver.SemverType.LOOSE), true, endExclusive, false) - } - - @Suppress("SpellCheckingInspection") - @Retention(AnnotationRetention.BINARY) - @DslMarker - internal annotation class ILoveKafuuChinoForever - } -} \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginDescription.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginDescription.kt index 0b61101bc..242249f21 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginDescription.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginDescription.kt @@ -11,12 +11,12 @@ package net.mamoe.mirai.console.plugin.jvm -import com.vdurmont.semver4j.Semver 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.plugin.description.VersionRequirement +import net.mamoe.mirai.console.util.SemVersion +import net.mamoe.mirai.console.util.SemVersionRangeRequirementBuilder /** * JVM 插件的描述. 通常作为 `plugin.yml` @@ -66,7 +66,7 @@ public interface JvmPluginDescription : PluginDescription { /** * @see [PluginDescription.version] */ - @ResolveContext(PLUGIN_VERSION) version: Semver, + @ResolveContext(PLUGIN_VERSION) version: SemVersion, /** * @see [PluginDescription.name] */ @@ -97,17 +97,15 @@ public interface JvmPluginDescription : PluginDescription { * * @see [JvmPluginDescription.invoke] */ -public class JvmPluginDescriptionBuilder -@Deprecated("Semver 将会在 1.0-RC 被替换为 Console 自己实现的版本。请临时使用 String。", level = DeprecationLevel.ERROR) -constructor( +public class JvmPluginDescriptionBuilder( private var id: String, - private var version: Semver, + private var version: SemVersion, ) { @Suppress("DEPRECATION_ERROR") public constructor( @ResolveContext(PLUGIN_NAME) id: String, @ResolveContext(PLUGIN_VERSION) version: String, - ) : this(id, Semver(version, Semver.SemverType.LOOSE)) + ) : this(id, SemVersion.parse(version)) private var name: String = id private var author: String = "" @@ -118,14 +116,12 @@ constructor( public fun name(@ResolveContext(PLUGIN_NAME) value: String): JvmPluginDescriptionBuilder = apply { this.name = value.trim() } - @Deprecated("Semver 将会在 1.0-RC 被替换为 Console 自己实现的版本。请临时使用 String。", level = DeprecationLevel.ERROR) @ILoveKuriyamaMiraiForever public fun version(@ResolveContext(PLUGIN_VERSION) value: String): JvmPluginDescriptionBuilder = - apply { this.version = Semver(value, Semver.SemverType.LOOSE) } + apply { this.version = SemVersion.parse(value) } - @Deprecated("Semver 将会在 1.0-RC 被替换为 Console 自己实现的版本。请临时使用 String。", level = DeprecationLevel.ERROR) @ILoveKuriyamaMiraiForever - public fun version(@ResolveContext(PLUGIN_VERSION) value: Semver): JvmPluginDescriptionBuilder = + public fun version(@ResolveContext(PLUGIN_VERSION) value: SemVersion): JvmPluginDescriptionBuilder = apply { this.version = value } @ILoveKuriyamaMiraiForever @@ -161,7 +157,7 @@ constructor( public fun dependsOn( @ResolveContext(PLUGIN_ID) pluginId: String, isOptional: Boolean = false, - versionRequirement: VersionRequirement, + versionRequirement: SemVersion.RangeRequirement, ): JvmPluginDescriptionBuilder = apply { this.dependencies.add(PluginDependency(pluginId, versionRequirement, isOptional)) } @@ -174,7 +170,7 @@ constructor( @ILoveKuriyamaMiraiForever public fun dependsOn( @ResolveContext(PLUGIN_ID) pluginId: String, - versionRequirement: VersionRequirement, + versionRequirement: SemVersion.RangeRequirement, ): JvmPluginDescriptionBuilder = apply { this.dependencies.add(PluginDependency(pluginId, versionRequirement, false)) } @@ -203,17 +199,17 @@ constructor( * ``` * * @see PluginDependency - * @see VersionRequirement.Builder + * @see SemVersionRangeRequirementBuilder */ @ILoveKuriyamaMiraiForever public fun dependsOn( @ResolveContext(PLUGIN_ID) pluginId: String, isOptional: Boolean = false, - versionRequirement: VersionRequirement.Builder.() -> VersionRequirement, + versionRequirement: SemVersionRangeRequirementBuilder.() -> SemVersion.RangeRequirement, ): JvmPluginDescriptionBuilder = apply { this.dependencies.add(PluginDependency(pluginId, - VersionRequirement.Builder().run(versionRequirement), + SemVersionRangeRequirementBuilder.run(versionRequirement), isOptional)) } @@ -259,7 +255,7 @@ public data class SimpleJvmPluginDescription ) @JvmOverloads public constructor( public override val name: String, - public override val version: Semver, + public override val version: SemVersion, public override val id: String = name, public override val author: String = "", public override val info: String = "", @@ -285,7 +281,7 @@ public data class SimpleJvmPluginDescription author: String = "", info: String = "", dependencies: Set = setOf(), - ) : this(name, Semver(version, Semver.SemverType.LOOSE), id, author, info, dependencies) + ) : this(name, SemVersion.parse(version), id, author, info, dependencies) init { require(!name.contains(':')) { "':' is forbidden in plugin name" } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt index 56e7ac81e..38903ccbd 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt @@ -20,6 +20,7 @@ import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializable import kotlinx.serialization.Transient import kotlinx.serialization.builtins.serializer +import net.mamoe.mirai.console.compiler.common.ResolveContext import net.mamoe.mirai.console.internal.data.map import net.mamoe.mirai.console.internal.util.SemVersionInternal import net.mamoe.mirai.console.util.SemVersion.Companion.equals @@ -89,7 +90,7 @@ public data class SemVersion internal constructor( */ @Throws(IllegalArgumentException::class, NumberFormatException::class) @JvmStatic - public fun parse(version: String): SemVersion = SemVersionInternal.parse(version) + public fun parse(@ResolveContext(ResolveContext.Kind.PLUGIN_VERSION) version: String): SemVersion = SemVersionInternal.parse(version) /** * 解析一条依赖需求描述, 在无法解析的时候抛出 [IllegalArgumentException] diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersionRangeRequirementBuilder.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersionRangeRequirementBuilder.kt new file mode 100644 index 000000000..ec4d663a4 --- /dev/null +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersionRangeRequirementBuilder.kt @@ -0,0 +1,90 @@ +/* + * 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.util + +/** + * 构造 [SemVersion.RangeRequirement] 的 DSL + */ +public object SemVersionRangeRequirementBuilder { + /** @see [SemVersion.parseRangeRequirement] */ + @ILoveHim188moeForever + public fun parse(rule: String): SemVersion.RangeRequirement = SemVersion.parseRangeRequirement(rule) + + @ILoveHim188moeForever + public infix fun SemVersion.RangeRequirement.or(other: SemVersion.RangeRequirement): SemVersion.RangeRequirement { + return object : SemVersion.RangeRequirement { + override fun test(version: SemVersion): Boolean { + return this@or.test(version) || other.test(version) + } + + override fun toString(): String { + return "(${this@or}) or ($other)" + } + } + } + + @ILoveHim188moeForever + public infix fun String.or(other: String): SemVersion.RangeRequirement = parse(this) or parse(other) + + @ILoveHim188moeForever + public infix fun SemVersion.RangeRequirement.or(other: String): SemVersion.RangeRequirement = or(parse(other)) + + @ILoveHim188moeForever + public infix fun String.or(other: SemVersion.RangeRequirement): SemVersion.RangeRequirement = parse(this) or other + + @ILoveHim188moeForever + public infix fun SemVersion.RangeRequirement.and(other: SemVersion.RangeRequirement): SemVersion.RangeRequirement { + return object : SemVersion.RangeRequirement { + override fun test(version: SemVersion): Boolean { + return this@and.test(version) && other.test(version) + } + + override fun toString(): String { + return "(${this@and}) or ($other)" + } + } + } + + @ILoveHim188moeForever + public infix fun String.and(other: String): SemVersion.RangeRequirement = parse(this) and parse(other) + + @ILoveHim188moeForever + public infix fun SemVersion.RangeRequirement.and(other: String): SemVersion.RangeRequirement = and(parse(other)) + + @ILoveHim188moeForever + public infix fun String.and(other: SemVersion.RangeRequirement): SemVersion.RangeRequirement = parse(this) and other + + @Suppress("NOTHING_TO_INLINE") + @ILoveHim188moeForever + public inline fun custom(rule: SemVersion.RangeRequirement): SemVersion.RangeRequirement = rule + + /** + * 标注一个 [SemVersionRangeRequirementBuilder] DSL + */ + @Suppress("SpellCheckingInspection") + @Retention(AnnotationRetention.BINARY) + @DslMarker + internal annotation class ILoveHim188moeForever + + /** [SemVersionRangeRequirementBuilder] 的使用示例 */ + @Suppress("unused") + private class ExampleOfBuilder { + val e1 = SemVersionRangeRequirementBuilder.run { + "1.0.0" or "1.1.5" + } + val e2 = SemVersionRangeRequirementBuilder.run { + parse("> 1.0.0") and parse("< 1.2.3") + } + val e3 = SemVersionRangeRequirementBuilder.run { + ("> 1.0.0" and "< 1.2.3") or "2.0.0" + } + } +} \ 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 8afa90d9a..87eda59e8 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 @@ -9,7 +9,6 @@ package net.mamoe.mirai.console -import com.vdurmont.semver4j.Semver import kotlinx.coroutines.* import net.mamoe.mirai.console.MiraiConsoleImplementation.Companion.start import net.mamoe.mirai.console.command.CommandManager @@ -20,6 +19,7 @@ import net.mamoe.mirai.console.plugin.loader.PluginLoader import net.mamoe.mirai.console.util.ConsoleExperimentalApi 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 @@ -43,8 +43,8 @@ fun initTestEnvironment() { get() = "Test" override val vendor: String get() = "Test" - override val version: Semver - get() = Semver("1.0.0") + override val version: SemVersion + get() = SemVersion.parse("1.0.0") } override val builtInPluginLoaders: List>> = listOf(lazy { JvmPluginLoader }) 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 b1af02164..c6d790a76 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 @@ -23,7 +23,6 @@ package net.mamoe.mirai.console.terminal -import com.vdurmont.semver4j.Semver import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.CoroutineName @@ -39,10 +38,7 @@ import net.mamoe.mirai.console.plugin.loader.PluginLoader import net.mamoe.mirai.console.terminal.ConsoleInputImpl.requestInput import net.mamoe.mirai.console.terminal.noconsole.AllEmptyLineReader import net.mamoe.mirai.console.terminal.noconsole.NoConsole -import net.mamoe.mirai.console.util.ConsoleExperimentalApi -import net.mamoe.mirai.console.util.ConsoleInput -import net.mamoe.mirai.console.util.ConsoleInternalApi -import net.mamoe.mirai.console.util.NamedSupervisorJob +import net.mamoe.mirai.console.util.* import net.mamoe.mirai.utils.* import org.fusesource.jansi.Ansi import org.jline.reader.LineReader @@ -155,7 +151,7 @@ val terminal: Terminal = run { private object ConsoleFrontEndDescImpl : MiraiConsoleFrontEndDescription { override val name: String get() = "Terminal" override val vendor: String get() = "Mamoe Technologies" - override val version: Semver = net.mamoe.mirai.console.internal.MiraiConsoleBuildConstants.version + override val version: SemVersion = net.mamoe.mirai.console.internal.MiraiConsoleBuildConstants.version } private val ANSI_RESET = Ansi().reset().toString() From e26e98d0303ce14a525f4c9ee15d13d3d70fd8ed Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 20 Sep 2020 18:54:51 +0800 Subject: [PATCH 10/23] Rename SemVersion.Companion.parse to SemVersion.Companion.invoke --- .../internal/MiraiConsoleBuildConstants.kt | 2 +- .../console/internal/util/SemVersionInternal.kt | 8 ++++---- .../console/plugin/jvm/JvmPluginDescription.kt | 6 +++--- .../net/mamoe/mirai/console/util/SemVersion.kt | 17 ++++++++++++----- .../net/mamoe/mirai/console/TestMiraiConosle.kt | 2 +- .../mamoe/mirai/console/util/TestSemVersion.kt | 6 +++--- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleBuildConstants.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleBuildConstants.kt index f1889aeab..f314be39c 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleBuildConstants.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/MiraiConsoleBuildConstants.kt @@ -17,5 +17,5 @@ internal object MiraiConsoleBuildConstants { // auto-filled on build (task :mira val buildDate: Instant = Instant.ofEpochSecond(1600596035) @JvmStatic - val version: SemVersion = SemVersion.parse("1.0-RC-dev-28") + val version: SemVersion = SemVersion("1.0-RC-dev-28") } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/SemVersionInternal.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/SemVersionInternal.kt index bcbd996a6..85a05ac4e 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/SemVersionInternal.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/SemVersionInternal.kt @@ -85,7 +85,7 @@ internal object SemVersionInternal { private fun String.parseRule(): SemVersion.RangeRequirement { val trimmed = trim() if (directVersion.matches(trimmed)) { - val parsed = SemVersion.parse(trimmed) + val parsed = SemVersion.invoke(trimmed) return SemVersion.RangeRequirement { it.compareTo(parsed) == 0 } @@ -101,8 +101,8 @@ internal object SemVersionInternal { } } (versionRange.matchEntire(trimmed) ?: versionMathRange.matchEntire(trimmed))?.let { range -> - var start = SemVersion.parse(range.groupValues[1]) - var end = SemVersion.parse(range.groupValues[4]) + var start = SemVersion.invoke(range.groupValues[1]) + var end = SemVersion.invoke(range.groupValues[4]) if (start > end) { val c = end end = start @@ -115,7 +115,7 @@ internal object SemVersionInternal { } versionRule.matchEntire(trimmed)?.let { result -> val operator = result.groupValues[1] - val version = SemVersion.parse(result.groupValues[7]) + val version = SemVersion.invoke(result.groupValues[7]) return when (operator) { ">=" -> { SemVersion.RangeRequirement { it >= version } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginDescription.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginDescription.kt index 242249f21..1948c7b9a 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginDescription.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginDescription.kt @@ -105,7 +105,7 @@ public class JvmPluginDescriptionBuilder( public constructor( @ResolveContext(PLUGIN_NAME) id: String, @ResolveContext(PLUGIN_VERSION) version: String, - ) : this(id, SemVersion.parse(version)) + ) : this(id, SemVersion(version)) private var name: String = id private var author: String = "" @@ -118,7 +118,7 @@ public class JvmPluginDescriptionBuilder( @ILoveKuriyamaMiraiForever public fun version(@ResolveContext(PLUGIN_VERSION) value: String): JvmPluginDescriptionBuilder = - apply { this.version = SemVersion.parse(value) } + apply { this.version = SemVersion(value) } @ILoveKuriyamaMiraiForever public fun version(@ResolveContext(PLUGIN_VERSION) value: SemVersion): JvmPluginDescriptionBuilder = @@ -281,7 +281,7 @@ public data class SimpleJvmPluginDescription author: String = "", info: String = "", dependencies: Set = setOf(), - ) : this(name, SemVersion.parse(version), id, author, info, dependencies) + ) : this(name, SemVersion(version), id, author, info, dependencies) init { require(!name.contains(':')) { "':' is forbidden in plugin name" } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt index 38903ccbd..a1abf883c 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt @@ -21,6 +21,7 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.Transient import kotlinx.serialization.builtins.serializer import net.mamoe.mirai.console.compiler.common.ResolveContext +import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.PLUGIN_VERSION import net.mamoe.mirai.console.internal.data.map import net.mamoe.mirai.console.internal.util.SemVersionInternal import net.mamoe.mirai.console.util.SemVersion.Companion.equals @@ -44,15 +45,20 @@ import net.mamoe.mirai.console.util.SemVersion.RangeRequirement * 对于核心版本号, 此实现稍微比 semver 宽松一些, 允许 x.y 的存在. * * @see RangeRequirement + * @see SemVersion.invoke */ @Serializable(with = SemVersion.SemVersionAsStringSerializer::class) -public data class SemVersion internal constructor( +public data class SemVersion +/** + * @see SemVersion.invoke 字符串解析 + */ +internal constructor( /** 核心版本号, 由主版本号, 次版本号和修订号组成, 其中修订号不一定存在 */ public val mainVersion: IntArray, /** 先行版本号识别符 */ public val identifier: String? = null, /** 版本号元数据, 不参与版本号对比([compareTo]), 但是参与版本号严格对比([equals]) */ - public val metadata: String? = null + public val metadata: String? = null, ) : Comparable { /** * 一条依赖规则 @@ -65,7 +71,7 @@ public data class SemVersion internal constructor( public object SemVersionAsStringSerializer : KSerializer by String.serializer().map( serializer = { it.toString() }, - deserializer = { parse(it) } + deserializer = { SemVersion(it) } ) public companion object { @@ -90,7 +96,8 @@ public data class SemVersion internal constructor( */ @Throws(IllegalArgumentException::class, NumberFormatException::class) @JvmStatic - public fun parse(@ResolveContext(ResolveContext.Kind.PLUGIN_VERSION) version: String): SemVersion = SemVersionInternal.parse(version) + @JvmName("parse") + public operator fun invoke(@ResolveContext(PLUGIN_VERSION) version: String): SemVersion = SemVersionInternal.parse(version) /** * 解析一条依赖需求描述, 在无法解析的时候抛出 [IllegalArgumentException] @@ -121,7 +128,7 @@ public data class SemVersion internal constructor( /** @see [RangeRequirement.test] */ @JvmStatic - public fun RangeRequirement.test(version: String): Boolean = test(parse(version)) + public fun RangeRequirement.test(version: String): Boolean = test(invoke(version)) /** * 当满足 [requirement] 时返回 true, 否则返回 false 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 87eda59e8..969f03425 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 @@ -44,7 +44,7 @@ fun initTestEnvironment() { override val vendor: String get() = "Test" override val version: SemVersion - get() = SemVersion.parse("1.0.0") + get() = SemVersion("1.0.0") } override val builtInPluginLoaders: List>> = listOf(lazy { JvmPluginLoader }) diff --git a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/util/TestSemVersion.kt b/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/util/TestSemVersion.kt index b76d610e1..e2ae8a8c1 100644 --- a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/util/TestSemVersion.kt +++ b/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/util/TestSemVersion.kt @@ -20,7 +20,7 @@ import org.junit.jupiter.api.Test internal class TestSemVersion { @Test internal fun testCompare() { - fun String.sem(): SemVersion = SemVersion.parse(this) + fun String.sem(): SemVersion = SemVersion.invoke(this) assert("1.0".sem() < "1.0.1".sem()) assert("1.0.0".sem() == "1.0".sem()) assert("1.1".sem() > "1.0.0".sem()) @@ -85,12 +85,12 @@ internal class TestSemVersion { } private fun String.check() { - val sem = SemVersion.parse(this) + val sem = SemVersion.invoke(this) assert(this == sem.toString()) { "$this != $sem" } } private fun String.checkInvalid() { - kotlin.runCatching { SemVersion.parse(this) } + kotlin.runCatching { SemVersion.invoke(this) } .onSuccess { assert(false) { "$this not a invalid sem-version" } } } From 09de9e7cd7f3139e48ea5193a7aa5edc346f5303 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 20 Sep 2020 18:57:10 +0800 Subject: [PATCH 11/23] Make SimpleJvmPluginDescription internal --- .../plugin/jvm/JvmPluginDescription.kt | 55 ++++--------------- 1 file changed, 12 insertions(+), 43 deletions(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginDescription.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginDescription.kt index 1948c7b9a..96a013405 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginDescription.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginDescription.kt @@ -34,6 +34,7 @@ public interface JvmPluginDescription : PluginDescription { * 构建 [JvmPluginDescription] * @see JvmPluginDescriptionBuilder */ + @JvmName("create") @JvmSynthetic public operator fun invoke( /** @@ -55,8 +56,7 @@ public interface JvmPluginDescription : PluginDescription { * 构建 [JvmPluginDescription] * @see JvmPluginDescriptionBuilder */ - @Suppress("DEPRECATION_ERROR") - @Deprecated("Semver 将会在 1.0-RC 被替换为 Console 自己实现的版本。请临时使用 String。", level = DeprecationLevel.ERROR) + @JvmName("create") @JvmSynthetic public operator fun invoke( /** @@ -101,9 +101,8 @@ public class JvmPluginDescriptionBuilder( private var id: String, private var version: SemVersion, ) { - @Suppress("DEPRECATION_ERROR") public constructor( - @ResolveContext(PLUGIN_NAME) id: String, + @ResolveContext(PLUGIN_ID) id: String, @ResolveContext(PLUGIN_VERSION) version: String, ) : this(id, SemVersion(version)) @@ -232,49 +231,19 @@ public class JvmPluginDescriptionBuilder( * * @see JvmPluginDescription */ -@Deprecated( - """ - 将在 1.0-RC 删除. 请使用 JvmPluginDescription. -""", - replaceWith = ReplaceWith( - "JvmPluginDescription", - "net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription" - ), - level = DeprecationLevel.ERROR -) -public data class SimpleJvmPluginDescription -@Deprecated( - """ - 构造器不稳定, 将在 1.0-RC 删除. 请使用 JvmPluginDescriptionBuilder. -""", - replaceWith = ReplaceWith( - "JvmPluginDescription(name, version) {}", - "net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription.Companion.invoke" - ), - level = DeprecationLevel.ERROR -) -@JvmOverloads public constructor( - public override val name: String, - public override val version: SemVersion, - public override val id: String = name, - public override val author: String = "", - public override val info: String = "", - public override val dependencies: Set = setOf(), +internal data class SimpleJvmPluginDescription +@JvmOverloads constructor( + override val name: String, + override val version: SemVersion, + override val id: String = name, + override val author: String = "", + override val info: String = "", + override val dependencies: Set = setOf(), ) : JvmPluginDescription { - @Deprecated( - """ - 构造器不稳定, 将在 1.0-RC 删除. 请使用 JvmPluginDescriptionBuilder. -""", - replaceWith = ReplaceWith( - "JvmPluginDescription.invoke(name, version) {}", - "net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription.Companion.invoke" - ), - level = DeprecationLevel.ERROR - ) @Suppress("DEPRECATION_ERROR") @JvmOverloads - public constructor( + constructor( name: String, version: String, id: String = name, From 47750c506069cd60e9c00b6f86e870a30cd50729 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 20 Sep 2020 18:58:26 +0800 Subject: [PATCH 12/23] Add ResolveContext for PluginDependency --- .../console/plugin/description/PluginDependency.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDependency.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDependency.kt index d22883093..25bedabc8 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDependency.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDependency.kt @@ -11,6 +11,8 @@ package net.mamoe.mirai.console.plugin.description +import net.mamoe.mirai.console.compiler.common.ResolveContext +import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.PLUGIN_ID import net.mamoe.mirai.console.util.SemVersion /** @@ -22,7 +24,7 @@ public data class PluginDependency @JvmOverloads constructor( /** * 依赖插件 ID, [PluginDescription.id] */ - public val id: String, + @ResolveContext(PLUGIN_ID) public val id: String, /** * 依赖版本号. 为 null 时则为不限制版本. * @@ -48,7 +50,10 @@ public data class PluginDependency @JvmOverloads constructor( /** * @see PluginDependency */ - public constructor(name: String, isOptional: Boolean = false) : this( - name, null, isOptional + public constructor( + @ResolveContext(PLUGIN_ID) id: String, + isOptional: Boolean = false, + ) : this( + id, null, isOptional ) } \ No newline at end of file From 2035e136f3b45f0ed83b766ceafccd68aa9e51a7 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 20 Sep 2020 18:59:37 +0800 Subject: [PATCH 13/23] Rename SemVersion.RangeRequirement to SemVersion.Requirement --- .../internal/util/SemVersionInternal.kt | 32 +++++++++---------- .../plugin/description/PluginDependency.kt | 5 ++- .../plugin/jvm/JvmPluginDescription.kt | 6 ++-- .../mamoe/mirai/console/util/SemVersion.kt | 18 +++++------ .../util/SemVersionRangeRequirementBuilder.kt | 26 +++++++-------- .../mirai/console/util/TestSemVersion.kt | 4 +-- 6 files changed, 45 insertions(+), 46 deletions(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/SemVersionInternal.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/SemVersionInternal.kt index 85a05ac4e..6f31a6a1f 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/SemVersionInternal.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/SemVersionInternal.kt @@ -82,21 +82,21 @@ internal object SemVersionInternal { } @JvmStatic - private fun String.parseRule(): SemVersion.RangeRequirement { + private fun String.parseRule(): SemVersion.Requirement { val trimmed = trim() if (directVersion.matches(trimmed)) { val parsed = SemVersion.invoke(trimmed) - return SemVersion.RangeRequirement { + return SemVersion.Requirement { it.compareTo(parsed) == 0 } } if (versionSelect.matches(trimmed)) { val regex = ("^" + - trimmed.replace(".", "\\.") + trimmed.replace(".", "\\.") .replace("x", ".+") + "$" ).toRegex() - return SemVersion.RangeRequirement { + return SemVersion.Requirement { regex.matches(it.toString()) } } @@ -109,7 +109,7 @@ internal object SemVersionInternal { start = c } val compareRange = start..end - return SemVersion.RangeRequirement { + return SemVersion.Requirement { it in compareRange } } @@ -118,19 +118,19 @@ internal object SemVersionInternal { val version = SemVersion.invoke(result.groupValues[7]) return when (operator) { ">=" -> { - SemVersion.RangeRequirement { it >= version } + SemVersion.Requirement { it >= version } } ">" -> { - SemVersion.RangeRequirement { it > version } + SemVersion.Requirement { it > version } } "<=" -> { - SemVersion.RangeRequirement { it <= version } + SemVersion.Requirement { it <= version } } "<" -> { - SemVersion.RangeRequirement { it < version } + SemVersion.Requirement { it < version } } "=" -> { - SemVersion.RangeRequirement { it.compareTo(version) == 0 } + SemVersion.Requirement { it.compareTo(version) == 0 } } else -> throw AssertionError("operator=$operator, version=$version") } @@ -138,8 +138,8 @@ internal object SemVersionInternal { throw UnsupportedOperationException("Cannot parse $this") } - private fun SemVersion.RangeRequirement.withRule(rule: String): SemVersion.RangeRequirement { - return object : SemVersion.RangeRequirement { + private fun SemVersion.Requirement.withRule(rule: String): SemVersion.Requirement { + return object : SemVersion.Requirement { override fun test(version: SemVersion): Boolean { return this@withRule.test(version) } @@ -151,7 +151,7 @@ internal object SemVersionInternal { } @JvmStatic - fun parseRangeRequirement(requirement: String): SemVersion.RangeRequirement { + fun parseRangeRequirement(requirement: String): SemVersion.Requirement { if (requirement.isBlank()) { throw IllegalArgumentException("Invalid requirement: Empty requirement rule.") } @@ -159,11 +159,11 @@ internal object SemVersionInternal { it.parseRule().withRule(it) }.let { checks -> if (checks.size == 1) return checks[0] - SemVersion.RangeRequirement { + SemVersion.Requirement { checks.forEach { rule -> - if (rule.test(it)) return@RangeRequirement true + if (rule.test(it)) return@Requirement true } - return@RangeRequirement false + return@Requirement false }.withRule(requirement) } } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDependency.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDependency.kt index 25bedabc8..d73ac9cec 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDependency.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/description/PluginDependency.kt @@ -30,10 +30,9 @@ public data class PluginDependency @JvmOverloads constructor( * * 版本遵循 [语义化版本 2.0 规范](https://semver.org/lang/zh-CN/), * - * ### 示例 - * `Requirement.buildIvy("[1.0, 2.0)")` + * @see SemVersion.Requirement */ - public val versionRequirement: SemVersion.RangeRequirement? = null, + public val versionRequirement: SemVersion.Requirement? = null, /** * 若为 `false`, 插件在找不到此依赖时也能正常加载. */ diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginDescription.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginDescription.kt index 96a013405..736517b52 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginDescription.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/JvmPluginDescription.kt @@ -156,7 +156,7 @@ public class JvmPluginDescriptionBuilder( public fun dependsOn( @ResolveContext(PLUGIN_ID) pluginId: String, isOptional: Boolean = false, - versionRequirement: SemVersion.RangeRequirement, + versionRequirement: SemVersion.Requirement, ): JvmPluginDescriptionBuilder = apply { this.dependencies.add(PluginDependency(pluginId, versionRequirement, isOptional)) } @@ -169,7 +169,7 @@ public class JvmPluginDescriptionBuilder( @ILoveKuriyamaMiraiForever public fun dependsOn( @ResolveContext(PLUGIN_ID) pluginId: String, - versionRequirement: SemVersion.RangeRequirement, + versionRequirement: SemVersion.Requirement, ): JvmPluginDescriptionBuilder = apply { this.dependencies.add(PluginDependency(pluginId, versionRequirement, false)) } @@ -204,7 +204,7 @@ public class JvmPluginDescriptionBuilder( public fun dependsOn( @ResolveContext(PLUGIN_ID) pluginId: String, isOptional: Boolean = false, - versionRequirement: SemVersionRangeRequirementBuilder.() -> SemVersion.RangeRequirement, + versionRequirement: SemVersionRangeRequirementBuilder.() -> SemVersion.Requirement, ): JvmPluginDescriptionBuilder = apply { this.dependencies.add(PluginDependency(pluginId, diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt index a1abf883c..b209a7226 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt @@ -25,7 +25,7 @@ import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.PLUGIN_VERSIO import net.mamoe.mirai.console.internal.data.map import net.mamoe.mirai.console.internal.util.SemVersionInternal import net.mamoe.mirai.console.util.SemVersion.Companion.equals -import net.mamoe.mirai.console.util.SemVersion.RangeRequirement +import net.mamoe.mirai.console.util.SemVersion.Requirement /** * [语义化版本](https://semver.org/lang/zh-CN/) 支持 @@ -44,7 +44,7 @@ import net.mamoe.mirai.console.util.SemVersion.RangeRequirement * * 对于核心版本号, 此实现稍微比 semver 宽松一些, 允许 x.y 的存在. * - * @see RangeRequirement + * @see Requirement * @see SemVersion.invoke */ @Serializable(with = SemVersion.SemVersionAsStringSerializer::class) @@ -64,7 +64,7 @@ internal constructor( * 一条依赖规则 * @see [parseRangeRequirement] */ - public fun interface RangeRequirement { + public fun interface Requirement { /** 在 [version] 满足此要求时返回 true */ public fun test(version: SemVersion): Boolean } @@ -124,27 +124,27 @@ internal constructor( */ @Throws(IllegalArgumentException::class) @JvmStatic - public fun parseRangeRequirement(requirement: String): RangeRequirement = SemVersionInternal.parseRangeRequirement(requirement) + public fun parseRangeRequirement(requirement: String): Requirement = SemVersionInternal.parseRangeRequirement(requirement) - /** @see [RangeRequirement.test] */ + /** @see [Requirement.test] */ @JvmStatic - public fun RangeRequirement.test(version: String): Boolean = test(invoke(version)) + public fun Requirement.test(version: String): Boolean = test(invoke(version)) /** * 当满足 [requirement] 时返回 true, 否则返回 false */ @JvmStatic - public fun SemVersion.satisfies(requirement: RangeRequirement): Boolean = requirement.test(this) + public fun SemVersion.satisfies(requirement: Requirement): Boolean = requirement.test(this) /** for Kotlin only */ @JvmStatic @JvmSynthetic - public operator fun RangeRequirement.contains(version: SemVersion): Boolean = test(version) + public operator fun Requirement.contains(version: SemVersion): Boolean = test(version) /** for Kotlin only */ @JvmStatic @JvmSynthetic - public operator fun RangeRequirement.contains(version: String): Boolean = test(version) + public operator fun Requirement.contains(version: String): Boolean = test(version) } @Transient diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersionRangeRequirementBuilder.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersionRangeRequirementBuilder.kt index ec4d663a4..74145d1f8 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersionRangeRequirementBuilder.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersionRangeRequirementBuilder.kt @@ -11,16 +11,16 @@ package net.mamoe.mirai.console.util /** - * 构造 [SemVersion.RangeRequirement] 的 DSL + * 构造 [SemVersion.Requirement] 的 DSL */ public object SemVersionRangeRequirementBuilder { /** @see [SemVersion.parseRangeRequirement] */ @ILoveHim188moeForever - public fun parse(rule: String): SemVersion.RangeRequirement = SemVersion.parseRangeRequirement(rule) + public fun parse(rule: String): SemVersion.Requirement = SemVersion.parseRangeRequirement(rule) @ILoveHim188moeForever - public infix fun SemVersion.RangeRequirement.or(other: SemVersion.RangeRequirement): SemVersion.RangeRequirement { - return object : SemVersion.RangeRequirement { + public infix fun SemVersion.Requirement.or(other: SemVersion.Requirement): SemVersion.Requirement { + return object : SemVersion.Requirement { override fun test(version: SemVersion): Boolean { return this@or.test(version) || other.test(version) } @@ -32,17 +32,17 @@ public object SemVersionRangeRequirementBuilder { } @ILoveHim188moeForever - public infix fun String.or(other: String): SemVersion.RangeRequirement = parse(this) or parse(other) + public infix fun String.or(other: String): SemVersion.Requirement = parse(this) or parse(other) @ILoveHim188moeForever - public infix fun SemVersion.RangeRequirement.or(other: String): SemVersion.RangeRequirement = or(parse(other)) + public infix fun SemVersion.Requirement.or(other: String): SemVersion.Requirement = or(parse(other)) @ILoveHim188moeForever - public infix fun String.or(other: SemVersion.RangeRequirement): SemVersion.RangeRequirement = parse(this) or other + public infix fun String.or(other: SemVersion.Requirement): SemVersion.Requirement = parse(this) or other @ILoveHim188moeForever - public infix fun SemVersion.RangeRequirement.and(other: SemVersion.RangeRequirement): SemVersion.RangeRequirement { - return object : SemVersion.RangeRequirement { + public infix fun SemVersion.Requirement.and(other: SemVersion.Requirement): SemVersion.Requirement { + return object : SemVersion.Requirement { override fun test(version: SemVersion): Boolean { return this@and.test(version) && other.test(version) } @@ -54,17 +54,17 @@ public object SemVersionRangeRequirementBuilder { } @ILoveHim188moeForever - public infix fun String.and(other: String): SemVersion.RangeRequirement = parse(this) and parse(other) + public infix fun String.and(other: String): SemVersion.Requirement = parse(this) and parse(other) @ILoveHim188moeForever - public infix fun SemVersion.RangeRequirement.and(other: String): SemVersion.RangeRequirement = and(parse(other)) + public infix fun SemVersion.Requirement.and(other: String): SemVersion.Requirement = and(parse(other)) @ILoveHim188moeForever - public infix fun String.and(other: SemVersion.RangeRequirement): SemVersion.RangeRequirement = parse(this) and other + public infix fun String.and(other: SemVersion.Requirement): SemVersion.Requirement = parse(this) and other @Suppress("NOTHING_TO_INLINE") @ILoveHim188moeForever - public inline fun custom(rule: SemVersion.RangeRequirement): SemVersion.RangeRequirement = rule + public inline fun custom(rule: SemVersion.Requirement): SemVersion.Requirement = rule /** * 标注一个 [SemVersionRangeRequirementBuilder] DSL diff --git a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/util/TestSemVersion.kt b/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/util/TestSemVersion.kt index e2ae8a8c1..c7325c177 100644 --- a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/util/TestSemVersion.kt +++ b/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/util/TestSemVersion.kt @@ -43,12 +43,12 @@ internal class TestSemVersion { @Test internal fun testRequirement() { - fun SemVersion.RangeRequirement.assert(version: String): SemVersion.RangeRequirement { + fun SemVersion.Requirement.assert(version: String): SemVersion.Requirement { assert(test(version)) { version } return this } - fun SemVersion.RangeRequirement.assertFalse(version: String): SemVersion.RangeRequirement { + fun SemVersion.Requirement.assertFalse(version: String): SemVersion.Requirement { assert(!test(version)) { version } return this } From 9514a5c3e8c22800c3c62f54a6aa4a26024f0e6e Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 20 Sep 2020 18:59:59 +0800 Subject: [PATCH 14/23] Make SemVersion.Requirement not fun --- .../src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt index b209a7226..e4940f1be 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt @@ -64,7 +64,7 @@ internal constructor( * 一条依赖规则 * @see [parseRangeRequirement] */ - public fun interface Requirement { + public interface Requirement { /** 在 [version] 满足此要求时返回 true */ public fun test(version: SemVersion): Boolean } From 57c30e4689dd25d312a7eb49462e49172388a8d2 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 20 Sep 2020 19:03:50 +0800 Subject: [PATCH 15/23] Fix build, Fix code style --- .../internal/util/SemVersionInternal.kt | 68 ++++++++++--------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/SemVersionInternal.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/SemVersionInternal.kt index 6f31a6a1f..02cec4490 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/SemVersionInternal.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/util/SemVersionInternal.kt @@ -26,11 +26,6 @@ internal object SemVersionInternal { private val versionMathRange = """\[([0-9]+(\.[0-9]+)+(|[\-+].+))\s*\,\s*([0-9]+(\.[0-9]+)+(|[\-+].+))\]""".toRegex() private val versionRule = """^((\>\=)|(\<\=)|(\=)|(\>)|(\<))\s*([0-9]+(\.[0-9]+)+(|[\-+].+))$""".toRegex() - private fun Collection<*>.dump() { - forEachIndexed { index, value -> - println("$index, $value") - } - } private val SEM_VERSION_REGEX = """^(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$""".toRegex() @@ -86,18 +81,18 @@ internal object SemVersionInternal { val trimmed = trim() if (directVersion.matches(trimmed)) { val parsed = SemVersion.invoke(trimmed) - return SemVersion.Requirement { - it.compareTo(parsed) == 0 + return object : SemVersion.Requirement { + override fun test(version: SemVersion): Boolean = version.compareTo(parsed) == 0 } } if (versionSelect.matches(trimmed)) { val regex = ("^" + trimmed.replace(".", "\\.") - .replace("x", ".+") + - "$" - ).toRegex() - return SemVersion.Requirement { - regex.matches(it.toString()) + .replace("x", ".+") + + "$" + ).toRegex() + return object : SemVersion.Requirement { + override fun test(version: SemVersion): Boolean = regex.matches(version.toString()) } } (versionRange.matchEntire(trimmed) ?: versionMathRange.matchEntire(trimmed))?.let { range -> @@ -109,44 +104,49 @@ internal object SemVersionInternal { start = c } val compareRange = start..end - return SemVersion.Requirement { - it in compareRange + return object : SemVersion.Requirement { + override fun test(version: SemVersion): Boolean = version in compareRange } } versionRule.matchEntire(trimmed)?.let { result -> val operator = result.groupValues[1] - val version = SemVersion.invoke(result.groupValues[7]) + val version1 = SemVersion.invoke(result.groupValues[7]) return when (operator) { ">=" -> { - SemVersion.Requirement { it >= version } + object : SemVersion.Requirement { + override fun test(version: SemVersion): Boolean = version >= version1 + } } ">" -> { - SemVersion.Requirement { it > version } + object : SemVersion.Requirement { + override fun test(version: SemVersion): Boolean = version > version1 + } } "<=" -> { - SemVersion.Requirement { it <= version } + object : SemVersion.Requirement { + override fun test(version: SemVersion): Boolean = version <= version1 + } } "<" -> { - SemVersion.Requirement { it < version } + object : SemVersion.Requirement { + override fun test(version: SemVersion): Boolean = version < version1 + } } "=" -> { - SemVersion.Requirement { it.compareTo(version) == 0 } + object : SemVersion.Requirement { + override fun test(version: SemVersion): Boolean = version.compareTo(version1) == 0 + } } - else -> throw AssertionError("operator=$operator, version=$version") + else -> error("operator=$operator, version=$version1") } } - throw UnsupportedOperationException("Cannot parse $this") + throw IllegalArgumentException("Cannot parse $this") } private fun SemVersion.Requirement.withRule(rule: String): SemVersion.Requirement { return object : SemVersion.Requirement { - override fun test(version: SemVersion): Boolean { - return this@withRule.test(version) - } - - override fun toString(): String { - return rule - } + override fun test(version: SemVersion): Boolean = this@withRule.test(version) + override fun toString(): String = rule } } @@ -159,11 +159,13 @@ internal object SemVersionInternal { it.parseRule().withRule(it) }.let { checks -> if (checks.size == 1) return checks[0] - SemVersion.Requirement { - checks.forEach { rule -> - if (rule.test(it)) return@Requirement true + object : SemVersion.Requirement { + override fun test(version: SemVersion): Boolean { + checks.forEach { rule -> + if (rule.test(version)) return true + } + return false } - return@Requirement false }.withRule(requirement) } } From 704674698f41b2aaf87fbcf007b9ac6b1f0fc658 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 20 Sep 2020 19:05:45 +0800 Subject: [PATCH 16/23] Add ResolveContext --- .../main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt index e4940f1be..095280b90 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/SemVersion.kt @@ -124,11 +124,12 @@ internal constructor( */ @Throws(IllegalArgumentException::class) @JvmStatic - public fun parseRangeRequirement(requirement: String): Requirement = SemVersionInternal.parseRangeRequirement(requirement) + public fun parseRangeRequirement(requirement: String): Requirement = + SemVersionInternal.parseRangeRequirement(requirement) /** @see [Requirement.test] */ @JvmStatic - public fun Requirement.test(version: String): Boolean = test(invoke(version)) + public fun Requirement.test(@ResolveContext(PLUGIN_VERSION) version: String): Boolean = test(invoke(version)) /** * 当满足 [requirement] 时返回 true, 否则返回 false @@ -144,7 +145,7 @@ internal constructor( /** for Kotlin only */ @JvmStatic @JvmSynthetic - public operator fun Requirement.contains(version: String): Boolean = test(version) + public operator fun Requirement.contains(@ResolveContext(PLUGIN_VERSION) version: String): Boolean = test(version) } @Transient From 453ad8f9e26c301c5241c59cb8e2efe8518a37d5 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 20 Sep 2020 19:32:00 +0800 Subject: [PATCH 17/23] Add ImageArgumentParser, fix #183 --- .../description/CommandArgumentContext.kt | 2 + .../CommandArgumentParserBuiltins.kt | 37 +++++++++++++------ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/description/CommandArgumentContext.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/description/CommandArgumentContext.kt index 8cf2456b5..47d02e1c3 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/description/CommandArgumentContext.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/description/CommandArgumentContext.kt @@ -20,6 +20,7 @@ import net.mamoe.mirai.console.permission.PermissionId import net.mamoe.mirai.console.permission.PermitteeId import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.contact.* +import net.mamoe.mirai.message.data.Image import kotlin.internal.LowPriorityInOverloadResolution import kotlin.reflect.KClass import kotlin.reflect.full.isSubclassOf @@ -74,6 +75,7 @@ public interface CommandArgumentContext { Long::class with LongArgumentParser Double::class with DoubleArgumentParser Float::class with FloatArgumentParser + Image::class with ImageArgumentParser Contact::class with ExistingContactArgumentParser User::class with ExistingUserArgumentParser diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/description/CommandArgumentParserBuiltins.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/description/CommandArgumentParserBuiltins.kt index 9e5e22fe4..851ba009c 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/description/CommandArgumentParserBuiltins.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/description/CommandArgumentParserBuiltins.kt @@ -19,10 +19,7 @@ import net.mamoe.mirai.console.permission.PermitteeId import net.mamoe.mirai.contact.* import net.mamoe.mirai.getFriendOrNull import net.mamoe.mirai.getGroupOrNull -import net.mamoe.mirai.message.data.At -import net.mamoe.mirai.message.data.MessageContent -import net.mamoe.mirai.message.data.SingleMessage -import net.mamoe.mirai.message.data.content +import net.mamoe.mirai.message.data.* /** @@ -80,15 +77,33 @@ public object StringArgumentParser : InternalCommandArgumentParserExtensions { + public override fun parse(raw: String, sender: CommandSender): Image { + return kotlin.runCatching { + Image(raw) + }.getOrElse { + illegalArgument("无法解析 $raw 为图片.") + } + } + + override fun parse(raw: MessageContent, sender: CommandSender): Image { + if (raw is Image) return raw + return super.parse(raw, sender) + } +} + /** * 当字符串内容为(不区分大小写) "true", "yes", "enabled" */ public object BooleanArgumentParser : InternalCommandArgumentParserExtensions { public override fun parse(raw: String, sender: CommandSender): Boolean = raw.trim().let { str -> str.equals("true", ignoreCase = true) - || str.equals("yes", ignoreCase = true) - || str.equals("enabled", ignoreCase = true) - || str.equals("on", ignoreCase = true) + || str.equals("yes", ignoreCase = true) + || str.equals("enabled", ignoreCase = true) + || str.equals("on", ignoreCase = true) } } @@ -365,10 +380,10 @@ internal interface InternalCommandArgumentParserExtensions : CommandArg } else { var index = 1 illegalArgument("无法找到成员 $idOrCard。 多个成员满足搜索结果或匹配度不足: \n\n" + - candidates.joinToString("\n", limit = 6) { - val percentage = (it.second * 100).toDecimalPlace(0) - "#${index++}(${percentage}%)${it.first.nameCardOrNick.truncate(10)}(${it.first.id})" // #1 15.4% - } + candidates.joinToString("\n", limit = 6) { + val percentage = (it.second * 100).toDecimalPlace(0) + "#${index++}(${percentage}%)${it.first.nameCardOrNick.truncate(10)}(${it.first.id})" // #1 15.4% + } ) } } From e10a17ccd4fb5f81f732ce9814748c94b8f8061e Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 20 Sep 2020 19:33:21 +0800 Subject: [PATCH 18/23] Add PlainTextArgumentParser --- .../command/description/CommandArgumentContext.kt | 3 +++ .../description/CommandArgumentParserBuiltins.kt | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/description/CommandArgumentContext.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/description/CommandArgumentContext.kt index 47d02e1c3..cacea64e0 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/description/CommandArgumentContext.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/description/CommandArgumentContext.kt @@ -21,6 +21,7 @@ import net.mamoe.mirai.console.permission.PermitteeId import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.contact.* import net.mamoe.mirai.message.data.Image +import net.mamoe.mirai.message.data.PlainText import kotlin.internal.LowPriorityInOverloadResolution import kotlin.reflect.KClass import kotlin.reflect.full.isSubclassOf @@ -75,7 +76,9 @@ public interface CommandArgumentContext { Long::class with LongArgumentParser Double::class with DoubleArgumentParser Float::class with FloatArgumentParser + Image::class with ImageArgumentParser + PlainText::class with PlainTextArgumentParser Contact::class with ExistingContactArgumentParser User::class with ExistingUserArgumentParser diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/description/CommandArgumentParserBuiltins.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/description/CommandArgumentParserBuiltins.kt index 851ba009c..28d49cd11 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/description/CommandArgumentParserBuiltins.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/description/CommandArgumentParserBuiltins.kt @@ -95,6 +95,17 @@ public object ImageArgumentParser : InternalCommandArgumentParserExtensions { + public override fun parse(raw: String, sender: CommandSender): PlainText { + return PlainText(raw) + } + + override fun parse(raw: MessageContent, sender: CommandSender): PlainText { + if (raw is PlainText) return raw + return super.parse(raw, sender) + } +} + /** * 当字符串内容为(不区分大小写) "true", "yes", "enabled" */ From 71a02e7630adcc981b87d5c9fbf449d09bd40229 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 20 Sep 2020 21:32:05 +0800 Subject: [PATCH 19/23] Import yamlkt using 'implementation', improve buildscript --- backend/mirai-console/build.gradle.kts | 5 ++--- buildSrc/src/main/kotlin/dependencyExtensions.kt | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/backend/mirai-console/build.gradle.kts b/backend/mirai-console/build.gradle.kts index 6aad5bba4..3bb13026b 100644 --- a/backend/mirai-console/build.gradle.kts +++ b/backend/mirai-console/build.gradle.kts @@ -65,10 +65,9 @@ dependencies { compileAndTestRuntime(kotlinx("serialization-core", Versions.serialization)) compileAndTestRuntime(kotlin("reflect")) - implementation("org.jetbrains:annotations:19.0.0") - + smartImplementation("net.mamoe.yamlkt:yamlkt:${Versions.yamlkt}") + smartImplementation("org.jetbrains:annotations:19.0.0") smartApi(kotlinx("coroutines-jdk8", Versions.coroutines)) - smartApi("net.mamoe.yamlkt:yamlkt:${Versions.yamlkt}") testApi("net.mamoe:mirai-core-qqandroid:${Versions.core}") testApi(kotlin("stdlib-jdk8")) diff --git a/buildSrc/src/main/kotlin/dependencyExtensions.kt b/buildSrc/src/main/kotlin/dependencyExtensions.kt index d1b817404..76b6fd9b5 100644 --- a/buildSrc/src/main/kotlin/dependencyExtensions.kt +++ b/buildSrc/src/main/kotlin/dependencyExtensions.kt @@ -26,9 +26,22 @@ fun DependencyHandler.compileAndTestRuntime(any: Any) { fun DependencyHandler.smartApi( dependencyNotation: String +): ExternalModuleDependency { + return smart("api", dependencyNotation) +} + +fun DependencyHandler.smartImplementation( + dependencyNotation: String +): ExternalModuleDependency { + return smart("implementation", dependencyNotation) +} + +private fun DependencyHandler.smart( + configuration: String, + dependencyNotation: String ): ExternalModuleDependency { return addDependencyTo( - this, "api", dependencyNotation + this, configuration, dependencyNotation ) { fun exclude(group: String, module: String) { exclude(mapOf( From 91c5f5f134245d25b1ee87f319ef782e74c08c35 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 20 Sep 2020 21:32:38 +0800 Subject: [PATCH 20/23] Use JSON to store data if YAML failed --- .../data/MultiFilePluginDataStorageImpl.kt | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/MultiFilePluginDataStorageImpl.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/MultiFilePluginDataStorageImpl.kt index 351ea18ea..45fa24f88 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/MultiFilePluginDataStorageImpl.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/data/MultiFilePluginDataStorageImpl.kt @@ -9,6 +9,8 @@ package net.mamoe.mirai.console.internal.data +import kotlinx.serialization.json.Json +import net.mamoe.mirai.console.MiraiConsole import net.mamoe.mirai.console.data.* import net.mamoe.mirai.console.internal.command.qualifiedNameOrTip import net.mamoe.mirai.console.util.ConsoleExperimentalApi @@ -59,23 +61,28 @@ internal open class MultiFilePluginDataStorageImpl( return file.toFile().also { it.createNewFile() } } + private val json = Json { + prettyPrint = true + ignoreUnknownKeys = true + isLenient = true + allowStructuredMapKeys = true + } + + private val yaml = Yaml.default + @ConsoleExperimentalApi public override fun store(holder: PluginDataHolder, instance: PluginData) { - val yaml =/* if (instance.saveName == "PermissionService") Json { - prettyPrint = true - ignoreUnknownKeys = true - isLenient = true - allowStructuredMapKeys = true - } /*Yaml( - configuration = YamlConfiguration( - mapSerialization = YamlConfiguration.MapSerialization.FLOW_MAP, - listSerialization = YamlConfiguration.ListSerialization.FLOW_SEQUENCE, - classSerialization = YamlConfiguration.MapSerialization.FLOW_MAP - ) - )*/ else */Yaml.default getPluginDataFile(holder, instance).writeText( kotlin.runCatching { yaml.encodeToString(instance.updaterSerializer, Unit) + }.recoverCatching { + // Just use mainLogger for convenience. + MiraiConsole.mainLogger.warning( + "Could not save ${instance.saveName} in YAML format due to exception in YAML encoder. " + + "Please report this exception and relevant configurations to https://github.com/mamoe/mirai-console/issues/new", + it + ) + json.encodeToString(instance.updaterSerializer, Unit) }.getOrElse { throw IllegalStateException("Exception while saving $instance, saveName=${instance.saveName}", it) } From 13a0444244bd5077f17d49f78ab7ad97b55f1faa Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 20 Sep 2020 21:35:31 +0800 Subject: [PATCH 21/23] Fix deprecation message on PluginData implementations --- .../net/mamoe/mirai/console/data/AutoSavePluginConfig.kt | 2 +- .../net/mamoe/mirai/console/data/AutoSavePluginData.kt | 6 +++--- .../mamoe/mirai/console/data/java/JAutoSavePluginConfig.kt | 2 +- .../mamoe/mirai/console/data/java/JAutoSavePluginData.kt | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AutoSavePluginConfig.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AutoSavePluginConfig.kt index df4a4c280..1e3793e5a 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AutoSavePluginConfig.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/AutoSavePluginConfig.kt @@ -24,7 +24,7 @@ import kotlinx.coroutines.Job * @see AutoSavePluginData */ public open class AutoSavePluginConfig : AutoSavePluginData, PluginConfig { - @Deprecated("请手动指定保存名称. 此构造器将在 1.0.0 删除", level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("AutoSavePluginConfig(\"改成保存的名称\")")) + @Deprecated("请手动指定保存名称. 此构造器将在 1.0.0 删除", level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("AutoSavePluginConfig(\"把我改成保存名称\")")) @Suppress("DEPRECATION_ERROR") public constructor() : super() 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 06410a113..a8405df03 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 @@ -30,7 +30,7 @@ import kotlin.reflect.full.findAnnotation * @see PluginData */ public open class AutoSavePluginData private constructor( - @Suppress("UNUSED_PARAMETER") primaryConstructorMark: Any? + @Suppress("UNUSED_PARAMETER") primaryConstructorMark: Any?, ) : AbstractPluginData() { private lateinit var owner_: AutoSavePluginDataHolder private val autoSaveIntervalMillis_: LongRange get() = owner_.autoSaveIntervalMillis @@ -45,7 +45,7 @@ public open class AutoSavePluginData private constructor( _saveName = saveName } - @Deprecated("请手动指定保存名称. 此构造器将在 1.0.0 删除", level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("AutoSavePluginConfig")) + @Deprecated("请手动指定保存名称. 此构造器将在 1.0.0 删除", level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("AutoSavePluginData(\"把我改成保存名称\")")) public constructor() : this(null) { val clazz = this::class _saveName = clazz.findAnnotation()?.value @@ -72,7 +72,7 @@ public open class AutoSavePluginData private constructor( ?.let { return@invokeOnCompletion } MiraiConsole.mainLogger.error( "An exception occurred when saving config ${this@AutoSavePluginData::class.qualifiedNameOrTip} " + - "but CoroutineExceptionHandler not found in PluginDataHolder.coroutineContext for ${owner::class.qualifiedNameOrTip}", + "but CoroutineExceptionHandler not found in PluginDataHolder.coroutineContext for ${owner::class.qualifiedNameOrTip}", e ) } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/java/JAutoSavePluginConfig.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/java/JAutoSavePluginConfig.kt index 5d9788dd1..1ca820466 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/java/JAutoSavePluginConfig.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/java/JAutoSavePluginConfig.kt @@ -38,7 +38,7 @@ import net.mamoe.mirai.console.data.PluginData * @see PluginConfig */ public abstract class JAutoSavePluginConfig : AutoSavePluginConfig, PluginConfig { - @Deprecated("请手动指定保存名称. 此构造器将在 1.0.0 删除", level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("AutoSavePluginConfig(\"改成保存的名称\")")) + @Deprecated("请手动指定保存名称. 此构造器将在 1.0.0 删除", level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("JAutoSavePluginConfig(\"把我改成保存名称\")")) @Suppress("DEPRECATION_ERROR") public constructor() : super() diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/java/JAutoSavePluginData.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/java/JAutoSavePluginData.kt index ec2986fbc..442f19cc9 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/java/JAutoSavePluginData.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/java/JAutoSavePluginData.kt @@ -67,7 +67,7 @@ import kotlin.reflect.full.createType * @see PluginData */ public abstract class JAutoSavePluginData : AutoSavePluginData, PluginConfig { - @Deprecated("请手动指定保存名称. 此构造器将在 1.0.0 删除", level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("AutoSavePluginConfig(\"改成保存的名称\")")) + @Deprecated("请手动指定保存名称. 此构造器将在 1.0.0 删除", level = DeprecationLevel.ERROR, replaceWith = ReplaceWith("JAutoSavePluginData(\"把我改成保存名称\")")) @Suppress("DEPRECATION_ERROR") public constructor() : super() From ff68342110049995bdf9882b31eb22be60fd121b Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 20 Sep 2020 21:38:31 +0800 Subject: [PATCH 22/23] Declare ValueName as stable --- .../main/kotlin/net/mamoe/mirai/console/data/ValueName.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/ValueName.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/ValueName.kt index d1017080b..e9de3a500 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/ValueName.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/ValueName.kt @@ -9,14 +9,12 @@ package net.mamoe.mirai.console.data -import net.mamoe.mirai.console.util.ConsoleExperimentalApi - /** * 序列化之后的名称. * * 例: * ``` - * object AccountPluginData : PluginData by ... { + * object AccountPluginData : AutoSavePluginData() { * @ValueName("info") * val map: Map by value("a" to "b") * } @@ -28,8 +26,10 @@ import net.mamoe.mirai.console.util.ConsoleExperimentalApi * map: * a: b * ``` + * + * @see PluginData + * @see Value */ -@ConsoleExperimentalApi @Target(AnnotationTarget.PROPERTY, AnnotationTarget.CLASS) @Retention(AnnotationRetention.RUNTIME) public annotation class ValueName(val value: String) From 7a8944b1d6ff50689d90ae19fd8599bb8fbc9f41 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 20 Sep 2020 21:38:43 +0800 Subject: [PATCH 23/23] Add note for reserved primary constructor --- .../kotlin/net/mamoe/mirai/console/data/AutoSavePluginData.kt | 1 + 1 file changed, 1 insertion(+) 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 a8405df03..0ab74fc19 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 @@ -30,6 +30,7 @@ import kotlin.reflect.full.findAnnotation * @see PluginData */ public open class AutoSavePluginData private constructor( + // KEEP THIS PRIMARY CONSTRUCTOR FOR FUTURE USE: WE'LL SUPPORT SERIALIZERS_MODULE FOR POLYMORPHISM @Suppress("UNUSED_PARAMETER") primaryConstructorMark: Any?, ) : AbstractPluginData() { private lateinit var owner_: AutoSavePluginDataHolder