Search in sources :

Example 11 with PlatformPluginRegistrationException

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

the class PentahoSystemPluginManager method createClassloader.

private ClassLoader createClassloader(IPlatformPlugin plugin) throws PlatformPluginRegistrationException {
    String pluginDirPath = PentahoSystem.getApplicationContext().getSolutionPath("system/" + plugin.getSourceDescription());
    // need to scrub out duplicate file delimeters otherwise we will
    // not be able to locate resources in jars. This classloader ultimately
    // needs to be made less fragile
    pluginDirPath = pluginDirPath.replace("//", "/");
    org.pentaho.platform.util.logging.Logger.debug(this, "plugin dir for " + plugin.getId() + " is [" + pluginDirPath + "]");
    File pluginDir = new File(pluginDirPath);
    if (!pluginDir.exists() || !pluginDir.isDirectory() || !pluginDir.canRead()) {
        throw new PlatformPluginRegistrationException(Messages.getInstance().getErrorString("PluginManager.ERROR_0027_PLUGIN_DIR_UNAVAILABLE", pluginDir.getAbsolutePath()));
    }
    PluginClassLoader loader = new PluginClassLoader(pluginDir, this.getClass().getClassLoader());
    if (plugin.getLoaderType() == IPlatformPlugin.ClassLoaderType.OVERRIDING) {
        loader.setOverrideLoad(true);
    }
    return loader;
}
Also used : File(java.io.File) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException)

Example 12 with PlatformPluginRegistrationException

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

the class PentahoSystemPluginManager 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, GenericApplicationContext beanFactory) 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", 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 = ws.getServiceType() + "-" + ws.getId() + "/" + serviceClassName;
        assertUnique(beanFactory, 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();
        beanFactory.registerBeanDefinition(serviceClassKey, beanDef);
        if (!this.isBeanRegistered(serviceClassKey)) {
            throw new PlatformPluginRegistrationException(Messages.getInstance().getErrorString("PluginManager.ERROR_0020_NO_SERVICE_CLASS_REGISTERED", 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), 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 13 with PlatformPluginRegistrationException

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

the class PentahoSystemPluginManager method registerPlugin.

@SuppressWarnings("unchecked")
private void registerPlugin(final IPlatformPlugin plugin) throws PlatformPluginRegistrationException, PluginLifecycleException {
    if (StringUtils.isEmpty(plugin.getId())) {
        throw new PlatformPluginRegistrationException(Messages.getInstance().getErrorString("PluginManager.ERROR_0026_PLUGIN_INVALID", plugin.getSourceDescription()));
    }
    ClassLoader loader = PentahoSystem.get(ClassLoader.class, null, Collections.singletonMap(PLUGIN_ID, plugin.getId()));
    GenericApplicationContext beanFactory = PentahoSystem.get(GenericApplicationContext.class, null, Collections.singletonMap(PLUGIN_ID, plugin.getId()));
    createAndRegisterLifecycleListeners(plugin, loader);
    plugin.init();
    registerContentTypes(plugin, loader, beanFactory);
    registerContentGenerators(plugin, loader, beanFactory);
    registerPerspectives(plugin, loader);
    registerOverlays(plugin);
    registerSettings(plugin, loader);
    // service registry must take place after bean registry since
    // a service class may be configured as a plugin bean
    registerServices(plugin, loader, beanFactory);
    PluginMessageLogger.add(Messages.getInstance().getString("PluginManager.PLUGIN_REGISTERED", plugin.getId()));
    try {
        plugin.loaded();
    } catch (Throwable t) {
        // The plugin has already been loaded, so there is really no logical response to any type
        // of failure here except to log an error and otherwise fail silently
        String msg = Messages.getInstance().getErrorString("PluginManager.ERROR_0015_PLUGIN_LOADED_HANDLING_FAILED", plugin.getId());
        org.pentaho.platform.util.logging.Logger.error(getClass().toString(), msg, t);
        PluginMessageLogger.add(msg);
    }
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException)

Example 14 with PlatformPluginRegistrationException

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

the class PentahoSystemPluginManager method createBeanFactory.

private GenericApplicationContext createBeanFactory(IPlatformPlugin plugin, ClassLoader classloader) throws PlatformPluginRegistrationException {
    if (!(classloader instanceof PluginClassLoader)) {
        throw new PlatformPluginRegistrationException("Can't determine plugin dir to load spring file because classloader is not of type PluginClassLoader.  " + "This is since we are probably in a unit test");
    }
    // 
    // Get the native factory (the factory that comes preconfigured via either Spring bean files or via JUnit test
    // 
    BeanFactory nativeBeanFactory = getNativeBeanFactory(plugin, classloader);
    // 
    // Now create the definable factory for accepting old style bean definitions from IPluginProvider
    // 
    GenericApplicationContext beanFactory = null;
    if (nativeBeanFactory != null && nativeBeanFactory instanceof GenericApplicationContext) {
        beanFactory = (GenericApplicationContext) nativeBeanFactory;
    } else {
        beanFactory = new GenericApplicationContext();
        beanFactory.setClassLoader(classloader);
        beanFactory.getBeanFactory().setBeanClassLoader(classloader);
        if (nativeBeanFactory != null) {
            beanFactory.getBeanFactory().setParentBeanFactory(nativeBeanFactory);
        }
    }
    beanFactory.addBeanFactoryPostProcessor(new PentahoBeanScopeValidatorPostProcessor());
    // been made available to the plugin manager
    for (PluginBeanDefinition def : plugin.getBeans()) {
        // register by classname if id is null
        def.setBeanId((def.getBeanId() == null) ? def.getClassname() : def.getBeanId());
        try {
            assertUnique(beanFactory, plugin.getId(), def.getBeanId());
        } catch (PlatformPluginRegistrationException e) {
            logger.error(MessageFormat.format("Unable to register plugin bean, a bean by the id {0} is already defined in plugin: {1}", def.getBeanId(), plugin.getId()));
            continue;
        }
        // defining plugin beans the old way through the plugin provider ifc supports only prototype scope
        BeanDefinition beanDef = BeanDefinitionBuilder.rootBeanDefinition(def.getClassname()).setScope(BeanDefinition.SCOPE_PROTOTYPE).getBeanDefinition();
        beanFactory.registerBeanDefinition(def.getBeanId(), beanDef);
    }
    return beanFactory;
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) PluginBeanDefinition(org.pentaho.platform.api.engine.PluginBeanDefinition) PentahoBeanScopeValidatorPostProcessor(org.pentaho.platform.engine.core.system.objfac.spring.PentahoBeanScopeValidatorPostProcessor) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory) BeanFactory(org.springframework.beans.factory.BeanFactory) ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) PluginBeanDefinition(org.pentaho.platform.api.engine.PluginBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException)

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