| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012, the Dart project authors. | 2 * Copyright (c) 2012, the Dart project authors. |
| 3 * | 3 * |
| 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except | 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
| 5 * in compliance with the License. You may obtain a copy of the License at | 5 * in compliance with the License. You may obtain a copy of the License at |
| 6 * | 6 * |
| 7 * http://www.eclipse.org/legal/epl-v10.html | 7 * http://www.eclipse.org/legal/epl-v10.html |
| 8 * | 8 * |
| 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License | 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
| 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express | 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
| 11 * or implied. See the License for the specific language governing permissions a
nd limitations under | 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
| 12 * the License. | 12 * the License. |
| 13 */ | 13 */ |
| 14 | 14 |
| 15 package com.google.dart.tools.debug.core.dartium; | 15 package com.google.dart.tools.debug.core.dartium; |
| 16 | 16 |
| 17 import com.google.dart.tools.core.utilities.resource.IFileUtilities; | 17 import com.google.dart.tools.core.utilities.resource.IFileUtilities; |
| 18 import com.google.dart.tools.debug.core.DartDebugCorePlugin; | 18 import com.google.dart.tools.debug.core.DartDebugCorePlugin; |
| 19 import com.google.dart.tools.debug.core.util.ResourceChangeManager; | 19 import com.google.dart.tools.debug.core.util.ResourceChangeManager; |
| 20 import com.google.dart.tools.debug.core.util.ResourceChangeParticipant; | 20 import com.google.dart.tools.debug.core.util.ResourceChangeParticipant; |
| 21 import com.google.dart.tools.debug.core.webkit.WebkitScript; | 21 import com.google.dart.tools.debug.core.webkit.WebkitScript; |
| 22 | 22 |
| 23 import org.eclipse.core.resources.IFile; | 23 import org.eclipse.core.resources.IFile; |
| 24 import org.eclipse.core.runtime.CoreException; | 24 import org.eclipse.core.runtime.CoreException; |
| 25 import org.eclipse.core.runtime.IProgressMonitor; |
| 26 import org.eclipse.core.runtime.IStatus; |
| 27 import org.eclipse.core.runtime.Status; |
| 28 import org.eclipse.core.runtime.jobs.Job; |
| 25 | 29 |
| 26 import java.io.IOException; | 30 import java.io.IOException; |
| 31 import java.util.Collection; |
| 27 | 32 |
| 28 /** | 33 /** |
| 29 * Manage known Dart files loaded in the target browser. Listen for resource cha
nge events (using | 34 * Manage known Dart files loaded in the target browser. Listen for resource cha
nge events (using |
| 30 * the ResourceChangeManager class). When a Dart file changes on disk that the b
rowser knows about, | 35 * the ResourceChangeManager class). When a Dart file changes on disk that the b
rowser knows about, |
| 31 * send the new contents to the browser using the Webkit inspector protocol. | 36 * send the new contents to the browser using the Webkit inspector protocol. |
| 32 */ | 37 */ |
| 33 public class DartCodeManager implements ResourceChangeParticipant { | 38 public class DartCodeManager implements ResourceChangeParticipant { |
| 39 |
| 40 private class UpdateDartFileJob extends Job { |
| 41 |
| 42 IFile file; |
| 43 |
| 44 public UpdateDartFileJob(IFile file) { |
| 45 super("Updating file"); |
| 46 this.file = file; |
| 47 } |
| 48 |
| 49 @Override |
| 50 protected IStatus run(IProgressMonitor monitor) { |
| 51 String fileUrl = target.getResourceResolver().getUrlForResource(file); |
| 52 |
| 53 if (fileUrl != null) { |
| 54 Collection<WebkitScript> scripts = target.getConnection().getDebugger().
getAllScripts(); |
| 55 |
| 56 for (WebkitScript script : scripts) { |
| 57 if (fileUrl.equals(script.getUrl())) { |
| 58 uploadNewSource(script.getScriptId(), file); |
| 59 } |
| 60 } |
| 61 } |
| 62 return Status.OK_STATUS; |
| 63 } |
| 64 |
| 65 } |
| 66 |
| 34 private DartiumDebugTarget target; | 67 private DartiumDebugTarget target; |
| 35 | 68 |
| 36 public DartCodeManager(DartiumDebugTarget target) { | 69 public DartCodeManager(DartiumDebugTarget target) { |
| 37 this.target = target; | 70 this.target = target; |
| 38 | 71 |
| 39 ResourceChangeManager.getManager().addChangeParticipant(this); | 72 ResourceChangeManager.getManager().addChangeParticipant(this); |
| 40 } | 73 } |
| 41 | 74 |
| 42 public void dispose() { | 75 public void dispose() { |
| 43 ResourceChangeManager.removeChangeParticipant(this); | 76 ResourceChangeManager.removeChangeParticipant(this); |
| 44 } | 77 } |
| 45 | 78 |
| 46 @Override | 79 @Override |
| 47 public void handleFileAdded(IFile file) { | 80 public void handleFileAdded(IFile file) { |
| 48 handleFileChanged(file); | 81 handleFileChanged(file); |
| 49 } | 82 } |
| 50 | 83 |
| 51 @Override | 84 @Override |
| 52 public void handleFileChanged(IFile file) { | 85 public void handleFileChanged(IFile file) { |
| 53 if (!target.supportsSetScriptSource()) { | 86 if (!target.supportsSetScriptSource()) { |
| 54 return; | 87 return; |
| 55 } | 88 } |
| 56 | 89 |
| 57 if ("dart".equals(file.getFileExtension())) { | 90 if ("dart".equals(file.getFileExtension())) { |
| 58 String fileUrl = target.getResourceResolver().getUrlForResource(file); | 91 UpdateDartFileJob job = new UpdateDartFileJob(file); |
| 59 | 92 job.schedule(); |
| 60 if (fileUrl != null) { | |
| 61 for (WebkitScript script : target.getConnection().getDebugger().getAllSc
ripts()) { | |
| 62 if (fileUrl.equals(script.getUrl())) { | |
| 63 uploadNewSource(script.getScriptId(), file); | |
| 64 } | |
| 65 } | |
| 66 } | |
| 67 } | 93 } |
| 68 } | 94 } |
| 69 | 95 |
| 70 @Override | 96 @Override |
| 71 public void handleFileRemoved(IFile file) { | 97 public void handleFileRemoved(IFile file) { |
| 72 | 98 |
| 73 } | 99 } |
| 74 | 100 |
| 75 private void uploadNewSource(String scriptId, IFile file) { | 101 private void uploadNewSource(String scriptId, IFile file) { |
| 76 try { | 102 try { |
| 77 target.getConnection().getDebugger().setScriptSource( | 103 target.getConnection().getDebugger().setScriptSource( |
| 78 scriptId, | 104 scriptId, |
| 79 IFileUtilities.getContents(file)); | 105 IFileUtilities.getContents(file)); |
| 80 } catch (IOException e) { | 106 } catch (IOException e) { |
| 81 DartDebugCorePlugin.logError(e); | 107 DartDebugCorePlugin.logError(e); |
| 82 } catch (CoreException e) { | 108 } catch (CoreException e) { |
| 83 DartDebugCorePlugin.logError(e); | 109 DartDebugCorePlugin.logError(e); |
| 84 } | 110 } |
| 85 } | 111 } |
| 86 | 112 |
| 87 } | 113 } |
| OLD | NEW |