|
1 package com.nokia.carbide.search.system.tests; |
|
2 |
|
3 import java.io.File; |
|
4 import java.net.URL; |
|
5 |
|
6 import org.eclipse.core.runtime.FileLocator; |
|
7 import org.eclipse.core.runtime.IPath; |
|
8 import org.eclipse.core.runtime.Path; |
|
9 import org.eclipse.core.runtime.Platform; |
|
10 import org.eclipse.core.runtime.Plugin; |
|
11 import org.osgi.framework.BundleContext; |
|
12 |
|
13 public class TestPlugin extends Plugin { |
|
14 |
|
15 private static BundleContext bundleContext; |
|
16 private static TestPlugin plugin; |
|
17 |
|
18 public static TestPlugin getDefault() { |
|
19 return plugin; |
|
20 } |
|
21 |
|
22 static BundleContext getBundleContext() { |
|
23 return bundleContext; |
|
24 } |
|
25 |
|
26 // The plug-in ID |
|
27 public static final String PLUGIN_ID = "com.nokia.carbide.search.system.tests"; |
|
28 |
|
29 public void start(BundleContext bundleContext) throws Exception { |
|
30 super.start(bundleContext); |
|
31 TestPlugin.bundleContext = bundleContext; |
|
32 plugin = this; |
|
33 URL pluginURL = FileLocator.find(bundleContext.getBundle(), new Path(""), null); //$NON-NLS-1$ |
|
34 pluginURL = FileLocator.resolve(pluginURL); |
|
35 String pluginFilePath = pluginURL.getFile(); |
|
36 pluginPath = new Path(pluginFilePath); |
|
37 } |
|
38 |
|
39 public void stop(BundleContext bundleContext) throws Exception { |
|
40 plugin = null; |
|
41 super.stop(bundleContext); |
|
42 } |
|
43 |
|
44 public static String projectRelativePath(String file) throws Exception { |
|
45 File f; |
|
46 if (!Platform.isRunning()) { |
|
47 // get file relative to CWD (i.e. this project) |
|
48 f = new File(file); |
|
49 f = f.getCanonicalFile(); |
|
50 } else { |
|
51 // get file relative to running plugin (still this project) |
|
52 f = new File(getDefault().getPluginFilePath(file).toOSString()); |
|
53 } |
|
54 |
|
55 return f.getAbsolutePath(); |
|
56 } |
|
57 private Path pluginPath; |
|
58 |
|
59 /** |
|
60 * Returns a path relative to this plugin. |
|
61 * |
|
62 * @param inPluginPath |
|
63 * @return |
|
64 */ |
|
65 public IPath getPluginFilePath(String inPluginPath) { |
|
66 return pluginPath.append(inPluginPath); |
|
67 } |
|
68 |
|
69 public static String getPluginPath(String inPluginPath) { |
|
70 return getDefault().getPluginFilePath(inPluginPath).toOSString(); |
|
71 } |
|
72 } |