1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
/*******************************************************************************
* Copyright (c) 2011, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.ui.trace.internal;
import java.io.File;
import java.util.*;
import org.eclipse.core.runtime.*;
import org.eclipse.osgi.service.runnable.StartupMonitor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.ui.trace.internal.utils.*;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
/**
* The activator class controls the plug-in life cycle
*/
public class TracingUIActivator extends AbstractUIPlugin {
/**
* The constructor
*/
public TracingUIActivator() {
// empty constructor
}
/**
* Returns the shared instance
*
* @return the shared instance
*/
public static TracingUIActivator getDefault() {
return TracingUIActivator.plugin;
}
@Override
public void start(final BundleContext context) throws Exception {
super.start(context);
TracingUIActivator.plugin = this;
if (DebugOptionsHandler.isTracingEnabled()) {
// Tracing options have been enabled using options file and debug mode
// Set option so we know debug mode is set, not preferences
DebugOptionsHandler.setLaunchInDebugMode(true);
} else {
// bug 395632: see if the instance location is defined. if not then defer accessing
// the preferences until it is defined by being notified via the org.eclipse.osgi.service.runnable.StartupMonitor
// service
if (!Platform.getInstanceLocation().isSet()) {
// register a startup monitor to notify us when the application is running
final TracingStartupMonitor startupMonitor = new TracingStartupMonitor();
final Dictionary<String, ?> properties = new Hashtable<String, Object>(1);
ServiceRegistration<StartupMonitor> registration = context.registerService(StartupMonitor.class, startupMonitor, properties);
startupMonitor.setRegistration(registration);
} else {
this.initPreferences();
}
}
}
@Override
public void stop(final BundleContext context) throws Exception {
TracingUIActivator.plugin = null;
super.stop(context);
}
/**
* Log the specified {@link Exception} to the workspace logging file.
*
* @param ex
* The {@link Exception} to log
*/
public final void logException(final Exception ex) {
if (ex != null) {
final IStatus errorStatus = new Status(IStatus.ERROR, TracingConstants.BUNDLE_ID, ex.getMessage(), ex);
this.getLog().log(errorStatus);
}
}
/**
* Initialize the tracing preferences if tracing is enabled.
*/
protected final void initPreferences() {
if (PreferenceHandler.isTracingEnabled()) {
// User has previously enabled tracing options
DebugOptionsHandler.setDebugEnabled(true);
DebugOptionsHandler.getDebugOptions().setFile(new File(PreferenceHandler.getFilePath()));
System.setProperty(TracingConstants.PROP_TRACE_SIZE_MAX, String.valueOf(PreferenceHandler.getMaxFileSize()));
System.setProperty(TracingConstants.PROP_TRACE_FILE_MAX, String.valueOf(PreferenceHandler.getMaxFileCount()));
Map<String, String> prefs = PreferenceHandler.getPreferenceProperties();
DebugOptionsHandler.getDebugOptions().setOptions(prefs);
}
}
/** The shared instance */
private static TracingUIActivator plugin = null;
}
|