1
0
mirror of https://github.com/mamoe/mirai.git synced 2025-04-25 04:50:26 +08:00

Warning if used undefined dependencies

This commit is contained in:
Karlatemp 2022-02-07 20:30:29 +08:00
parent 22d2bd79df
commit 8e77109d26
No known key found for this signature in database
GPG Key ID: C6B606FF23D8FED7
2 changed files with 18 additions and 5 deletions
mirai-console/backend/mirai-console/src/internal/plugin

View File

@ -143,7 +143,9 @@ internal class BuiltInJvmPluginLoaderImpl(
JvmPlugin::class,
KotlinPlugin::class,
JavaPlugin::class
).loadAllServices()
).loadAllServices().also { plugins ->
plugins.firstOrNull()?.logger?.let { pluginClassLoader.linkedLogger = it }
}
}.flatMap { (f, list) ->
list.associateBy { f }.asSequence()

View File

@ -10,10 +10,9 @@
package net.mamoe.mirai.console.internal.plugin
import net.mamoe.mirai.console.MiraiConsole
import net.mamoe.mirai.console.plugin.jvm.ExportManager
import net.mamoe.mirai.utils.MiraiLogger
import net.mamoe.mirai.utils.debug
import net.mamoe.mirai.utils.verbose
import net.mamoe.mirai.utils.*
import org.eclipse.aether.artifact.Artifact
import org.eclipse.aether.graph.DependencyFilter
import java.io.File
@ -94,6 +93,12 @@ internal class JvmPluginClassLoaderN : URLClassLoader {
lateinit var pluginSharedCL: DynLibClassLoader
lateinit var pluginIndependentCL: DynLibClassLoader
@Suppress("PrivatePropertyName")
private val file_: File
get() = file
var linkedLogger by lateinitMutableProperty { MiraiConsole.createLogger("JvmPlugin[" + file_.name + "]") }
val undefinedDependencies = mutableSetOf<String>()
private constructor(file: File, ctx: JvmPluginsLoadingCtx, unused: Unit) : super(
arrayOf(), ctx.sharedLibrariesLoader
@ -241,7 +246,13 @@ internal class JvmPluginClassLoaderN : URLClassLoader {
// Finally, try search from other plugins and console system
ctx.pluginClassLoaders.forEach { other ->
if (other !== this && other !in dependencies) {
other.resolvePluginPublicClass(name)?.let { return it }
other.resolvePluginPublicClass(name)?.let {
if (undefinedDependencies.add(other.file.name)) {
linkedLogger.warning { "Linked class $name in ${other.file.name} but plugin not depend on it." }
linkedLogger.warning { "Class loading logic may change in feature." }
}
return it
}
}
}
return AllDependenciesClassesHolder.appClassLoader.loadClass(name)