Search in sources :

Example 11 with IPlatformPlugin

use of org.pentaho.platform.api.engine.IPlatformPlugin 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 12 with IPlatformPlugin

use of org.pentaho.platform.api.engine.IPlatformPlugin 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)

Example 13 with IPlatformPlugin

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

the class DefaultPluginManager method unloadPlugins.

/**
 * Clears all the lists and maps in preparation for reloading the state from the plugin provider. Fires the plugin
 * unloaded event for each known plugin.
 */
private void unloadPlugins() {
    overlaysCache.clear();
    classLoaderMap.clear();
    // TODO: can we reset/reload the spring bean factory here?
    contentTypeByExtension.clear();
    // is called within the synchronized block in reload
    for (IPlatformPlugin plugin : registeredPlugins.values()) {
        try {
            plugin.unLoaded();
        } catch (Throwable t) {
            // we do not want any type of exception to leak out and cause a problem here
            // A plugin unload should not adversely affect anything downstream, it should
            // log an error and otherwise fail silently
            String msg = Messages.getInstance().getErrorString("PluginManager.ERROR_0014_PLUGIN_FAILED_TO_PROPERLY_UNLOAD", // $NON-NLS-1$
            plugin.getId());
            Logger.error(getClass().toString(), msg, t);
            PluginMessageLogger.add(msg);
        }
    }
    registeredPlugins.clear();
}
Also used : IPlatformPlugin(org.pentaho.platform.api.engine.IPlatformPlugin)

Example 14 with IPlatformPlugin

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

the class DefaultPluginManager method getStaticResource.

@Deprecated
public InputStream getStaticResource(String path) {
    for (IPlatformPlugin plugin : registeredPlugins.values()) {
        Map<String, String> resourceMap = plugin.getStaticResourceMap();
        for (String url : resourceMap.keySet()) {
            if (isRequested(url, path)) {
                IPluginResourceLoader resLoader = PentahoSystem.get(IPluginResourceLoader.class, null);
                ClassLoader classLoader = classLoaderMap.get(plugin.getId());
                String resourcePath = path.replace(url, resourceMap.get(url));
                return resLoader.getResourceAsStream(classLoader, resourcePath);
            }
        }
    }
    return null;
}
Also used : IPluginResourceLoader(org.pentaho.platform.api.engine.IPluginResourceLoader) IPlatformPlugin(org.pentaho.platform.api.engine.IPlatformPlugin)

Example 15 with IPlatformPlugin

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

the class FileSystemXmlPluginProvider method getPlugins.

@Override
public List<IPlatformPlugin> getPlugins(IPentahoSession session) throws PlatformPluginRegistrationException {
    List<IPlatformPlugin> plugins = new ArrayList<IPlatformPlugin>();
    // look in each of the system setting folders looking for plugin.xml files
    // $NON-NLS-1$
    String systemPath = PentahoSystem.getApplicationContext().getSolutionPath("system");
    File systemDir = new File(systemPath);
    if (!systemDir.exists() || !systemDir.isDirectory()) {
        throw new PlatformPluginRegistrationException(Messages.getInstance().getErrorString(// $NON-NLS-1$
        "PluginManager.ERROR_0004_CANNOT_FIND_SYSTEM_FOLDER"));
    }
    File[] kids = systemDir.listFiles();
    // look at each child to see if it is a folder
    for (File kid : kids) {
        if (kid.isDirectory()) {
            try {
                processDirectory(plugins, kid, session);
            } catch (Throwable t) {
                // don't throw an exception. we need to continue to process any remaining good plugins
                String msg = Messages.getInstance().getErrorString("SystemPathXmlPluginProvider.ERROR_0001_FAILED_TO_PROCESS_PLUGIN", // $NON-NLS-1$
                kid.getAbsolutePath());
                Logger.error(getClass().toString(), msg, t);
                PluginMessageLogger.add(msg);
            }
        }
    }
    return Collections.unmodifiableList(plugins);
}
Also used : ArrayList(java.util.ArrayList) File(java.io.File) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException) IPlatformPlugin(org.pentaho.platform.api.engine.IPlatformPlugin)

Aggregations

IPlatformPlugin (org.pentaho.platform.api.engine.IPlatformPlugin)21 Test (org.junit.Test)9 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)7 PlatformPluginRegistrationException (org.pentaho.platform.api.engine.PlatformPluginRegistrationException)6 IPluginProvider (org.pentaho.platform.api.engine.IPluginProvider)5 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)4 ArrayList (java.util.ArrayList)3 Predicate (org.apache.commons.collections.Predicate)3 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)3 File (java.io.File)2 IPentahoObjectRegistration (org.pentaho.platform.api.engine.IPentahoObjectRegistration)2 IPluginResourceLoader (org.pentaho.platform.api.engine.IPluginResourceLoader)2 IServiceManager (org.pentaho.platform.api.engine.IServiceManager)2 PluginBeanDefinition (org.pentaho.platform.api.engine.PluginBeanDefinition)2 ServiceInitializationException (org.pentaho.platform.api.engine.ServiceInitializationException)2 StandaloneSpringPentahoObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1