From cb936e32c8a357b0e45cd0679efa7b0de9dfdc55 Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Mon, 17 Jan 2022 23:34:24 +0300 Subject: [PATCH] Extract WSL execution code to separate module (wip) WSL execution code: * Depends on ktor (nobody wants ktor to be bundled with all IDEs) * Only useful on Windows installations Our task is to move it to the separate module and then convert it to the plugin or platform module. In this change we: * Move all code that depends on ktor to the separate module As a next step, we should all targets-api specific code there GitOrigin-RevId: 1b4911bb7a646a3a88dcaa56749ef36c8b9e2c29 --- .idea/modules.xml | 1 + .../intellij.platform.execution.impl.iml | 1 + .../execution/wsl/AbstractWslDistribution.kt | 24 ++++++++ .../intellij.platform.ide.impl.iml | 24 -------- .../execution/wsl/WSLDistribution.java | 11 +--- .../wsl-impl/intellij.platform.wsl.impl.iml | 56 +++++++++++++++++++ .../com/intellij/execution/wsl/WslProxy.kt | 6 +- 7 files changed, 89 insertions(+), 34 deletions(-) create mode 100644 platform/execution/src/com/intellij/execution/wsl/AbstractWslDistribution.kt create mode 100644 platform/wsl-impl/intellij.platform.wsl.impl.iml rename platform/{platform-impl => wsl-impl}/src/com/intellij/execution/wsl/WslProxy.kt (95%) diff --git a/.idea/modules.xml b/.idea/modules.xml index 96a2c4b915bf..18642a0018e5 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -833,6 +833,7 @@ + diff --git a/platform/execution-impl/intellij.platform.execution.impl.iml b/platform/execution-impl/intellij.platform.execution.impl.iml index 09207963cb15..67a0ca52921c 100644 --- a/platform/execution-impl/intellij.platform.execution.impl.iml +++ b/platform/execution-impl/intellij.platform.execution.impl.iml @@ -25,5 +25,6 @@ + \ No newline at end of file diff --git a/platform/execution/src/com/intellij/execution/wsl/AbstractWslDistribution.kt b/platform/execution/src/com/intellij/execution/wsl/AbstractWslDistribution.kt new file mode 100644 index 000000000000..afc8a3de61dd --- /dev/null +++ b/platform/execution/src/com/intellij/execution/wsl/AbstractWslDistribution.kt @@ -0,0 +1,24 @@ +// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.execution.wsl + +import com.intellij.execution.ExecutionException +import com.intellij.execution.configurations.GeneralCommandLine +import com.intellij.openapi.util.NlsSafe + +/** + * This is a temporary interface used for wsl classes transition. Please, do not use it + */ +interface AbstractWslDistribution { + /** + * @return Linux path for a file pointed by `windowsPath` or null if unavailable, like \\MACHINE\path + */ + @NlsSafe + fun getWslPath(windowsPath: String): String? + + /** + * @return creates and patches command line, e.g: + * `ruby -v` => `bash -c "ruby -v"` + */ + @Throws(ExecutionException::class) + fun createWslCommandLine(vararg command: String): GeneralCommandLine +} \ No newline at end of file diff --git a/platform/platform-impl/intellij.platform.ide.impl.iml b/platform/platform-impl/intellij.platform.ide.impl.iml index 0607ec773630..3721c180e3e2 100644 --- a/platform/platform-impl/intellij.platform.ide.impl.iml +++ b/platform/platform-impl/intellij.platform.ide.impl.iml @@ -137,30 +137,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/platform/platform-impl/src/com/intellij/execution/wsl/WSLDistribution.java b/platform/platform-impl/src/com/intellij/execution/wsl/WSLDistribution.java index c6ddeb8af24f..cfaea78f268b 100644 --- a/platform/platform-impl/src/com/intellij/execution/wsl/WSLDistribution.java +++ b/platform/platform-impl/src/com/intellij/execution/wsl/WSLDistribution.java @@ -51,7 +51,7 @@ import static com.intellij.openapi.util.NullableLazyValue.lazyNullable; * * @see WSLUtil */ -public class WSLDistribution { +public class WSLDistribution implements AbstractWslDistribution { public static final String DEFAULT_WSL_MNT_ROOT = "/mnt/"; private static final int RESOLVE_SYMLINK_TIMEOUT = 10000; private static final String RUN_PARAMETER = "run"; @@ -135,10 +135,7 @@ public class WSLDistribution { return myVersion; } - /** - * @return creates and patches command line, e.g: - * {@code ruby -v} => {@code bash -c "ruby -v"} - */ + @Override public @NotNull GeneralCommandLine createWslCommandLine(String @NotNull ... command) throws ExecutionException { return patchCommandLine(new GeneralCommandLine(command), null, new WSLCommandLineOptions()); } @@ -506,9 +503,7 @@ public class WSLDistribution { return getUNCRoot() + FileUtil.toSystemDependentName(FileUtil.normalize(wslPath)); } - /** - * @return Linux path for a file pointed by {@code windowsPath} or null if unavailable, like \\MACHINE\path - */ + @Override public @Nullable @NlsSafe String getWslPath(@NotNull String windowsPath) { if (FileUtil.toSystemDependentName(windowsPath).startsWith(WslConstants.UNC_PREFIX)) { windowsPath = StringUtil.trimStart(FileUtil.toSystemDependentName(windowsPath), WslConstants.UNC_PREFIX); diff --git a/platform/wsl-impl/intellij.platform.wsl.impl.iml b/platform/wsl-impl/intellij.platform.wsl.impl.iml new file mode 100644 index 000000000000..f0d48d9b777d --- /dev/null +++ b/platform/wsl-impl/intellij.platform.wsl.impl.iml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/execution/wsl/WslProxy.kt b/platform/wsl-impl/src/com/intellij/execution/wsl/WslProxy.kt similarity index 95% rename from platform/platform-impl/src/com/intellij/execution/wsl/WslProxy.kt rename to platform/wsl-impl/src/com/intellij/execution/wsl/WslProxy.kt index 79cf0dd18c51..3e9731ec1fe8 100644 --- a/platform/platform-impl/src/com/intellij/execution/wsl/WslProxy.kt +++ b/platform/wsl-impl/src/com/intellij/execution/wsl/WslProxy.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.execution.wsl import com.intellij.openapi.Disposable @@ -11,6 +11,7 @@ import io.ktor.network.sockets.openWriteChannel import io.ktor.utils.io.ByteReadChannel import io.ktor.utils.io.ByteWriteChannel import io.ktor.utils.io.close +import io.ktor.utils.io.core.ExperimentalIoApi import io.ktor.utils.io.jvm.javaio.toByteReadChannel import io.ktor.utils.io.readUTF8Line import kotlinx.coroutines.* @@ -34,7 +35,8 @@ import kotlin.coroutines.coroutineContext * [dispose] this object to stop forwarding. * */ -class WslProxy(distro: WSLDistribution, private val applicationPort: Int) : Disposable { +@OptIn(ExperimentalIoApi::class) +class WslProxy(distro: AbstractWslDistribution, private val applicationPort: Int) : Disposable { private companion object { suspend fun connectChannels(source: ByteReadChannel, dest: ByteWriteChannel) { val buffer = ByteBuffer.allocate(4096)