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 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 /** | 51 /** |
52 * An action that installs an available Dart Editor update. | 52 * An action that installs an available Dart Editor update. |
53 */ | 53 */ |
54 public class InstallUpdateAction extends Action { | 54 public class InstallUpdateAction extends Action { |
55 | 55 |
56 /** | 56 /** |
57 * Internal representation of an executable file that needs to be renamed befo
re update and | 57 * Internal representation of an executable file that needs to be renamed befo
re update and |
58 * cleaned up after update. | 58 * cleaned up after update. |
59 */ | 59 */ |
60 private static class Executable { | 60 private static class Executable { |
| 61 static void add(List<Executable> list, String name, File executable) { |
| 62 if (executable != null) { |
| 63 list.add(new Executable(name, executable)); |
| 64 } |
| 65 } |
| 66 |
61 private final String name; | 67 private final String name; |
62 private final File executable; | 68 private final File executable; |
63 private final File oldExecutable; | 69 private final File oldExecutable; |
64 | 70 |
65 Executable(String name, File executable) { | 71 Executable(String name, File executable) { |
66 this.name = name; | 72 this.name = name; |
67 this.executable = executable; | 73 this.executable = executable; |
68 this.oldExecutable = new File(executable.getAbsolutePath() + ".old"); | 74 this.oldExecutable = new File(executable.getAbsolutePath() + ".old"); |
69 } | 75 } |
70 | 76 |
71 boolean deleteOld() { | 77 boolean deleteOld() { |
72 return !oldExecutable.exists() || oldExecutable.delete(); | 78 return !oldExecutable.exists() || oldExecutable.delete(); |
73 } | 79 } |
74 | 80 |
75 String getExistingProcessMessage() { | 81 String getExistingProcessMessage() { |
76 return "Update complete, but existing " + name + " process still running.\
n\n" | 82 return "Update complete, but existing " + name + " process still running.\
n\n" |
77 + oldExecutable.getAbsolutePath(); | 83 + oldExecutable.getAbsolutePath(); |
78 } | 84 } |
79 | 85 |
80 String getRenameFailedMessage() { | 86 String getRenameFailedMessage() { |
81 return "Could not update " + name + ". Please terminate any running\n" + n
ame | 87 return "Could not update " + name + ". Please terminate any running\n" + n
ame |
82 + " processes, check the file permissions, and try again.\n\n" | 88 + " processes, check the file permissions, and try again.\n\n" |
83 + executable.getAbsolutePath() + "\n" + oldExecutable.getAbsolutePath(
); | 89 + executable.getAbsolutePath() + "\n" + oldExecutable.getAbsolutePath(
); |
84 } | 90 } |
85 | 91 |
86 boolean rename() { | 92 boolean rename() { |
87 return deleteOld() && executable.renameTo(oldExecutable); | 93 return !executable.exists() || (deleteOld() && executable.renameTo(oldExec
utable)); |
88 } | 94 } |
89 | 95 |
90 void restore() { | 96 void restore() { |
91 oldExecutable.renameTo(executable); | 97 oldExecutable.renameTo(executable); |
92 } | 98 } |
93 } | 99 } |
94 | 100 |
95 private static class RetryUpdateDialog extends MessageDialog { | 101 private static class RetryUpdateDialog extends MessageDialog { |
96 | 102 |
97 public RetryUpdateDialog(Shell parentShell) { | 103 public RetryUpdateDialog(Shell parentShell) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 if (!PlatformUI.getWorkbench().saveAllEditors(false)) { | 186 if (!PlatformUI.getWorkbench().saveAllEditors(false)) { |
181 MessageDialog.openError( | 187 MessageDialog.openError( |
182 getShell(), | 188 getShell(), |
183 UpdateJobMessages.InstallUpdateAction_errorTitle, | 189 UpdateJobMessages.InstallUpdateAction_errorTitle, |
184 UpdateJobMessages.InstallUpdateAction_error_in_save); | 190 UpdateJobMessages.InstallUpdateAction_error_in_save); |
185 return; | 191 return; |
186 } | 192 } |
187 } | 193 } |
188 | 194 |
189 DirectoryBasedDartSdk sdk = DartSdkManager.getManager().getSdk(); | 195 DirectoryBasedDartSdk sdk = DartSdkManager.getManager().getSdk(); |
190 Executable[] executables = new Executable[] { | 196 List<Executable> executables = new ArrayList<Executable>(); |
191 new Executable("Dart VM", sdk.getVmExecutable()), | 197 Executable.add(executables, "Dart VM", sdk.getVmExecutable()); |
192 new Executable("Dartium", sdk.getDartiumExecutable())}; | 198 Executable.add(executables, "Dartium", sdk.getDartiumExecutable()); |
193 int index = 0; | 199 int index = 0; |
194 while (index < executables.length) { | 200 while (index < executables.size()) { |
195 if (!executables[index].rename()) { | 201 if (!executables.get(index).rename()) { |
196 Executable failedRename = executables[index]; | 202 Executable failedRename = executables.get(index); |
197 --index; | 203 --index; |
198 while (index >= 0) { | 204 while (index >= 0) { |
199 executables[index].restore(); | 205 executables.get(index).restore(); |
200 --index; | 206 --index; |
201 } | 207 } |
202 MessageDialog.openError( | 208 MessageDialog.openError( |
203 getShell(), | 209 getShell(), |
204 UpdateJobMessages.InstallUpdateAction_errorTitle, | 210 UpdateJobMessages.InstallUpdateAction_errorTitle, |
205 failedRename.getRenameFailedMessage()); | 211 failedRename.getRenameFailedMessage()); |
206 return; | 212 return; |
207 } | 213 } |
208 ++index; | 214 ++index; |
209 } | 215 } |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 private void terminateRunningDartLaunches() { | 536 private void terminateRunningDartLaunches() { |
531 ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); | 537 ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); |
532 for (ILaunch launch : launchManager.getLaunches()) { | 538 for (ILaunch launch : launchManager.getLaunches()) { |
533 if (!launch.isTerminated() && isDartLaunch(launch) && launch.canTerminate(
)) { | 539 if (!launch.isTerminated() && isDartLaunch(launch) && launch.canTerminate(
)) { |
534 terminate(launch); | 540 terminate(launch); |
535 } | 541 } |
536 } | 542 } |
537 } | 543 } |
538 | 544 |
539 } | 545 } |
OLD | NEW |