Merge commit '8e4e41fa135641b23f68e205832e0696951c5f63'
[simantics/platform.git] / bundles / org.simantics.fileimport / src / org / simantics / fileimport / Activator.java
1 package org.simantics.fileimport;\r
2 \r
3 import java.io.IOException;\r
4 import java.nio.file.Files;\r
5 import java.nio.file.Path;\r
6 import java.nio.file.Paths;\r
7 \r
8 import org.eclipse.core.runtime.IPath;\r
9 import org.eclipse.core.runtime.Platform;\r
10 import org.osgi.framework.BundleActivator;\r
11 import org.osgi.framework.BundleContext;\r
12 import org.simantics.fileimport.dropins.FileImportDropins;\r
13 \r
14 public class Activator implements BundleActivator {\r
15 \r
16         private static BundleContext context;\r
17         \r
18         private static Path dropinsFolder = null;\r
19 \r
20         static BundleContext getContext() {\r
21                 return context;\r
22         }\r
23 \r
24         /*\r
25          * (non-Javadoc)\r
26          * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)\r
27          */\r
28         public void start(BundleContext bundleContext) throws Exception {\r
29                 Activator.context = bundleContext;\r
30         }\r
31 \r
32         /*\r
33          * (non-Javadoc)\r
34          * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)\r
35          */\r
36         public void stop(BundleContext bundleContext) throws Exception {\r
37                 Activator.context = null;\r
38                 FileImportDropins.unwatchDropinsFolder();\r
39         }\r
40         \r
41         public static Path getDropinsFolder() throws IOException {\r
42             if (dropinsFolder == null) {\r
43                 IPath state = Platform.getStateLocation(context.getBundle());\r
44                 dropinsFolder = Paths.get(state.append("dropins").toOSString());\r
45                 if (!Files.exists(dropinsFolder))\r
46                     Files.createDirectories(dropinsFolder);\r
47             }\r
48             return dropinsFolder;\r
49         }\r
50 \r
51 }\r