diff --git a/backend/mirai-console/build.gradle.kts b/backend/mirai-console/build.gradle.kts index 3bb13026b..4795a996c 100644 --- a/backend/mirai-console/build.gradle.kts +++ b/backend/mirai-console/build.gradle.kts @@ -100,8 +100,8 @@ tasks { })""" } .replace( - Regex("""val version: SemVersion = SemVersion.parse\(".*"\)""") - ) { """val version: SemVersion = SemVersion.parse("${project.version}")""" } + Regex("""const val versionConst:\s+String\s+=\s+".*"""") + ) { """const val versionConst: String = "${project.version}"""" } ) } } 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 6b7426d4d..f8155a9d1 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 @@ -43,6 +43,5 @@ public interface MiraiConsoleFrontEndDescription { /** * 返回显示在 [MiraiConsole] 启动时的信息 */ - @JvmDefault public fun render(): String = "Frontend ${name}: version ${version}, provided by $vendor" } \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt index 94aee7ae3..a1fd6347a 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/MiraiConsoleImplementation.kt @@ -108,12 +108,10 @@ public interface MiraiConsoleImplementation : CoroutineScope { @JvmSynthetic - @JvmDefault public override suspend fun sendMessage(message: Message): Unit = withContext(Dispatchers.IO) { sendMessageJ(message) } @JvmSynthetic - @JvmDefault public override suspend fun sendMessage(message: String): Unit = withContext(Dispatchers.IO) { sendMessageJ(message) } } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandSender.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandSender.kt index d3ff18fd5..8c3b1d8ed 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandSender.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/CommandSender.kt @@ -170,7 +170,6 @@ public interface CommandSender : CoroutineScope, Permittee { * * 对于 [MemberCommandSender], 这个函数总是发送给所在群 */ - @JvmDefault @JvmBlockingBridge public suspend fun sendMessage(message: String): MessageReceipt? diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandValueArgumentParser.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandValueArgumentParser.kt index f87d0d66d..43cd2c984 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandValueArgumentParser.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/command/descriptor/CommandValueArgumentParser.kt @@ -77,7 +77,6 @@ public interface CommandValueArgumentParser { * @see CommandArgumentParserException */ @Throws(CommandArgumentParserException::class) - @JvmDefault public fun parse(raw: MessageContent, sender: CommandSender): T = parse(raw.content, sender) } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataHolder.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataHolder.kt index 06d655913..af2bae5db 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataHolder.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/data/PluginDataHolder.kt @@ -41,7 +41,6 @@ public interface PluginDataHolder { * @see Companion.newPluginDataInstance * @see KClass.createType */ - @JvmDefault public fun newPluginDataInstance(type: KType): T = newPluginDataInstanceUsingReflection(type) as T @@ -64,7 +63,6 @@ public interface AutoSavePluginDataHolder : PluginDataHolder, CoroutineScope { /** * 仅支持确切的 [PluginData] 类型 */ - @JvmDefault public override fun newPluginDataInstance(type: KType): T { val classifier = type.classifier?.cast>() require(classifier != null && classifier.java == PluginData::class.java) { 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 95306d28e..b3abe5cbd 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 @@ -14,8 +14,9 @@ import java.time.Instant internal object MiraiConsoleBuildConstants { // auto-filled on build (task :mirai-console:fillBuildConstants) @JvmStatic - val buildDate: Instant = Instant.ofEpochSecond(1600663022) + val buildDate: Instant = Instant.ofEpochSecond(1601134282) + const val versionConst: String = "1.0-RC-dev-29" @JvmStatic - val version: SemVersion = SemVersion("1.0-RC-dev-28") + val version: SemVersion = SemVersion(versionConst) } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/permission/parseFromStringImpl.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/permission/parseFromStringImpl.kt index 71a055ade..343832ab6 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/permission/parseFromStringImpl.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/permission/parseFromStringImpl.kt @@ -16,6 +16,7 @@ import net.mamoe.mirai.console.permission.AbstractPermitteeId.* internal fun parseFromStringImpl(string: String): AbstractPermitteeId { val str = string.trim { it.isWhitespace() }.toLowerCase() + if (str == "*") return AnyContact if (str == "console") return Console if (str.isNotEmpty()) { when (str[0]) { diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/BuiltInJvmPluginLoaderImpl.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/BuiltInJvmPluginLoaderImpl.kt index ad335f874..d9acd38b8 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/BuiltInJvmPluginLoaderImpl.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/BuiltInJvmPluginLoaderImpl.kt @@ -42,7 +42,7 @@ internal object BuiltInJvmPluginLoaderImpl : override val dataStorage: PluginDataStorage get() = MiraiConsoleImplementationBridge.dataStorageForJvmPluginLoader - internal val classLoaders: MutableList = mutableListOf() + internal val classLoaders: MutableList = mutableListOf() @Suppress("EXTENSION_SHADOWED_BY_MEMBER") // doesn't matter override fun getPluginDescription(plugin: JvmPlugin): JvmPluginDescription = plugin.description @@ -68,7 +68,7 @@ internal object BuiltInJvmPluginLoaderImpl : val filePlugins = this.filterNot { pluginFileToInstanceMap.containsKey(it) }.associateWith { - URLClassLoader(arrayOf(it.toURI().toURL()), MiraiConsole::class.java.classLoader) + JvmPluginClassLoader(it, MiraiConsole::class.java.classLoader) }.onEach { (_, classLoader) -> classLoaders.add(classLoader) }.asSequence().findAllInstances().onEach { diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/JvmPluginClassLoader.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/JvmPluginClassLoader.kt new file mode 100644 index 000000000..1787c3809 --- /dev/null +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/JvmPluginClassLoader.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2019-2020 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AFFERO GENERAL PUBLIC LICENSE version 3 license that can be found via the following link. + * + * https://github.com/mamoe/mirai/blob/master/LICENSE + * + */ + +package net.mamoe.mirai.console.internal.plugin + +import java.io.File +import java.net.URL +import java.net.URLClassLoader +import java.util.* + +internal class JvmPluginClassLoader( + file: File, + parent: ClassLoader?, +) : URLClassLoader(arrayOf(file.toURI().toURL()), parent) { + //// 只允许插件 getResource 时获取插件自身资源, #205 + override fun getResources(name: String?): Enumeration = findResources(name) + override fun getResource(name: String?): URL? = findResource(name) + // getResourceAsStream 在 URLClassLoader 中通过 getResource 确定资源 + // 因此无需 override getResourceAsStream +} diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/JvmPluginInternal.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/JvmPluginInternal.kt index 9cd06244f..9284baaa1 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/JvmPluginInternal.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/JvmPluginInternal.kt @@ -18,7 +18,6 @@ import net.mamoe.mirai.console.extension.PluginComponentStorage import net.mamoe.mirai.console.internal.data.mkdir import net.mamoe.mirai.console.permission.Permission import net.mamoe.mirai.console.permission.PermissionService -import net.mamoe.mirai.console.permission.PermissionService.Companion.allocatePermissionIdForPlugin import net.mamoe.mirai.console.plugin.Plugin import net.mamoe.mirai.console.plugin.PluginManager import net.mamoe.mirai.console.plugin.PluginManager.INSTANCE.safeLoader @@ -26,7 +25,6 @@ import net.mamoe.mirai.console.plugin.ResourceContainer.Companion.asResourceCont import net.mamoe.mirai.console.plugin.jvm.AbstractJvmPlugin import net.mamoe.mirai.console.plugin.jvm.JvmPlugin import net.mamoe.mirai.console.plugin.jvm.JvmPlugin.Companion.onLoad -import net.mamoe.mirai.console.plugin.name import net.mamoe.mirai.console.util.NamedSupervisorJob import net.mamoe.mirai.utils.MiraiLogger import java.io.File @@ -50,7 +48,7 @@ internal abstract class JvmPluginInternal( final override val parentPermission: Permission by lazy { PermissionService.INSTANCE.register( - PermissionService.INSTANCE.allocatePermissionIdForPlugin(name, "*"), + PermissionService.INSTANCE.allocatePermissionIdForPlugin(this, "*", PermissionService.PluginPermissionIdRequestType.ROOT_PERMISSION), "The base permission" ) } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionId.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionId.kt index 86fb7e3c3..9a92e8be2 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionId.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionId.kt @@ -31,6 +31,13 @@ public data class PermissionId( @ResolveContext(PERMISSION_NAME) public val name: String, ) { init { + require(!namespace.contains(' ')) { + "' ' is not allowed in namespace" + } + require(!name.contains(' ')) { + "' ' is not allowed in id" + } + require(!namespace.contains(':')) { "':' is not allowed in namespace" } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionService.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionService.kt index 88c55556d..32e3d57fd 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionService.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermissionService.kt @@ -16,6 +16,8 @@ import net.mamoe.mirai.console.compiler.common.ResolveContext.Kind.COMMAND_NAME import net.mamoe.mirai.console.extensions.PermissionServiceProvider import net.mamoe.mirai.console.internal.permission.checkType import net.mamoe.mirai.console.permission.Permission.Companion.parentsWithSelf +import net.mamoe.mirai.console.plugin.Plugin +import net.mamoe.mirai.console.plugin.name import kotlin.reflect.KClass /** @@ -89,6 +91,13 @@ public interface PermissionService

{ parent: Permission = RootPermission, ): P + /** 为 [Plugin] 分配一个 [PermissionId] */ + public fun allocatePermissionIdForPlugin( + plugin: Plugin, + @ResolveContext(COMMAND_NAME) permissionName: String, + reason: PluginPermissionIdRequestType + ): PermissionId = allocatePermissionIdForPluginDefaultImplement(plugin, permissionName, reason) + /////////////////////////////////////////////////////////////////////////// /** @@ -116,6 +125,15 @@ public interface PermissionService

{ @Throws(UnsupportedOperationException::class) public fun cancel(permitteeId: PermitteeId, permission: P, recursive: Boolean) + /** [Plugin] 尝试分配的 [PermissionId] 来源 */ + public enum class PluginPermissionIdRequestType { + /** For [Plugin.parentPermission] */ + ROOT_PERMISSION, + + /** For [Plugin.permissionId] */ + PERMISSION_ID + } + public companion object { internal var instanceField: PermissionService<*>? = null @@ -131,8 +149,14 @@ public interface PermissionService

{ public fun

PermissionService

.getOrFail(id: PermissionId): P = get(id) ?: throw NoSuchElementException("Permission not found: $id") - internal fun PermissionService<*>.allocatePermissionIdForPlugin(pluginName: String, @ResolveContext(COMMAND_NAME) permissionName: String) = - PermissionId("plugin.${pluginName.toLowerCase()}", permissionName.toLowerCase()) + internal fun PermissionService<*>.allocatePermissionIdForPluginDefaultImplement( + plugin: Plugin, + @ResolveContext(COMMAND_NAME) permissionName: String, + reason: PluginPermissionIdRequestType + ) = PermissionId( + plugin.name.toLowerCase().replace(' ', '.'), + permissionName.toLowerCase() + ) public fun PermissionId.findCorrespondingPermission(): Permission? = INSTANCE[this] @@ -202,4 +226,4 @@ public interface PermissionService

{ return p.testPermission(permissible) } } -} \ No newline at end of file +} diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermitteeId.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermitteeId.kt index ec46d5da7..3379e3b6d 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermitteeId.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/permission/PermitteeId.kt @@ -266,13 +266,13 @@ public sealed class AbstractPermitteeId( /** * 表示唯一的一个好友 * - * - **直接父标识符**: [ExactUser] + * - **直接父标识符**: [ExactUser], [AnyFriend] * - **间接父标识符**: [AnyUser], [AnyContact] * - 字符串表示: "f$id" */ public data class ExactFriend( public val id: Long, - ) : AbstractPermitteeId(ExactUser(id)) { + ) : AbstractPermitteeId(ExactUser(id), AnyFriend) { override fun asString(): String = "f$id" } @@ -304,7 +304,7 @@ public sealed class AbstractPermitteeId( * 表示唯一的一个 *在临时会话发送消息的* [群成员][Member] * * - **直接父标识符**: [ExactMember] - * - **间接父标识符**: [AnyUser], [AnyMember], [ExactUser], [AnyContact] + * - **间接父标识符**: [AnyUser], [AnyMember], [ExactUser], [AnyContact], [AnyMemberFromAnyGroup] * - 字符串表示: "t$groupId.$memberId" */ public data class ExactTemp( diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/PluginFileExtensions.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/PluginFileExtensions.kt index 276113880..459d768b4 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/PluginFileExtensions.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/PluginFileExtensions.kt @@ -41,28 +41,24 @@ public interface PluginFileExtensions { * 从数据目录获取一个文件. * @see dataFolderPath */ - @JvmDefault public fun resolveDataFile(relativePath: String): File = dataFolderPath.resolve(relativePath).toFile() /** * 从数据目录获取一个文件. * @see dataFolderPath */ - @JvmDefault public fun resolveDataPath(relativePath: String): Path = dataFolderPath.resolve(relativePath) /** * 从数据目录获取一个文件. * @see dataFolderPath */ - @JvmDefault public fun resolveDataFile(relativePath: Path): File = dataFolderPath.resolve(relativePath).toFile() /** * 从数据目录获取一个文件路径. * @see dataFolderPath */ - @JvmDefault public fun resolveDataPath(relativePath: Path): Path = dataFolderPath.resolve(relativePath) @@ -83,27 +79,23 @@ public interface PluginFileExtensions { * 从配置目录获取一个文件. * @see configFolderPath */ - @JvmDefault public fun resolveConfigFile(relativePath: String): File = configFolderPath.resolve(relativePath).toFile() /** * 从配置目录获取一个文件. * @see configFolderPath */ - @JvmDefault public fun resolveConfigPath(relativePath: String): Path = configFolderPath.resolve(relativePath) /** * 从配置目录获取一个文件. * @see configFolderPath */ - @JvmDefault public fun resolveConfigFile(relativePath: Path): File = configFolderPath.resolve(relativePath).toFile() /** * 从配置目录获取一个文件路径. * @see configFolderPath */ - @JvmDefault public fun resolveConfigPath(relativePath: Path): Path = configFolderPath.resolve(relativePath) } \ No newline at end of file diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/ResourceContainer.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/ResourceContainer.kt index e2e26cc0c..8937f4146 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/ResourceContainer.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/ResourceContainer.kt @@ -37,7 +37,6 @@ public interface ResourceContainer { * * @return 资源文件内容. 在未找到文件时返回 `null`. */ - @JvmDefault public fun getResource(path: String): String? = getResource(path, Charsets.UTF_8) /** @@ -45,7 +44,6 @@ public interface ResourceContainer { * * @return 资源文件内容. 在未找到文件时返回 `null`. */ - @JvmDefault public fun getResource(path: String, charset: Charset): String? = this.getResourceAsStream(path)?.use(InputStream::readBytes)?.let(::String) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/AbstractJvmPlugin.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/AbstractJvmPlugin.kt index 9ed8caa29..fb1f1849f 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/AbstractJvmPlugin.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/AbstractJvmPlugin.kt @@ -16,6 +16,7 @@ import net.mamoe.mirai.console.data.PluginConfig import net.mamoe.mirai.console.data.PluginData import net.mamoe.mirai.console.internal.plugin.JvmPluginInternal import net.mamoe.mirai.console.permission.PermissionId +import net.mamoe.mirai.console.permission.PermissionService import net.mamoe.mirai.console.util.ConsoleExperimentalApi import net.mamoe.mirai.utils.minutesToMillis import net.mamoe.mirai.utils.secondsToMillis @@ -37,7 +38,8 @@ public abstract class AbstractJvmPlugin @JvmOverloads constructor( public final override val loader: JvmPluginLoader get() = super.loader - public final override fun permissionId(name: String): PermissionId = PermissionId(description.id, name) + public final override fun permissionId(name: String): PermissionId = + PermissionService.INSTANCE.allocatePermissionIdForPlugin(this, name, PermissionService.PluginPermissionIdRequestType.PERMISSION_ID) /** * 重载 [PluginData] @@ -73,4 +75,4 @@ public inline fun AbstractJvmPlugin.reloadPluginData(instance: PluginData): Unit * @see AbstractJvmPlugin.reload */ @JvmSynthetic -public inline fun AbstractJvmPlugin.reloadPluginConfig(instance: PluginConfig): Unit = this.run { instance.reload() } \ No newline at end of file +public inline fun AbstractJvmPlugin.reloadPluginConfig(instance: PluginConfig): Unit = this.run { instance.reload() } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/MessageScope.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/MessageScope.kt index d10324141..92a82a616 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/MessageScope.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/util/MessageScope.kt @@ -96,7 +96,7 @@ import kotlin.internal.LowPriorityInOverloadResolution */ public interface MessageScope { /** - * 如果此 [MessageScope], 仅包含一个消息对象, 则 [realTarget] 指向这个对象. + * 如果此 [MessageScope] 仅包含一个消息对象, 则 [realTarget] 指向这个对象. 否则 [realTarget] 为 `null`. * * 对于 [CommandSender] 作为 [MessageScope], [realTarget] 总是指令执行者 [User], 即 [CommandSender.user] * @@ -116,7 +116,6 @@ public interface MessageScope { /** * 立刻以此发送消息给所有在此 [MessageScope] 下的消息对象 */ - @JvmDefault @JvmBlockingBridge public suspend fun sendMessage(message: String) } diff --git a/buildSrc/src/main/kotlin/MiraiConsoleBuildPlugin.kt b/buildSrc/src/main/kotlin/MiraiConsoleBuildPlugin.kt index b8567aaec..8dbd47d8a 100644 --- a/buildSrc/src/main/kotlin/MiraiConsoleBuildPlugin.kt +++ b/buildSrc/src/main/kotlin/MiraiConsoleBuildPlugin.kt @@ -36,8 +36,8 @@ class MiraiConsoleBuildPlugin : Plugin { attributes( "Manifest-Version" to "1", "Implementation-Vendor" to "Mamoe Technologies", - "Implementation-Title" to target.name.toString(), - "Implementation-Version" to target.version.toString() + "+" + gitVersion + "Implementation-Title" to target.name, + "Implementation-Version" to target.version.toString() //+ "+" + gitVersion ) } @Suppress("UNCHECKED_CAST") @@ -120,15 +120,16 @@ fun Project.findLatestFile(): Pair { } ?: error("cannot find any file to upload")*/ } +/* val gitVersion: String by lazy { runCatching { val exec = Runtime.getRuntime().exec("git rev-parse HEAD") exec.waitFor() exec.inputStream.readBytes().toString(Charsets.UTF_8).trim().also { println("Git commit id: $it") - } - }.onFailure { + } }.onFailure { it.printStackTrace() return@lazy "UNKNOWN" }.getOrThrow() } +*/ \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 801f93344..d5f4b7ac6 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -9,7 +9,7 @@ object Versions { const val core = "1.3.0" - const val console = "1.0-RC-dev-29" + const val console = "1.0-RC-dev-30" const val consoleGraphical = "0.0.7" const val consoleTerminal = console @@ -26,6 +26,6 @@ object Versions { const val bintray = "1.8.5" - const val blockingBridge = "1.0.5" + const val blockingBridge = "1.1.0" const val yamlkt = "0.5.3" } \ No newline at end of file diff --git a/docs/ConfiguringProjects.md b/docs/ConfiguringProjects.md index 3fa2db93f..6831ff24d 100644 --- a/docs/ConfiguringProjects.md +++ b/docs/ConfiguringProjects.md @@ -28,6 +28,8 @@ console 由后端和前端一起工作. 使用时必须选择一个前端. ## 配置项目 +请选择以下三种方法之一。 + ### 使用模板项目 Mirai 鼓励插件开发者将自己的作品开源,并为此提供了模板项目。 @@ -77,4 +79,4 @@ dependencies { ``` 之后还需要配置 Kotlin `jvm-default` 编译参数,Kotlin 和 Java 的编译目标等。 -在打包插件时必须将依赖一并打包进插件 JAR,且排除 `mirai-core`,`mirai-console` 和它们的间接依赖,否则插件不会被加载。 \ No newline at end of file +在打包插件时必须将依赖一并打包进插件 JAR,且排除 `mirai-core`,`mirai-console` 和它们的间接依赖,否则插件不会被加载。 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 c6d790a76..1cd89f853 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 @@ -151,7 +151,9 @@ val terminal: Terminal = run { private object ConsoleFrontEndDescImpl : MiraiConsoleFrontEndDescription { override val name: String get() = "Terminal" override val vendor: String get() = "Mamoe Technologies" - override val version: SemVersion = net.mamoe.mirai.console.internal.MiraiConsoleBuildConstants.version + // net.mamoe.mirai.console.internal.MiraiConsoleBuildConstants.version + // is console's version not frontend's version + override val version: SemVersion = SemVersion(net.mamoe.mirai.console.internal.MiraiConsoleBuildConstants.versionConst) } private val ANSI_RESET = Ansi().reset().toString() diff --git a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleTerminalLoader.kt b/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleTerminalLoader.kt index 2aa23e0b6..930e72b48 100644 --- a/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleTerminalLoader.kt +++ b/frontend/mirai-console-terminal/src/main/kotlin/net/mamoe/mirai/console/terminal/MiraiConsoleTerminalLoader.kt @@ -59,7 +59,8 @@ object MiraiConsoleTerminalLoader { @ConsoleTerminalExperimentalApi fun printHelpMessage() { val help = listOf( - "" to "Mirai-Console[Terminal FrontEnd] v" + kotlin.runCatching { + "" to "Mirai-Console[Terminal FrontEnd] v" + net.mamoe.mirai.console.internal.MiraiConsoleBuildConstants.versionConst, + "" to " [ BackEnd] v" + kotlin.runCatching { net.mamoe.mirai.console.internal.MiraiConsoleBuildConstants.version }.getOrElse { "" }, "" to "", @@ -171,14 +172,18 @@ internal fun overrideSTD() { PrintStream( BufferedOutputStream( logger = DefaultLogger("stdout").run { ({ line: String? -> info(line) }) } - ) + ), + false, + "UTF-8" ) ) System.setErr( PrintStream( BufferedOutputStream( logger = DefaultLogger("stderr").run { ({ line: String? -> warning(line) }) } - ) + ), + false, + "UTF-8" ) ) } diff --git a/tools/gradle-plugin/src/main/kotlin/net/mamoe/mirai/console/gradle/VersionConstants.kt b/tools/gradle-plugin/src/main/kotlin/net/mamoe/mirai/console/gradle/VersionConstants.kt index c4fc5e2bf..6c293ee10 100644 --- a/tools/gradle-plugin/src/main/kotlin/net/mamoe/mirai/console/gradle/VersionConstants.kt +++ b/tools/gradle-plugin/src/main/kotlin/net/mamoe/mirai/console/gradle/VersionConstants.kt @@ -10,6 +10,6 @@ package net.mamoe.mirai.console.gradle internal object VersionConstants { - const val CONSOLE_VERSION = "1.0-RC-dev-29" // value is written here automatically during build + const val CONSOLE_VERSION = "1.0-RC-dev-30" // value is written here automatically during build const val CORE_VERSION = "1.3.0" // value is written here automatically during build } \ No newline at end of file diff --git a/tools/intellij-plugin/build.gradle.kts b/tools/intellij-plugin/build.gradle.kts index 93a94e3f8..2c02d5f7c 100644 --- a/tools/intellij-plugin/build.gradle.kts +++ b/tools/intellij-plugin/build.gradle.kts @@ -52,7 +52,7 @@ tasks.withType { sinceBuild("193.*") untilBuild("205.*") pluginDescription(""" - Plugin development support for Mirai Conosle + Plugin development support for Mirai Console

Features

    diff --git a/tools/intellij-plugin/run/projects/test-project/build.gradle.kts b/tools/intellij-plugin/run/projects/test-project/build.gradle.kts index 72f695b95..e1c0ff8b7 100644 --- a/tools/intellij-plugin/run/projects/test-project/build.gradle.kts +++ b/tools/intellij-plugin/run/projects/test-project/build.gradle.kts @@ -22,7 +22,7 @@ dependencies { compileOnly(kotlin("stdlib-jdk8")) val core = "1.3.0" - val console = "1.0-RC-dev-4" + val console = "1.0-RC-dev-28" compileOnly("net.mamoe:mirai-console:$console") compileOnly("net.mamoe:mirai-core:$core") diff --git a/tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/resolve/resolveIdea.kt b/tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/resolve/resolveIdea.kt index a03640687..723da4408 100644 --- a/tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/resolve/resolveIdea.kt +++ b/tools/intellij-plugin/src/main/kotlin/net/mamoe/mirai/console/intellij/resolve/resolveIdea.kt @@ -19,7 +19,6 @@ import net.mamoe.mirai.console.compiler.common.resolve.findParent import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.descriptors.VariableDescriptor -import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall import org.jetbrains.kotlin.idea.refactoring.fqName.getKotlinFqName import org.jetbrains.kotlin.idea.references.KtSimpleNameReference import org.jetbrains.kotlin.idea.search.usagesSearch.descriptor @@ -98,7 +97,7 @@ fun KtDeclaration.resolveAllCallsWithElement(bindingContext: BindingContext): Se .filterIsInstance() .mapNotNull { val callee = it.calleeExpression ?: return@mapNotNull null - val resolved = callee.getResolvedCallOrResolveToCall(bindingContext) ?: return@mapNotNull null + val resolved = callee.getResolvedCall(bindingContext) ?: return@mapNotNull null resolved to it } @@ -128,7 +127,7 @@ fun KtElement?.getResolvedCallOrResolveToCall( context: BindingContext, bodyResolveMode: BodyResolveMode = BodyResolveMode.PARTIAL, ): ResolvedCall? { - return this?.getCall(context)?.getResolvedCall(context) ?: this?.resolveToCall(bodyResolveMode) + return this?.getCall(context)?.getResolvedCall(context)// ?: this?.resolveToCall(bodyResolveMode) } val ResolvedCall.valueParameters: List get() = this.resultingDescriptor.valueParameters