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
CommitLineData
d18dd09b 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2009, 2014 Ericsson
54a7a54c 3 *
d18dd09b
ASL
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
54a7a54c 8 *
d18dd09b
ASL
9 * Contributors:
10 * Francois Chouinard - Initial API and implementation
11 *******************************************************************************/
12
2bdf0193 13package org.eclipse.tracecompass.tmf.core.tests;
d18dd09b 14
ec52ed4a
GB
15import java.io.IOException;
16import java.net.URL;
17
18import org.eclipse.core.runtime.FileLocator;
19import org.eclipse.core.runtime.IPath;
20import org.eclipse.core.runtime.Path;
d18dd09b 21import org.eclipse.core.runtime.Plugin;
ec52ed4a 22import org.eclipse.jdt.annotation.NonNull;
2bdf0193 23import org.eclipse.tracecompass.internal.tmf.core.TmfCoreTracer;
cbd4ad82 24import org.osgi.framework.BundleContext;
d18dd09b
ASL
25
26/**
27 * <b><u>TmfTestPlugin</u></b>
28 * <p>
29 * The activator class controls the plug-in life cycle
30 */
31public class TmfCoreTestPlugin extends Plugin {
32
cbd4ad82 33 // ------------------------------------------------------------------------
d18dd09b 34 // Attributes
cbd4ad82 35 // ------------------------------------------------------------------------
d18dd09b 36
d5efe032
AF
37 // The plug-in ID
38 @SuppressWarnings("javadoc")
c77a695a 39 public static final String PLUGIN_ID = "org.eclipse.tracecompass.tmf.tests";
d18dd09b 40
d5efe032
AF
41 // The shared instance
42 private static TmfCoreTestPlugin fPlugin;
54a7a54c 43
cbd4ad82 44 // ------------------------------------------------------------------------
d18dd09b 45 // Constructors
cbd4ad82 46 // ------------------------------------------------------------------------
d18dd09b 47
d5efe032
AF
48 /**
49 * The constructor
50 */
51 public TmfCoreTestPlugin() {
52 setDefault(this);
53 }
d18dd09b 54
d5efe032 55 // ------------------------------------------------------------------------
d18dd09b 56 // Accessors
d5efe032 57 // ------------------------------------------------------------------------
d18dd09b
ASL
58
59 /**
60 * @return the shared instance
61 */
cbd4ad82
FC
62 public static TmfCoreTestPlugin getDefault() {
63 return fPlugin;
d18dd09b
ASL
64 }
65
d5efe032
AF
66 /**
67 * @param plugin the shared instance
68 */
69 private static void setDefault(TmfCoreTestPlugin plugin) {
70 fPlugin = plugin;
71 }
cbd4ad82 72
d5efe032 73 // ------------------------------------------------------------------------
cbd4ad82 74 // Operations
d5efe032 75 // ------------------------------------------------------------------------
cbd4ad82 76
d5efe032
AF
77 @Override
78 public void start(BundleContext context) throws Exception {
79 super.start(context);
80 setDefault(this);
81 TmfCoreTracer.init();
82 }
cbd4ad82 83
d5efe032
AF
84 @Override
85 public void stop(BundleContext context) throws Exception {
86 TmfCoreTracer.stop();
87 setDefault(null);
88 super.stop(context);
89 }
cbd4ad82 90
ec52ed4a
GB
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
d18dd09b 115}
This page took 0.100628 seconds and 5 git commands to generate.