-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #58: Progress report for Installing
- Add a progress dialog to the installation process - Use the output of the toolchain downloading commands to give the user more info - Fix typo in messages - Abstracted running commands to a new Job class Signed-off-by: Lucas Bullen <[email protected]>
- Loading branch information
Lucas Bullen
committed
Jun 1, 2018
1 parent
8e247ac
commit f2af9a5
Showing
5 changed files
with
177 additions
and
95 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
org.eclipse.corrosion/src/org/eclipse/corrosion/CommandJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/********************************************************************* | ||
* Copyright (c) 2018 Red Hat Inc. and others. | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Lucas Bullen (Red Hat Inc.) - Initial implementation | ||
*******************************************************************************/ | ||
package org.eclipse.corrosion; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import org.eclipse.core.runtime.IProgressMonitor; | ||
import org.eclipse.core.runtime.IStatus; | ||
import org.eclipse.core.runtime.Status; | ||
import org.eclipse.core.runtime.SubMonitor; | ||
import org.eclipse.core.runtime.jobs.Job; | ||
|
||
public class CommandJob extends Job { | ||
private Process process; | ||
private String[] command; | ||
private String progressMessage; | ||
private String errorTitle; | ||
private String errorMessage; | ||
private int expectedWork; | ||
|
||
public CommandJob(String[] command, String progressMessage, String errorTitle, String errorMessage, | ||
int expectedWork) { | ||
super(progressMessage); | ||
this.command = command; | ||
this.progressMessage = progressMessage; | ||
this.errorTitle = errorTitle; | ||
this.errorMessage = errorMessage; | ||
this.expectedWork = expectedWork; | ||
} | ||
|
||
@Override | ||
protected IStatus run(IProgressMonitor monitor) { | ||
SubMonitor subMonitor = SubMonitor.convert(monitor, expectedWork); | ||
try { | ||
subMonitor.beginTask(progressMessage, expectedWork); | ||
process = new ProcessBuilder(command).start(); | ||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getErrorStream())); | ||
CompletableFuture.runAsync(() -> { | ||
reader.lines().forEachOrdered(line -> { | ||
subMonitor.subTask(line); | ||
if (expectedWork > 0) { | ||
subMonitor.worked(1); | ||
} | ||
}); | ||
}); | ||
if (process.waitFor() != 0) { | ||
if (!subMonitor.isCanceled()) { | ||
CorrosionPlugin.showError(errorTitle, errorMessage); | ||
} | ||
return Status.CANCEL_STATUS; | ||
} | ||
return Status.OK_STATUS; | ||
} catch (IOException | InterruptedException e) { | ||
CorrosionPlugin.showError(errorTitle, errorMessage, e); | ||
return Status.CANCEL_STATUS; | ||
} | ||
} | ||
|
||
@Override | ||
protected void canceling() { | ||
if (process != null) { | ||
process.destroyForcibly(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters