-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathPluginDependOnOther.kt
56 lines (52 loc) · 2.36 KB
/
PluginDependOnOther.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Copyright 2019-2022 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/dev/LICENSE
*/
package net.mamoe.console.integrationtest.ep.dependonother
import net.mamoe.console.integrationtest.ep.mcitselftest.MCITSelfTestPlugin
import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescription
import net.mamoe.mirai.console.plugin.jvm.KotlinPlugin
import net.mamoe.mirai.utils.info
import kotlin.test.assertFails
import kotlin.test.assertFailsWith
import kotlin.test.assertNotEquals
import kotlin.test.assertSame
/*
PluginDependOnOther: 测试插件依赖其他插件的情况
*/
public object PluginDependOnOther : KotlinPlugin(
JvmPluginDescription(
id = "net.mamoe.tester.plugin-depend-on-other",
version = "1.0.0",
name = "Plugin Depend On Other",
) {
dependsOn("net.mamoe.tester.mirai-console-self-test")
dependsOn("net.mamoe.tester.plugin-dynamic-dependencies-download")
}
) {
override fun onEnable() {
logger.info { "Do dependency call: " + MCITSelfTestPlugin::class.java }
logger.info { "No Depends on: " + Class.forName("samepkg.P") }
logger.info(Throwable("Stack trace"))
MCITSelfTestPlugin.someAction()
logger.info { "Shared library: " + Class.forName("net.mamoe.console.it.psl.PluginSharedLib") }
assertNotEquals(javaClass.classLoader, Class.forName("net.mamoe.console.it.psl.PluginSharedLib").classLoader)
// dependencies-shared
kotlin.run {
val pluginDepDynDownload = Class.forName("net.mamoe.console.integrationtest.ep.pddd.P")
val gsonC = Class.forName("com.google.gson.Gson")
logger.info { "Gson located $gsonC <${gsonC.classLoader}>" }
assertSame(gsonC, Class.forName(gsonC.name, false, pluginDepDynDownload.classLoader))
assertFailsWith<ClassNotFoundException> {
Class.forName("com.zaxxer.sparsebits.SparseBitSet") // private in dynamic-dep-download
}
assertFailsWith<ClassNotFoundException> {
Class.forName("net.mamoe.assertion.something.not.existing")
}
}
}
}