From 7e480c2de2bc72f5167988e5e4b91b07390498eb Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Tue, 27 Oct 2020 12:49:05 +0800 Subject: [PATCH] Update ExportManager rule --- .../internal/plugin/ExportManagerImpl.kt | 17 ++++-------- .../mirai/console/plugin/jvm/ExportManager.kt | 27 ++++++++++++------- docs/Plugins.md | 13 +++------ 3 files changed, 26 insertions(+), 31 deletions(-) diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/ExportManagerImpl.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/ExportManagerImpl.kt index 008723470..5797aece0 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/ExportManagerImpl.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/internal/plugin/ExportManagerImpl.kt @@ -36,21 +36,14 @@ internal class ExportManagerImpl( }.forEach { line -> val command = line.substringBefore(' ') val argument = line.substringAfter(' ', missingDelimiterValue = "").trim() + val argumentPackage = "$argument." when (command) { - "exports", "export-package" -> rules.add { - it.startsWith(argument).without(false) + "exports" -> rules.add { + (it == argument || it.startsWith(argumentPackage)).without(false) } - "export", "export-class" -> rules.add { - (it == argument).without(false) - } - "protects", "protect-package" -> rules.add { - if (it.startsWith(argument)) - false - else null - } - "protect", "protect-class" -> rules.add { - if (it == argument) + "protects" -> rules.add { + if (it == argument || it.startsWith(argumentPackage)) false else null } diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/ExportManager.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/ExportManager.kt index e99970c72..1c2626720 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/ExportManager.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/plugin/jvm/ExportManager.kt @@ -11,7 +11,6 @@ package net.mamoe.mirai.console.plugin.jvm import net.mamoe.mirai.console.internal.plugin.ExportManagerImpl import net.mamoe.mirai.console.util.ConsoleExperimentalApi -import kotlin.reflect.KClass /** * 插件的类导出管理器 @@ -27,24 +26,19 @@ import kotlin.reflect.KClass * * # #开头的行全部识别为注释 * - * # export, 允许其他插件直接使用某个类 + * # exports, 允许其他插件直接使用某个类 * * # 导出了一个internal包的一个类 * # - * # 别名: export-class - * export org.example.miraiconsole.myplugin.internal.OpenInternal - * # 可以使用别名 - * export-class org.example.miraiconsole.myplugin.internal.OpenInternal + * exports org.example.miraiconsole.myplugin.internal.OpenInternal * * # 导出了整个 api 包 * # - * # 别名: export-package * exports org.example.miraiconsole.myplugin.api * * # 保护 org.example.miraiconsole.myplugin.api2.Internal, 不允许其他插件直接使用 * # - * # 别名: protect-class - * protect org.example.miraiconsole.myplugin.api2.Internal + * protects org.example.miraiconsole.myplugin.api2.Internal * * # 保护整个包 * # @@ -53,7 +47,7 @@ import kotlin.reflect.KClass * * # 此规则不会生效, 因为在此条规则之前, * # org.example.miraiconsole.myplugin.internal 已经被加入到保护域中 - * export org.example.miraiconsole.myplugin.internal.NotOpenInternal + * exports org.example.miraiconsole.myplugin.internal.NotOpenInternal * * * # export-plugin, 允许其他插件使用除了已经被保护的全部类 @@ -69,6 +63,19 @@ import kotlin.reflect.KClass * * ``` * + * 插件也可以通过 Service 来自定义导出控制 + * + * Example: + * ```kotlin + * @AutoService(ExportManager::class) + * object MyExportManager: ExportManager { + * override fun isExported(className: String): Boolean { + * println(" <== $className") + * return true + * } + * } + * ``` + * */ @ConsoleExperimentalApi public interface ExportManager { diff --git a/docs/Plugins.md b/docs/Plugins.md index a74a4d6bc..f472c8f30 100644 --- a/docs/Plugins.md +++ b/docs/Plugins.md @@ -174,24 +174,19 @@ Example: # #开头的行全部识别为注释 -# export, 允许其他插件直接使用某个类 +# exports, 允许其他插件直接使用某个类 # 导出了一个internal包的一个类 # -# 别名: export-class -export org.example.miraiconsole.myplugin.internal.OpenInternal -# 可以使用别名 -export-class org.example.miraiconsole.myplugin.internal.OpenInternal +exports org.example.miraiconsole.myplugin.internal.OpenInternal # 导出了整个 api 包 # -# 别名: export-package exports org.example.miraiconsole.myplugin.api # 保护 org.example.miraiconsole.myplugin.api2.Internal, 不允许其他插件直接使用 # -# 别名: protect-class -protect org.example.miraiconsole.myplugin.api2.Internal +protects org.example.miraiconsole.myplugin.api2.Internal # 保护整个包 # @@ -200,7 +195,7 @@ protects org.example.miraiconsole.myplugin.internal # 此规则不会生效, 因为在此条规则之前, # org.example.miraiconsole.myplugin.internal 已经被加入到保护域中 -export org.example.miraiconsole.myplugin.internal.NotOpenInternal +exports org.example.miraiconsole.myplugin.internal.NotOpenInternal # export-plugin, 允许其他插件使用除了已经被保护的全部类