Skip to content

Commit 74f1319

Browse files
committed
Warning if used undefined dependencies
1 parent b0dcae6 commit 74f1319

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

mirai-console/backend/mirai-console/src/internal/plugin/BuiltInJvmPluginLoaderImpl.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ internal class BuiltInJvmPluginLoaderImpl(
143143
JvmPlugin::class,
144144
KotlinPlugin::class,
145145
JavaPlugin::class
146-
).loadAllServices()
146+
).loadAllServices().also { plugins ->
147+
plugins.firstOrNull()?.logger?.let { pluginClassLoader.linkedLogger = it }
148+
}
147149
}.flatMap { (f, list) ->
148150

149151
list.associateBy { f }.asSequence()

mirai-console/backend/mirai-console/src/internal/plugin/JvmPluginClassLoader.kt

+15-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010

1111
package net.mamoe.mirai.console.internal.plugin
1212

13+
import net.mamoe.mirai.console.MiraiConsole
1314
import net.mamoe.mirai.console.plugin.jvm.ExportManager
14-
import net.mamoe.mirai.utils.MiraiLogger
15-
import net.mamoe.mirai.utils.debug
16-
import net.mamoe.mirai.utils.verbose
15+
import net.mamoe.mirai.utils.*
1716
import org.eclipse.aether.artifact.Artifact
1817
import org.eclipse.aether.graph.DependencyFilter
1918
import java.io.File
@@ -94,6 +93,12 @@ internal class JvmPluginClassLoaderN : URLClassLoader {
9493
lateinit var pluginSharedCL: DynLibClassLoader
9594
lateinit var pluginIndependentCL: DynLibClassLoader
9695

96+
@Suppress("PrivatePropertyName")
97+
private val file_: File
98+
get() = file
99+
100+
var linkedLogger by lateinitMutableProperty { MiraiConsole.createLogger("JvmPlugin[" + file_.name + "]") }
101+
val undefinedDependencies = mutableSetOf<String>()
97102

98103
private constructor(file: File, ctx: JvmPluginsLoadingCtx, unused: Unit) : super(
99104
arrayOf(), ctx.sharedLibrariesLoader
@@ -241,7 +246,13 @@ internal class JvmPluginClassLoaderN : URLClassLoader {
241246
// Finally, try search from other plugins and console system
242247
ctx.pluginClassLoaders.forEach { other ->
243248
if (other !== this && other !in dependencies) {
244-
other.resolvePluginPublicClass(name)?.let { return it }
249+
other.resolvePluginPublicClass(name)?.let {
250+
if (undefinedDependencies.add(other.file.name)) {
251+
linkedLogger.warning { "Linked class $name in ${other.file.name} but plugin not depend on it." }
252+
linkedLogger.warning { "Class loading logic may change in feature." }
253+
}
254+
return it
255+
}
245256
}
246257
}
247258
return AllDependenciesClassesHolder.appClassLoader.loadClass(name)

0 commit comments

Comments
 (0)