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));
}
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"));
}
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);
}
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;
}
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);
}
Aggregations