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());
}
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);
}
}
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();
}
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;
}
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);
}
Aggregations