Skip to content

Commit

Permalink
Warning if used undefined dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Karlatemp committed Feb 20, 2022
1 parent b0dcae6 commit 74f1319
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 74f1319

Please sign in to comment.