Make tracing 3.4 compatible and plug-in local
[egit/spearce.git] / org.eclipse.egit.ui / src / org / eclipse / egit / ui / internal / trace / GitTraceLocation.java
blob40682ac6750001b0ae7dc97d692f69868cc000c3
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
8 * Contributors:
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;
19 /**
20 * EGit Trace locations
22 public enum GitTraceLocation implements ITraceLocation {
24 /** UI */
25 UI("/debug/ui"); //$NON-NLS-1$
27 /**
28 * Initialize the locations
30 * @param options
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(),
42 false);
43 loc.setActive(active);
45 } else {
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()) {
49 loc.setActive(false);
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;
64 this.location = path;
67 /**
68 * Convenience method
70 * @return the debug trace (may be null)
72 **/
73 public static DebugTrace getTrace() {
74 return GitTraceLocation.myTrace;
77 /**
78 * @return <code>true</code> if this location is active
80 public boolean isActive() {
81 return this.active;
84 /**
85 * @return the full path
87 public String getFullPath() {
88 return this.fullPath;
91 public String getLocation() {
92 return this.location;
95 /**
96 * Sets the "active" flag for this location.
97 * <p>
98 * Used by the initializer
100 * @param active
101 * the "active" flag
103 private void setActive(boolean active) {
104 this.active = active;
107 private static final class DebugTraceImpl implements DebugTrace {
109 private ILog myLog;
111 public void trace(String location, String message) {
112 getLog().log(
113 new Status(IStatus.INFO, Activator.getPluginId(), message));
117 public void trace(String location, String message, Throwable error) {
119 getLog().log(
120 new Status(IStatus.INFO, Activator.getPluginId(), message));
121 if (error != null)
122 getLog().log(
123 new Status(IStatus.INFO, Activator.getPluginId(), error
124 .getMessage()));
128 public void traceEntry(String location) {
129 // not implemented
132 public void traceEntry(String location, String message) {
133 // not implemented
136 private ILog getLog() {
137 if (myLog == null) {
138 myLog = Activator.getDefault().getLog();
140 return myLog;