X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.spreadsheet.common%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fcommon%2FActivator.java;fp=bundles%2Forg.simantics.spreadsheet.common%2Fsrc%2Forg%2Fsimantics%2Fspreadsheet%2Fcommon%2FActivator.java;h=5eda19ef39bbe42bd739fd914285b6f04bf47636;hp=0000000000000000000000000000000000000000;hb=969bd23cab98a79ca9101af33334000879fb60c5;hpb=866dba5cd5a3929bbeae85991796acb212338a08 diff --git a/bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/common/Activator.java b/bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/common/Activator.java new file mode 100644 index 000000000..5eda19ef3 --- /dev/null +++ b/bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/common/Activator.java @@ -0,0 +1,82 @@ +package org.simantics.spreadsheet.common; +import java.io.File; +import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLDecoder; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + + +public class Activator implements BundleActivator { + + /** + * Name of the log file. + */ + public static String LOG_FILE_NAME = "spreadsheet.log"; + + // The plug-in ID + public static final String BUNDLE_ID = "org.simantics.spreadsheet.common"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + @Override + public void start(BundleContext context) throws Exception { + plugin = this; + + String prop = System.getProperty("osgi.instance.area", null); + if (prop != null) { + try { + URL url = new URL(prop); + if ("file".equals(url .getProtocol())) { + try { + File path = new File(URLDecoder.decode(url.getPath(), "UTF-8")); + if (!path.exists()) + path.mkdirs(); + if (path.exists() && path.canWrite()) { + File logFile = new File(path, LOG_FILE_NAME); + if (!logFile.exists() || (logFile.isFile() && logFile.canWrite())) + LOG_FILE_NAME = logFile.getAbsolutePath(); + + } + } catch (UnsupportedEncodingException e) { + // Should never happen since UTF-8 is always supported. + } + } + } catch (MalformedURLException e) { + // Ignore. + } + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + @Override + public void stop(BundleContext context) throws Exception { + plugin = null; + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} \ No newline at end of file