use of com.alipay.sofa.ark.container.model.BizModel in project sofa-ark by alipay.
the class BizClassloaderTest method testGetPluginClassResource.
@Test
public void testGetPluginClassResource() throws Exception {
PluginModel pluginA = new PluginModel();
pluginA.setPluginName("plugin A").setClassPath(new URL[] { classPathURL }).setImportClasses(Collections.<String>emptySet()).setImportPackages(Collections.<String>emptySet()).setExportIndex(new HashSet<>(Collections.singletonList(ITest.class.getName()))).setPluginClassLoader(new PluginClassLoader(pluginA.getPluginName(), pluginA.getClassPath()));
pluginManagerService.registerPlugin(pluginA);
pluginDeployService.deploy();
classloaderService.prepareExportClassCache();
BizModel bizModel = new BizModel();
bizModel.setBizName("biz A").setClassPath(new URL[] { classPathURL }).setClassLoader(new BizClassLoader(bizModel.getBizName(), bizModel.getClassPath()));
bizManagerService.registerBiz(bizModel);
Assert.assertNotNull(bizModel.getBizClassLoader().getResource(ITest.class.getName().replace(".", "/") + ".class"));
}
use of com.alipay.sofa.ark.container.model.BizModel in project sofa-ark by alipay.
the class BizClassloaderTest method testImport.
@Test
public void testImport() throws Exception {
PluginModel pluginA = new PluginModel();
pluginA.setPluginName("plugin A").setClassPath(new URL[] { classPathURL }).setImportClasses(Collections.<String>emptySet()).setImportPackages(Collections.<String>emptySet()).setExportIndex(new HashSet<>(Collections.singletonList(ITest.class.getName()))).setPluginClassLoader(new PluginClassLoader(pluginA.getPluginName(), pluginA.getClassPath()));
pluginManagerService.registerPlugin(pluginA);
pluginDeployService.deploy();
classloaderService.prepareExportClassCache();
BizModel bizModel = new BizModel();
bizModel.setBizName("biz A").setClassPath(new URL[] { classPathURL }).setClassLoader(new BizClassLoader(bizModel.getBizName(), bizModel.getClassPath()));
bizManagerService.registerBiz(bizModel);
Assert.assertEquals(pluginA.getPluginClassLoader().loadClass(ITest.class.getName()), bizModel.getBizClassLoader().loadClass(ITest.class.getName()));
}
use of com.alipay.sofa.ark.container.model.BizModel in project sofa-ark by alipay.
the class BizFactoryServiceImpl method createBiz.
@Override
public Biz createBiz(BizArchive bizArchive) throws IOException {
AssertUtils.isTrue(isArkBiz(bizArchive), "Archive must be a ark biz!");
BizModel bizModel = new BizModel();
Attributes manifestMainAttributes = bizArchive.getManifest().getMainAttributes();
bizModel.setBizState(BizState.RESOLVED).setBizName(manifestMainAttributes.getValue(ARK_BIZ_NAME)).setBizVersion(manifestMainAttributes.getValue(ARK_BIZ_VERSION)).setMainClass(manifestMainAttributes.getValue(MAIN_CLASS_ATTRIBUTE)).setPriority(manifestMainAttributes.getValue(PRIORITY_ATTRIBUTE)).setWebContextPath(manifestMainAttributes.getValue(WEB_CONTEXT_PATH)).setDenyImportPackages(manifestMainAttributes.getValue(DENY_IMPORT_PACKAGES)).setDenyImportClasses(manifestMainAttributes.getValue(DENY_IMPORT_CLASSES)).setDenyImportResources(manifestMainAttributes.getValue(DENY_IMPORT_RESOURCES)).setInjectPluginDependencies(getInjectDependencies(manifestMainAttributes.getValue(INJECT_PLUGIN_DEPENDENCIES))).setInjectExportPackages(manifestMainAttributes.getValue(INJECT_EXPORT_PACKAGES)).setClassPath(bizArchive.getUrls()).setClassLoader(new BizClassLoader(bizModel.getIdentity(), getBizUcp(bizModel.getClassPath()), bizArchive instanceof ExplodedBizArchive));
return bizModel;
}
use of com.alipay.sofa.ark.container.model.BizModel in project sofa-ark by alipay.
the class BizClassLoaderTest method testLoadClassFromAgentClassLoader.
@Test
public void testLoadClassFromAgentClassLoader() throws ClassNotFoundException {
BizModel bizModel = new BizModel().setBizState(BizState.RESOLVED);
bizModel.setBizName("MockBiz").setBizVersion("1.0.0").setClassPath(new URL[] {}).setClassLoader(new BizClassLoader(bizModel.getIdentity(), bizModel.getClassPath()));
bizModel.setDenyImportResources(StringUtils.EMPTY_STRING);
bizModel.setDenyImportClasses(StringUtils.EMPTY_STRING);
bizModel.setDenyImportPackages(StringUtils.EMPTY_STRING);
bizManagerService.registerBiz(bizModel);
BizClassLoader bizClassLoader = (BizClassLoader) bizModel.getBizClassLoader();
Assert.assertNotNull(bizClassLoader.loadClass("SampleClass", false));
Class clazz = bizClassLoader.loadClass(ArkClient.class.getCanonicalName());
Assert.assertTrue(clazz.getClassLoader().equals(classloaderService.getArkClassLoader()));
}
use of com.alipay.sofa.ark.container.model.BizModel in project sofa-ark by alipay.
the class BizClassLoaderTest method testDenyImport.
@Test
public void testDenyImport() throws Exception {
PluginModel pluginA = new PluginModel();
pluginA.setPluginName("pluginA").setClassPath(new URL[] { classPathURL }).setImportClasses(StringUtils.EMPTY_STRING).setImportPackages(StringUtils.EMPTY_STRING).setImportResources(StringUtils.EMPTY_STRING).setExportResources("pluginA_export_resource1.xml,pluginA_export_resource2.xml").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[] {}).setClassLoader(new BizClassLoader(bizModel.getIdentity(), bizModel.getClassPath()));
bizModel.setDenyImportResources(StringUtils.EMPTY_STRING);
bizModel.setDenyImportPackages(StringUtils.EMPTY_STRING);
bizModel.setDenyImportClasses(StringUtils.EMPTY_STRING);
bizManagerService.registerBiz(bizModel);
Assert.assertNotNull(bizModel.getBizClassLoader().getResource("pluginA_export_resource1.xml"));
Assert.assertNotNull(bizModel.getBizClassLoader().getResource("pluginA_export_resource2.xml"));
bizModel.setDenyImportResources("pluginA_export_resource2.xml");
invalidClassLoaderCache(bizModel.getBizClassLoader());
Assert.assertNull(bizModel.getBizClassLoader().getResource("pluginA_export_resource2.xml"));
Assert.assertTrue(bizModel.getBizClassLoader().loadClass(ITest.class.getName()).getClassLoader() instanceof PluginClassLoader);
bizModel.setDenyImportPackages("com.alipay.sofa.ark.container.testdata");
invalidClassLoaderCache(bizModel.getBizClassLoader());
Assert.assertFalse(bizModel.getBizClassLoader().loadClass(ITest.class.getName()).getClassLoader() instanceof PluginClassLoader);
bizModel.setDenyImportPackages(StringUtils.EMPTY_STRING);
bizModel.setDenyImportClasses(ITest.class.getCanonicalName());
invalidClassLoaderCache(bizModel.getBizClassLoader());
Assert.assertFalse(bizModel.getBizClassLoader().loadClass(ITest.class.getName()).getClassLoader() instanceof PluginClassLoader);
}
Aggregations