|
1 /******************************************************************************* |
|
2 * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Symbian Foundation - initial contribution. |
|
11 * Contributors: |
|
12 * Description: |
|
13 * Overview: |
|
14 * Details: |
|
15 * Platforms/Drives/Compatibility: |
|
16 * Assumptions/Requirement/Pre-requisites: |
|
17 * Failures and causes: |
|
18 *******************************************************************************/ |
|
19 package org.symbian.tools.tmw.debug.internal.launch; |
|
20 |
|
21 import java.util.ArrayList; |
|
22 import java.util.Collection; |
|
23 |
|
24 import org.chromium.debug.core.model.BreakpointSynchronizer.Callback; |
|
25 import org.chromium.debug.core.model.BreakpointSynchronizer.Direction; |
|
26 import org.chromium.debug.core.model.ChromiumLineBreakpoint; |
|
27 import org.chromium.debug.core.model.DebugTargetImpl; |
|
28 import org.chromium.debug.core.model.VmResource; |
|
29 import org.chromium.debug.core.model.VmResourceId; |
|
30 import org.chromium.debug.core.model.WorkspaceBridge; |
|
31 import org.chromium.sdk.CallFrame; |
|
32 import org.chromium.sdk.JavascriptVm; |
|
33 import org.chromium.sdk.JavascriptVm.ScriptsCallback; |
|
34 import org.chromium.sdk.Script; |
|
35 import org.eclipse.core.resources.IFile; |
|
36 import org.eclipse.core.resources.IMarker; |
|
37 import org.eclipse.core.resources.IProject; |
|
38 import org.eclipse.core.resources.IResource; |
|
39 import org.eclipse.core.runtime.CoreException; |
|
40 import org.eclipse.debug.core.DebugPlugin; |
|
41 import org.eclipse.debug.core.ILaunch; |
|
42 import org.eclipse.debug.core.sourcelookup.ISourceContainer; |
|
43 import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector; |
|
44 import org.eclipse.debug.core.sourcelookup.containers.DirectorySourceContainer; |
|
45 import org.eclipse.debug.core.sourcelookup.containers.ProjectSourceContainer; |
|
46 import org.symbian.tools.tmw.debug.internal.Activator; |
|
47 import org.symbian.tools.tmw.debug.internal.model.ResourceManager; |
|
48 import org.symbian.tools.tmw.debug.internal.model.WorkspaceBreakpointHandler; |
|
49 |
|
50 public class ChromeToolsWorkspaceBridge implements WorkspaceBridge { |
|
51 public static final class Factory implements WorkspaceBridge.Factory { |
|
52 private final IProject project; |
|
53 |
|
54 public Factory(IProject workspaceProject) { |
|
55 this.project = workspaceProject; |
|
56 } |
|
57 |
|
58 public WorkspaceBridge attachedToVm(DebugTargetImpl debugTargetImpl, JavascriptVm javascriptVm) { |
|
59 return new ChromeToolsWorkspaceBridge(debugTargetImpl, javascriptVm, project); |
|
60 } |
|
61 |
|
62 public String getDebugModelIdentifier() { |
|
63 return DEBUG_MODEL_ID; |
|
64 } |
|
65 |
|
66 public JsLabelProvider getLabelProvider() { |
|
67 return new TmwLabelProvider(); |
|
68 } |
|
69 } |
|
70 |
|
71 public static final String DEBUG_MODEL_ID = "org.symbian.debug"; |
|
72 |
|
73 private final BreakpointHandler breakpointHandler; |
|
74 private final JavascriptVm javascriptVm; |
|
75 private final IProject project; |
|
76 private final ResourceManager resourceManager; |
|
77 |
|
78 public ChromeToolsWorkspaceBridge(DebugTargetImpl debugTargetImpl, JavascriptVm vm, IProject workspaceProject) { |
|
79 this.javascriptVm = vm; |
|
80 this.project = workspaceProject; |
|
81 this.resourceManager = new ResourceManager(); |
|
82 this.sourceLocator = new WebApplicationSourceLocator(resourceManager); |
|
83 breakpointHandler = new WorkspaceBreakpointHandler(debugTargetImpl); |
|
84 ILaunch launch = debugTargetImpl.getLaunch(); |
|
85 try { |
|
86 sourceLocator.initializeDefaults(launch.getLaunchConfiguration()); |
|
87 sourceLocator.setSourceContainers(new ISourceContainer[] { |
|
88 new ProjectSourceContainer(workspaceProject, false), |
|
89 new DirectorySourceContainer(Activator.getDefault().getStateLocation(), true) }); |
|
90 } catch (CoreException e) { |
|
91 throw new RuntimeException(e); |
|
92 } |
|
93 launch.setSourceLocator(sourceLocator); |
|
94 } |
|
95 |
|
96 public void beforeDetach() { |
|
97 // Do nothing |
|
98 } |
|
99 |
|
100 public BreakpointHandler getBreakpointHandler() { |
|
101 return breakpointHandler; |
|
102 } |
|
103 |
|
104 public void handleVmResetEvent() { |
|
105 resourceManager.clear(); |
|
106 } |
|
107 |
|
108 public void launchRemoved() { |
|
109 // Do nothing |
|
110 } |
|
111 |
|
112 public void reloadScriptsAtStart() { |
|
113 javascriptVm.getScripts(new ScriptsCallback() { |
|
114 public void failure(String errorMessage) { |
|
115 Activator.log(errorMessage); |
|
116 } |
|
117 |
|
118 public void success(Collection<Script> scripts) { |
|
119 if (!javascriptVm.isAttached()) { |
|
120 return; |
|
121 } |
|
122 for (Script script : scripts) { |
|
123 resourceManager.addScript(script); |
|
124 } |
|
125 |
|
126 IMarker[] markers; |
|
127 try { |
|
128 markers = project.findMarkers(ChromiumLineBreakpoint.BREAKPOINT_MARKER, true, |
|
129 IResource.DEPTH_INFINITE); |
|
130 Collection<ChromiumLineBreakpoint> breakpoints = new ArrayList<ChromiumLineBreakpoint>( |
|
131 markers.length); |
|
132 for (IMarker marker : markers) { |
|
133 // If it is not ChromiumLineBreakpoint - something's gone horribly wrong. Better get ClassCastException |
|
134 ChromiumLineBreakpoint breakpoint = (ChromiumLineBreakpoint) DebugPlugin.getDefault() |
|
135 .getBreakpointManager().getBreakpoint(marker); |
|
136 breakpointHandler.breakpointAdded(breakpoint); |
|
137 breakpoints.add(breakpoint); |
|
138 } |
|
139 } catch (CoreException e) { |
|
140 Activator.log(e); |
|
141 } |
|
142 |
|
143 } |
|
144 }); |
|
145 } |
|
146 |
|
147 public void scriptLoaded(Script newScript) { |
|
148 resourceManager.addScript(newScript); |
|
149 } |
|
150 |
|
151 public int getLineNumber(CallFrame stackFrame) { |
|
152 int offset = 0; |
|
153 Script script = stackFrame.getScript(); |
|
154 if (script != null) { |
|
155 offset = script.getStartLine(); |
|
156 } |
|
157 return offset + stackFrame.getLineNumber() + 1; |
|
158 } |
|
159 |
|
160 private final ISourceLookupDirector sourceLocator; |
|
161 |
|
162 public VmResource findVmResourceFromWorkspaceFile(IFile file) throws CoreException { |
|
163 return new VmResourceImpl(resourceManager.findVmResource(file), resourceManager.getScript(file), file.getName()); |
|
164 } |
|
165 |
|
166 private static final class VmResourceImpl implements VmResource { |
|
167 private final String name; |
|
168 private final Script script; |
|
169 private final VmResourceId id; |
|
170 |
|
171 public VmResourceImpl(VmResourceId resourceId, Script browserScript, String resourceName) { |
|
172 super(); |
|
173 this.id = resourceId; |
|
174 this.script = browserScript; |
|
175 this.name = resourceName; |
|
176 } |
|
177 |
|
178 public VmResourceId getId() { |
|
179 return id; |
|
180 } |
|
181 |
|
182 public Script getScript() { |
|
183 return script; |
|
184 } |
|
185 |
|
186 public String getFileName() { |
|
187 return name; |
|
188 } |
|
189 |
|
190 } |
|
191 |
|
192 public void reloadScript(Script script) { |
|
193 System.out.println(script); |
|
194 |
|
195 } |
|
196 |
|
197 public void synchronizeBreakpoints(Direction direction, Callback callback) { |
|
198 System.out.println(direction); |
|
199 |
|
200 } |
|
201 |
|
202 } |