78
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2007 Tom Schindl and others.
|
|
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
|
|
7 *
|
|
8 * Contributors:
|
|
9 * Tom Schindl - initial API and implementation
|
|
10 ******************************************************************************/
|
|
11
|
|
12 module org.eclipse.core.internal.databinding.Activator;
|
|
13
|
|
14 import java.lang.all;
|
|
15
|
|
16 import java.util.ArrayList;
|
|
17
|
|
18 import org.eclipse.core.databinding.util.ILogger;
|
|
19 import org.eclipse.core.databinding.util.Policy;
|
|
20 import org.eclipse.core.runtime.CoreException;
|
|
21 import org.eclipse.core.runtime.IStatus;
|
|
22 import org.eclipse.osgi.framework.log.FrameworkLog;
|
|
23 import org.eclipse.osgi.framework.log.FrameworkLogEntry;
|
|
24 import org.osgi.framework.BundleActivator;
|
|
25 import org.osgi.framework.BundleContext;
|
|
26 import org.osgi.util.tracker.ServiceTracker;
|
|
27
|
|
28 /**
|
|
29 * @since 3.3
|
|
30 *
|
|
31 */
|
|
32 public class Activator : BundleActivator {
|
|
33 /**
|
|
34 * The plug-in ID
|
|
35 */
|
|
36 public static final String PLUGIN_ID = "org.eclipse.core.databinding"; //$NON-NLS-1$
|
|
37
|
|
38 private /+volatile+/ static ServiceTracker _frameworkLogTracker;
|
|
39
|
|
40 /**
|
|
41 * The constructor
|
|
42 */
|
|
43 public this() {
|
|
44 }
|
|
45
|
|
46 public void start(BundleContext context) {
|
|
47 _frameworkLogTracker = new ServiceTracker(context, FrameworkLog.classinfo.getName(), null);
|
|
48 _frameworkLogTracker.open();
|
|
49
|
|
50 Policy.setLog(new class() ILogger {
|
|
51
|
|
52 public void log(IStatus status) {
|
|
53 ServiceTracker frameworkLogTracker = _frameworkLogTracker;
|
|
54 FrameworkLog log = frameworkLogTracker is null ? null : cast(FrameworkLog) frameworkLogTracker.getService();
|
|
55 if (log !is null) {
|
|
56 log.log(createLogEntry(status));
|
|
57 } else {
|
|
58 // fall back to System.err
|
|
59 System.err.println(status.getPlugin() + " - " + status.getCode() + " - " + status.getMessage()); //$NON-NLS-1$//$NON-NLS-2$
|
|
60 if( status.getException() !is null ) {
|
|
61 status.getException().printStackTrace(System.err);
|
|
62 }
|
|
63 }
|
|
64 }
|
|
65
|
|
66 });
|
|
67 }
|
|
68
|
|
69 // Code copied from PlatformLogWriter.getLog(). Why is logging an IStatus so
|
|
70 // hard?
|
|
71 FrameworkLogEntry createLogEntry(IStatus status) {
|
|
72 Throwable t = status.getException();
|
|
73 ArrayList childlist = new ArrayList();
|
|
74
|
|
75 int stackCode = null !is cast(CoreException )t ? 1 : 0;
|
|
76 // ensure a substatus inside a CoreException is properly logged
|
|
77 if (stackCode is 1) {
|
|
78 IStatus coreStatus = (cast(CoreException) t).getStatus();
|
|
79 if (coreStatus !is null) {
|
|
80 childlist.add(createLogEntry(coreStatus));
|
|
81 }
|
|
82 }
|
|
83
|
|
84 if (status.isMultiStatus()) {
|
|
85 IStatus[] children = status.getChildren();
|
|
86 for (int i = 0; i < children.length; i++) {
|
|
87 childlist.add(createLogEntry(children[i]));
|
|
88 }
|
|
89 }
|
|
90
|
|
91 FrameworkLogEntry[] children = cast(FrameworkLogEntry[]) (childlist.size() is 0 ? null : childlist.toArray(new FrameworkLogEntry[childlist.size()]));
|
|
92
|
|
93 return new FrameworkLogEntry(status.getPlugin(), status.getSeverity(), status.getCode(), status.getMessage(), stackCode, t, children);
|
|
94 }
|
|
95
|
|
96
|
|
97 public void stop(BundleContext context) {
|
|
98 if (_frameworkLogTracker !is null) {
|
|
99 _frameworkLogTracker.close();
|
|
100 _frameworkLogTracker = null;
|
|
101 }
|
|
102 }
|
|
103
|
|
104 }
|