Search in sources :

Example 1 with IPluginProvider

use of org.pentaho.platform.api.engine.IPluginProvider in project pentaho-platform by pentaho.

the class DefaultPluginManager method reload.

@Override
public final boolean reload() {
    IPentahoSession session = PentahoSessionHolder.getSession();
    boolean anyErrors = false;
    IPluginProvider pluginProvider = PentahoSystem.get(IPluginProvider.class, "IPluginProvider", session);
    List<IPlatformPlugin> providedPlugins = null;
    try {
        synchronized (registeredPlugins) {
            this.unloadPlugins();
        }
        // the plugin may fail to load during getPlugins without an exception thrown if the provider
        // is capable of discovering the plugin fine but there are structural problems with the plugin
        // itself. In this case a warning should be logged by the provider, but, again, no exception
        // is expected.
        providedPlugins = pluginProvider.getPlugins(session);
    } catch (PlatformPluginRegistrationException e1) {
        String msg = // $NON-NLS-1$
        Messages.getInstance().getErrorString("PluginManager.ERROR_0012_PLUGIN_DISCOVERY_FAILED");
        Logger.error(getClass().toString(), msg, e1);
        PluginMessageLogger.add(msg);
        anyErrors = true;
    }
    synchronized (providedPlugins) {
        for (IPlatformPlugin plugin : providedPlugins) {
            try {
                registeredPlugins.put(plugin.getId(), plugin);
                ClassLoader loader = setPluginClassLoader(plugin);
                initializeBeanFactory(plugin, loader);
            } catch (Throwable t) {
                // this has been logged already
                anyErrors = true;
                String msg = Messages.getInstance().getErrorString("PluginManager.ERROR_0011_FAILED_TO_REGISTER_PLUGIN", // $NON-NLS-1$
                plugin.getId());
                Logger.error(getClass().toString(), msg, t);
                PluginMessageLogger.add(msg);
            }
        }
        registeredPlugins.clear();
        for (IPlatformPlugin plugin : providedPlugins) {
            try {
                GenericApplicationContext beanFactory = beanFactoryMap.get(plugin.getId());
                if (beanFactory != null) {
                    beanFactory.refresh();
                }
                registerPlugin(plugin);
                registeredPlugins.put(plugin.getId(), plugin);
            } catch (Throwable t) {
                // this has been logged already
                anyErrors = true;
                String msg = Messages.getInstance().getErrorString("PluginManager.ERROR_0011_FAILED_TO_REGISTER_PLUGIN", // $NON-NLS-1$
                plugin.getId());
                Logger.error(getClass().toString(), msg, t);
                PluginMessageLogger.add(msg);
            }
        }
    }
    IServiceManager svcManager = PentahoSystem.get(IServiceManager.class, null);
    if (svcManager != null) {
        try {
            svcManager.initServices();
        } catch (ServiceInitializationException e) {
            String msg = Messages.getInstance().getErrorString(// $NON-NLS-1$
            "PluginManager.ERROR_0022_SERVICE_INITIALIZATION_FAILED");
            Logger.error(getClass().toString(), msg, e);
            PluginMessageLogger.add(msg);
        }
    }
    return !anyErrors;
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IPluginProvider(org.pentaho.platform.api.engine.IPluginProvider) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException) IServiceManager(org.pentaho.platform.api.engine.IServiceManager) IPlatformPlugin(org.pentaho.platform.api.engine.IPlatformPlugin) ServiceInitializationException(org.pentaho.platform.api.engine.ServiceInitializationException)

Example 2 with IPluginProvider

use of org.pentaho.platform.api.engine.IPluginProvider in project pentaho-platform by pentaho.

the class PentahoSystemPluginManager method reload.

@Override
public boolean reload(IPentahoSession session) {
    boolean anyErrors = false;
    IPluginProvider pluginProvider = PentahoSystem.get(IPluginProvider.class, "IPluginProvider", session);
    List<IPlatformPlugin> providedPlugins = Collections.emptyList();
    try {
        this.unloadPlugins();
        // the plugin may fail to load during getPlugins without an exception thrown if the provider
        // is capable of discovering the plugin fine but there are structural problems with the plugin
        // itself. In this case a warning should be logged by the provider, but, again, no exception
        // is expected.
        providedPlugins = pluginProvider.getPlugins(session);
    } catch (PlatformPluginRegistrationException e1) {
        String msg = Messages.getInstance().getErrorString("PluginManager.ERROR_0012_PLUGIN_DISCOVERY_FAILED");
        org.pentaho.platform.util.logging.Logger.error(getClass().toString(), msg, e1);
        PluginMessageLogger.add(msg);
        anyErrors = true;
    }
    for (IPlatformPlugin plugin : providedPlugins) {
        try {
            IPlatformPlugin existingPlugin = PentahoSystem.get(IPlatformPlugin.class, null, Collections.singletonMap(PLUGIN_ID, plugin.getId()));
            if (existingPlugin != null) {
                throw new PlatformPluginRegistrationException(Messages.getInstance().getErrorString("PluginManager.ERROR_0024_PLUGIN_ALREADY_LOADED_BY_SAME_NAME", plugin.getId()));
            }
            final ClassLoader classloader = createClassloader(plugin);
            // Register the classloader, Spring App Context and Object Factory with PentahoSystem
            IPentahoObjectRegistration handle = PentahoSystem.registerReference(new SingletonPentahoObjectReference.Builder<IPlatformPlugin>(IPlatformPlugin.class).object(plugin).attributes(Collections.<String, Object>singletonMap(PLUGIN_ID, plugin.getId())).build(), IPlatformPlugin.class);
            registerReference(plugin.getId(), handle);
            handle = PentahoSystem.registerReference(new SingletonPentahoObjectReference.Builder<ClassLoader>(ClassLoader.class).object(classloader).attributes(Collections.<String, Object>singletonMap(PLUGIN_ID, plugin.getId())).build(), ClassLoader.class);
            registerReference(plugin.getId(), handle);
            final GenericApplicationContext beanFactory = createBeanFactory(plugin, classloader);
            final StandaloneSpringPentahoObjectFactory pentahoFactory = new StandaloneSpringPentahoObjectFactory("Plugin Factory ( " + plugin.getId() + " )");
            pentahoFactory.init(null, beanFactory);
            beanFactory.refresh();
            handle = PentahoSystem.registerReference(new SingletonPentahoObjectReference.Builder<GenericApplicationContext>(GenericApplicationContext.class).object(beanFactory).attributes(Collections.<String, Object>singletonMap(PLUGIN_ID, plugin.getId())).build(), IPentahoRegistrableObjectFactory.Types.ALL);
            registerReference(plugin.getId(), handle);
            handle = PentahoSystem.registerReference(new SingletonPentahoObjectReference.Builder<IPentahoObjectFactory>(IPentahoObjectFactory.class).object(pentahoFactory).attributes(Collections.<String, Object>singletonMap(PLUGIN_ID, plugin.getId())).build(), IPentahoObjectFactory.class);
            registerReference(plugin.getId(), handle);
        } catch (Throwable t) {
            // this has been logged already
            anyErrors = true;
            String msg = Messages.getInstance().getErrorString("PluginManager.ERROR_0011_FAILED_TO_REGISTER_PLUGIN", plugin.getId());
            org.pentaho.platform.util.logging.Logger.error(getClass().toString(), msg, t);
            PluginMessageLogger.add(msg);
        }
    }
    for (IPlatformPlugin plugin : providedPlugins) {
        try {
            registerPlugin(plugin);
        } catch (Throwable t) {
            // this has been logged already
            anyErrors = true;
            String msg = Messages.getInstance().getErrorString("PluginManager.ERROR_0011_FAILED_TO_REGISTER_PLUGIN", plugin.getId());
            org.pentaho.platform.util.logging.Logger.error(getClass().toString(), msg, t);
            PluginMessageLogger.add(msg);
        }
    }
    IServiceManager svcManager = PentahoSystem.get(IServiceManager.class, null);
    if (svcManager != null) {
        try {
            svcManager.initServices();
        } catch (ServiceInitializationException e) {
            String msg = Messages.getInstance().getErrorString("PluginManager.ERROR_0022_SERVICE_INITIALIZATION_FAILED");
            org.pentaho.platform.util.logging.Logger.error(getClass().toString(), msg, e);
            PluginMessageLogger.add(msg);
        }
    }
    for (IPluginManagerListener listener : listeners) {
        listener.onReload();
    }
    return !anyErrors;
}
Also used : IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) SingletonPentahoObjectReference(org.pentaho.platform.engine.core.system.objfac.references.SingletonPentahoObjectReference) IPluginProvider(org.pentaho.platform.api.engine.IPluginProvider) IPlatformPlugin(org.pentaho.platform.api.engine.IPlatformPlugin) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) IPluginManagerListener(org.pentaho.platform.api.engine.IPluginManagerListener) IPentahoObjectRegistration(org.pentaho.platform.api.engine.IPentahoObjectRegistration) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException) IServiceManager(org.pentaho.platform.api.engine.IServiceManager) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory) ServiceInitializationException(org.pentaho.platform.api.engine.ServiceInitializationException)

Example 3 with IPluginProvider

use of org.pentaho.platform.api.engine.IPluginProvider in project pentaho-platform by pentaho.

the class DefaultPluginManagerIT method test17_getPluginIdForType.

@Test
public void test17_getPluginIdForType() throws PlatformInitializationException, PluginBeanException {
    IPluginProvider provider = new IPluginProvider() {

        public List<IPlatformPlugin> getPlugins(IPentahoSession session) throws PlatformPluginRegistrationException {
            PlatformPlugin p = new PlatformPlugin(new DefaultListableBeanFactory());
            p.setId("testPlugin");
            ContentGeneratorInfo cg1 = new ContentGeneratorInfo();
            cg1.setDescription("test 9 plugin description");
            cg1.setId("oldworldCGid");
            cg1.setType("oldworldCGtype");
            cg1.setTitle("test");
            cg1.setClassname("org.pentaho.test.platform.plugin.pluginmgr.ContentGenerator1");
            // cg1.setFileInfoGeneratorClassname("org.pentaho.test.platform.plugin.pluginmgr.FileInfoGenerator");
            p.addContentGenerator(cg1);
            BeanDefinition beanDef = BeanDefinitionBuilder.rootBeanDefinition("org.pentaho.test.platform.plugin.pluginmgr.ContentGenerator1").setScope(BeanDefinition.SCOPE_PROTOTYPE).getBeanDefinition();
            p.getBeanFactory().registerBeanDefinition("springDefinedCGid", beanDef);
            p.getBeanFactory().registerAlias("springDefinedCGid", "springDefinedCGtype");
            return Arrays.asList((IPlatformPlugin) p);
        }
    };
    microPlatform.defineInstance(IPluginProvider.class, provider).start();
    pluginManager.reload();
    assertEquals("testPlugin", pluginManager.getPluginIdForType("oldworldCGtype"));
    assertEquals("testPlugin", pluginManager.getPluginIdForType("springDefinedCGtype"));
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) PlatformPlugin(org.pentaho.platform.plugin.services.pluginmgr.PlatformPlugin) IPlatformPlugin(org.pentaho.platform.api.engine.IPlatformPlugin) ContentGeneratorInfo(org.pentaho.platform.engine.core.solution.ContentGeneratorInfo) IPluginProvider(org.pentaho.platform.api.engine.IPluginProvider) PluginBeanDefinition(org.pentaho.platform.api.engine.PluginBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) IPlatformPlugin(org.pentaho.platform.api.engine.IPlatformPlugin) Test(org.junit.Test)

Example 4 with IPluginProvider

use of org.pentaho.platform.api.engine.IPluginProvider in project pentaho-platform by pentaho.

the class PentahoSystemPluginManagerIT method testPerspectiveUnRegistration.

@Test
public void testPerspectiveUnRegistration() throws Exception {
    PentahoSystem.clearObjectFactory();
    PentahoSystem.registerObject(new IPluginProvider() {

        @Override
        public List<IPlatformPlugin> getPlugins(IPentahoSession session) throws PlatformPluginRegistrationException {
            return Arrays.asList((IPlatformPlugin) new PlatformPlugin() {

                @Override
                public List<IPluginPerspective> getPluginPerspectives() {
                    return Arrays.asList(mock(IPluginPerspective.class));
                }

                @Override
                public String getId() {
                    return "foo";
                }
            });
        }
    }, IPluginProvider.class);
    pluginManager = new PentahoSystemPluginManager();
    pluginManager.reload();
    assertEquals(1, PentahoSystem.getAll(IPluginPerspective.class).size());
    assertEquals(1, PentahoSystem.getAll(IPlatformPlugin.class).size());
    pluginManager.unloadAllPlugins();
    assertEquals(0, PentahoSystem.getAll(IPluginPerspective.class).size());
    assertEquals(0, PentahoSystem.getAll(IPlatformPlugin.class).size());
    pluginManager.reload();
    assertEquals(1, PentahoSystem.getAll(IPluginPerspective.class).size());
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IPlatformPlugin(org.pentaho.platform.api.engine.IPlatformPlugin) List(java.util.List) IPluginProvider(org.pentaho.platform.api.engine.IPluginProvider) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException) IPlatformPlugin(org.pentaho.platform.api.engine.IPlatformPlugin) Test(org.junit.Test)

Example 5 with IPluginProvider

use of org.pentaho.platform.api.engine.IPluginProvider in project pentaho-platform by pentaho.

the class PentahoSystemReadyListener method contextInitialized.

@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
    IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class);
    IPentahoSession session = PentahoSessionHolder.getSession();
    IPluginProvider pluginProvider = PentahoSystem.get(IPluginProvider.class, "IPluginProvider", session);
    try {
        List<IPlatformPlugin> providedPlugins = pluginProvider.getPlugins(session);
        for (IPlatformPlugin plugin : providedPlugins) {
            try {
                if (!StringUtils.isEmpty(plugin.getLifecycleListenerClassname())) {
                    ClassLoader loader = pluginManager.getClassLoader(plugin.getId());
                    Object listener = loader.loadClass(plugin.getLifecycleListenerClassname()).newInstance();
                    if (IPlatformReadyListener.class.isAssignableFrom(listener.getClass())) {
                        ((IPlatformReadyListener) listener).ready();
                    }
                }
            } catch (Exception e) {
                Logger.warn(PentahoSystemReadyListener.class.getName(), e.getMessage(), e);
            }
        }
    } catch (PlatformPluginRegistrationException e) {
        Logger.warn(PentahoSystemReadyListener.class.getName(), e.getMessage(), e);
    }
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) IPluginManager(org.pentaho.platform.api.engine.IPluginManager) IPluginProvider(org.pentaho.platform.api.engine.IPluginProvider) IPlatformReadyListener(org.pentaho.platform.api.engine.IPlatformReadyListener) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException) IPlatformPlugin(org.pentaho.platform.api.engine.IPlatformPlugin)

Aggregations

IPlatformPlugin (org.pentaho.platform.api.engine.IPlatformPlugin)5 IPluginProvider (org.pentaho.platform.api.engine.IPluginProvider)5 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)4 PlatformPluginRegistrationException (org.pentaho.platform.api.engine.PlatformPluginRegistrationException)4 Test (org.junit.Test)2 IServiceManager (org.pentaho.platform.api.engine.IServiceManager)2 ServiceInitializationException (org.pentaho.platform.api.engine.ServiceInitializationException)2 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)2 List (java.util.List)1 IPentahoObjectFactory (org.pentaho.platform.api.engine.IPentahoObjectFactory)1 IPentahoObjectRegistration (org.pentaho.platform.api.engine.IPentahoObjectRegistration)1 IPlatformReadyListener (org.pentaho.platform.api.engine.IPlatformReadyListener)1 IPluginManager (org.pentaho.platform.api.engine.IPluginManager)1 IPluginManagerListener (org.pentaho.platform.api.engine.IPluginManagerListener)1 PluginBeanDefinition (org.pentaho.platform.api.engine.PluginBeanDefinition)1 ContentGeneratorInfo (org.pentaho.platform.engine.core.solution.ContentGeneratorInfo)1 StandaloneSpringPentahoObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)1 SingletonPentahoObjectReference (org.pentaho.platform.engine.core.system.objfac.references.SingletonPentahoObjectReference)1 PlatformPlugin (org.pentaho.platform.plugin.services.pluginmgr.PlatformPlugin)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1