/* * Copyright 2006 Pentaho Corporation. All rights reserved. * This software was developed by Pentaho Corporation and is provided under the terms * of the Mozilla Public License, Version 1.1, or any later version. You may not use * this file except in compliance with the license. If you need a copy of the license, * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho * BI Platform. The Initial Developer is Pentaho Corporation. * * Software distributed under the Mozilla Public License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to * the license for the specific language governing your rights and limitations. * * Created Jan 9, 2006 * @author mbatchel */ package org.pentaho.plugin.kettle; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.Map; import java.util.Properties; import org.pentaho.core.repository.ISolutionRepository; import org.pentaho.core.session.IPentahoSession; import org.pentaho.core.system.IPentahoSystemListener; import org.pentaho.core.system.PentahoSystem; import org.pentaho.di.core.exception.KettleException; import org.pentaho.di.core.util.EnvUtil; import org.pentaho.di.job.JobEntryLoader; import org.pentaho.di.trans.StepLoader; import org.pentaho.messages.Messages; import org.pentaho.util.logging.Logger; public class KettleSystemListener implements IPentahoSystemListener { public boolean startup(IPentahoSession session) { try { // Initialize the environment variables, etc. // environmentInit(session); /* Load the plugins etc. */ try { StepLoader.init(); } catch(KettleException e) { Logger.error(KettleSystemListener.class.getName(), Messages.getErrorString("KettleSystemListener.ERROR_0001_STEP_LOAD_FAILED"), e); //$NON-NLS-1$ throw(e); } try { JobEntryLoader.init(); } catch(KettleException e) { Logger.error(KettleSystemListener.class.getName(), Messages.getString("KettleSystemListener.ERROR_0002_JOB_ENTRY_LOAD_FAILED")); //$NON-NLS-1$ throw(e); } } catch (Exception ex) { Logger.error(KettleSystemListener.class.getName(), Messages.getErrorString("KettleSystemListener.ERROR_0001_STEP_LOAD_FAILED"), ex); //$NON-NLS-1$ } return true; } public static Map readProperties(IPentahoSession session) { Properties props = new Properties(); String kettlePropsFilename = "system" + File.separator + "kettle" + File.separator + "kettle.properties"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ InputStream is = null; try { ISolutionRepository repository = PentahoSystem.getSolutionRepository(session); if (!repository.resourceExists(kettlePropsFilename)) { return props; } is = repository.getResourceInputStream(kettlePropsFilename, false); props.load(is); } catch (IOException ioe) { Logger.error(KettleSystemListener.class.getName(), Messages .getString("KettleSystemListener.ERROR_0003_PROPERTY_FILE_READ_FAILED") + ioe.getMessage(), ioe); //$NON-NLS-1$ } finally { if (is != null) try { is.close(); } catch (IOException e) { // ignore } } props.put("pentaho.solutionpath", PentahoSystem.getApplicationContext().getFileOutputPath("")); //$NON-NLS-1$ //$NON-NLS-2$ return props; } public static void environmentInit(IPentahoSession session) { EnvUtil.environmentInit(); } public void shutdown() { // Nothing required } }