Search in sources :

Example 1 with PlatformPluginRegistrationException

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

the class DefaultPluginManager method setPluginClassLoader.

private ClassLoader setPluginClassLoader(IPlatformPlugin plugin) throws PlatformPluginRegistrationException {
    ClassLoader loader = classLoaderMap.get(plugin.getId());
    if (loader == null) {
        String pluginDirPath = PentahoSystem.getApplicationContext().getSolutionPath(// $NON-NLS-1$
        "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
        // $NON-NLS-1$ //$NON-NLS-2$
        pluginDirPath = pluginDirPath.replace("//", "/");
        Logger.debug(this, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "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", // $NON-NLS-1$
            pluginDir.getAbsolutePath()));
        }
        loader = new PluginClassLoader(pluginDir, this.getClass().getClassLoader());
        if (plugin.getLoaderType() == IPlatformPlugin.ClassLoaderType.OVERRIDING) {
            ((PluginClassLoader) loader).setOverrideLoad(true);
        }
        classLoaderMap.put(plugin.getId(), loader);
    }
    return loader;
}
Also used : File(java.io.File) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException)

Example 2 with PlatformPluginRegistrationException

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

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

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

the class SystemPathXmlPluginProvider method processDirectory.

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" + RepositoryFile.SEPARATOR + folder.getName() + RepositoryFile.SEPARATOR + "plugin.xml";
    Document doc = null;
    try {
        try {
            org.dom4j.io.SAXReader reader = XMLParserFactoryProducer.getSAXReader(new SolutionURIResolver());
            doc = reader.read(ActionSequenceResource.getInputStream(path, LocaleHelper.getLocale()));
        } catch (Throwable t) {
        // XML document can't be read. We'll just return a null document.
        }
        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) Document(org.dom4j.Document) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException) SolutionURIResolver(org.pentaho.platform.engine.services.SolutionURIResolver) FilenameFilter(java.io.FilenameFilter) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException)

Example 5 with PlatformPluginRegistrationException

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

the class SystemPathXmlPluginProvider method getPlugins.

/**
 * Gets the list of plugins that this provider class has discovered.
 *
 * @return an read-only list of plugins
 * @see IPluginProvider#getPlugins()
 * @throws PlatformPluginRegistrationException
 *           if there is a problem preventing the impl from looking for plugins
 */
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) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) 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