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