mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 06:02:11 +02:00
Bug 574519: Always collect WSL entries in a Job
Change-Id: I35abec7ca075bf525e972e4cbc03af4361d1d490
This commit is contained in:
parent
da616bcc43
commit
1071e55fb1
2 changed files with 93 additions and 53 deletions
|
@ -2,7 +2,7 @@ Manifest-Version: 1.0
|
|||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: %pluginName
|
||||
Bundle-SymbolicName: org.eclipse.tm.terminal.view.ui;singleton:=true
|
||||
Bundle-Version: 4.9.0.qualifier
|
||||
Bundle-Version: 4.9.1.qualifier
|
||||
Bundle-Activator: org.eclipse.tm.terminal.view.ui.activator.UIPlugin
|
||||
Bundle-Vendor: %providerName
|
||||
Require-Bundle: org.eclipse.core.expressions;bundle-version="3.4.400",
|
||||
|
|
|
@ -24,16 +24,19 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.tm.terminal.view.ui.interfaces.IExternalExecutablesProperties;
|
||||
import org.eclipse.tm.terminal.view.ui.local.showin.IDetectExternalExecutable;
|
||||
|
||||
public class DetectWSL implements IDetectExternalExecutable {
|
||||
|
||||
/**
|
||||
* Don't access directly, use {@link #getEntries()}
|
||||
*/
|
||||
List<Map<String, String>> result = null;
|
||||
private List<Map<String, String>> result = null;
|
||||
private WslDetectJob detectJob = null;
|
||||
|
||||
@Override
|
||||
public boolean hasEntries() {
|
||||
|
@ -55,16 +58,51 @@ public class DetectWSL implements IDetectExternalExecutable {
|
|||
}
|
||||
|
||||
private synchronized List<Map<String, String>> getEntries() {
|
||||
// getEntries can be called in many contexts, even from within
|
||||
// menu creation (see Bug 574519). Therefore we spawn a job to
|
||||
// get the real entries, which means until the job is done, this
|
||||
// method will return no entries.
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
if (detectJob == null) {
|
||||
detectJob = new WslDetectJob();
|
||||
detectJob.schedule();
|
||||
}
|
||||
try {
|
||||
if (detectJob.join(10, null)) {
|
||||
result = detectJob.result;
|
||||
detectJob = null;
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
} catch (OperationCanceledException | InterruptedException e) {
|
||||
result = Collections.emptyList();
|
||||
detectJob = null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static class WslDetectJob extends Job {
|
||||
private List<Map<String, String>> result = null;
|
||||
|
||||
public WslDetectJob() {
|
||||
super("Detect WSL Instances"); //$NON-NLS-1$
|
||||
setSystem(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
if (result == null) {
|
||||
result = Collections.emptyList();
|
||||
if (Platform.OS_WIN32.equals(Platform.getOS())) {
|
||||
String windir = System.getenv("windir"); //$NON-NLS-1$
|
||||
if (windir == null) {
|
||||
return result;
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
String wsl = windir + "\\System32\\wsl.exe"; //$NON-NLS-1$
|
||||
if (!Files.isExecutable(Paths.get(wsl))) {
|
||||
return result;
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
|
||||
ProcessBuilder pb = new ProcessBuilder(wsl, "--list", "--quiet"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
@ -73,7 +111,7 @@ public class DetectWSL implements IDetectExternalExecutable {
|
|||
try (InputStream is = process.getErrorStream()) {
|
||||
// drain the error stream
|
||||
if (is.readAllBytes().length != 0) {
|
||||
return result;
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,7 +143,9 @@ public class DetectWSL implements IDetectExternalExecutable {
|
|||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue