Skip to content

Commit

Permalink
fix: correctly retrieve resources when undeclared dependencies exist …
Browse files Browse the repository at this point in the history
…during the loading of the delegate base from
  • Loading branch information
fanyue committed Nov 21, 2024
1 parent 7ab39b4 commit 479a85c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 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,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

0 comments on commit 479a85c

Please sign in to comment.