| /******************************************************************************* |
| * Copyright (c) 2008 Innoopract Informationssysteme GmbH. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Innoopract Informationssysteme GmbH - initial API and implementation |
| ******************************************************************************/ |
| package org.eclipse.epp.wizard.internal; |
| |
| import java.io.File; |
| import java.io.FileInputStream; |
| import java.io.FileNotFoundException; |
| import java.io.IOException; |
| import java.util.Properties; |
| |
| import org.apache.log4j.Logger; |
| import org.eclipse.epp.wizard.model.EPPModel; |
| import org.eclipse.ui.plugin.AbstractUIPlugin; |
| import org.osgi.framework.BundleContext; |
| |
| /** |
| * The activator class controls the plug-in life cycle |
| */ |
| public class Activator extends AbstractUIPlugin { |
| |
| static Logger logger = Logger.getLogger( Activator.class ); |
| public static final String PROPERTY_CONFIGURATION = "org.eclipse.epp.wizard.configuration"; |
| public static final String PROPERTY_CONFIGURATION_DEFAULT_VALUE = "eppwizard.properties"; |
| // The plug-in ID |
| public static final String PLUGIN_ID = "org.eclipse.epp.wizard"; |
| // The shared instance |
| private static Activator plugin; |
| |
| /** |
| * The constructor |
| */ |
| public Activator() { |
| } |
| |
| /* |
| * (non-Javadoc) |
| * @see |
| * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext |
| * ) |
| */ |
| public void start( BundleContext context ) throws Exception { |
| super.start( context ); |
| // PropertyConfigurator.configure("log4j.properties"); |
| plugin = this; |
| modelCache = new ModelCache( getConfiguration() ); |
| statsLogger = new StatsLogger( configuration.getStatsLoggingFile() ); |
| } |
| |
| /* |
| * (non-Javadoc) |
| * @see |
| * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext |
| * ) |
| */ |
| public void stop( BundleContext context ) throws Exception { |
| plugin = null; |
| super.stop( context ); |
| } |
| |
| /** |
| * Returns the shared instance |
| * |
| * @return the shared instance |
| */ |
| public static Activator getDefault() { |
| return plugin; |
| } |
| /* |
| * public static void log(final Exception exc) { IStatus status = new |
| * Status(IStatus.ERROR, PLUGIN_ID, exc.getMessage(), exc); |
| * getDefault().getLog().log(status); } public static void log(final IStatus |
| * status) { System.err.println(status.getMessage() + "\n" + |
| * status.getException()); getDefault().getLog().log(status); } |
| */ |
| private Configuration configuration = null; |
| private ModelCache modelCache; |
| private StatsLogger statsLogger; |
| |
| public synchronized Configuration getConfiguration() { |
| if( configuration == null ) { |
| String configurationFile = System.getProperty( PROPERTY_CONFIGURATION, |
| PROPERTY_CONFIGURATION_DEFAULT_VALUE ); |
| logger.info( "Loading configuration from file: " |
| + new File( configurationFile ).getAbsolutePath() ); |
| Properties properties = new Properties(); |
| FileInputStream inStream = null; |
| try { |
| inStream = new FileInputStream( configurationFile ); |
| properties.load( inStream ); |
| configuration = new Configuration( properties ); |
| } catch( FileNotFoundException exc ) { |
| logger.error( "Unable to load configuration", exc ); |
| } catch( IOException exc ) { |
| logger.error( "Unable to load configuration", exc ); |
| } finally { |
| if( inStream != null ) { |
| try { |
| inStream.close(); |
| } catch( IOException e ) { |
| logger.warn( "Could not close file '" + configurationFile, e ); |
| } |
| } |
| } |
| } |
| return configuration; |
| } |
| |
| public EPPModel getModel() throws Exception { |
| return modelCache.getModel(); |
| } |
| |
| public StatsLogger getStatsLogger() { |
| return statsLogger; |
| } |
| } |