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

fix: 修复委托基座加载资源过程中,模块未声明的依赖存在该资源时,无法正确获取资源(#1030) #1031

Merged
merged 6 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void testLoadClassFromPluginClassLoader() throws Exception {
.setExportClasses("")
.setExportPackages(ClassUtils.getPackageName(ITest.class.getName()))
.setImportResources(StringUtils.EMPTY_STRING)
.setExportResources("META-INF/services/sofa-ark/com.alipay.sofa.ark.container.service.extension.spi.ServiceB")
.setExportResources("META-INF/services/sofa-ark/com.alipay.sofa.ark.container.service.extension.spi.ServiceB, Sample_Resource_Exported_A")
.setPluginClassLoader(
new PluginClassLoader(pluginA.getPluginName(), pluginA.getClassPath()));

Expand All @@ -157,7 +157,7 @@ public void testLoadClassFromPluginClassLoader() throws Exception {
.setExportClasses("com.alipay.sofa.ark.sample.common.SampleClassExported,org.aopalliance.aop.Advice")
.setExportPackages("")
.setImportResources(StringUtils.EMPTY_STRING)
.setExportResources("Sample_Resource_Exported, META-INF/spring/service.xml")
.setExportResources("Sample_Resource_Exported, META-INF/spring/service.xml, Sample_Resource_Exported_A")
.setPluginClassLoader(
new PluginClassLoader(pluginB.getPluginName(), pluginB.getClassPath()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,17 @@ public URL postFindResource(String name, ClassLoaderService classLoaderService,
if (resourceUrl != null && biz.isDeclared(resourceUrl, name)) {
return resourceUrl;
}
return null;

Enumeration<URL> matchResourceUrls = postFindResources(name, classLoaderService, biz);

// get the first resource url when match multiple resources
if (matchResourceUrls != null && matchResourceUrls.hasMoreElements()) {
return matchResourceUrls.nextElement();
}
} catch (Exception e) {
return null;
}
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ public void testLoadClassFromClassLoaderHook() throws Exception {
Assert.assertNotNull(bizModel.getBizClassLoader().getResource(
"sample-ark-1.0.0-ark-biz.jar"));

// case 7: find resource from master in jar
Assert.assertNotNull(bizModel.getBizClassLoader().getResource("Sample_Resource_Exported"));

// case 7: find resource from master in multiple jar
Assert.assertNotNull(bizModel.getBizClassLoader().getResource("Sample_Resource_Exported_A"));
:
// case 8: find resources from master but not set provided in biz model
Assert.assertFalse(bizModel.getBizClassLoader().getResources("org/slf4j/ILoggerFactory.class")
.hasMoreElements());
Expand Down
Loading