Skip to content

Commit

Permalink
fix: 修复委托基座加载资源过程中,模块未声明的依赖存在该资源时,无法正确获取资源(#1030) (#1031)
Browse files Browse the repository at this point in the history
* fix: correctly retrieve resources when undeclared dependencies exist during the loading of the delegate base from

* fix: spaces map type forcible transfer

* fix: test

---------

Co-authored-by: fanyue <[email protected]>
Co-authored-by: leo james <[email protected]>

(cherry picked from commit cd1e640)
  • Loading branch information
Jackisome authored and lvjing2 committed Dec 10, 2024
1 parent 027cc74 commit 4bc342f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
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,8 +140,8 @@ 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.assertNull(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")
Expand Down

0 comments on commit 4bc342f

Please sign in to comment.