mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 18:40:15 +08:00
Fix build
This commit is contained in:
parent
4b58c76385
commit
ce49e27e95
@ -16,7 +16,7 @@ import java.net.URLClassLoader
|
||||
internal class PluginsLoader(private val parentClassLoader: ClassLoader) {
|
||||
private val loggerName = "PluginsLoader"
|
||||
private val pluginLoaders = linkedMapOf<String, PluginClassLoader>()
|
||||
private val classesCache = mutableMapOf<String,Class<*>>()
|
||||
private val classesCache = mutableMapOf<String, Class<*>>()
|
||||
private val logger = MiraiConsole.newLogger(loggerName)
|
||||
|
||||
/**
|
||||
@ -93,9 +93,9 @@ internal class PluginsLoader(private val parentClassLoader: ClassLoader) {
|
||||
* A Adapted URL Class Loader that supports Android and JVM for single URL(File) Class Load
|
||||
*/
|
||||
|
||||
internal open class AdaptiveURLClassLoader(file: File, parent: ClassLoader):ClassLoader(){
|
||||
internal open class AdaptiveURLClassLoader(file: File, parent: ClassLoader) : ClassLoader() {
|
||||
|
||||
private val internalClassLoader:ClassLoader by lazy {
|
||||
private val internalClassLoader: ClassLoader by lazy {
|
||||
kotlin.runCatching {
|
||||
val loaderClass = Class.forName("dalvik.system.PathClassLoader")
|
||||
loaderClass.getConstructor(String::class.java, ClassLoader::class.java)
|
||||
@ -110,19 +110,19 @@ internal open class AdaptiveURLClassLoader(file: File, parent: ClassLoader):Clas
|
||||
}
|
||||
|
||||
|
||||
private val internalClassCache = mutableMapOf<String,Class<*>>()
|
||||
private val internalClassCache = mutableMapOf<String, Class<*>>()
|
||||
|
||||
internal val classesCache:Map<String,Class<*>>
|
||||
internal val classesCache: Map<String, Class<*>>
|
||||
get() = internalClassCache
|
||||
|
||||
internal fun addClassCache(string: String, clazz: Class<*>){
|
||||
synchronized(internalClassCache){
|
||||
internal fun addClassCache(string: String, clazz: Class<*>) {
|
||||
synchronized(internalClassCache) {
|
||||
internalClassCache[string] = clazz
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun close(){
|
||||
fun close() {
|
||||
if (internalClassLoader is URLClassLoader) {
|
||||
(internalClassLoader as URLClassLoader).close()
|
||||
}
|
||||
@ -135,24 +135,25 @@ internal class PluginClassLoader(
|
||||
file: File,
|
||||
private val pluginsLoader: PluginsLoader,
|
||||
parent: ClassLoader
|
||||
) :AdaptiveURLClassLoader(file,parent){
|
||||
) : AdaptiveURLClassLoader(file, parent) {
|
||||
|
||||
override fun findClass(name: String): Class<*> {
|
||||
return findClass(name,true)
|
||||
return findClass(name, true)
|
||||
}
|
||||
|
||||
fun findClass(name: String, global: Boolean = true): Class<*>{
|
||||
return classesCache[name]?: kotlin.run {
|
||||
fun findClass(name: String, global: Boolean = true): Class<*> {
|
||||
return classesCache[name] ?: kotlin.run {
|
||||
var clazz: Class<*>? = null
|
||||
if (global) {
|
||||
clazz = pluginsLoader.findClassByName(name)
|
||||
}
|
||||
if(clazz == null) {
|
||||
if (clazz == null) {
|
||||
clazz = loadClass(name)//这里应该是find, 如果不行就要改
|
||||
}
|
||||
pluginsLoader.addClassCache(name, clazz)
|
||||
this.addClassCache(name, clazz)
|
||||
clazz
|
||||
@Suppress("UNNECESSARY_NOT_NULL_ASSERTION")
|
||||
clazz!! // compiler bug
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,32 +15,32 @@ import net.mamoe.mirai.console.setting.Setting
|
||||
import net.mamoe.mirai.console.setting.Value
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KType
|
||||
import kotlin.reflect.full.isSubclassOf
|
||||
|
||||
|
||||
@PublishedApi
|
||||
internal fun Setting.valueFromKTypeImpl(type: KType): Value<*> {
|
||||
require(type.classifier is KClass<*>)
|
||||
val classifier = type.classifier
|
||||
require(classifier is KClass<*>)
|
||||
|
||||
if (type.classifier.isPrimitiveOrBuiltInSerializableValue()) {
|
||||
if (classifier.isPrimitiveOrBuiltInSerializableValue()) {
|
||||
TODO("是基础类型, 可以直接创建 ValueImpl. ")
|
||||
}
|
||||
|
||||
// 复合类型
|
||||
|
||||
when {
|
||||
type.classifier.isSubclassOf(Map::class) -> {
|
||||
classifier == Map::class -> {
|
||||
|
||||
TODO()
|
||||
}
|
||||
type.classifier.isSubclassOf(List::class) -> {
|
||||
classifier == List::class -> {
|
||||
|
||||
TODO()
|
||||
}
|
||||
type.classifier.isSubclassOf(Set::class) -> {
|
||||
classifier == Set::class -> {
|
||||
TODO()
|
||||
}
|
||||
else -> error("Custom composite value is not supported yet (${type.classifier.qualifiedName})")
|
||||
else -> error("Custom composite value is not supported yet (${classifier.qualifiedName})")
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user