lttng: Add a common plugin for LTTng
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.common.core.tests / src / org / eclipse / tracecompass / lttng2 / common / core / tests / Activator.java
1 /*******************************************************************************
2 * Copyright (c) 2016 École Polytechnique de Montréal
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *******************************************************************************/
9
10 package org.eclipse.tracecompass.lttng2.common.core.tests;
11
12 import java.io.IOException;
13 import java.net.URL;
14
15 import org.eclipse.core.runtime.FileLocator;
16 import org.eclipse.core.runtime.IPath;
17 import org.eclipse.core.runtime.Path;
18 import org.eclipse.core.runtime.Plugin;
19 import org.osgi.framework.BundleContext;
20
21 /**
22 * Activator for the lttng2.common.core.tests plugin
23 *
24 * @author Geneviève Bastien
25 */
26 public class Activator extends Plugin {
27 // ------------------------------------------------------------------------
28 // Attributes
29 // ------------------------------------------------------------------------
30
31 /**
32 * The plug-in ID
33 */
34 public static final String PLUGIN_ID = "org.eclipse.tracecompass.lttng2.common.core.tests"; //$NON-NLS-1$
35
36 /**
37 * The shared instance
38 */
39 private static Activator PLUGIN;
40
41 // ------------------------------------------------------------------------
42 // Constructors
43 // ------------------------------------------------------------------------
44
45 /**
46 * The constructor
47 */
48 public Activator() {
49 }
50
51 // ------------------------------------------------------------------------
52 // Accessors
53 // ------------------------------------------------------------------------
54
55 /**
56 * Returns the shared instance
57 *
58 * @return the shared instance
59 */
60 public static Activator getDefault() {
61 return PLUGIN;
62 }
63
64 // ------------------------------------------------------------------------
65 // Operators
66 // ------------------------------------------------------------------------
67
68 @Override
69 public void start(BundleContext context) throws Exception {
70 super.start(context);
71 PLUGIN = this;
72 }
73
74 @Override
75 public void stop(BundleContext context) throws Exception {
76 PLUGIN = null;
77 super.stop(context);
78 }
79
80 /**
81 * Return a path to a file relative to this plugin's base directory
82 *
83 * @param relativePath
84 * The path relative to the plugin's root directory
85 * @return The path corresponding to the relative path in parameter
86 */
87 public static IPath getAbsoluteFilePath(String relativePath) {
88 Activator plugin = Activator.getDefault();
89 if (plugin == null) {
90 /*
91 * Shouldn't happen but at least throw something to get the test to
92 * fail early
93 */
94 throw new IllegalStateException();
95 }
96 URL location = FileLocator.find(plugin.getBundle(), new Path(relativePath), null);
97 try {
98 return new Path(FileLocator.toFileURL(location).getPath());
99 } catch (IOException e) {
100 throw new IllegalStateException();
101 }
102 }
103 }
This page took 0.0322 seconds and 5 git commands to generate.