1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
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
10 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.common
.core
;
15 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
16 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.nullToEmptyString
;
18 import java
.util
.Collections
;
19 import java
.util
.HashMap
;
22 import org
.eclipse
.core
.runtime
.IStatus
;
23 import org
.eclipse
.core
.runtime
.Plugin
;
24 import org
.eclipse
.core
.runtime
.Status
;
25 import org
.eclipse
.jdt
.annotation
.Nullable
;
26 import org
.osgi
.framework
.BundleContext
;
29 * The activator class controls the plug-in life cycle
31 * @author Alexandre Montplaisir
33 public abstract class TraceCompassActivator
extends Plugin
{
35 // ------------------------------------------------------------------------
37 // ------------------------------------------------------------------------
39 /** Map of all the registered activators, indexed by plugin ID */
40 private static final Map
<String
, TraceCompassActivator
> ACTIVATORS
=
41 checkNotNull(Collections
.synchronizedMap(new HashMap
<String
, TraceCompassActivator
>()));
43 /** This instance's plug-in ID */
44 private final String fPluginId
;
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
54 * The ID of the plugin
56 public TraceCompassActivator(String pluginID
) {
60 // ------------------------------------------------------------------------
62 // ------------------------------------------------------------------------
65 * Return this plug-in's ID.
67 * @return The plug-in ID
69 public String
getPluginId() {
74 * Get a registered activator. Subclasses should implement their own public
75 * getInstance() method, which returns the result of this.
78 * The activator's plugin ID
79 * @return The corresponding activator
81 protected static TraceCompassActivator
getInstance(String id
) {
82 TraceCompassActivator ret
= ACTIVATORS
.get(id
);
84 /* The activator should be registered at this point! */
85 throw new IllegalStateException();
90 // ------------------------------------------------------------------------
92 // ------------------------------------------------------------------------
95 * Additional actions to run at the plug-in startup
97 protected abstract void startActions();
100 * Additional actions to run at the plug-in shtudown
102 protected abstract void stopActions();
104 // ------------------------------------------------------------------------
105 // ore.eclipse.core.runtime.Plugin
106 // ------------------------------------------------------------------------
109 public final void start(@Nullable BundleContext context
) throws Exception
{
110 super.start(context
);
111 String id
= this.getPluginId();
112 synchronized (ACTIVATORS
) {
113 if (ACTIVATORS
.containsKey(id
)) {
114 logError("Duplicate Activator ID : " + id
); //$NON-NLS-1$
116 ACTIVATORS
.put(id
, this);
122 public final void stop(@Nullable BundleContext context
) throws Exception
{
124 ACTIVATORS
.remove(this.getPluginId());
128 // ------------------------------------------------------------------------
130 // ------------------------------------------------------------------------
133 * Logs a message with severity INFO in the runtime log of the plug-in.
138 public void logInfo(@Nullable String message
) {
139 getLog().log(new Status(IStatus
.INFO
, fPluginId
, nullToEmptyString(message
)));
143 * Logs a message and exception with severity INFO in the runtime log of the
151 public void logInfo(@Nullable String message
, Throwable exception
) {
152 getLog().log(new Status(IStatus
.INFO
, fPluginId
, nullToEmptyString(message
), exception
));
156 * Logs a message and exception with severity WARNING in the runtime log of
162 public void logWarning(@Nullable String message
) {
163 getLog().log(new Status(IStatus
.WARNING
, fPluginId
, nullToEmptyString(message
)));
167 * Logs a message and exception with severity WARNING in the runtime log of
175 public void logWarning(@Nullable String message
, Throwable exception
) {
176 getLog().log(new Status(IStatus
.WARNING
, fPluginId
, nullToEmptyString(message
), exception
));
180 * Logs a message and exception with severity ERROR in the runtime log of
186 public void logError(@Nullable String message
) {
187 getLog().log(new Status(IStatus
.ERROR
, fPluginId
, nullToEmptyString(message
)));
191 * Logs a message and exception with severity ERROR in the runtime log of
199 public void logError(@Nullable String message
, Throwable exception
) {
200 getLog().log(new Status(IStatus
.ERROR
, fPluginId
, nullToEmptyString(message
), exception
));