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