Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Commit 33736f7

Browse files
authored
Merge pull request #184 from eharris369/44-improveInstallerProgressMonitors
Issue #44: Improve the progress monitors for Codewind installer operations
2 parents 137f2e3 + 9522dc2 commit 33736f7

File tree

4 files changed

+76
-34
lines changed

4 files changed

+76
-34
lines changed

dev/org.eclipse.codewind.core/src/org/eclipse/codewind/core/internal/ProcessHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static ProcessResult waitForProcess(final Process p, int pollingDelay, in
6464
StringBuilder inBuilder = new StringBuilder();
6565
StringBuilder errBuilder = new StringBuilder();
6666
int iter = timeout * 1000 / pollingDelay;
67-
int work = 20;
67+
int work = 50;
6868
SubMonitor mon = SubMonitor.convert(monitor, work);
6969
try {
7070
in = p.getInputStream();

dev/org.eclipse.codewind.ui/src/org/eclipse/codewind/ui/internal/actions/CodewindInstall.java

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public static void codewindInstallerDialog(IProject project) {
8585
public static void installerActiveDialog(InstallerStatus status) {
8686
if (status == null) {
8787
// This should not happen
88-
Logger.logError("The installerActiveDialog method is invoked but the installer status is null");
88+
Logger.logError("The installerActiveDialog method is invoked but the installer status is null"); //$NON-NLS-1$
8989
return;
9090
}
9191
String msg = null;
@@ -99,7 +99,7 @@ public static void installerActiveDialog(InstallerStatus status) {
9999
msg = Messages.InstallCodewindUninstallingMessage;
100100
break;
101101
default:
102-
Logger.logError("The installerActiveDialog method is invoked but the installer status is not recognized: " + status);
102+
Logger.logError("The installerActiveDialog method is invoked but the installer status is not recognized: " + status); //$NON-NLS-1$
103103
return;
104104
}
105105
MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.InstallCodewindDialogTitle, msg);
@@ -110,29 +110,41 @@ public static void installCodewind(Runnable prompt) {
110110
try {
111111
Job job = new Job(Messages.InstallCodewindJobLabel) {
112112
@Override
113-
protected IStatus run(IProgressMonitor monitor) {
113+
protected IStatus run(IProgressMonitor progressMon) {
114114

115115
try {
116+
SubMonitor mon = SubMonitor.convert(progressMon, 100);
117+
mon.setTaskName(Messages.InstallingCodewindTask);
118+
ProcessResult result = InstallUtil.installCodewind(mon.split(95));
116119

117-
ProcessResult result = InstallUtil.installCodewind(monitor);
120+
if (mon.isCanceled()) {
121+
removeCodewind();
122+
return Status.CANCEL_STATUS;
123+
}
118124

119-
if (monitor.isCanceled()) {
125+
if (result.getExitValue() != 0) {
126+
return getErrorStatus(result, Messages.CodewindInstallFail);
127+
}
128+
129+
mon.setTaskName(Messages.StartingCodewindJobLabel);
130+
result = InstallUtil.startCodewind(mon.split(5));
131+
132+
if (mon.isCanceled()) {
120133
removeCodewind();
121134
return Status.CANCEL_STATUS;
122135
}
123136

124137
if (result.getExitValue() != 0) {
125-
return getErrorStatus(result, "There was a problem trying to install Codewind: ");
138+
return getErrorStatus(result, Messages.CodewindStartFail);
126139
}
127140

128-
if (result.getExitValue() == 0) {
129-
startCodewind(prompt);
141+
if (prompt != null) {
142+
Display.getDefault().asyncExec(prompt);
130143
}
131-
132144
} catch (IOException e) {
133-
return getErrorStatus("An error occurred trying to install Codewind.", e);
145+
return getErrorStatus(Messages.CodewindInstallError, e);
134146
} catch (TimeoutException e) {
135-
return getErrorStatus("Codewind did not install in the expected time.", e);
147+
return getErrorStatus(Messages.CodewindInstallTimeout, e);
136148
}
137149

138150
ViewHelper.refreshCodewindExplorerView(null);
@@ -163,17 +175,17 @@ protected IStatus run(IProgressMonitor monitor) {
163175
}
164176

165177
if (result.getExitValue() != 0) {
166-
return getErrorStatus(result, "There was a problem trying to start Codewind: ");
178+
return getErrorStatus(result, Messages.CodewindStartFail);
167179
}
168180

169181
if (prompt != null) {
170182
Display.getDefault().asyncExec(prompt);
171183
}
172184

173185
} catch (IOException e) {
174-
return getErrorStatus("An error occurred trying to start Codewind.", e);
186+
return getErrorStatus(Messages.CodewindStartError, e);
175187
} catch (TimeoutException e) {
176-
return getErrorStatus("Codewind did not start in the expected time.", e);
188+
return getErrorStatus(Messages.CodewindStartTimeout, e);
177189
}
178190

179191
ViewHelper.refreshCodewindExplorerView(null);
@@ -209,13 +221,13 @@ protected IStatus run(IProgressMonitor monitor) {
209221
}
210222

211223
if (result.getExitValue() != 0) {
212-
return getErrorStatus(result, "There was a problem trying to stop Codewind: ");
224+
return getErrorStatus(result, Messages.CodewindStopFail);
213225
}
214226

215227
} catch (IOException e) {
216-
return getErrorStatus("An error occurred trying to stop Codewind.", e);
228+
return getErrorStatus(Messages.CodewindStopError, e);
217229
} catch (TimeoutException e) {
218-
return getErrorStatus("Codewind did not stop in the expected time.", e);
230+
return getErrorStatus(Messages.CodewindStopTimeout, e);
219231
}
220232

221233
ViewHelper.refreshCodewindExplorerView(null);
@@ -257,7 +269,7 @@ public void run() {
257269
Wizard wizard = new BindProjectWizard(connection, project);
258270
WizardLauncher.launchWizardWithoutSelection(wizard);
259271
} else {
260-
Logger.logError("In BindProjectAction run method and Codewind is not installed or has unknown status.");
272+
Logger.logError("Codewind not installed or has unknown status when trying to bind project: " + project.getName()); //$NON-NLS-1$
261273
return;
262274
}
263275
}
@@ -270,44 +282,46 @@ public static void removeCodewind() {
270282
try {
271283
Job job = new Job(Messages.RemovingCodewindJobLabel) {
272284
@Override
273-
protected IStatus run(IProgressMonitor mon) {
274-
SubMonitor monitor = SubMonitor.convert(mon, 100);
285+
protected IStatus run(IProgressMonitor progressMon) {
286+
SubMonitor mon = SubMonitor.convert(progressMon, 100);
275287
try {
276288
InstallStatus status = InstallUtil.getInstallStatus();
277289
if (status == InstallStatus.RUNNING) {
278290
// Stop Codewind before uninstalling
279291
// All containers must be stopped or uninstall won't work
280-
ProcessResult result = InstallUtil.stopCodewind(true, monitor.split(20));
292+
mon.setTaskName(Messages.StoppingCodewindJobLabel);
293+
ProcessResult result = InstallUtil.stopCodewind(true, mon.split(80));
281294

282-
if (monitor.isCanceled()) {
295+
if (mon.isCanceled()) {
283296
return Status.CANCEL_STATUS;
284297
}
285298

286299
if (result.getExitValue() != 0) {
287-
return getErrorStatus(result, "There was a problem trying to stop Codewind: ");
300+
return getErrorStatus(result, Messages.CodewindStopFail);
288301
}
289302
}
290303

291-
if (monitor.isCanceled()) {
304+
if (mon.isCanceled()) {
292305
return Status.CANCEL_STATUS;
293306
}
294307

295-
monitor.setWorkRemaining(80);
296-
ProcessResult result = InstallUtil.removeCodewind(monitor);
308+
mon.setTaskName(Messages.UninstallingCodewindTask);
309+
mon.setWorkRemaining(20);
310+
ProcessResult result = InstallUtil.removeCodewind(mon.split(20));
297311

298-
if (monitor.isCanceled()) {
312+
if (mon.isCanceled()) {
299313
return Status.CANCEL_STATUS;
300314
}
301315

302316
if (result.getExitValue() != 0) {
303-
return getErrorStatus(result, "There was a problem trying to remove Codewind: ");
317+
return getErrorStatus(result, Messages.CodewindUninstallFail);
304318
}
305319

306320

307321
} catch (IOException e) {
308-
return getErrorStatus("An error occurred trying to remove Codewind.", e);
322+
return getErrorStatus(Messages.CodewindUninstallError, e);
309323
} catch (TimeoutException e) {
310-
return getErrorStatus("Codewind did not remove in the expected time.", e);
324+
return getErrorStatus(Messages.CodewindUninstallTimeout, e);
311325
}
312326

313327
ViewHelper.refreshCodewindExplorerView(null);
@@ -323,12 +337,12 @@ protected IStatus run(IProgressMonitor mon) {
323337
}
324338

325339
private static IStatus getErrorStatus(ProcessResult result, String msg) {
326-
Logger.logError("Installer failed with return code: " + result.getExitValue() + ", output: " + result.getOutput() + ", error: " + result.getError());
340+
Logger.logError("Installer failed with return code: " + result.getExitValue() + ", output: " + result.getOutput() + ", error: " + result.getError()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
327341
String errorText = result.getError() != null && !result.getError().isEmpty() ? result.getError() : result.getOutput();
328342
if (errorText == null || errorText.trim().isEmpty()) {
329343
errorText = NLS.bind(Messages.InstallCodewindFailNoMessage, result.getExitValue());
330344
}
331-
return getErrorStatus(msg + errorText, null);
345+
return getErrorStatus(NLS.bind(msg, errorText), null);
332346
}
333347

334348
private static IStatus getErrorStatus(String msg, Throwable t) {

dev/org.eclipse.codewind.ui/src/org/eclipse/codewind/ui/internal/messages/Messages.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,27 @@ public class Messages extends NLS {
103103
public static String StartingCodewindJobLabel;
104104
public static String StoppingCodewindJobLabel;
105105
public static String RemovingCodewindJobLabel;
106+
public static String InstallingCodewindTask;
107+
public static String UninstallingCodewindTask;
106108
public static String InstallCodewindDialogTitle;
107109
public static String InstallCodewindDialogMessage;
108110
public static String InstallCodewindNewProjectMessage;
109111
public static String InstallCodewindAddProjectMessage;
110112
public static String InstallCodewindInstallingMessage;
111113
public static String InstallCodewindUninstallingMessage;
112114
public static String InstallCodewindFailNoMessage;
115+
public static String CodewindStartFail;
116+
public static String CodewindStopFail;
117+
public static String CodewindInstallFail;
118+
public static String CodewindUninstallFail;
119+
public static String CodewindStartError;
120+
public static String CodewindStopError;
121+
public static String CodewindInstallError;
122+
public static String CodewindUninstallError;
123+
public static String CodewindStartTimeout;
124+
public static String CodewindStopTimeout;
125+
public static String CodewindInstallTimeout;
126+
public static String CodewindUninstallTimeout;
113127

114128
public static String BindProjectErrorTitle;
115129
public static String BindProjectConnectionError;

dev/org.eclipse.codewind.ui/src/org/eclipse/codewind/ui/internal/messages/messages.properties

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,28 @@ BindProjectWizardError=An error occurred trying to add the {0} project to Codewi
104104
InstallCodewindJobLabel=Installing Codewind
105105
StartingCodewindJobLabel=Starting Codewind
106106
StoppingCodewindJobLabel=Stopping Codewind
107-
RemovingCodewindJobLabel=Removing Codewind docker images
107+
RemovingCodewindJobLabel=Uninstalling Codewind
108+
InstallingCodewindTask=Downloading and Installing Codewind
109+
UninstallingCodewindTask=Removing Codewind
108110
InstallCodewindDialogTitle=Codewind Installer
109111
InstallCodewindDialogMessage=Codewind requires the installation of Docker containers to run, which might take a few minutes to download. Do you want to complete the installation now?
110112
InstallCodewindNewProjectMessage=Codewind installation is complete, do you want to create a new Codewind project?
111113
InstallCodewindAddProjectMessage=Codewind installation is complete, do you want to add the {0} project to Codewind?
112114
InstallCodewindInstallingMessage=Please wait for Codewind to be fully installed and running before trying to create or add projects.
113115
InstallCodewindUninstallingMessage=Projects cannot be created or added while Codewind is stopping or uninstalling.
114116
InstallCodewindFailNoMessage=The installer failed with error code {0}. Check logs for more information.
117+
CodewindStartFail=There was a problem trying to start Codewind: {0}
118+
CodewindStopFail=There was a problem trying to stop Codewind: {0}
119+
CodewindInstallFail=There was a problem trying to install Codewind: {0}
120+
CodewindUninstallFail=There was a problem trying to uninstall Codewind: {0}
121+
CodewindStartError=An error occurred trying to start Codewind.
122+
CodewindStopError=An error occurred trying to stop Codewind.
123+
CodewindInstallError=An error occurred trying to install Codewind.
124+
CodewindUninstallError=An error occurred trying to uninstall Codewind.
125+
CodewindStartTimeout=Codewind did not start in the expected time.
126+
CodewindStopTimeout=Codewind did not stop in the expected time.
127+
CodewindInstallTimeout=Codewind did not install in the expected time.
128+
CodewindUninstallTimeout=Codewind did not uninstall in the expected time.
115129

116130
SelectProjectTypePageName=Select Project Type
117131
SelectProjectTypePageTitle=Project Type and Language Selection

0 commit comments

Comments
 (0)