Search in sources :

Example 16 with Plugin

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);
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) Plugin(com.alipay.sofa.ark.spi.model.Plugin) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest)

Example 17 with 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);
}
Also used : PluginManagerService(com.alipay.sofa.ark.spi.service.plugin.PluginManagerService) PluginModel(com.alipay.sofa.ark.container.model.PluginModel) Plugin(com.alipay.sofa.ark.spi.model.Plugin)

Example 18 with 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));
}
Also used : Biz(com.alipay.sofa.ark.spi.model.Biz) File(java.io.File) URL(java.net.URL) Plugin(com.alipay.sofa.ark.spi.model.Plugin) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest)

Example 19 with Plugin

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());
}
Also used : File(java.io.File) URL(java.net.URL) Plugin(com.alipay.sofa.ark.spi.model.Plugin) Test(org.junit.Test) BaseTest(com.alipay.sofa.ark.container.BaseTest)

Example 20 with Plugin

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;
}
Also used : Plugin(com.alipay.sofa.ark.spi.model.Plugin)

Aggregations

Plugin (com.alipay.sofa.ark.spi.model.Plugin)42 Test (org.junit.Test)22 BaseTest (com.alipay.sofa.ark.container.BaseTest)20 PluginModel (com.alipay.sofa.ark.container.model.PluginModel)14 URL (java.net.URL)14 Biz (com.alipay.sofa.ark.spi.model.Biz)10 File (java.io.File)10 JarFile (com.alipay.sofa.ark.loader.jar.JarFile)6 PluginArchive (com.alipay.sofa.ark.spi.archive.PluginArchive)6 HashSet (java.util.HashSet)6 BizModel (com.alipay.sofa.ark.container.model.BizModel)4 ArkRuntimeException (com.alipay.sofa.ark.exception.ArkRuntimeException)4 JarPluginArchive (com.alipay.sofa.ark.loader.JarPluginArchive)4 JarFileArchive (com.alipay.sofa.ark.loader.archive.JarFileArchive)4 ExecutableArchive (com.alipay.sofa.ark.spi.archive.ExecutableArchive)4 AfterBizStartupEvent (com.alipay.sofa.ark.spi.event.biz.AfterBizStartupEvent)4 BeforePluginStartupEvent (com.alipay.sofa.ark.spi.event.plugin.BeforePluginStartupEvent)4 OrderComparator (com.alipay.sofa.ark.common.util.OrderComparator)2 DirectoryBizArchive (com.alipay.sofa.ark.loader.DirectoryBizArchive)2 JarBizArchive (com.alipay.sofa.ark.loader.JarBizArchive)2