Search in sources :

Example 16 with PluginModel

use of com.alipay.sofa.ark.container.model.PluginModel in project sofa-ark by alipay.

the class BizClassLoaderTest method testDenyImportResourceStems.

@Test
public void testDenyImportResourceStems() {
    PluginModel pluginA = new PluginModel();
    pluginA.setPluginName("pluginA").setClassPath(new URL[] { classPathURL }).setImportClasses(StringUtils.EMPTY_STRING).setImportPackages(StringUtils.EMPTY_STRING).setImportResources(StringUtils.EMPTY_STRING).setExportResources("export/folderA/*,export/folderB/*").setExportClasses(ITest.class.getName()).setPluginClassLoader(new PluginClassLoader(pluginA.getPluginName(), pluginA.getClassPath()));
    pluginManagerService.registerPlugin(pluginA);
    pluginDeployService.deploy();
    classloaderService.prepareExportClassAndResourceCache();
    BizModel bizModel = new BizModel().setBizState(BizState.RESOLVED);
    bizModel.setBizName("bizA").setBizVersion("1.0.0").setClassPath(new URL[0]).setClassLoader(new BizClassLoader(bizModel.getIdentity(), bizModel.getClassPath()));
    bizModel.setDenyImportResources("export/folderA/*,export/folderB/test3.xml");
    bizModel.setDenyImportPackages(StringUtils.EMPTY_STRING);
    bizModel.setDenyImportClasses(StringUtils.EMPTY_STRING);
    bizManagerService.registerBiz(bizModel);
    String testResource1 = "export/folderA/test1.xml";
    String testResource2 = "export/folderA/test2.xml";
    String testResource3 = "export/folderB/test3.xml";
    String testResource4 = "export/folderB/test4.xml";
    Assert.assertNull(bizModel.getBizClassLoader().getResource(testResource1));
    Assert.assertNull(bizModel.getBizClassLoader().getResource(testResource2));
    Assert.assertNull(bizModel.getBizClassLoader().getResource(testResource3));
    // testResource4 not in deny-import
    Assert.assertNotNull(bizModel.getBizClassLoader().getResource(testResource4));
    Assert.assertEquals(pluginA.getPluginClassLoader().getResource(testResource4), bizModel.getBizClassLoader().getResource(testResource4));
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) BizModel(com.alipay.sofa.ark.container.model.BizModel) URL(java.net.URL) BaseTest(com.alipay.sofa.ark.container.BaseTest) ITest(com.alipay.sofa.ark.container.testdata.ITest) Test(org.junit.Test)

Example 17 with PluginModel

use of com.alipay.sofa.ark.container.model.PluginModel in project sofa-ark by alipay.

the class BizClassLoaderTest method testGetPluginClassResource.

@Test
public void testGetPluginClassResource() {
    PluginModel pluginA = new PluginModel();
    pluginA.setPluginName("plugin A").setClassPath(new URL[] { classPathURL }).setImportClasses(StringUtils.EMPTY_STRING).setImportPackages(StringUtils.EMPTY_STRING).setExportPackages("").setExportClasses(ITest.class.getName()).setImportResources(StringUtils.EMPTY_STRING).setExportResources(StringUtils.EMPTY_STRING).setPluginClassLoader(new PluginClassLoader(pluginA.getPluginName(), pluginA.getClassPath()));
    pluginManagerService.registerPlugin(pluginA);
    pluginDeployService.deploy();
    classloaderService.prepareExportClassAndResourceCache();
    BizModel bizModel = new BizModel().setBizState(BizState.RESOLVED);
    bizModel.setBizName("biz A").setBizVersion("1.0.0").setClassPath(new URL[0]).setDenyImportClasses(StringUtils.EMPTY_STRING).setDenyImportResources(StringUtils.EMPTY_STRING).setDenyImportPackages(StringUtils.EMPTY_STRING).setClassLoader(new BizClassLoader(bizModel.getIdentity(), bizModel.getClassPath()));
    bizManagerService.registerBiz(bizModel);
    Assert.assertNotNull(bizModel.getBizClassLoader().getResource(ITest.class.getName().replace(".", "/") + ".class"));
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) BizModel(com.alipay.sofa.ark.container.model.BizModel) URL(java.net.URL) BaseTest(com.alipay.sofa.ark.container.BaseTest) ITest(com.alipay.sofa.ark.container.testdata.ITest) Test(org.junit.Test)

Example 18 with PluginModel

use of com.alipay.sofa.ark.container.model.PluginModel 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 19 with PluginModel

use of com.alipay.sofa.ark.container.model.PluginModel in project sofa-ark by alipay.

the class PluginFactoryServiceImpl method createPlugin.

@Override
public Plugin createPlugin(PluginArchive pluginArchive) throws IOException, IllegalArgumentException {
    AssertUtils.isTrue(isArkPlugin(pluginArchive), "Archive must be a ark plugin!");
    PluginModel plugin = new PluginModel();
    Attributes manifestMainAttributes = pluginArchive.getManifest().getMainAttributes();
    plugin.setPluginName(manifestMainAttributes.getValue(PLUGIN_NAME_ATTRIBUTE)).setGroupId(manifestMainAttributes.getValue(GROUP_ID_ATTRIBUTE)).setArtifactId(manifestMainAttributes.getValue(ARTIFACT_ID_ATTRIBUTE)).setVersion(manifestMainAttributes.getValue(PLUGIN_VERSION_ATTRIBUTE)).setPriority(manifestMainAttributes.getValue(PRIORITY_ATTRIBUTE)).setPluginActivator(manifestMainAttributes.getValue(ACTIVATOR_ATTRIBUTE)).setClassPath(pluginArchive.getUrls()).setPluginUrl(pluginArchive.getUrl()).setExportClasses(manifestMainAttributes.getValue(EXPORT_CLASSES_ATTRIBUTE)).setExportPackages(manifestMainAttributes.getValue(EXPORT_PACKAGES_ATTRIBUTE)).setImportClasses(manifestMainAttributes.getValue(IMPORT_CLASSES_ATTRIBUTE)).setImportPackages(manifestMainAttributes.getValue(IMPORT_PACKAGES_ATTRIBUTE)).setImportResources(manifestMainAttributes.getValue(IMPORT_RESOURCES_ATTRIBUTE)).setExportResources(manifestMainAttributes.getValue(EXPORT_RESOURCES_ATTRIBUTE)).setPluginClassLoader(new PluginClassLoader(plugin.getPluginName(), plugin.getClassPath())).setPluginContext(new PluginContextImpl(plugin));
    return plugin;
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) PluginContextImpl(com.alipay.sofa.ark.container.model.PluginContextImpl) Attributes(java.util.jar.Attributes) PluginClassLoader(com.alipay.sofa.ark.container.service.classloader.PluginClassLoader)

Example 20 with PluginModel

use of com.alipay.sofa.ark.container.model.PluginModel 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)

Aggregations

PluginModel (com.alipay.sofa.ark.container.model.PluginModel)47 Test (org.junit.Test)42 BaseTest (com.alipay.sofa.ark.container.BaseTest)34 ITest (com.alipay.sofa.ark.container.testdata.ITest)25 URL (java.net.URL)16 PluginContextImpl (com.alipay.sofa.ark.container.model.PluginContextImpl)9 HashSet (java.util.HashSet)9 BizModel (com.alipay.sofa.ark.container.model.BizModel)8 PluginClassLoader (com.alipay.sofa.ark.container.service.classloader.PluginClassLoader)7 Plugin (com.alipay.sofa.ark.spi.model.Plugin)7 TestObjectA (com.alipay.sofa.ark.container.testdata.impl.TestObjectA)5 PluginManagerService (com.alipay.sofa.ark.spi.service.plugin.PluginManagerService)5 ArkContainerTest (com.alipay.sofa.ark.container.ArkContainerTest)4 HandleArchiveStage (com.alipay.sofa.ark.container.pipeline.HandleArchiveStage)4 URLClassLoader (java.net.URLClassLoader)4 Attributes (java.util.jar.Attributes)4 DefaultServiceFilter (com.alipay.sofa.ark.container.registry.DefaultServiceFilter)3 PluginServiceProvider (com.alipay.sofa.ark.container.registry.PluginServiceProvider)3 ArkRuntimeException (com.alipay.sofa.ark.exception.ArkRuntimeException)3 ContainerServiceProvider (com.alipay.sofa.ark.container.registry.ContainerServiceProvider)2