author | Eugene Ostroukhov <eugeneo@symbian.org> |
Mon, 07 Jun 2010 16:51:19 -0700 | |
changeset 355 | 8726e95bcbba |
parent 52 | f577ea64429e |
permissions | -rw-r--r-- |
2 | 1 |
// Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 |
// Use of this source code is governed by a BSD-style license that can be |
|
3 |
// found in the LICENSE file. |
|
4 |
||
5 |
package org.chromium.debug.core; |
|
6 |
||
7 |
import java.text.MessageFormat; |
|
8 |
||
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
52
diff
changeset
|
9 |
import org.chromium.debug.core.model.BreakpointMap; |
2 | 10 |
import org.chromium.debug.core.model.ChromiumBreakpointWBAFactory; |
11 |
import org.chromium.debug.core.model.ChromiumLineBreakpoint; |
|
12 |
import org.eclipse.core.runtime.CoreException; |
|
13 |
import org.eclipse.core.runtime.IAdapterManager; |
|
14 |
import org.eclipse.core.runtime.IStatus; |
|
15 |
import org.eclipse.core.runtime.Platform; |
|
16 |
import org.eclipse.core.runtime.Plugin; |
|
17 |
import org.eclipse.core.runtime.Status; |
|
18 |
import org.osgi.framework.BundleContext; |
|
19 |
||
20 |
/** |
|
21 |
* The activator class that controls the plug-in life cycle. |
|
22 |
*/ |
|
23 |
public class ChromiumDebugPlugin extends Plugin { |
|
24 |
||
25 |
/** The plug-in ID. */ |
|
26 |
public static final String PLUGIN_ID = "org.chromium.debug.core"; //$NON-NLS-1$ |
|
27 |
||
28 |
/** The JavaScript line breakpoint marker. */ |
|
29 |
public static final String BP_MARKER = PLUGIN_ID + ".LineBP"; //$NON-NLS-1$ |
|
30 |
||
31 |
/** The shared instance. */ |
|
32 |
private static ChromiumDebugPlugin plugin; |
|
33 |
||
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
52
diff
changeset
|
34 |
private final BreakpointMap breakpointMap = new BreakpointMap(); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
52
diff
changeset
|
35 |
|
2 | 36 |
private ChromiumBreakpointWBAFactory breakpointWorkbenchAdapterFactory; |
37 |
||
38 |
public ChromiumDebugPlugin() { |
|
39 |
} |
|
40 |
||
41 |
@Override |
|
42 |
public void start(BundleContext context) throws Exception { |
|
43 |
super.start(context); |
|
44 |
IAdapterManager manager = Platform.getAdapterManager(); |
|
45 |
breakpointWorkbenchAdapterFactory = new ChromiumBreakpointWBAFactory(); |
|
46 |
manager.registerAdapters(breakpointWorkbenchAdapterFactory, ChromiumLineBreakpoint.class); |
|
47 |
plugin = this; |
|
48 |
} |
|
49 |
||
50 |
@Override |
|
51 |
public void stop(BundleContext context) throws Exception { |
|
52 |
plugin = null; |
|
53 |
IAdapterManager manager = Platform.getAdapterManager(); |
|
54 |
manager.unregisterAdapters(breakpointWorkbenchAdapterFactory); |
|
55 |
super.stop(context); |
|
56 |
} |
|
57 |
||
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
52
diff
changeset
|
58 |
public BreakpointMap getBreakpointMap() { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
52
diff
changeset
|
59 |
return breakpointMap; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
52
diff
changeset
|
60 |
} |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
52
diff
changeset
|
61 |
|
2 | 62 |
/** |
63 |
* @return the shared instance |
|
64 |
*/ |
|
65 |
public static ChromiumDebugPlugin getDefault() { |
|
66 |
return plugin; |
|
67 |
} |
|
68 |
||
69 |
public static boolean isDebug() { |
|
70 |
ChromiumDebugPlugin thePlugin = getDefault(); |
|
71 |
return thePlugin != null && thePlugin.isDebugging(); |
|
72 |
} |
|
73 |
||
74 |
public static boolean isTransportDebug() { |
|
75 |
return isDebug() && |
|
76 |
Boolean.valueOf(Platform.getDebugOption(PLUGIN_ID + "/debug/transport")); //$NON-NLS-1$ |
|
77 |
} |
|
78 |
||
79 |
public static boolean isV8DebuggerToolDebug() { |
|
80 |
return isDebug() && |
|
81 |
Boolean.valueOf(Platform.getDebugOption(PLUGIN_ID + "/debug/v8DebuggerTool")); //$NON-NLS-1$ |
|
82 |
} |
|
83 |
||
84 |
public static void log(IStatus status) { |
|
85 |
ChromiumDebugPlugin plugin = getDefault(); |
|
86 |
if (plugin != null) { |
|
87 |
plugin.getLog().log(status); |
|
88 |
} else { |
|
89 |
System.err.println(status.getPlugin() + ": " + status.getMessage()); //$NON-NLS-1$ |
|
90 |
} |
|
91 |
} |
|
92 |
||
93 |
public static void log(Throwable e) { |
|
94 |
if (e instanceof CoreException) { |
|
95 |
log(new Status(IStatus.ERROR, PLUGIN_ID, |
|
96 |
((CoreException) e).getStatus().getSeverity(), e.getMessage(), e.getCause())); |
|
97 |
} else { |
|
98 |
log(new Status(IStatus.ERROR, PLUGIN_ID, Messages.ChromiumDebugPlugin_InternalError, e)); |
|
99 |
} |
|
100 |
} |
|
101 |
||
102 |
public static void logError(String message, Object... arguments) { |
|
103 |
log(new Status(Status.ERROR, PLUGIN_ID, getPossiblyFormattedString(message, arguments))); |
|
104 |
} |
|
105 |
||
106 |
public static void logWarning(String message, Object... arguments) { |
|
107 |
log(new Status(Status.WARNING, PLUGIN_ID, getPossiblyFormattedString(message, arguments))); |
|
108 |
} |
|
109 |
||
110 |
private static String getPossiblyFormattedString(String message, Object... arguments) { |
|
111 |
return arguments.length > 0 |
|
112 |
? MessageFormat.format(message, arguments) |
|
113 |
: message; |
|
114 |
} |
|
115 |
||
116 |
} |