mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 06:50:54 +07:00
Eel API: remove usages of EelPath methods that do not throw exceptions
See the previous commit for a rationale of the API change. IJ-CR-147046 (cherry picked from commit 8bfda4365d77e044680075abad3faaf28a3c0372) GitOrigin-RevId: c053fc88f31fb08e48384689be5590b4857ac1cd
This commit is contained in:
committed by
intellij-monorepo-bot
parent
545bea185c
commit
12e8ddbcae
@@ -1,9 +1,7 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.platform.eel.path
|
||||
|
||||
import com.intellij.platform.eel.EelResult
|
||||
import io.kotest.matchers.shouldBe
|
||||
import io.kotest.matchers.types.shouldBeInstanceOf
|
||||
import org.junit.jupiter.api.DynamicTest
|
||||
import org.junit.jupiter.api.DynamicTest.dynamicTest
|
||||
import org.junit.jupiter.api.TestFactory
|
||||
@@ -35,10 +33,7 @@ class EelAbsolutePathTest {
|
||||
|
||||
for (rawPath in (unixPaths + windowsPaths)) {
|
||||
add(dynamicTest(rawPath) {
|
||||
val eelPath = EelPath.Absolute
|
||||
.parse(rawPath, null)
|
||||
.shouldBeInstanceOf<EelResult.Ok<EelPath.Absolute, EelPathError>>()
|
||||
.value
|
||||
val eelPath = EelPath.Absolute.parseE(rawPath, null)
|
||||
eelPath.toString() shouldBe rawPath
|
||||
})
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ class EelRelativePathTest {
|
||||
abc/./def/../ghi, abc/ghi
|
||||
./abc/def/../ghi, abc/ghi """)
|
||||
fun normalize(source: String?, expected: String?) {
|
||||
val sourcePath = EelPath.Relative.parse(source ?: "").getOrThrow()
|
||||
val expectedPath = EelPath.Relative.parse(expected ?: "").getOrThrow()
|
||||
val sourcePath = EelPath.Relative.parseE(source ?: "")
|
||||
val expectedPath = EelPath.Relative.parseE(expected ?: "")
|
||||
sourcePath.normalize() should be(expectedPath)
|
||||
}
|
||||
|
||||
@@ -39,9 +39,9 @@ class EelRelativePathTest {
|
||||
inner class getChild {
|
||||
@Test
|
||||
fun positive() {
|
||||
val empty = EelPath.Relative.build().getOrThrow()
|
||||
empty.getChild("a") should be(EelPath.Relative.build("a"))
|
||||
empty.getChild("a").getOrThrow().getChild("bc") should be(EelPath.Relative.build("a", "bc"))
|
||||
val empty = EelPath.Relative.buildE()
|
||||
empty.getChildE("a") should be(EelPath.Relative.buildE("a"))
|
||||
empty.getChildE("a").getChildE("bc") should be(EelPath.Relative.buildE("a", "bc"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,11 +49,11 @@ class EelRelativePathTest {
|
||||
inner class resolve {
|
||||
@Test
|
||||
fun `parent directory should persist`() {
|
||||
val path = EelPath.Relative.parse("abc/..").getOrThrow()
|
||||
val targetPath = EelPath.Relative.parse("def").getOrThrow()
|
||||
val path = EelPath.Relative.parseE("abc/..")
|
||||
val targetPath = EelPath.Relative.parseE("def")
|
||||
|
||||
withClue("IjentPath.Relative.resolve must not normalize paths") {
|
||||
EelPath.Relative.parse("abc/../def") should be(path.resolve(targetPath))
|
||||
EelPath.Relative.parseE("abc/../def") should be(path.resolveE(targetPath))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,15 +63,15 @@ class EelRelativePathTest {
|
||||
@Test
|
||||
fun positive() {
|
||||
val raw = "a/b/c"
|
||||
val path = EelPath.Relative.parse(raw).getOrThrow()
|
||||
val expected = EelPath.Relative.parse("b").getOrThrow()
|
||||
val path = EelPath.Relative.parseE(raw)
|
||||
val expected = EelPath.Relative.parseE("b")
|
||||
expected should be(path.getName(1))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `out of bound`() {
|
||||
val raw = "a/b/c"
|
||||
val path = EelPath.Relative.parse(raw).getOrThrow()
|
||||
val path = EelPath.Relative.parseE(raw)
|
||||
|
||||
shouldThrowAny {
|
||||
path.getName(10)
|
||||
@@ -84,14 +84,14 @@ class EelRelativePathTest {
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = ["a/b", "a/b/c"])
|
||||
fun `is not null`(raw: String) {
|
||||
val path = EelPath.Relative.parse(raw).getOrThrow()
|
||||
val path = EelPath.Relative.parseE(raw)
|
||||
path.parent shouldNot be(null)
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = ["", "a"])
|
||||
fun `is null`(raw: String) {
|
||||
val path = EelPath.Relative.parse(raw).getOrThrow()
|
||||
val path = EelPath.Relative.parseE(raw)
|
||||
path.parent should be(null)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,16 +5,15 @@ import com.intellij.openapi.util.SystemInfo
|
||||
import com.intellij.platform.eel.*
|
||||
import com.intellij.platform.eel.fs.EelFileSystemPosixApi
|
||||
import com.intellij.platform.eel.fs.EelFileSystemWindowsApi
|
||||
import com.intellij.platform.eel.fs.getPath
|
||||
import com.intellij.platform.eel.fs.getPathE
|
||||
import com.intellij.platform.eel.path.EelPath
|
||||
import com.intellij.platform.eel.path.getOrThrow
|
||||
import com.intellij.platform.eel.provider.EelUserPosixInfoImpl
|
||||
import com.intellij.platform.eel.provider.EelUserWindowsInfoImpl
|
||||
import java.nio.file.Path
|
||||
|
||||
internal class LocalEelPathMapper(private val eelApi: EelApi) : EelPathMapper {
|
||||
override fun getOriginalPath(path: Path): EelPath.Absolute {
|
||||
return eelApi.fs.getPath(path.toString()).getOrThrow()
|
||||
return eelApi.fs.getPathE(path.toString())
|
||||
}
|
||||
|
||||
override fun toNioPath(path: EelPath.Absolute): Path {
|
||||
|
||||
@@ -3,9 +3,8 @@ package com.intellij.platform.eel.provider.utils
|
||||
|
||||
import com.intellij.execution.process.ProcessOutput
|
||||
import com.intellij.platform.eel.*
|
||||
import com.intellij.platform.eel.fs.getPath
|
||||
import com.intellij.platform.eel.fs.getPathE
|
||||
import com.intellij.platform.eel.path.EelPath
|
||||
import com.intellij.platform.eel.path.getOrThrow
|
||||
import com.intellij.util.io.computeDetached
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.channels.consumeEach
|
||||
@@ -85,6 +84,6 @@ suspend fun EelApi.where(exe: String): EelPath.Absolute? {
|
||||
return null
|
||||
}
|
||||
else {
|
||||
return fs.getPath(result.stdout).getOrThrow()
|
||||
return fs.getPathE(result.stdout)
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
package com.intellij.platform.ijent.community.impl.nio
|
||||
|
||||
import com.intellij.platform.eel.path.EelPath
|
||||
import com.intellij.platform.eel.path.getOrThrow
|
||||
import com.intellij.platform.ijent.fs.IjentFileSystemApi
|
||||
import com.intellij.platform.ijent.fs.IjentFileSystemPosixApi
|
||||
import com.intellij.platform.ijent.fs.IjentFileSystemWindowsApi
|
||||
@@ -71,10 +70,8 @@ class IjentNioFileSystem internal constructor(
|
||||
is IjentFileSystemPosixApi -> EelPath.Absolute.OS.UNIX
|
||||
is IjentFileSystemWindowsApi -> EelPath.Absolute.OS.WINDOWS
|
||||
}
|
||||
return EelPath.parse(first, os)
|
||||
.getOrThrow()
|
||||
.resolve(EelPath.Relative.build(*more).getOrThrow())
|
||||
.getOrThrow()
|
||||
return EelPath.parseE(first, os)
|
||||
.resolveE(EelPath.Relative.buildE(*more))
|
||||
.toNioPath()
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import com.intellij.platform.eel.fs.EelFileSystemPosixApi.CreateDirectoryExcepti
|
||||
import com.intellij.platform.eel.fs.EelFileSystemPosixApi.CreateSymbolicLinkException
|
||||
import com.intellij.platform.eel.fs.EelPosixFileInfo.Type.Symlink
|
||||
import com.intellij.platform.eel.path.EelPath
|
||||
import com.intellij.platform.eel.path.getOrThrow
|
||||
import com.intellij.platform.eel.provider.EelFsResultImpl
|
||||
import com.intellij.platform.ijent.community.impl.nio.IjentNioFileSystemProvider.Companion.newFileSystemMap
|
||||
import com.intellij.platform.ijent.community.impl.nio.IjentNioFileSystemProvider.UnixFilePermissionBranch.*
|
||||
@@ -206,7 +205,7 @@ class IjentNioFileSystemProvider : FileSystemProvider() {
|
||||
.getOrThrowFileSystemException()
|
||||
.asSequence()
|
||||
.map { (childName, childStat) ->
|
||||
val childIjentPath = dir.eelPath.getChild(childName).getOrThrow()
|
||||
val childIjentPath = dir.eelPath.getChildE(childName)
|
||||
val childAttrs = when (childStat) {
|
||||
is EelPosixFileInfo -> IjentNioPosixFileAttributes(childStat)
|
||||
is EelWindowsFileInfo -> TODO()
|
||||
@@ -220,7 +219,7 @@ class IjentNioFileSystemProvider : FileSystemProvider() {
|
||||
.getOrThrowFileSystemException()
|
||||
.asSequence()
|
||||
.map { childName ->
|
||||
val childIjentPath = dir.eelPath.getChild(childName).getOrThrow()
|
||||
val childIjentPath = dir.eelPath.getChildE(childName)
|
||||
IjentNioPath(childIjentPath, nioFs, null)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import com.intellij.platform.eel.fs.EelFileSystemApi
|
||||
import com.intellij.platform.eel.fs.EelFsError
|
||||
import com.intellij.platform.eel.fs.EelOpenedFile
|
||||
import com.intellij.platform.eel.path.EelPath
|
||||
import com.intellij.platform.eel.path.getOrThrow
|
||||
import com.intellij.util.text.nullize
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import java.io.IOException
|
||||
@@ -55,7 +54,7 @@ internal fun Path.toEelPath(): EelPath =
|
||||
|
||||
isAbsolute -> throw InvalidPathException(toString(), "This path can't be converted to IjentPath")
|
||||
|
||||
else -> EelPath.Relative.parse(toString()).getOrThrow()
|
||||
else -> EelPath.Relative.parseE(toString())
|
||||
}
|
||||
|
||||
internal fun <T> fsBlocking(body: suspend () -> T): T = invokeSuspending(body)
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.intellij.platform.ijent.community.impl.nio
|
||||
|
||||
import com.intellij.platform.core.nio.fs.BasicFileAttributesHolder2
|
||||
import com.intellij.platform.eel.path.EelPath
|
||||
import com.intellij.platform.eel.path.getOrThrow
|
||||
import java.net.URI
|
||||
import java.nio.file.*
|
||||
import java.nio.file.attribute.BasicFileAttributes
|
||||
@@ -40,8 +39,7 @@ class IjentNioPath internal constructor(
|
||||
|
||||
override fun getFileName(): IjentNioPath? =
|
||||
EelPath.Relative
|
||||
.parse(eelPath.fileName)
|
||||
.getOrThrow()
|
||||
.parseE(eelPath.fileName)
|
||||
.toNioPath()
|
||||
.takeIf { it.nameCount > 0 }
|
||||
|
||||
@@ -85,20 +83,20 @@ class IjentNioPath internal constructor(
|
||||
|
||||
override fun normalize(): IjentNioPath =
|
||||
when (eelPath) {
|
||||
is EelPath.Absolute -> eelPath.normalize().getOrThrow().toNioPath()
|
||||
is EelPath.Absolute -> eelPath.normalizeE().toNioPath()
|
||||
is EelPath.Relative -> eelPath.normalize().toNioPath()
|
||||
}
|
||||
|
||||
override fun resolve(other: Path): IjentNioPath =
|
||||
when (val otherIjentPath = other.toEelPath()) {
|
||||
is EelPath.Absolute -> otherIjentPath.toNioPath() // TODO is it the desired behaviour?
|
||||
is EelPath.Relative -> eelPath.resolve(otherIjentPath).getOrThrow().toNioPath()
|
||||
is EelPath.Relative -> eelPath.resolveE(otherIjentPath).toNioPath()
|
||||
}
|
||||
|
||||
override fun relativize(other: Path): IjentNioPath =
|
||||
when (val otherIjentPath = other.toEelPath()) {
|
||||
is EelPath.Absolute -> when (eelPath) {
|
||||
is EelPath.Absolute -> eelPath.relativize(otherIjentPath).getOrThrow().toNioPath()
|
||||
is EelPath.Absolute -> eelPath.relativizeE(otherIjentPath).toNioPath()
|
||||
is EelPath.Relative -> throw InvalidPathException("$this.relativize($other)",
|
||||
"Can't relativize these paths")
|
||||
}
|
||||
@@ -127,7 +125,7 @@ class IjentNioPath internal constructor(
|
||||
override fun toRealPath(vararg options: LinkOption): IjentNioPath =
|
||||
when (eelPath) {
|
||||
is EelPath.Absolute ->
|
||||
eelPath.normalize().getOrThrow()
|
||||
eelPath.normalizeE()
|
||||
.let { normalizedPath ->
|
||||
if (LinkOption.NOFOLLOW_LINKS in options)
|
||||
normalizedPath
|
||||
|
||||
@@ -7,8 +7,12 @@ import com.intellij.platform.core.nio.fs.MultiRoutingFsPath
|
||||
import com.intellij.platform.eel.*
|
||||
import com.intellij.platform.eel.EelExecApi.ExecuteProcessError
|
||||
import com.intellij.platform.eel.fs.getPath
|
||||
import com.intellij.platform.eel.fs.EelFileSystemApi
|
||||
import com.intellij.platform.eel.fs.getPathE
|
||||
import com.intellij.platform.eel.path.EelPath
|
||||
import com.intellij.platform.eel.path.getOrThrow
|
||||
import com.intellij.util.awaitCancellationAndInvoke
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import org.jetbrains.annotations.ApiStatus.Internal
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.pathString
|
||||
@@ -51,7 +55,7 @@ private class EelEphemeralRootAwareMapper(
|
||||
private val eelApi: EelApiBase,
|
||||
) : EelPathMapper {
|
||||
override fun getOriginalPath(path: Path): EelPath.Absolute? {
|
||||
return path.toEphemeralRootAwarePath()?.originalPath?.let { eelApi.fs.getPath(it.toString()).getOrThrow() }
|
||||
return path.toEphemeralRootAwarePath()?.originalPath?.let { eelApi.fs.getPathE(it.toString()) }
|
||||
}
|
||||
|
||||
override fun toNioPath(path: EelPath.Absolute): Path {
|
||||
|
||||
Reference in New Issue
Block a user