mirror of
https://github.com/LamGC/ScalaBot.git
synced 2025-07-01 12:57:24 +00:00
feat(extension): 支持 ExtensionPackageFinder 设置优先级.
添加 FinderRules 注解, 发现器标记注解后, 将根据优先级选择加载扩展包; 该改动有助于支持远端扩展包加载的开发, 例如可以直接从 maven 中央仓库获取支持加载的构件, 支持该功能将大大增加便捷性. Closed #1
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
package net.lamgc.scalabot.util
|
||||
|
||||
import net.lamgc.scalabot.ExtensionPackageFinder
|
||||
import net.lamgc.scalabot.FinderRules
|
||||
import org.eclipse.aether.artifact.Artifact
|
||||
import java.io.File
|
||||
import java.io.FileFilter
|
||||
@ -53,3 +55,11 @@ internal fun File.deepListFiles(
|
||||
return result.toTypedArray()
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 Finder 的 [FinderRules] 注解中获取优先级.
|
||||
* @return 获取 Finder 的优先级.
|
||||
* @throws NoSuchFieldException 如果 Finder 没有添加 [FinderRules] 注解时抛出该异常.
|
||||
*/
|
||||
internal fun ExtensionPackageFinder.getPriority() =
|
||||
this::class.java.getDeclaredAnnotation(FinderRules::class.java)?.priority
|
||||
?: throw NoSuchFieldException("Finder did not add `FinderRules` annotation")
|
||||
|
Reference in New Issue
Block a user