--- /dev/null
+package org.simantics.internal;\r
+\r
+import java.io.File;\r
+import java.io.UnsupportedEncodingException;\r
+import java.net.MalformedURLException;\r
+import java.net.URL;\r
+import java.net.URLDecoder;\r
+\r
+import org.eclipse.core.runtime.Plugin;\r
+import org.osgi.framework.BundleContext;\r
+import org.simantics.internal.startup.StartupRegistry;\r
+\r
+public class Activator extends Plugin {\r
+\r
+ /**\r
+ * Name of the log file. \r
+ */\r
+ public static String LOG_FILE_NAME = "simantics.log";\r
+\r
+ public static final String PLUGIN_ID = "org.simantics";\r
+\r
+ // The shared instance\r
+ private static Activator plugin;\r
+\r
+ private static BundleContext context;\r
+\r
+ private StartupRegistry startupRegistry;\r
+\r
+ static BundleContext getContext() {\r
+ return context;\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)\r
+ */\r
+ public void start(BundleContext bundleContext) throws Exception {\r
+ super.start(bundleContext);\r
+ Activator.context = bundleContext;\r
+ plugin = this;\r
+\r
+ String prop = System.getProperty("osgi.instance.area", null);\r
+ if (prop != null) {\r
+ try {\r
+ URL url = new URL(prop);\r
+ if ("file".equals(url .getProtocol())) {\r
+ try {\r
+ File path = new File(URLDecoder.decode(url.getPath(), "UTF-8"));\r
+ if (!path.exists())\r
+ path.mkdirs();\r
+ if (path.exists() && path.canWrite()) {\r
+ File logFile = new File(path, LOG_FILE_NAME);\r
+ if (!logFile.exists() || (logFile.isFile() && logFile.canWrite()))\r
+ LOG_FILE_NAME = logFile.getAbsolutePath();\r
+\r
+ }\r
+ } catch (UnsupportedEncodingException e) {\r
+ // Should never happen since UTF-8 is always supported.\r
+ }\r
+ }\r
+ } catch (MalformedURLException e) {\r
+ // Ignore.\r
+ }\r
+ } \r
+\r
+ startupRegistry = new StartupRegistry();\r
+ }\r
+\r
+ /*\r
+ * (non-Javadoc)\r
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)\r
+ */\r
+ public void stop(BundleContext bundleContext) throws Exception {\r
+ Activator.context = null;\r
+ plugin = null;\r
+ super.stop(bundleContext);\r
+ }\r
+\r
+ /**\r
+ * @return the context of this bundle.\r
+ */\r
+ public static BundleContext getBundleContext() {\r
+ return context;\r
+ }\r
+\r
+ /**\r
+ * Returns the shared instance\r
+ *\r
+ * @return the shared instance\r
+ */\r
+ public static Activator getDefault() {\r
+ return plugin;\r
+ }\r
+\r
+ /**\r
+ * @return\r
+ */\r
+ public StartupRegistry getStartupRegistry() {\r
+ return startupRegistry;\r
+ }\r
+\r
+}\r