]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.help.core/src/org/simantics/help/core/Activator.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.help.core / src / org / simantics / help / core / Activator.java
1 package org.simantics.help.core;
2
3 import java.net.URL;
4 import java.nio.file.Files;
5 import java.nio.file.Path;
6 import java.nio.file.Paths;
7 import java.nio.file.StandardCopyOption;
8
9 import org.eclipse.core.runtime.IPath;
10 import org.eclipse.core.runtime.Platform;
11 import org.eclipse.ui.plugin.AbstractUIPlugin;
12 import org.osgi.framework.Bundle;
13 import org.osgi.framework.BundleContext;
14
15 /**
16  * The activator class controls the plug-in life cycle
17  */
18 public class Activator extends AbstractUIPlugin {
19
20         // The plug-in ID
21         public static final String PLUGIN_ID = "org.simantics.help.core"; //$NON-NLS-1$
22
23         public static final String HTML_FOLDER = "html";
24         
25         // The shared instance
26         private static Activator plugin;
27         private static Path directory;
28         
29         /**
30          * The constructor
31          */
32         public Activator() {
33         }
34
35         /*
36          * (non-Javadoc)
37          * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
38          */
39         public void start(BundleContext context) throws Exception {
40                 super.start(context);
41                 plugin = this;
42         Bundle bundle = context.getBundle();
43         IPath path = Platform.getStateLocation(bundle);
44         Path p = Paths.get(path.toOSString());
45         directory = p.resolve(HTML_FOLDER);
46         if (!Files.exists(directory))
47             Files.createDirectories(directory);
48         
49         // Ensure that style.css is inside the html directory
50         Path css = directory.resolve("style.css");
51         if (!Files.exists(css)) {
52             Files.createFile(css);
53             URL url = bundle.getEntry("css/style.css");
54             Files.copy(url.openStream(), css, StandardCopyOption.REPLACE_EXISTING);
55         }
56         }
57
58         /*
59          * (non-Javadoc)
60          * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
61          */
62         public void stop(BundleContext context) throws Exception {
63                 plugin = null;
64                 super.stop(context);
65         }
66
67         /**
68          * Returns the shared instance
69          *
70          * @return the shared instance
71          */
72         public static Activator getDefault() {
73                 return plugin;
74         }
75         
76     public static Path getHtmlDirectory() {
77         return directory;
78     }
79
80 }