]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.fileimport/src/org/simantics/fileimport/Activator.java
Sync git svn branch with SVN repository r33144.
[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                 FileImportDropins.watchDropinsFolder();\r
31         }\r
32 \r
33         /*\r
34          * (non-Javadoc)\r
35          * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)\r
36          */\r
37         public void stop(BundleContext bundleContext) throws Exception {\r
38                 Activator.context = null;\r
39                 FileImportDropins.unwatchDropinsFolder();\r
40         }\r
41         \r
42         public static Path getDropinsFolder() throws IOException {\r
43             if (dropinsFolder == null) {\r
44                 IPath state = Platform.getStateLocation(context.getBundle());\r
45                 dropinsFolder = Paths.get(state.append("dropins").toOSString());\r
46                 if (!Files.exists(dropinsFolder))\r
47                     Files.createDirectories(dropinsFolder);\r
48             }\r
49             return dropinsFolder;\r
50         }\r
51 \r
52 }\r