From eb7aa70a9f1a1289c13dac024b77dafa937e29b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torbj=C3=B6rn=20Svensson?= Date: Sun, 15 Aug 2021 14:52:10 +0200 Subject: [PATCH] Only spawn WSL detct job on Windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is no need to spawn the WSL detect job for other platforms than Windows. Contributed by STMicroelectronics Change-Id: I85256a9f6a4f5e9e9276458ba67e2f6adf02afa7 Signed-off-by: Torbjörn Svensson --- .../ui/local/showin/detectors/DetectWSL.java | 90 ++++++++++--------- 1 file changed, 47 insertions(+), 43 deletions(-) diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/local/showin/detectors/DetectWSL.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/local/showin/detectors/DetectWSL.java index dd315ea10f0..0f1300b1c95 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/local/showin/detectors/DetectWSL.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/local/showin/detectors/DetectWSL.java @@ -38,6 +38,12 @@ public class DetectWSL implements IDetectExternalExecutable { private List> result = null; private WslDetectJob detectJob = null; + public DetectWSL() { + if (!Platform.OS_WIN32.equals(Platform.getOS())) { + result = Collections.emptyList(); + } + } + @Override public boolean hasEntries() { return !getEntries().isEmpty(); @@ -95,52 +101,50 @@ public class DetectWSL implements IDetectExternalExecutable { 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 Status.OK_STATUS; - } - String wsl = windir + "\\System32\\wsl.exe"; //$NON-NLS-1$ - if (!Files.isExecutable(Paths.get(wsl))) { - return Status.OK_STATUS; - } + String windir = System.getenv("windir"); //$NON-NLS-1$ + if (windir == null) { + return Status.OK_STATUS; + } + String wsl = windir + "\\System32\\wsl.exe"; //$NON-NLS-1$ + if (!Files.isExecutable(Paths.get(wsl))) { + return Status.OK_STATUS; + } - ProcessBuilder pb = new ProcessBuilder(wsl, "--list", "--quiet"); //$NON-NLS-1$ //$NON-NLS-2$ - try { - Process process = pb.start(); - try (InputStream is = process.getErrorStream()) { - // drain the error stream - if (is.readAllBytes().length != 0) { - return Status.OK_STATUS; - } + ProcessBuilder pb = new ProcessBuilder(wsl, "--list", "--quiet"); //$NON-NLS-1$ //$NON-NLS-2$ + try { + Process process = pb.start(); + try (InputStream is = process.getErrorStream()) { + // drain the error stream + if (is.readAllBytes().length != 0) { + return Status.OK_STATUS; } - - try (BufferedReader reader = new BufferedReader( - new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_16LE))) { - result = new ArrayList<>(); - String line = null; - while ((line = reader.readLine()) != null) { - String distribution = line.trim(); - if (distribution.isBlank()) { - continue; - } - // docker-desktop entries are not "real" so shouldn't be shown in UI - if (distribution.startsWith("docker-desktop")) { //$NON-NLS-1$ - continue; - } - - String name = distribution + " (WSL)"; //$NON-NLS-1$ - Map m = new HashMap<>(); - m.put(IExternalExecutablesProperties.PROP_NAME, name); - m.put(IExternalExecutablesProperties.PROP_PATH, wsl); - m.put(IExternalExecutablesProperties.PROP_ARGS, "--distribution " + distribution); //$NON-NLS-1$ - m.put(IExternalExecutablesProperties.PROP_TRANSLATE, Boolean.TRUE.toString()); - result.add(m); - } - } - - } catch (IOException e) { } + + try (BufferedReader reader = new BufferedReader( + new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_16LE))) { + result = new ArrayList<>(); + String line = null; + while ((line = reader.readLine()) != null) { + String distribution = line.trim(); + if (distribution.isBlank()) { + continue; + } + // docker-desktop entries are not "real" so shouldn't be shown in UI + if (distribution.startsWith("docker-desktop")) { //$NON-NLS-1$ + continue; + } + + String name = distribution + " (WSL)"; //$NON-NLS-1$ + Map m = new HashMap<>(); + m.put(IExternalExecutablesProperties.PROP_NAME, name); + m.put(IExternalExecutablesProperties.PROP_PATH, wsl); + m.put(IExternalExecutablesProperties.PROP_ARGS, "--distribution " + distribution); //$NON-NLS-1$ + m.put(IExternalExecutablesProperties.PROP_TRANSLATE, Boolean.TRUE.toString()); + result.add(m); + } + } + + } catch (IOException e) { } } return Status.OK_STATUS;