tmf.core.tests: Add method to simplify XML Trace stub setup
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core.tests / src / org / eclipse / tracecompass / tmf / core / tests / TmfCoreTestPlugin.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2014 Ericsson
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 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.tmf.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.eclipse.tracecompass.internal.tmf.core.TmfCoreTracer;
24 import org.osgi.framework.BundleContext;
25
26 /**
27 * <b><u>TmfTestPlugin</u></b>
28 * <p>
29 * The activator class controls the plug-in life cycle
30 */
31 public class TmfCoreTestPlugin extends Plugin {
32
33 // ------------------------------------------------------------------------
34 // Attributes
35 // ------------------------------------------------------------------------
36
37 // The plug-in ID
38 @SuppressWarnings("javadoc")
39 public static final String PLUGIN_ID = "org.eclipse.tracecompass.tmf.tests";
40
41 // The shared instance
42 private static TmfCoreTestPlugin fPlugin;
43
44 // ------------------------------------------------------------------------
45 // Constructors
46 // ------------------------------------------------------------------------
47
48 /**
49 * The constructor
50 */
51 public TmfCoreTestPlugin() {
52 setDefault(this);
53 }
54
55 // ------------------------------------------------------------------------
56 // Accessors
57 // ------------------------------------------------------------------------
58
59 /**
60 * @return the shared instance
61 */
62 public static TmfCoreTestPlugin getDefault() {
63 return fPlugin;
64 }
65
66 /**
67 * @param plugin the shared instance
68 */
69 private static void setDefault(TmfCoreTestPlugin plugin) {
70 fPlugin = plugin;
71 }
72
73 // ------------------------------------------------------------------------
74 // Operations
75 // ------------------------------------------------------------------------
76
77 @Override
78 public void start(BundleContext context) throws Exception {
79 super.start(context);
80 setDefault(this);
81 TmfCoreTracer.init();
82 }
83
84 @Override
85 public void stop(BundleContext context) throws Exception {
86 TmfCoreTracer.stop();
87 setDefault(null);
88 super.stop(context);
89 }
90
91 /**
92 * Return a path to a file relative to this plugin's base directory
93 *
94 * @param relativePath
95 * The path relative to the plugin's root directory
96 * @return The path corresponding to the relative path in parameter
97 */
98 public static @NonNull IPath getAbsoluteFilePath(String relativePath) {
99 Plugin plugin = TmfCoreTestPlugin.getDefault();
100 if (plugin == null) {
101 /*
102 * Shouldn't happen but at least throw something to get the test to
103 * fail early
104 */
105 throw new IllegalStateException();
106 }
107 URL location = FileLocator.find(plugin.getBundle(), new Path(relativePath), null);
108 try {
109 return new Path(FileLocator.toFileURL(location).getPath());
110 } catch (IOException e) {
111 throw new IllegalStateException();
112 }
113 }
114
115 }
This page took 0.057637 seconds and 6 git commands to generate.