tmf.core.tests: Add method to simplify XML Trace stub setup
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.graph.core.tests / src / org / eclipse / tracecompass / analysis / graph / core / tests / Activator.java
1 /*******************************************************************************
2 * Copyright (c) 2015 É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 * Contributors:
10 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.analysis.graph.core.tests;
14
15 import java.io.IOException;
16 import java.net.URL;
17
18 import org.eclipse.core.runtime.FileLocator;
19 import org.eclipse.core.runtime.IPath;
20 import org.eclipse.core.runtime.Path;
21 import org.eclipse.core.runtime.Plugin;
22 import org.eclipse.jdt.annotation.NonNull;
23 import org.osgi.framework.BundleContext;
24
25 /**
26 * Activator for this plugin
27 *
28 * @author Geneviève Bastien
29 */
30 public class Activator extends Plugin {
31 // ------------------------------------------------------------------------
32 // Attributes
33 // ------------------------------------------------------------------------
34
35 /**
36 * The plug-in ID
37 */
38 public static final String PLUGIN_ID = "org.eclipse.tracecompass.analysis.graph.core.tests"; //$NON-NLS-1$
39
40 /**
41 * The shared instance
42 */
43 private static Activator PLUGIN;
44
45 // ------------------------------------------------------------------------
46 // Constructors
47 // ------------------------------------------------------------------------
48
49 /**
50 * The constructor
51 */
52 public Activator() {
53 }
54
55 // ------------------------------------------------------------------------
56 // Accessors
57 // ------------------------------------------------------------------------
58
59 /**
60 * Returns the shared instance
61 *
62 * @return the shared instance
63 */
64 public static Activator getDefault() {
65 return PLUGIN;
66 }
67
68 // ------------------------------------------------------------------------
69 // Operators
70 // ------------------------------------------------------------------------
71
72 @Override
73 public void start(BundleContext context) throws Exception {
74 super.start(context);
75 PLUGIN = this;
76 }
77
78 @Override
79 public void stop(BundleContext context) throws Exception {
80 PLUGIN = null;
81 super.stop(context);
82 }
83
84 /**
85 * Return a path to a file relative to this plugin's base directory
86 *
87 * @param relativePath
88 * The path relative to the plugin's root directory
89 * @return The path corresponding to the relative path in parameter
90 */
91 public static @NonNull IPath getAbsoluteFilePath(String relativePath) {
92 Activator plugin = Activator.getDefault();
93 if (plugin == null) {
94 /*
95 * Shouldn't happen but at least throw something to get the test to
96 * fail early
97 */
98 throw new IllegalStateException();
99 }
100 URL location = FileLocator.find(plugin.getBundle(), new Path(relativePath), null);
101 try {
102 return new Path(FileLocator.toFileURL(location).getPath());
103 } catch (IOException e) {
104 throw new IllegalStateException();
105 }
106 }
107 }
108
This page took 0.036051 seconds and 5 git commands to generate.