Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复JvmPlugin无法通过自己的classLoader以getResource的方法获取全局依赖的class文件 #2536

Merged
merged 13 commits into from
Mar 12, 2023

Conversation

ArgonarioD
Copy link
Contributor

fix #2535
原本JvmPlugin的classLoader可以正确地加载到全局依赖的Class对象,但无法通过getResource方法获取到其class文件。

@Him188 Him188 requested a review from Karlatemp February 27, 2023 00:12
@Him188 Him188 added the s:console 子系统: mirai-console label Feb 27, 2023
@ArgonarioD ArgonarioD requested a review from Karlatemp February 27, 2023 16:43
@Karlatemp
Copy link
Member

添加测试单元

@ArgonarioD
Copy link
Contributor Author

ArgonarioD commented Feb 28, 2023

添加测试单元

我阅读集成单元测试的测试报告以及源码后发现在testers中的service-loader/service-loader-2dep-plugin中,net.mamoe.console.itest.serviceloader.ndep.PMain类的onEnable方法中有如下两个断言:

assertNull(javaClass.getResource("/net/mamoe/mirai/console/MiraiConsole.class"))
assertNull(javaClass.getResource("/net/mamoe/mirai/Bot.class"))

正是这两句断言导致我的集成测试失败,但是看起来似乎最初这里是不希望JvmPluginClassLoader可以通过getResource(String)方法获取到类的资源文件所以才编写的上文中的两句断言的吗?

@Karlatemp
Copy link
Member

已经不太记得当时为啥添加这个限制了,你可以在 jvmpluginclasspath 添加个方法启动搜索

@ArgonarioD ArgonarioD requested a review from Karlatemp March 4, 2023 15:48
@ArgonarioD ArgonarioD requested a review from Karlatemp March 5, 2023 06:26
@Karlatemp Karlatemp added the z:ready-to-merge 状态: PR 已经可以合并, 正在等待一些安排 label Mar 6, 2023
@ArgonarioD
Copy link
Contributor Author

话说我应该Update branch吗,还是就这样一直放着就好(小声
@Karlatemp

@Him188
Copy link
Member

Him188 commented Mar 12, 2023

GitHub 没说有冲突就不用更新

@Him188 Him188 added this to the 2.15.0-M1 milestone Mar 12, 2023
@Him188
Copy link
Member

Him188 commented Mar 12, 2023

@Karlatemp merge?

@Karlatemp
Copy link
Member

@Karlatemp merge?

ok

@Karlatemp Karlatemp merged commit 4f0f733 into mamoe:dev Mar 12, 2023
StageGuard pushed a commit to StageGuard/mirai that referenced this pull request Apr 14, 2023
* [console] Fixed classLoaders of JvmPlugin cannot getResource(classes of global dependencies), fix mamoe#2535

* [core/utils/jvm] new fun: addAll(Enumeration)

* [console] modify DynLibClassLoader.tryFastOrStrictResolveResource to tryFastOrStrictResolveResources

* [console] remove allClassesAsResources field

* [console] add var to control whether class files of mirai dependencies could be load as resources

* [console/integration-test] modify loader test

* [console] dump new apis

* [console] rename JvmPluginClasspath.openMiraiDependenciesClassResource and standardize its KDoc

* [console] modify the KDoc of JvmPluginClasspath.shouldResolveConsoleSystemResource

* [console/integration-test] improve resources loading test cases

* [console/integration-test] modify assert to assertTrue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s:console 子系统: mirai-console z:ready-to-merge 状态: PR 已经可以合并, 正在等待一些安排
Projects
None yet
Development

Successfully merging this pull request may close these issues.

无法通过JvmPlugin的JvmPluginClassLoader获取到mirai-console的class文件资源
3 participants