Search in sources :

Example 41 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, URL[] extensions, Set<String> exportPackages) throws IOException, IllegalArgumentException {
    AssertUtils.isTrue(isArkPlugin(pluginArchive), "Archive must be a ark plugin!");
    if (extensions == null || extensions.length == 0) {
        return createPlugin(pluginArchive);
    }
    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(getFinalPluginUrls(pluginArchive, extensions, plugin.getPluginName())).setPluginUrl(pluginArchive.getUrl()).setExportClasses(manifestMainAttributes.getValue(EXPORT_CLASSES_ATTRIBUTE)).setExportPackages(manifestMainAttributes.getValue(EXPORT_PACKAGES_ATTRIBUTE), exportPackages).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 42 with PluginModel

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

the class PluginFactoryServiceImpl method createEmbedPlugin.

@Override
public Plugin createEmbedPlugin(PluginArchive pluginArchive, ClassLoader masterClassLoader) throws IOException {
    AssertUtils.isTrue(isArkPlugin(pluginArchive), "Archive must be a ark plugin!");
    PluginModel plugin = new PluginModel();
    Attributes manifestMainAttributes = pluginArchive.getManifest().getMainAttributes();
    boolean enableExportClass = "true".equals(System.getProperty(PLUGIN_EXPORT_CLASS_ENABLE));
    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(((URLClassLoader) masterClassLoader).getURLs()).setPluginUrl(pluginArchive.getUrl()).setExportClasses(enableExportClass ? manifestMainAttributes.getValue(EXPORT_CLASSES_ATTRIBUTE) : null).setExportPackages(enableExportClass ? manifestMainAttributes.getValue(EXPORT_PACKAGES_ATTRIBUTE) : null).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(masterClassLoader).setPluginContext(new PluginContextImpl(plugin));
    return plugin;
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) PluginContextImpl(com.alipay.sofa.ark.container.model.PluginContextImpl) URLClassLoader(java.net.URLClassLoader) Attributes(java.util.jar.Attributes)

Example 43 with PluginModel

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

the class ClassLoaderServiceTest method testIsClassImport.

@Test
public void testIsClassImport() {
    Plugin plugin = new PluginModel().setPluginName("mockPlugin").setImportClasses(null).setImportPackages("a.c,a.b.c.*,a.b.c");
    pluginManagerService.registerPlugin(plugin);
    Assert.assertTrue(classloaderService.isClassInImport("mockPlugin", "a.c.e"));
    Assert.assertFalse(classloaderService.isClassInImport("mockPlugin", "a.c"));
    Assert.assertFalse(classloaderService.isClassInImport("mockPlugin", "a.c.e.f"));
    Assert.assertFalse(classloaderService.isClassInImport("mockPlugin", "a.b.c"));
    Assert.assertTrue(classloaderService.isClassInImport("mockPlugin", "a.b.c.e"));
    Assert.assertTrue(classloaderService.isClassInImport("mockPlugin", "a.b.c.e.f"));
}
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 44 with PluginModel

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

the class ClassLoaderServiceTest method testFindExportResources.

@Test
public void testFindExportResources() {
    PluginClassLoader pluginClassLoader = new PluginClassLoader("mockPlugin", new URL[] {});
    String exportResources = "spring-beans.xsd,*.xsd,com/alipay/sofa/*,xml-test.xml";
    Plugin plugin = new PluginModel().setPluginName("mockPlugin").setExportPackages("").setExportClasses("").setPluginClassLoader(pluginClassLoader).setExportResources(exportResources);
    pluginManagerService.registerPlugin(plugin);
    classloaderService.prepareExportClassAndResourceCache();
    Set<String> exportPrefixResourceStems = plugin.getExportPrefixResourceStems();
    Assert.assertTrue(exportPrefixResourceStems.contains("com/alipay/sofa/"));
    Set<String> exportSuffixResourceStems = plugin.getExportSuffixResourceStems();
    Assert.assertTrue(exportSuffixResourceStems.contains(".xsd"));
    Set<String> resources = plugin.getExportResources();
    Assert.assertTrue(resources.contains("xml-test.xml"));
    Assert.assertTrue(resources.contains("spring-beans.xsd"));
    plugin.getExportPrefixResourceStems().clear();
    plugin.getExportSuffixResourceStems().clear();
    plugin.getExportResources().clear();
    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 45 with PluginModel

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

the class ServiceRegistrationTest method testPublishDuplicateServiceInPlugin.

@Test
public void testPublishDuplicateServiceInPlugin() throws Exception {
    PluginModel pluginA = new PluginModel();
    pluginA.setPluginName("plugin A").setPriority("10").setClassPath(new URL[] { classPathURL }).setImportClasses(StringUtils.EMPTY_STRING).setImportPackages(StringUtils.EMPTY_STRING).setExportPackages(ClassUtils.getPackageName(INTERFACE_CLASS)).setExportClasses(StringUtils.EMPTY_STRING).setImportResources(StringUtils.EMPTY_STRING).setExportResources(StringUtils.EMPTY_STRING).setPluginActivator(PluginActivatorADup.class.getName()).setPluginClassLoader(new PluginClassLoader(pluginA.getPluginName(), pluginA.getClassPath())).setPluginContext(new PluginContextImpl(pluginA));
    pluginManagerService.registerPlugin(pluginA);
    classloaderService.prepareExportClassAndResourceCache();
    pluginDeployService.deploy();
    Assert.assertEquals(1, registryService.referenceServices(pluginA.getPluginClassLoader().loadClass(ITest.class.getCanonicalName())).size());
    int c = registryService.unPublishServices(new DefaultServiceFilter().setProviderType(ServiceProviderType.ARK_PLUGIN));
    Assert.assertTrue(c == 1);
}
Also used : PluginModel(com.alipay.sofa.ark.container.model.PluginModel) PluginContextImpl(com.alipay.sofa.ark.container.model.PluginContextImpl) DefaultServiceFilter(com.alipay.sofa.ark.container.registry.DefaultServiceFilter) URL(java.net.URL) PluginActivatorADup(com.alipay.sofa.ark.container.testdata.activator.PluginActivatorADup) PluginClassLoader(com.alipay.sofa.ark.container.service.classloader.PluginClassLoader) BaseTest(com.alipay.sofa.ark.container.BaseTest) ITest(com.alipay.sofa.ark.container.testdata.ITest) Test(org.junit.Test)

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