Commit | Line | Data |
---|---|---|
ff71e543 | 1 | /******************************************************************************* |
c19380ab | 2 | * Copyright (c) 2014, 2015 Ericsson |
ff71e543 MK |
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 | * Matthew Khouzam - Initial implementation | |
11 | *******************************************************************************/ | |
12 | ||
7ce90559 | 13 | package org.eclipse.tracecompass.btf.core; |
ff71e543 MK |
14 | |
15 | import org.eclipse.core.runtime.IStatus; | |
16 | import org.eclipse.core.runtime.Plugin; | |
17 | import org.eclipse.core.runtime.Status; | |
18 | import org.osgi.framework.BundleContext; | |
19 | ||
20 | /** | |
21 | * The activator class controls the plug-in life cycle. No more than one such | |
22 | * plug-in can exist at any time. | |
23 | * <p> | |
24 | * It also provides the plug-in's general logging facility and manages the | |
25 | * internal tracer. | |
26 | */ | |
27 | public class Activator extends Plugin { | |
28 | ||
29 | // ------------------------------------------------------------------------ | |
30 | // Attributes | |
31 | // ------------------------------------------------------------------------ | |
32 | ||
33 | /** | |
34 | * The plug-in ID | |
35 | */ | |
c19380ab | 36 | public static final String PLUGIN_ID = "org.eclipse.tracecompass.btf.core"; //$NON-NLS-1$ |
ff71e543 MK |
37 | |
38 | /** | |
39 | * The shared instance | |
40 | */ | |
41 | private static Activator fPlugin; | |
42 | ||
43 | // ------------------------------------------------------------------------ | |
44 | // Constructors | |
45 | // ------------------------------------------------------------------------ | |
46 | ||
47 | /** | |
48 | * Constructor | |
49 | */ | |
50 | public Activator() { | |
51 | setDefault(this); | |
52 | } | |
53 | ||
54 | // ------------------------------------------------------------------------ | |
55 | // Accessors | |
56 | // ------------------------------------------------------------------------ | |
57 | ||
58 | /** | |
59 | * Returns the BTF plug-in instance. | |
60 | * | |
61 | * @return the BTF plug-in instance. | |
62 | */ | |
63 | public static Activator getDefault() { | |
64 | return fPlugin; | |
65 | } | |
66 | ||
67 | // Sets plug-in instance | |
68 | private static void setDefault(Activator plugin) { | |
69 | fPlugin = plugin; | |
70 | } | |
71 | ||
72 | // ------------------------------------------------------------------------ | |
73 | // Plugin | |
74 | // ------------------------------------------------------------------------ | |
75 | ||
76 | @Override | |
77 | public void start(BundleContext context) throws Exception { | |
78 | super.start(context); | |
79 | setDefault(this); | |
80 | } | |
81 | ||
82 | @Override | |
83 | public void stop(BundleContext context) throws Exception { | |
84 | setDefault(null); | |
85 | super.stop(context); | |
86 | } | |
87 | ||
88 | ||
89 | // ------------------------------------------------------------------------ | |
90 | // Log an IStatus | |
91 | // ------------------------------------------------------------------------ | |
92 | ||
93 | /** | |
94 | * Log an IStatus object directly | |
95 | * | |
96 | * @param status | |
97 | * The status to log | |
98 | */ | |
99 | public static void log(IStatus status) { | |
100 | fPlugin.getLog().log(status); | |
101 | } | |
102 | ||
103 | // ------------------------------------------------------------------------ | |
104 | // Log INFO | |
105 | // ------------------------------------------------------------------------ | |
106 | ||
107 | /** | |
108 | * Logs a message with severity INFO in the runtime log of the plug-in. | |
109 | * | |
110 | * @param message | |
111 | * A message to log | |
112 | */ | |
113 | public static void logInfo(String message) { | |
114 | fPlugin.getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message)); | |
115 | } | |
116 | ||
117 | /** | |
118 | * Logs a message and exception with severity INFO in the runtime log of the | |
119 | * plug-in. | |
120 | * | |
121 | * @param message | |
122 | * A message to log | |
123 | * @param exception | |
124 | * The corresponding exception | |
125 | */ | |
126 | public static void logInfo(String message, Throwable exception) { | |
127 | fPlugin.getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message, exception)); | |
128 | } | |
129 | ||
130 | // ------------------------------------------------------------------------ | |
131 | // Log WARNING | |
132 | // ------------------------------------------------------------------------ | |
133 | ||
134 | /** | |
135 | * Logs a message and exception with severity WARNING in the runtime log of | |
136 | * the plug-in. | |
137 | * | |
138 | * @param message | |
139 | * A message to log | |
140 | */ | |
141 | public static void logWarning(String message) { | |
142 | fPlugin.getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, message)); | |
143 | } | |
144 | ||
145 | /** | |
146 | * Logs a message and exception with severity WARNING in the runtime log of | |
147 | * the plug-in. | |
148 | * | |
149 | * @param message | |
150 | * A message to log | |
151 | * @param exception | |
152 | * The corresponding exception | |
153 | */ | |
154 | public static void logWarning(String message, Throwable exception) { | |
155 | fPlugin.getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, message, exception)); | |
156 | } | |
157 | ||
158 | // ------------------------------------------------------------------------ | |
159 | // Log ERROR | |
160 | // ------------------------------------------------------------------------ | |
161 | ||
162 | /** | |
163 | * Logs a message and exception with severity ERROR in the runtime log of | |
164 | * the plug-in. | |
165 | * | |
166 | * @param message | |
167 | * A message to log | |
168 | */ | |
169 | public static void logError(String message) { | |
170 | fPlugin.getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message)); | |
171 | } | |
172 | ||
173 | /** | |
174 | * Logs a message and exception with severity ERROR in the runtime log of | |
175 | * the plug-in. | |
176 | * | |
177 | * @param message | |
178 | * A message to log | |
179 | * @param exception | |
180 | * The corresponding exception | |
181 | */ | |
182 | public static void logError(String message, Throwable exception) { | |
183 | fPlugin.getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message, exception)); | |
184 | } | |
185 | } |