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
This commit is contained in:
Ilya.Kazakevich
2022-01-17 23:34:24 +03:00
committed by intellij-monorepo-bot
parent fa82bf6c38
commit cb936e32c8
7 changed files with 89 additions and 34 deletions

1
.idea/modules.xml generated
View File

@@ -833,6 +833,7 @@
<module fileurl="file://$PROJECT_DIR$/platform/workspaceModel/storage/intellij.platform.workspaceModel.storage.iml" filepath="$PROJECT_DIR$/platform/workspaceModel/storage/intellij.platform.workspaceModel.storage.iml" />
<module fileurl="file://$PROJECT_DIR$/platform/workspaceModel/storage/testEntities/intellij.platform.workspaceModel.storage.testEntities.iml" filepath="$PROJECT_DIR$/platform/workspaceModel/storage/testEntities/intellij.platform.workspaceModel.storage.testEntities.iml" />
<module fileurl="file://$PROJECT_DIR$/platform/workspaceModel/storage/tests/intellij.platform.workspaceModel.storage.tests.iml" filepath="$PROJECT_DIR$/platform/workspaceModel/storage/tests/intellij.platform.workspaceModel.storage.tests.iml" />
<module fileurl="file://$PROJECT_DIR$/platform/wsl-impl/intellij.platform.wsl.impl.iml" filepath="$PROJECT_DIR$/platform/wsl-impl/intellij.platform.wsl.impl.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/properties/intellij.properties.iml" filepath="$PROJECT_DIR$/plugins/properties/intellij.properties.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/properties/properties-psi-api/intellij.properties.psi.iml" filepath="$PROJECT_DIR$/plugins/properties/properties-psi-api/intellij.properties.psi.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/properties/properties-psi-impl/intellij.properties.psi.impl.iml" filepath="$PROJECT_DIR$/plugins/properties/properties-psi-impl/intellij.properties.psi.impl.iml" />

View File

@@ -25,5 +25,6 @@
<orderEntry type="module" module-name="intellij.platform.execution" />
<orderEntry type="library" scope="TEST" name="JUnit4" level="project" />
<orderEntry type="library" name="jediterm-typeahead" level="project" />
<orderEntry type="module" module-name="intellij.platform.wsl.impl" />
</component>
</module>

View File

@@ -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
}

View File

@@ -137,30 +137,6 @@
<orderEntry type="library" scope="RUNTIME" name="jgoodies-common" level="project" />
<orderEntry type="library" scope="RUNTIME" name="jgoodies-forms" level="project" />
<orderEntry type="library" name="jbr-api" level="project" />
<orderEntry type="module-library">
<library name="io.ktor.network.jvm" type="repository">
<properties maven-id="io.ktor:ktor-network-jvm:1.6.0">
<exclude>
<dependency maven-id="org.jetbrains.kotlin:kotlin-stdlib" />
<dependency maven-id="org.slf4j:slf4j-api" />
<dependency maven-id="org.jetbrains.kotlin:kotlin-stdlib-common" />
<dependency maven-id="org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm" />
<dependency maven-id="org.jetbrains.kotlin:kotlin-stdlib-jdk7" />
</exclude>
</properties>
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/io/ktor/ktor-network-jvm/1.6.0/ktor-network-jvm-1.6.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/io/ktor/ktor-utils-jvm/1.6.0/ktor-utils-jvm-1.6.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/io/ktor/ktor-io-jvm/1.6.0/ktor-io-jvm-1.6.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/io/ktor/ktor-network-jvm/1.6.0/ktor-network-jvm-1.6.0-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/io/ktor/ktor-utils-jvm/1.6.0/ktor-utils-jvm-1.6.0-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/io/ktor/ktor-io-jvm/1.6.0/ktor-io-jvm-1.6.0-sources.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="library" name="kotlinx-serialization-json" level="project" />
<orderEntry type="library" name="kotlinx-serialization-core" level="project" />
</component>

View File

@@ -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);

View File

@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="kotlin-language" name="Kotlin">
<configuration version="5" platform="JVM 11" allPlatforms="JVM [11]">
<compilerSettings>
<option name="additionalArguments" value="-version -Xstrict-java-nullability-assertions -Xjvm-default=enable -Xuse-old-backend -Xopt-in=kotlin.io.path.ExperimentalPathApi -Xopt-in=kotlin.RequiresOptIn -Xopt-in=com.intellij.openapi.util.IntellijInternalApi" />
</compilerSettings>
<compilerArguments>
<stringArguments>
<stringArg name="jvmTarget" arg="11" />
<stringArg name="apiVersion" arg="1.5" />
<stringArg name="languageVersion" arg="1.5" />
</stringArguments>
</compilerArguments>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="kotlin-stdlib-jdk8" level="project" />
<orderEntry type="module" module-name="intellij.platform.execution" />
<orderEntry type="module" module-name="intellij.platform.util" />
<orderEntry type="module-library">
<library name="io.ktor.network.jvm" type="repository">
<properties maven-id="io.ktor:ktor-network-jvm:1.6.0">
<exclude>
<dependency maven-id="org.jetbrains.kotlin:kotlin-stdlib" />
<dependency maven-id="org.slf4j:slf4j-api" />
<dependency maven-id="org.jetbrains.kotlin:kotlin-stdlib-common" />
<dependency maven-id="org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm" />
<dependency maven-id="org.jetbrains.kotlin:kotlin-stdlib-jdk7" />
</exclude>
</properties>
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/io/ktor/ktor-network-jvm/1.6.0/ktor-network-jvm-1.6.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/io/ktor/ktor-utils-jvm/1.6.0/ktor-utils-jvm-1.6.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/io/ktor/ktor-io-jvm/1.6.0/ktor-io-jvm-1.6.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/io/ktor/ktor-network-jvm/1.6.0/ktor-network-jvm-1.6.0-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/io/ktor/ktor-utils-jvm/1.6.0/ktor-utils-jvm-1.6.0-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/io/ktor/ktor-io-jvm/1.6.0/ktor-io-jvm-1.6.0-sources.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="library" name="kotlinx-coroutines-jdk8" level="project" />
<orderEntry type="module" module-name="intellij.platform.ide.util.io" />
</component>
</module>

View File

@@ -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)