]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics/src/org/simantics/internal/Activator.java
Merge changes I7c81eac8,I15581be9
[simantics/platform.git] / bundles / org.simantics / src / org / simantics / internal / Activator.java
1 package org.simantics.internal;
2
3 import java.io.File;
4 import java.io.UnsupportedEncodingException;
5 import java.net.MalformedURLException;
6 import java.net.URL;
7 import java.net.URLDecoder;
8
9 import org.eclipse.core.runtime.Plugin;
10 import org.osgi.framework.BundleContext;
11 import org.simantics.internal.startup.StartupRegistry;
12
13 public class Activator extends Plugin {
14
15         /**
16          * Name of the log file. 
17          */
18         public static String LOG_FILE_NAME = "simantics.log";
19
20         public static final String PLUGIN_ID = "org.simantics";
21
22         // The shared instance
23         private static Activator plugin;
24
25         private static BundleContext context;
26
27         private StartupRegistry startupRegistry;
28
29         static BundleContext getContext() {
30                 return context;
31         }
32
33         /*
34          * (non-Javadoc)
35          * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
36          */
37         public void start(BundleContext bundleContext) throws Exception {
38                 super.start(bundleContext);
39                 Activator.context = bundleContext;
40                 plugin = this;
41
42                 String prop = System.getProperty("osgi.instance.area", null);
43                 if (prop != null) {
44                         try {
45                                 URL url = new URL(prop);
46                                 if ("file".equals(url .getProtocol())) {
47                                         try {
48                                                 File path = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
49                                                 if (!path.exists())
50                                                         path.mkdirs();
51                                                 if (path.exists() && path.canWrite()) {
52                                                         File logFile = new File(path, LOG_FILE_NAME);
53                                                         if (!logFile.exists() || (logFile.isFile() && logFile.canWrite()))
54                                                                 LOG_FILE_NAME = logFile.getAbsolutePath();
55
56                                                 }
57                                         } catch (UnsupportedEncodingException e) {
58                                                 // Should never happen since UTF-8 is always supported.
59                                         }
60                                 }
61                         } catch (MalformedURLException e) {
62                                 // Ignore.
63                         }
64                 }               
65
66                 startupRegistry = new StartupRegistry();
67         }
68
69         /*
70          * (non-Javadoc)
71          * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
72          */
73         public void stop(BundleContext bundleContext) throws Exception {
74                 Activator.context = null;
75                 plugin = null;
76                 super.stop(bundleContext);
77         }
78
79         /**
80          * @return the context of this bundle.
81          */
82         public static BundleContext getBundleContext() {
83                 return context;
84         }
85
86         /**
87          * Returns the shared instance
88          *
89          * @return the shared instance
90          */
91         public static Activator getDefault() {
92                 return plugin;
93         }
94
95         /**
96          * @return
97          */
98         public StartupRegistry getStartupRegistry() {
99                 return startupRegistry;
100         }
101
102 }