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