| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2009, 2012 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.linuxtools.internal.tmf.core; |
| 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 | */ |
| 36 | public static final String PLUGIN_ID = "org.eclipse.linuxtools.tmf.core"; //$NON-NLS-1$ |
| 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 TMF Core plug-in instance. |
| 60 | * |
| 61 | * @return the TMF Core 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 | /* |
| 77 | * (non-Javadoc) |
| 78 | * @see org.eclipse.core.runtime.Plugin#start(org.osgi.framework.BundleContext) |
| 79 | */ |
| 80 | @Override |
| 81 | public void start(BundleContext context) throws Exception { |
| 82 | super.start(context); |
| 83 | setDefault(this); |
| 84 | TmfCoreTracer.init(); |
| 85 | } |
| 86 | |
| 87 | /* |
| 88 | * (non-Javadoc) |
| 89 | * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext) |
| 90 | */ |
| 91 | @Override |
| 92 | public void stop(BundleContext context) throws Exception { |
| 93 | TmfCoreTracer.stop(); |
| 94 | setDefault(null); |
| 95 | super.stop(context); |
| 96 | } |
| 97 | |
| 98 | // ------------------------------------------------------------------------ |
| 99 | // Log INFO |
| 100 | // ------------------------------------------------------------------------ |
| 101 | |
| 102 | /** |
| 103 | * Logs a message with severity INFO in the runtime log of the plug-in. |
| 104 | * |
| 105 | * @param message A message to log |
| 106 | */ |
| 107 | public static void logInfo(String message) { |
| 108 | fPlugin.getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message)); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * Logs a message and exception with severity INFO in the runtime log of the plug-in. |
| 113 | * |
| 114 | * @param message A message to log |
| 115 | * @param exception The corresponding exception |
| 116 | */ |
| 117 | public static void logInfo(String message, Throwable exception) { |
| 118 | fPlugin.getLog().log(new Status(IStatus.INFO, PLUGIN_ID, message, exception)); |
| 119 | } |
| 120 | |
| 121 | // ------------------------------------------------------------------------ |
| 122 | // Log WARNING |
| 123 | // ------------------------------------------------------------------------ |
| 124 | |
| 125 | /** |
| 126 | * Logs a message and exception with severity WARNING in the runtime log of the plug-in. |
| 127 | * |
| 128 | * @param message A message to log |
| 129 | */ |
| 130 | public static void logWarning(String message) { |
| 131 | fPlugin.getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, message)); |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Logs a message and exception with severity WARNING in the runtime log of the plug-in. |
| 136 | * |
| 137 | * @param message A message to log |
| 138 | * @param exception The corresponding exception |
| 139 | */ |
| 140 | public static void logWarning(String message, Throwable exception) { |
| 141 | fPlugin.getLog().log(new Status(IStatus.WARNING, PLUGIN_ID, message, exception)); |
| 142 | } |
| 143 | |
| 144 | // ------------------------------------------------------------------------ |
| 145 | // Log ERROR |
| 146 | // ------------------------------------------------------------------------ |
| 147 | |
| 148 | /** |
| 149 | * Logs a message and exception with severity ERROR in the runtime log of the plug-in. |
| 150 | * |
| 151 | * @param message A message to log |
| 152 | */ |
| 153 | public static void logError(String message) { |
| 154 | fPlugin.getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message)); |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Logs a message and exception with severity ERROR in the runtime log of the plug-in. |
| 159 | * |
| 160 | * @param message A message to log |
| 161 | * @param exception The corresponding exception |
| 162 | */ |
| 163 | public static void logError(String message, Throwable exception) { |
| 164 | fPlugin.getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message, exception)); |
| 165 | } |
| 166 | |
| 167 | } |