]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.spreadsheet.common/src/org/simantics/spreadsheet/common/Activator.java
Sync git svn branch with SVN repository r33269.
[simantics/platform.git] / bundles / org.simantics.spreadsheet.common / src / org / simantics / spreadsheet / common / Activator.java
1 package org.simantics.spreadsheet.common;\r
2 import java.io.File;\r
3 import java.io.UnsupportedEncodingException;\r
4 import java.net.MalformedURLException;\r
5 import java.net.URL;\r
6 import java.net.URLDecoder;\r
7 \r
8 import org.osgi.framework.BundleActivator;\r
9 import org.osgi.framework.BundleContext;\r
10 \r
11 \r
12 public class Activator implements BundleActivator {\r
13 \r
14         /**\r
15          * Name of the log file. \r
16          */\r
17         public static String LOG_FILE_NAME = "spreadsheet.log";\r
18 \r
19         // The plug-in ID\r
20         public static final String BUNDLE_ID = "org.simantics.spreadsheet.common"; //$NON-NLS-1$\r
21 \r
22         // The shared instance\r
23         private static Activator plugin;\r
24 \r
25         /**\r
26          * The constructor\r
27          */\r
28         public Activator() {\r
29         }\r
30 \r
31         /*\r
32          * (non-Javadoc)\r
33          * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)\r
34          */\r
35         @Override\r
36         public void start(BundleContext context) throws Exception {\r
37                 plugin = this;\r
38 \r
39                 String prop = System.getProperty("osgi.instance.area", null);\r
40                 if (prop != null) {\r
41                         try {\r
42                                 URL url = new URL(prop);\r
43                                 if ("file".equals(url .getProtocol())) {\r
44                                         try {\r
45                                                 File path = new File(URLDecoder.decode(url.getPath(), "UTF-8"));\r
46                                                 if (!path.exists())\r
47                                                         path.mkdirs();\r
48                                                 if (path.exists() && path.canWrite()) {\r
49                                                         File logFile = new File(path, LOG_FILE_NAME);\r
50                                                         if (!logFile.exists() || (logFile.isFile() && logFile.canWrite()))\r
51                                                                 LOG_FILE_NAME = logFile.getAbsolutePath();\r
52 \r
53                                                 }\r
54                                         } catch (UnsupportedEncodingException e) {\r
55                                                 // Should never happen since UTF-8 is always supported.\r
56                                         }\r
57                                 }\r
58                         } catch (MalformedURLException e) {\r
59                                 // Ignore.\r
60                         }\r
61                 }\r
62         }\r
63 \r
64         /*\r
65          * (non-Javadoc)\r
66          * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)\r
67          */\r
68         @Override\r
69         public void stop(BundleContext context) throws Exception {\r
70                 plugin = null;\r
71         }\r
72 \r
73         /**\r
74          * Returns the shared instance\r
75          *\r
76          * @return the shared instance\r
77          */\r
78         public static Activator getDefault() {\r
79                 return plugin;\r
80         }\r
81 \r
82 }