1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 17:56:01 +02:00

Only spawn WSL detct job on Windows

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 <torbjorn.svensson@st.com>
This commit is contained in:
Torbjörn Svensson 2021-08-15 14:52:10 +02:00
parent 432ca56fd3
commit eb7aa70a9f

View file

@ -38,6 +38,12 @@ public class DetectWSL implements IDetectExternalExecutable {
private List<Map<String, String>> result = null; private List<Map<String, String>> result = null;
private WslDetectJob detectJob = null; private WslDetectJob detectJob = null;
public DetectWSL() {
if (!Platform.OS_WIN32.equals(Platform.getOS())) {
result = Collections.emptyList();
}
}
@Override @Override
public boolean hasEntries() { public boolean hasEntries() {
return !getEntries().isEmpty(); return !getEntries().isEmpty();
@ -95,52 +101,50 @@ public class DetectWSL implements IDetectExternalExecutable {
protected IStatus run(IProgressMonitor monitor) { protected IStatus run(IProgressMonitor monitor) {
if (result == null) { if (result == null) {
result = Collections.emptyList(); result = Collections.emptyList();
if (Platform.OS_WIN32.equals(Platform.getOS())) { String windir = System.getenv("windir"); //$NON-NLS-1$
String windir = System.getenv("windir"); //$NON-NLS-1$ if (windir == null) {
if (windir == null) { return Status.OK_STATUS;
return Status.OK_STATUS; }
} String wsl = windir + "\\System32\\wsl.exe"; //$NON-NLS-1$
String wsl = windir + "\\System32\\wsl.exe"; //$NON-NLS-1$ if (!Files.isExecutable(Paths.get(wsl))) {
if (!Files.isExecutable(Paths.get(wsl))) { return Status.OK_STATUS;
return Status.OK_STATUS; }
}
ProcessBuilder pb = new ProcessBuilder(wsl, "--list", "--quiet"); //$NON-NLS-1$ //$NON-NLS-2$ ProcessBuilder pb = new ProcessBuilder(wsl, "--list", "--quiet"); //$NON-NLS-1$ //$NON-NLS-2$
try { try {
Process process = pb.start(); Process process = pb.start();
try (InputStream is = process.getErrorStream()) { try (InputStream is = process.getErrorStream()) {
// drain the error stream // drain the error stream
if (is.readAllBytes().length != 0) { if (is.readAllBytes().length != 0) {
return Status.OK_STATUS; 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<String, String> 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<String, String> 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; return Status.OK_STATUS;