Update ExportManager rule

This commit is contained in:
Karlatemp 2020-10-27 12:49:05 +08:00
parent 9b042a439c
commit 7e480c2de2
No known key found for this signature in database
GPG Key ID: 21FBDDF664FF06F8
3 changed files with 26 additions and 31 deletions

View File

@ -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
}

View File

@ -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 {

View File

@ -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, 允许其他插件使用除了已经被保护的全部类