1 /*******************************************************************************
2 * Copyright (c) 2010 SAP AG.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * Mathias Kinzler (SAP AG) - initial implementation
10 *******************************************************************************/
11 package org
.eclipse
.egit
.ui
.internal
.trace
;
13 import org
.eclipse
.core
.runtime
.ILog
;
14 import org
.eclipse
.core
.runtime
.IStatus
;
15 import org
.eclipse
.core
.runtime
.Status
;
16 import org
.eclipse
.egit
.ui
.Activator
;
17 import org
.eclipse
.osgi
.service
.debug
.DebugOptions
;
20 * EGit Trace locations
22 public enum GitTraceLocation
implements ITraceLocation
{
25 UI("/debug/ui"); //$NON-NLS-1$
28 * Initialize the locations
31 * @param pluginIsDebugging
33 public static void initializeFromOptions(DebugOptions options
,
34 boolean pluginIsDebugging
) {
36 // we evaluate the plug-in switch
37 if (pluginIsDebugging
) {
38 myTrace
= new DebugTraceImpl();
40 for (GitTraceLocation loc
: values()) {
41 boolean active
= options
.getBooleanOption(loc
.getFullPath(),
43 loc
.setActive(active
);
46 // if the plug-in switch is off, we don't set the trace instance
47 // to null to avoid problems with possibly running trace calls
48 for (GitTraceLocation loc
: values()) {
54 private final String location
;
56 private final String fullPath
;
58 private boolean active
= false;
60 private static DebugTrace myTrace
;
62 private GitTraceLocation(String path
) {
63 this.fullPath
= Activator
.getPluginId() + path
;
70 * @return the debug trace (may be null)
73 public static DebugTrace
getTrace() {
74 return GitTraceLocation
.myTrace
;
78 * @return <code>true</code> if this location is active
80 public boolean isActive() {
85 * @return the full path
87 public String
getFullPath() {
91 public String
getLocation() {
96 * Sets the "active" flag for this location.
98 * Used by the initializer
103 private void setActive(boolean active
) {
104 this.active
= active
;
107 private static final class DebugTraceImpl
implements DebugTrace
{
111 public void trace(String location
, String message
) {
113 new Status(IStatus
.INFO
, Activator
.getPluginId(), message
));
117 public void trace(String location
, String message
, Throwable error
) {
120 new Status(IStatus
.INFO
, Activator
.getPluginId(), message
));
123 new Status(IStatus
.INFO
, Activator
.getPluginId(), error
128 public void traceEntry(String location
) {
132 public void traceEntry(String location
, String message
) {
136 private ILog
getLog() {
138 myLog
= Activator
.getDefault().getLog();