]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.common/src/org/simantics/db/common/internal/Activator.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / internal / Activator.java
1 package org.simantics.db.common.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.osgi.framework.BundleActivator;
10 import org.osgi.framework.BundleContext;
11 import org.simantics.db.common.internal.config.InternalClientConfig;
12
13 /**
14  * @author Tuukka Lehtonen
15  *
16  */
17 public class Activator implements BundleActivator {
18
19         // The plug-in ID
20         public static final String BUNDLE_ID = "org.simantics.db.common"; //$NON-NLS-1$
21
22         // The shared instance
23         private static Activator plugin;
24
25         /**
26          * The constructor
27          */
28         public Activator() {
29         }
30
31         /*
32          * (non-Javadoc)
33          * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
34          */
35         @Override
36         public void start(BundleContext context) throws Exception {
37                 plugin = this;
38
39                 String prop = System.getProperty("osgi.instance.area", null);
40                 if (prop != null) {
41                         try {
42                                 URL url = new URL(prop);
43                                 if ("file".equals(url .getProtocol())) {
44                                         try {
45                                                 File path = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
46                                                 if (!path.exists())
47                                                         path.mkdirs();
48                                                 if (path.exists() && path.canWrite()) {
49                                                         File logFile = new File(path, InternalClientConfig.DB_CLIENT_LOG_FILE_NAME);
50                                                         if (!logFile.exists() || (logFile.isFile() && logFile.canWrite()))
51                                                                 InternalClientConfig.DB_CLIENT_LOG_FILE = logFile.getAbsolutePath();
52
53                                                         File tempDir = new File(path, InternalClientConfig.DB_CLIENT_TEMP_DIR_NAME);
54                                                         if (!tempDir.exists() || (tempDir.isDirectory() && tempDir.canWrite()))
55                                                                 InternalClientConfig.DB_CLIENT_TEMP_DIR = tempDir;
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
67         /*
68          * (non-Javadoc)
69          * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
70          */
71         @Override
72         public void stop(BundleContext context) throws Exception {
73                 plugin = null;
74         }
75
76         /**
77          * Returns the shared instance
78          *
79          * @return the shared instance
80          */
81         public static Activator getDefault() {
82                 return plugin;
83         }
84
85 }