use of org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory in project pentaho-metaverse by pentaho.
the class IntegrationTestUtil method initializePentahoSystem.
public static synchronized void initializePentahoSystem(String solutionPath) throws Exception {
// this setting is useful only for running the integration tests from within IntelliJ
// this same property is set for integration tests via the pom when running with mvn
String folderPaths = "target/spoon/plugins";
File f = new File(folderPaths);
System.setProperty("KETTLE_PLUGIN_BASE_FOLDERS", f.getAbsolutePath());
StandaloneApplicationContext appContext = new StandaloneApplicationContext(solutionPath, "");
PentahoSystem.setSystemSettingsService(new PathBasedSystemSettings());
if (solutionPath == null) {
throw new MetaverseException(Messages.getString("ERROR.MetaverseInit.BadConfigPath", solutionPath));
}
try {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(MetaverseUtil.class.getClassLoader());
IPentahoObjectFactory pentahoObjectFactory = new StandaloneSpringPentahoObjectFactory();
pentahoObjectFactory.init(solutionPath, PentahoSystem.getApplicationContext());
PentahoSystem.registerObjectFactory(pentahoObjectFactory);
// Restore context classloader
Thread.currentThread().setContextClassLoader(cl);
} catch (Exception e) {
throw new MetaverseException(Messages.getString("ERROR.MetaverseInit.CouldNotInit"), e);
}
PentahoSystem.init(appContext);
PentahoSessionHolder.setSession(new StandaloneSession());
registerKettlePlugins();
try {
KettleEnvironment.init();
} catch (KettleException e) {
e.printStackTrace();
}
}
use of org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryBase method setUpClass.
@BeforeClass
public static void setUpClass() throws Exception {
// folder cannot be deleted at teardown shutdown hooks have not yet necessarily completed
// parent folder must match jcrRepository.homeDir bean property in repository-test-override.spring.xml
FileUtils.deleteDirectory(new File("/tmp/repository-future/jackrabbit-test-TRUNK"));
PentahoSessionHolder.setStrategyName(PentahoSessionHolder.MODE_GLOBAL);
// register repository spring context for correct work of <pen:list>
final StandaloneSpringPentahoObjectFactory pentahoObjectFactory = new StandaloneSpringPentahoObjectFactory();
GenericApplicationContext appCtx = new GenericApplicationContext();
XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(appCtx);
xmlReader.loadBeanDefinitions(new ClassPathResource("repository.spring.xml"));
xmlReader.loadBeanDefinitions(new ClassPathResource("repository-test-override.spring.xml"));
pentahoObjectFactory.init(null, appCtx);
PentahoSystem.registerObjectFactory(pentahoObjectFactory);
}
use of org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory in project pentaho-platform by pentaho.
the class DefaultPluginManager method initializeBeanFactory.
/**
* Initializes a bean factory for serving up instance of plugin classes.
*
* @return an instance of the factory that allows callers to continue to define more beans on it programmatically
*/
protected void initializeBeanFactory(final IPlatformPlugin plugin, final ClassLoader loader) throws PlatformPluginRegistrationException {
if (!(loader instanceof PluginClassLoader)) {
logger.warn("Can't determine plugin dir to load spring file because classloader is not of type PluginClassLoader. " + // $NON-NLS-1$
"This is since we are probably in a unit test");
// $NON-NLS-1$
return;
}
//
// Get the native factory (the factory that comes preconfigured via either Spring bean files or via JUnit test
//
BeanFactory nativeBeanFactory = getNativeBeanFactory(plugin, loader);
//
// 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(loader);
beanFactory.getBeanFactory().setBeanClassLoader(loader);
if (nativeBeanFactory != null) {
beanFactory.getBeanFactory().setParentBeanFactory(nativeBeanFactory);
}
}
beanFactory.addBeanFactoryPostProcessor(new PentahoBeanScopeValidatorPostProcessor());
beanFactoryMap.put(plugin.getId(), beanFactory);
// 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());
assertUnique(plugin.getId(), def.getBeanId());
// 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);
}
StandaloneSpringPentahoObjectFactory pentahoFactory = new StandaloneSpringPentahoObjectFactory("Plugin Factory ( " + plugin.getId() + " )");
pentahoFactory.init(null, beanFactory);
}
use of org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory 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;
}
use of org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory in project pentaho-platform by pentaho.
the class PentahoSystemPluginManager method unloadPlugins.
private void unloadPlugins() {
// is called within the synchronized block in reload
for (IPlatformPlugin plugin : PentahoSystem.getAll(IPlatformPlugin.class)) {
try {
plugin.unLoaded();
// if a spring app context was registered for this plugin, remove and close it
final GenericApplicationContext appContext = PentahoSystem.get(GenericApplicationContext.class, null, Collections.singletonMap(PLUGIN_ID, plugin.getId()));
if (appContext != null) {
final StandaloneSpringPentahoObjectFactory pentahoObjectFactory = StandaloneSpringPentahoObjectFactory.getInstance(appContext);
if (pentahoObjectFactory != null) {
PentahoSystem.deregisterObjectFactory(pentahoObjectFactory);
}
appContext.close();
}
} 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);
}
final ClassLoader classLoader = PentahoSystem.get(ClassLoader.class, null, Collections.singletonMap(PLUGIN_ID, plugin.getId()));
if (classLoader != null) {
try {
((PluginClassLoader) classLoader).close();
} catch (IOException e) {
logger.error("errror closing plugin clasloader", e);
}
}
}
for (Map.Entry<String, IPentahoObjectRegistration> entry : handleRegistry.entries()) {
entry.getValue().remove();
}
handleRegistry.clear();
}
Aggregations