[ijent] IJPL-232220 encode os platform in path

GitOrigin-RevId: f0fafdfe6c8501fc53db3b0e321e707110bd1d85
This commit is contained in:
Mihail Buryakov
2026-02-02 15:32:33 +02:00
committed by intellij-monorepo-bot
parent 2239489cfd
commit cb29f205f7
9 changed files with 38 additions and 25 deletions

View File

@@ -6,7 +6,7 @@ import com.intellij.platform.eel.EelOsFamily
import com.intellij.platform.eel.EelPathBoundDescriptor
import java.nio.file.Path
abstract class TcpEelDescriptor : EelDescriptorWithoutNativeFileChooserSupport, EelPathBoundDescriptor {
abstract class TcpEelDescriptor(override val osFamily: EelOsFamily) : EelDescriptorWithoutNativeFileChooserSupport, EelPathBoundDescriptor {
abstract val rootPathString: String
override val rootPath: Path
get() = Path.of(rootPathString)
@@ -20,6 +20,4 @@ abstract class TcpEelDescriptor : EelDescriptorWithoutNativeFileChooserSupport,
}
override fun hashCode(): Int = rootPathString.hashCode()
override val osFamily: EelOsFamily = EelOsFamily.Posix // FIXME
}

View File

@@ -57,9 +57,12 @@ abstract class TcpEelMachine(override val internalName: String) : EelMachine {
protected abstract suspend fun createStrategy(): IjentIsolatedTcpDeployingStrategy
override suspend fun toEelApi(descriptor: EelDescriptor): EelApi {
return getOrCreateIjentSession().getIjentInstance(descriptor)
}
suspend fun getOrCreateIjentSession(): IjentSession<IjentApi> {
// Fast path: check if session is still running without acquiring mutex
(state as? SessionState.Started)?.session?.takeIf { it.isRunning }?.let {
return it.getIjentInstance(descriptor)
return it
}
// Slow path: get or create session under mutex
@@ -88,7 +91,7 @@ abstract class TcpEelMachine(override val internalName: String) : EelMachine {
}
}
}
return session.getIjentInstance(descriptor)
return session
}
/**
@@ -111,7 +114,7 @@ abstract class TcpEelMachine(override val internalName: String) : EelMachine {
}
override fun ownsPath(path: Path): Boolean {
val pathInternalName = TcpEelPathParser.extractInternalMachineId(path) ?: return false
val pathInternalName = TcpEelPathParser.extractInternalMachineId(path)?.first ?: return false
return pathInternalName == this.internalName
}

View File

@@ -24,10 +24,10 @@ class TcpEelMrfsBackend(private val scope: CoroutineScope) : MultiRoutingFileSys
private val cache = ConcurrentHashMap<String, FileSystem>()
override fun compute(localFS: FileSystem, sanitizedPath: String): FileSystem? {
val internalName = TcpEelPathParser.extractInternalMachineId(sanitizedPath) ?: return null
val descriptor = TcpEelPathParser.toDescriptor(internalName) ?: return null
val (internalName, osFamily) = TcpEelPathParser.extractInternalMachineId(sanitizedPath) ?: return null
val descriptor = TcpEelPathParser.toDescriptor(internalName, osFamily) ?: return null
return cache.computeIfAbsent(internalName) { createFilesystem(internalName, localFS, descriptor) }
return cache.computeIfAbsent("$internalName-${osFamily.name.lowercase()}") { createFilesystem(internalName, localFS, descriptor) }
}
private fun createFilesystem(internalName: String, localFS: FileSystem, descriptor: TcpEelDescriptor): FileSystem {
@@ -57,7 +57,7 @@ class TcpEelMrfsBackend(private val scope: CoroutineScope) : MultiRoutingFileSys
}
override fun getCustomRoots(): Collection<@MultiRoutingFileSystemPath String> {
return cache.keys.map { "${TcpEelConstants.TCP_PROTOCOL_PREFIX}$it" }
return cache.keys.map { "${TcpEelConstants.TCP_PATH_PREFIX}$it" }
}
override fun getCustomFileStores(localFS: FileSystem): Collection<FileStore> {

View File

@@ -2,6 +2,7 @@
package com.intellij.platform.eel.tcp
import com.intellij.openapi.extensions.ExtensionPointName
import com.intellij.platform.eel.EelOsFamily
import java.nio.file.Path
import kotlin.io.path.pathString
@@ -9,15 +10,15 @@ interface TcpEelPathParser {
companion object {
val EP_NAME: ExtensionPointName<TcpEelPathParser> = ExtensionPointName("com.intellij.eelTcpPathParser")
private fun findCompatibleParser(path: String): TcpEelPathParser? {
if (!path.startsWith(TcpEelConstants.TCP_PROTOCOL_PREFIX)) return null
if (!path.startsWith(TcpEelConstants.TCP_PATH_PREFIX)) return null
return EP_NAME.findFirstSafe { it.isPathCompatible(path) }
}
fun extractInternalMachineId(path: String): String? = findCompatibleParser(path)?.extractInternalMachineId(path)
fun extractInternalMachineId(path: Path): String? = extractInternalMachineId(path.pathString)
fun toDescriptor(internalName: String): TcpEelDescriptor? = EP_NAME.extensionList.firstNotNullOfOrNull { it.toDescriptor(internalName) }
fun extractInternalMachineId(path: String): Pair<String, EelOsFamily>? = findCompatibleParser(path)?.extractInternalMachineId(path)
fun extractInternalMachineId(path: Path): Pair<String, EelOsFamily>? = extractInternalMachineId(path.pathString)
fun toDescriptor(internalName: String, osFamily: EelOsFamily): TcpEelDescriptor? = EP_NAME.extensionList.firstNotNullOfOrNull { it.toDescriptor(internalName, osFamily) }
}
fun isPathCompatible(path: String): Boolean
fun extractInternalMachineId(path: String): String?
fun toDescriptor(internalName: String): TcpEelDescriptor?
fun extractInternalMachineId(path: String): Pair<String, EelOsFamily>?
fun toDescriptor(internalName: String, osFamily: EelOsFamily): TcpEelDescriptor?
}

View File

@@ -10,16 +10,16 @@ import java.nio.file.Path
class TcpEelProvider : EelProvider {
override suspend fun tryInitialize(path: @MultiRoutingFileSystemPath String): EelMachine? {
val internalName = TcpEelPathParser.extractInternalMachineId(path) ?: return null
val descriptor = TcpEelPathParser.toDescriptor(internalName) ?: return null
val (internalName, osFamily) = TcpEelPathParser.extractInternalMachineId(path) ?: return null
val descriptor = TcpEelPathParser.toDescriptor(internalName, osFamily) ?: return null
val tcpMachine = descriptor.resolveEelMachine() as? TcpEelMachine ?: return null
tcpMachine.toEelApi(descriptor) // deploy ijent
return tcpMachine
}
override fun getEelDescriptor(path: @MultiRoutingFileSystemPath Path): EelDescriptor? {
val internalName = TcpEelPathParser.extractInternalMachineId(path) ?: return null
return TcpEelPathParser.toDescriptor(internalName)
val (internalName, osFamily) = TcpEelPathParser.extractInternalMachineId(path) ?: return null
return TcpEelPathParser.toDescriptor(internalName, osFamily)
}
override fun getCustomRoots(eelDescriptor: EelDescriptor): Collection<@MultiRoutingFileSystemPath String>? {

View File

@@ -2,8 +2,15 @@
package com.intellij.platform.eel.tcp
import com.intellij.platform.ijent.tcp.TcpEndpoint
import java.io.File
object TcpEelConstants {
@Suppress("IO_FILE_USAGE")
private val IS_WINDOWS: Boolean = File.separatorChar == '\\'
val TCP_PATH_PREFIX: String get() = if (IS_WINDOWS) "//tcp.ij/" else $$"/$tcp.ij/"
const val TCP_PROTOCOL_PREFIX: String = "/tcp-"
const val TCP_RAW_SCHEME: String = "raw"
const val TCP_RAW_PREFIX: String = "/tcp-raw-"

View File

@@ -1,13 +1,14 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.platform.eel.tcp.raw
import com.intellij.platform.eel.EelOsFamily
import com.intellij.platform.eel.tcp.TcpEelConstants
import com.intellij.platform.eel.tcp.TcpEelDescriptor
import com.intellij.platform.eel.tcp.toPath
import com.intellij.platform.ijent.tcp.TcpEndpoint
import org.jetbrains.annotations.NonNls
internal class RawTcpEelDescriptor(tcpEndpoint: TcpEndpoint) : TcpEelDescriptor() {
internal class RawTcpEelDescriptor(tcpEndpoint: TcpEndpoint, osFamily: EelOsFamily) : TcpEelDescriptor(osFamily) {
override val rootPathString: String = "${TcpEelConstants.TCP_RAW_PREFIX}${tcpEndpoint.toPath()}"
override val name: @NonNls String = "Raw Tcp Eel to ${tcpEndpoint.host}"
}

View File

@@ -1,6 +1,7 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.platform.eel.tcp.raw
import com.intellij.platform.eel.EelOsFamily
import com.intellij.platform.eel.tcp.TcpEelConstants
import com.intellij.platform.eel.tcp.TcpEelDescriptor
import com.intellij.platform.eel.tcp.TcpEelPathParser
@@ -12,14 +13,14 @@ class RawTcpPathParser : TcpEelPathParser {
}
override fun extractInternalMachineId(path: String): String? {
override fun extractInternalMachineId(path: String): Pair<String, EelOsFamily>? {
if (!isPathCompatible(path)) return null
return path.substringAfter(TcpEelConstants.TCP_PROTOCOL_PREFIX).substringBefore("/")
return path.substringAfter(TcpEelConstants.TCP_PROTOCOL_PREFIX).substringBefore("/") to EelOsFamily.Posix
}
override fun toDescriptor(internalName: String): TcpEelDescriptor? {
override fun toDescriptor(internalName: String, osFamily: EelOsFamily): TcpEelDescriptor? {
if (!internalName.startsWith(TcpEelConstants.TCP_RAW_SCHEME)) return null
val host = internalName.substringAfter(TcpEelConstants.TCP_RAW_SCHEME).drop(1)
return RawTcpEelDescriptor(TcpEndpoint(host))
return RawTcpEelDescriptor(TcpEndpoint(host), EelOsFamily.Posix)
}
}

View File

@@ -4,9 +4,11 @@
package com.intellij.platform.ijent
import com.intellij.platform.eel.EelDescriptor
import com.intellij.platform.eel.EelPlatform
interface IjentSession<T : IjentApi> {
val isRunning: Boolean
val platform: EelPlatform
val remotePathToBinary: String // TODO Use IjentPath.Absolute.
suspend fun updateLogLevel()