]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.fileimport/src/org/simantics/fileimport/Activator.java
Fixed multiple issues causing dangling references to discarded queries
[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 modelsFolder = null;
19         private static Path dropinsFolder = null;
20
21         static BundleContext getContext() {
22                 return context;
23         }
24
25         /*
26          * (non-Javadoc)
27          * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
28          */
29         public void start(BundleContext bundleContext) throws Exception {
30                 Activator.context = bundleContext;
31         }
32
33         /*
34          * (non-Javadoc)
35          * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
36          */
37         public void stop(BundleContext bundleContext) throws Exception {
38                 Activator.context = null;
39                 FileImportDropins.unwatchDropinsFolder();
40         }
41         
42         public static Path getDropinsFolder() throws IOException {
43             if (dropinsFolder == null) {
44                 IPath state = Platform.getStateLocation(context.getBundle());
45                 dropinsFolder = Paths.get(state.append("dropins").toOSString());
46                 Files.createDirectories(dropinsFolder);
47             }
48             return dropinsFolder;
49         }
50
51     public static Path getModelsFolder() throws IOException {
52         if (modelsFolder == null) {
53             IPath state = Platform.getStateLocation(context.getBundle());
54             modelsFolder = Paths.get(state.append("models").toOSString());
55             Files.createDirectories(modelsFolder);
56         }
57         return modelsFolder;
58     }
59
60 }