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