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