Search in sources :

Example 6 with PlatformPluginRegistrationException

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

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

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

the class DefaultPluginManager method createServiceConfigs.

/*
   * A utility method to convert plugin version of webservice definition to the official engine version consumable by an
   * IServiceManager
   */
private Collection<ServiceConfig> createServiceConfigs(PluginServiceDefinition pws, IPlatformPlugin plugin, ClassLoader loader) throws PlatformPluginRegistrationException {
    Collection<ServiceConfig> services = new ArrayList<ServiceConfig>();
    // 
    if (pws.getTypes() == null || pws.getTypes().length < 1) {
        throw new PlatformPluginRegistrationException(Messages.getInstance().getErrorString("PluginManager.ERROR_0023_SERVICE_TYPE_UNSPECIFIED", // $NON-NLS-1$
        pws.getId()));
    }
    for (String type : pws.getTypes()) {
        ServiceConfig ws = new ServiceConfig();
        ws.setServiceType(type);
        ws.setTitle(pws.getTitle());
        ws.setDescription(pws.getDescription());
        String serviceClassName = (StringUtils.isEmpty(pws.getServiceClass())) ? pws.getServiceBeanId() : pws.getServiceClass();
        String serviceId;
        if (!StringUtils.isEmpty(pws.getId())) {
            serviceId = pws.getId();
        } else {
            serviceId = serviceClassName;
            if (serviceClassName.indexOf('.') > 0) {
                serviceId = serviceClassName.substring(serviceClassName.lastIndexOf('.') + 1);
            }
        }
        ws.setId(serviceId);
        // Register the service class
        // 
        final String serviceClassKey = // $NON-NLS-1$ //$NON-NLS-2$
        ws.getServiceType() + "-" + ws.getId() + "/" + serviceClassName;
        assertUnique(plugin.getId(), serviceClassKey);
        // defining plugin beans the old way through the plugin provider ifc supports only prototype scope
        BeanDefinition beanDef = BeanDefinitionBuilder.rootBeanDefinition(serviceClassName).setScope(BeanDefinition.SCOPE_PROTOTYPE).getBeanDefinition();
        beanFactoryMap.get(plugin.getId()).registerBeanDefinition(serviceClassKey, beanDef);
        if (!this.isBeanRegistered(serviceClassKey)) {
            throw new PlatformPluginRegistrationException(Messages.getInstance().getErrorString("PluginManager.ERROR_0020_NO_SERVICE_CLASS_REGISTERED", // $NON-NLS-1$
            serviceClassKey));
        }
        // 
        try {
            ws.setServiceClass(loadClass(serviceClassKey));
            ArrayList<Class<?>> classes = new ArrayList<Class<?>>();
            if (pws.getExtraClasses() != null) {
                for (String extraClass : pws.getExtraClasses()) {
                    classes.add(loadClass(extraClass));
                }
            }
            ws.setExtraClasses(classes);
        } catch (PluginBeanException e) {
            throw new PlatformPluginRegistrationException(Messages.getInstance().getErrorString("PluginManager.ERROR_0021_SERVICE_CLASS_LOAD_FAILED", serviceClassKey), // $NON-NLS-1$
            e);
        }
        services.add(ws);
    }
    return services;
}
Also used : PluginBeanException(org.pentaho.platform.api.engine.PluginBeanException) ServiceConfig(org.pentaho.platform.plugin.services.pluginmgr.servicemgr.ServiceConfig) ArrayList(java.util.ArrayList) PluginBeanDefinition(org.pentaho.platform.api.engine.PluginBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException)

Example 9 with PlatformPluginRegistrationException

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

the class FileSystemXmlPluginProvider method processDirectory.

@Override
protected void processDirectory(List<IPlatformPlugin> plugins, File folder, IPentahoSession session) throws PlatformPluginRegistrationException {
    // see if there is a plugin.xml file
    // $NON-NLS-1$
    FilenameFilter filter = new NameFileFilter("plugin.xml", IOCase.SENSITIVE);
    File[] kids = folder.listFiles(filter);
    if (kids == null || kids.length == 0) {
        return;
    }
    boolean hasLib = false;
    // $NON-NLS-1$
    filter = new NameFileFilter("lib", IOCase.SENSITIVE);
    kids = folder.listFiles(filter);
    if (kids != null && kids.length > 0) {
        hasLib = kids[0].exists() && kids[0].isDirectory();
    }
    // we have found a plugin.xml file
    // get the file from the repository
    // $NON-NLS-1$ //$NON-NLS-2$
    String path = "system" + File.separatorChar + folder.getName() + File.separatorChar + "plugin.xml";
    Document doc;
    try {
        File f = new File(PentahoSystem.getApplicationContext().getSolutionPath(path));
        InputStream in = new FileInputStream(f);
        SAXReader reader = XMLParserFactoryProducer.getSAXReader(null);
        doc = reader.read(in);
        if (doc != null) {
            plugins.add(createPlugin(doc, session, folder.getName(), hasLib));
        }
    } catch (Exception e) {
        throw new PlatformPluginRegistrationException(Messages.getInstance().getErrorString("PluginManager.ERROR_0005_CANNOT_PROCESS_PLUGIN_XML", path), // $NON-NLS-1$
        e);
    }
    if (doc == null) {
        throw new PlatformPluginRegistrationException(Messages.getInstance().getErrorString("PluginManager.ERROR_0005_CANNOT_PROCESS_PLUGIN_XML", // $NON-NLS-1$
        path));
    }
}
Also used : NameFileFilter(org.apache.commons.io.filefilter.NameFileFilter) FilenameFilter(java.io.FilenameFilter) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SAXReader(org.dom4j.io.SAXReader) Document(org.dom4j.Document) File(java.io.File) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException) FileInputStream(java.io.FileInputStream) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException)

Example 10 with PlatformPluginRegistrationException

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

PlatformPluginRegistrationException (org.pentaho.platform.api.engine.PlatformPluginRegistrationException)14 File (java.io.File)6 IPlatformPlugin (org.pentaho.platform.api.engine.IPlatformPlugin)6 ArrayList (java.util.ArrayList)4 IPluginProvider (org.pentaho.platform.api.engine.IPluginProvider)4 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)4 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)3 PluginBeanDefinition (org.pentaho.platform.api.engine.PluginBeanDefinition)3 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)3 FilenameFilter (java.io.FilenameFilter)2 NameFileFilter (org.apache.commons.io.filefilter.NameFileFilter)2 Document (org.dom4j.Document)2 IServiceManager (org.pentaho.platform.api.engine.IServiceManager)2 PluginBeanException (org.pentaho.platform.api.engine.PluginBeanException)2 ServiceInitializationException (org.pentaho.platform.api.engine.ServiceInitializationException)2 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)2 ServiceConfig (org.pentaho.platform.plugin.services.pluginmgr.servicemgr.ServiceConfig)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 List (java.util.List)1