]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.help.core/src/org/simantics/help/core/Activator.java
Removed redundant Files.exists/isDirectory checks
[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         Files.createDirectories(directory);
47         
48         // Ensure that style.css is inside the html directory
49         Path css = directory.resolve("style.css");
50         if (!Files.exists(css)) {
51             Files.createFile(css);
52             URL url = bundle.getEntry("css/style.css");
53             Files.copy(url.openStream(), css, StandardCopyOption.REPLACE_EXISTING);
54         }
55         }
56
57         /*
58          * (non-Javadoc)
59          * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
60          */
61         public void stop(BundleContext context) throws Exception {
62                 plugin = null;
63                 super.stop(context);
64         }
65
66         /**
67          * Returns the shared instance
68          *
69          * @return the shared instance
70          */
71         public static Activator getDefault() {
72                 return plugin;
73         }
74         
75     public static Path getHtmlDirectory() {
76         return directory;
77     }
78
79 }