Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: editor/tools/plugins/com.google.dart.tools.update.core/src/com/google/dart/tools/update/core/internal/jobs/InstallUpdateAction.java

Issue 561293004: check vm and dartium before update (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: merge Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 package com.google.dart.tools.update.core.internal.jobs; 14 package com.google.dart.tools.update.core.internal.jobs;
15 15
16 import com.google.dart.engine.sdk.DirectoryBasedDartSdk;
16 import com.google.dart.tools.core.DartCore; 17 import com.google.dart.tools.core.DartCore;
17 import com.google.dart.tools.core.dart2js.ProcessRunner; 18 import com.google.dart.tools.core.dart2js.ProcessRunner;
18 import com.google.dart.tools.core.model.DartSdkManager; 19 import com.google.dart.tools.core.model.DartSdkManager;
19 import com.google.dart.tools.update.core.Revision; 20 import com.google.dart.tools.update.core.Revision;
20 import com.google.dart.tools.update.core.UpdateCore; 21 import com.google.dart.tools.update.core.UpdateCore;
21 import com.google.dart.tools.update.core.UpdateManager; 22 import com.google.dart.tools.update.core.UpdateManager;
22 import com.google.dart.tools.update.core.internal.UpdateUtils; 23 import com.google.dart.tools.update.core.internal.UpdateUtils;
23 24
24 import org.eclipse.core.runtime.AssertionFailedException; 25 import org.eclipse.core.runtime.AssertionFailedException;
25 import org.eclipse.core.runtime.CoreException; 26 import org.eclipse.core.runtime.CoreException;
(...skipping 19 matching lines...) Expand all
45 import java.io.IOException; 46 import java.io.IOException;
46 import java.lang.reflect.InvocationTargetException; 47 import java.lang.reflect.InvocationTargetException;
47 import java.util.ArrayList; 48 import java.util.ArrayList;
48 import java.util.List; 49 import java.util.List;
49 50
50 /** 51 /**
51 * An action that installs an available Dart Editor update. 52 * An action that installs an available Dart Editor update.
52 */ 53 */
53 public class InstallUpdateAction extends Action { 54 public class InstallUpdateAction extends Action {
54 55
56 /**
57 * Internal representation of an executable file that needs to be renamed befo re update and
58 * cleaned up after update.
59 */
60 private static class Executable {
61 private final String name;
62 private final File executable;
63 private final File oldExecutable;
64
65 Executable(String name, File executable) {
66 this.name = name;
67 this.executable = executable;
68 this.oldExecutable = new File(executable.getAbsolutePath() + ".old");
69 }
70
71 boolean deleteOld() {
72 return !oldExecutable.exists() || oldExecutable.delete();
73 }
74
75 String getExistingProcessMessage() {
76 return "Update complete, but existing " + name + " process still running.\ n\n"
77 + oldExecutable.getAbsolutePath();
78 }
79
80 String getRenameFailedMessage() {
81 return "Could not update " + name + ". Please terminate any running\n" + n ame
82 + " processes, check the file permissions, and try again.\n\n"
83 + executable.getAbsolutePath() + "\n" + oldExecutable.getAbsolutePath( );
84 }
85
86 boolean rename() {
87 return deleteOld() && executable.renameTo(oldExecutable);
88 }
89
90 void restore() {
91 oldExecutable.renameTo(executable);
92 }
93 }
94
55 private static class RetryUpdateDialog extends MessageDialog { 95 private static class RetryUpdateDialog extends MessageDialog {
56 96
57 public RetryUpdateDialog(Shell parentShell) { 97 public RetryUpdateDialog(Shell parentShell) {
58 super( 98 super(
59 parentShell, 99 parentShell,
60 UpdateJobMessages.InstallUpdateAction_bad_zip_dialog_title, 100 UpdateJobMessages.InstallUpdateAction_bad_zip_dialog_title,
61 null, 101 null,
62 UpdateJobMessages.InstallUpdateAction_bad_zip_dialog_msg, 102 UpdateJobMessages.InstallUpdateAction_bad_zip_dialog_msg,
63 MessageDialog.QUESTION, 103 MessageDialog.QUESTION,
64 new String[] { 104 new String[] {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 //attempt to close dirty editors 179 //attempt to close dirty editors
140 if (!PlatformUI.getWorkbench().saveAllEditors(false)) { 180 if (!PlatformUI.getWorkbench().saveAllEditors(false)) {
141 MessageDialog.openError( 181 MessageDialog.openError(
142 getShell(), 182 getShell(),
143 UpdateJobMessages.InstallUpdateAction_errorTitle, 183 UpdateJobMessages.InstallUpdateAction_errorTitle,
144 UpdateJobMessages.InstallUpdateAction_error_in_save); 184 UpdateJobMessages.InstallUpdateAction_error_in_save);
145 return; 185 return;
146 } 186 }
147 } 187 }
148 188
189 DirectoryBasedDartSdk sdk = DartSdkManager.getManager().getSdk();
190 Executable[] executables = new Executable[] {
191 new Executable("Dart VM", sdk.getVmExecutable()),
192 new Executable("Dartium", sdk.getDartiumExecutable())};
193 int index = 0;
194 while (index < executables.length) {
195 if (!executables[index].rename()) {
196 Executable failedRename = executables[index];
197 --index;
198 while (index >= 0) {
199 executables[index].restore();
200 --index;
201 }
202 MessageDialog.openError(
203 getShell(),
204 UpdateJobMessages.InstallUpdateAction_errorTitle,
205 failedRename.getRenameFailedMessage());
206 return;
207 }
208 ++index;
209 }
210
149 try { 211 try {
150 if (applyUpdate()) { 212 if (applyUpdate()) {
213 for (Executable executable : executables) {
214 if (!executable.deleteOld()) {
215 MessageDialog.openError(
216 getShell(),
217 UpdateJobMessages.InstallUpdateAction_errorTitle,
218 executable.getExistingProcessMessage());
219 }
220 }
151 restart(); 221 restart();
152 } 222 }
153 } catch (Throwable th) { 223 } catch (Throwable th) {
154 UpdateCore.logError(th); 224 UpdateCore.logError(th);
155 MessageDialog.openError( 225 MessageDialog.openError(
156 getShell(), 226 getShell(),
157 UpdateJobMessages.InstallUpdateAction_errorTitle, 227 UpdateJobMessages.InstallUpdateAction_errorTitle,
158 UpdateJobMessages.InstallUpdateAction_errorMessage); 228 UpdateJobMessages.InstallUpdateAction_errorMessage);
159 } 229 }
160 } 230 }
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 private void terminateRunningDartLaunches() { 530 private void terminateRunningDartLaunches() {
461 ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); 531 ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
462 for (ILaunch launch : launchManager.getLaunches()) { 532 for (ILaunch launch : launchManager.getLaunches()) {
463 if (!launch.isTerminated() && isDartLaunch(launch) && launch.canTerminate( )) { 533 if (!launch.isTerminated() && isDartLaunch(launch) && launch.canTerminate( )) {
464 terminate(launch); 534 terminate(launch);
465 } 535 }
466 } 536 }
467 } 537 }
468 538
469 } 539 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698