Search in sources :

Example 6 with IPlatformPlugin

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

Example 7 with IPlatformPlugin

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

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

the class SystemPathPluginProviderIT method tesLoadtLifecycleListener.

@SuppressWarnings("deprecation")
@Test
public void tesLoadtLifecycleListener() throws PlatformPluginRegistrationException {
    microPlatform.init();
    PluginMessageLogger.clear();
    List<IPlatformPlugin> plugins = provider.getPlugins(new StandaloneSession());
    // first make sure Plugin 1 was loaded, otherwise our check for lifcycle class will never happen
    assertTrue("plugin1 was not found", CollectionUtils.exists(plugins, new PluginNameMatcherPredicate("Plugin 1")));
    for (IPlatformPlugin plugin : plugins) {
        if (plugin.getId().equals("Plugin 1")) {
            assertEquals("org.pentaho.test.platform.plugin.pluginmgr.FooInitializer", plugin.getLifecycleListenerClassname());
        }
        if (plugin.getId().equals("Plugin 2")) {
            // no listener defined to for Plugin 2
            assertNull(plugin.getLifecycleListenerClassname());
        }
    }
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPlatformPlugin(org.pentaho.platform.api.engine.IPlatformPlugin) Test(org.junit.Test)

Example 9 with IPlatformPlugin

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

the class SystemPathPluginProviderIT method testLoadLifeCycleListener.

@SuppressWarnings("deprecation")
@Test
public void testLoadLifeCycleListener() throws PlatformPluginRegistrationException {
    microPlatform.init();
    List<IPlatformPlugin> plugins = provider.getPlugins(new StandaloneSession());
    IPlatformPlugin plugin = (IPlatformPlugin) CollectionUtils.find(plugins, new PluginNameMatcherPredicate("Plugin 1"));
    assertNotNull("Plugin 1 should have been found", plugin);
    assertEquals("org.pentaho.test.platform.plugin.pluginmgr.FooInitializer", plugin.getLifecycleListenerClassname());
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPlatformPlugin(org.pentaho.platform.api.engine.IPlatformPlugin) Test(org.junit.Test)

Example 10 with IPlatformPlugin

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

the class SystemPathPluginProviderIT method testLoadWebservices.

@SuppressWarnings("deprecation")
@Test
public void testLoadWebservices() throws PlatformPluginRegistrationException {
    microPlatform.init();
    List<IPlatformPlugin> plugins = provider.getPlugins(new StandaloneSession());
    System.out.println(PluginMessageLogger.getAll());
    IPlatformPlugin plugin = (IPlatformPlugin) CollectionUtils.find(plugins, new PluginNameMatcherPredicate("Plugin 1"));
    assertNotNull("Plugin 1 should have been found", plugin);
    Collection<PluginServiceDefinition> webservices = plugin.getServices();
    Object wsobj = CollectionUtils.find(webservices, new Predicate() {

        public boolean evaluate(Object object) {
            PluginServiceDefinition ws = (PluginServiceDefinition) object;
            boolean ret = ws.getTitle().equals("%TestWS1.TITLE%");
            return ret;
        }
    });
    assertNotNull("Webservice \"%TestWS1.TITLE%\" should have been loaded", wsobj);
    PluginServiceDefinition wsDfn = (PluginServiceDefinition) wsobj;
    assertEquals("org.pentaho.test.platform.engine.core.EchoServiceBean", wsDfn.getServiceClass());
    assertEquals("xml", wsDfn.getTypes()[0]);
    assertEquals("gwt", wsDfn.getTypes()[1]);
    assertEquals("A test webservice", wsDfn.getDescription());
    assertEquals(1, wsDfn.getExtraClasses().size());
    assertEquals("java.lang.String", wsDfn.getExtraClasses().iterator().next());
}
Also used : PluginServiceDefinition(org.pentaho.platform.api.engine.PluginServiceDefinition) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPlatformPlugin(org.pentaho.platform.api.engine.IPlatformPlugin) Predicate(org.apache.commons.collections.Predicate) Test(org.junit.Test)

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