]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.fileimport/src/org/simantics/fileimport/Activator.java
Some fixes for FileImportService to throw exceptions forward
[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                 if (!Files.exists(dropinsFolder))
47                     Files.createDirectories(dropinsFolder);
48             }
49             return dropinsFolder;
50         }
51
52     public static Path getModelsFolder() throws IOException {
53         if (modelsFolder == null) {
54             IPath state = Platform.getStateLocation(context.getBundle());
55             modelsFolder = Paths.get(state.append("models").toOSString());
56             if (!Files.exists(modelsFolder))
57                 Files.createDirectories(modelsFolder);
58         }
59         return modelsFolder;
60     }
61
62 }