Avoid Exception construction in utility method
[egit/spearce.git] / org.eclipse.egit.core / src / org / eclipse / egit / core / Activator.java
blobcf78246e74b04c073cee88fc0a35293e04e3ec72
1 /*******************************************************************************
2 * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
3 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
9 *******************************************************************************/
10 package org.eclipse.egit.core;
12 import org.eclipse.core.runtime.IStatus;
13 import org.eclipse.core.runtime.Plugin;
14 import org.eclipse.core.runtime.Status;
15 import org.eclipse.egit.core.internal.trace.GitTraceLocation;
16 import org.eclipse.egit.core.project.GitProjectData;
17 import org.eclipse.osgi.service.debug.DebugOptions;
18 import org.osgi.framework.BundleContext;
19 import org.osgi.util.tracker.ServiceTracker;
21 /**
22 * The plugin class for the org.eclipse.egit.core plugin. This
23 * is a singleton class.
25 public class Activator extends Plugin {
26 private static Activator plugin;
28 /**
29 * @return the singleton {@link Activator}
31 public static Activator getDefault() {
32 return plugin;
35 /**
36 * @return the name of this plugin
38 public static String getPluginId() {
39 return getDefault().getBundle().getSymbolicName();
42 /**
43 * Utility to create an error status for this plug-in.
45 * @param message User comprehensible message
46 * @param thr cause
47 * @return an initialized error status
49 public static IStatus error(final String message, final Throwable thr) {
50 return new Status(IStatus.ERROR, getPluginId(), 0, message, thr);
53 /**
54 * Utility method to log errors in the Egit plugin.
55 * @param message User comprehensible message
56 * @param thr The exception through which we noticed the error
58 public static void logError(final String message, final Throwable thr) {
59 getDefault().getLog().log(
60 new Status(IStatus.ERROR, getPluginId(), 0, message, thr));
63 /**
64 * Construct the {@link Activator} singleton instance
66 public Activator() {
67 plugin = this;
70 public void start(final BundleContext context) throws Exception {
72 super.start(context);
74 if (isDebugging()) {
75 ServiceTracker debugTracker = new ServiceTracker(context,
76 DebugOptions.class.getName(), null);
77 debugTracker.open();
79 DebugOptions opts = (DebugOptions) debugTracker.getService();
80 GitTraceLocation.initializeFromOptions(opts, true);
83 GitProjectData.reconfigureWindowCache();
84 GitProjectData.attachToWorkspace(true);
87 public void stop(final BundleContext context) throws Exception {
88 GitProjectData.detachFromWorkspace();
89 super.stop(context);
90 plugin = null;