use of com.alipay.sofa.ark.spi.model.Plugin in project sofa-ark by alipay.
the class ClassLoaderServiceTest method testFindExportClass.
@Test
public void testFindExportClass() {
PluginClassLoader pluginClassLoader = new PluginClassLoader("mockPlugin", new URL[] {});
Plugin plugin = new PluginModel().setPluginName("mockPlugin").setExportPackages("a.b.*,a.f,a.b.f").setExportClasses("a.e.f.G").setPluginClassLoader(pluginClassLoader).setExportResources("");
pluginManagerService.registerPlugin(plugin);
classloaderService.prepareExportClassAndResourceCache();
Assert.assertNull(classloaderService.findExportClassLoader("a.b"));
Assert.assertTrue(pluginClassLoader.equals(classloaderService.findExportClassLoader("a.b.e.f")));
Assert.assertTrue(pluginClassLoader.equals(classloaderService.findExportClassLoader("a.f.g")));
Assert.assertTrue(pluginClassLoader.equals(classloaderService.findExportClassLoader("a.e.f.G")));
Assert.assertTrue(pluginClassLoader.equals(classloaderService.findExportClassLoader("a.b.f.m")));
Assert.assertTrue(pluginClassLoader.equals(classloaderService.findExportClassLoader("a.b.f.m.g")));
Assert.assertNull(classloaderService.findExportClassLoader("a.f.h.m"));
Assert.assertNull(classloaderService.findExportClassLoader("a"));
pluginManagerService.getPluginsInOrder().remove(plugin);
}
use of com.alipay.sofa.ark.spi.model.Plugin in project sofa-ark by alipay.
the class BaseTest method registerMockPlugin.
protected void registerMockPlugin() {
if (arkContainer == null) {
String[] args = new String[] { "-Ajar=" + jarURL.toExternalForm() };
arkContainer = (ArkContainer) ArkContainer.main(args);
}
PluginManagerService pluginManagerService = ArkServiceContainerHolder.getContainer().getService(PluginManagerService.class);
Plugin plugin = new PluginModel().setPluginName("mock").setPluginClassLoader(this.getClass().getClassLoader()).setImportClasses("").setImportPackages("").setImportResources("");
pluginManagerService.registerPlugin(plugin);
}
use of com.alipay.sofa.ark.spi.model.Plugin in project sofa-ark by alipay.
the class BizFactoryServiceTest method test.
@Test
public void test() throws Throwable {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL samplePlugin = cl.getResource("sample-plugin.jar");
Plugin plugin = pluginFactoryService.createPlugin(new File(samplePlugin.getFile()));
pluginManagerService.registerPlugin(plugin);
URL sampleBiz = cl.getResource("sample-biz.jar");
Biz biz = bizFactoryService.createBiz(new File(sampleBiz.getFile()));
bizManagerService.registerBiz(biz);
Assert.assertNotNull(biz);
Assert.assertNotNull(biz.getBizClassLoader().getResource(Constants.ARK_PLUGIN_MARK_ENTRY));
}
use of com.alipay.sofa.ark.spi.model.Plugin in project sofa-ark by alipay.
the class BizFactoryServiceTest method testPackageInfo.
@Test
public void testPackageInfo() throws Throwable {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL samplePlugin = cl.getResource("sample-ark-plugin.jar");
Plugin plugin = pluginFactoryService.createPlugin(new File(samplePlugin.getFile()));
ClassLoader pluginClassLoader = plugin.getPluginClassLoader();
pluginManagerService.registerPlugin(plugin);
Class mdc = pluginClassLoader.loadClass("org.slf4j.MDC");
Assert.assertTrue(mdc.getClassLoader().equals(pluginClassLoader));
Assert.assertNotNull(mdc.getPackage().getImplementationVersion());
}
use of com.alipay.sofa.ark.spi.model.Plugin in project sofa-ark by alipay.
the class ClassLoaderServiceImpl method isClassInImport.
@Override
public boolean isClassInImport(String pluginName, String className) {
Plugin plugin = pluginManagerService.getPluginByName(pluginName);
AssertUtils.assertNotNull(plugin, "plugin: " + pluginName + " is null");
for (String importName : plugin.getImportClasses()) {
if (className.equals(importName)) {
return true;
}
}
String pkg = ClassUtils.getPackageName(className);
for (String pattern : plugin.getImportPackageNodes()) {
if (pkg.equals(pattern)) {
return true;
}
}
for (String pattern : plugin.getImportPackageStems()) {
if (pkg.startsWith(pattern)) {
return true;
}
}
return false;
}
Aggregations