mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IJ-CR-100762 extracted getResolvedNioPath from NioPathUtil.createFile
made all function in NioPathUtil as extensions GitOrigin-RevId: fc33f3b8377c3391ab6ea35306a7553c5a6fb547
This commit is contained in:
committed by
intellij-monorepo-bot
parent
28490600c8
commit
079d025125
+3
-3
@@ -10,8 +10,8 @@ import com.intellij.ide.starters.local.generator.AssetsProcessor
|
||||
import com.intellij.ide.wizard.*
|
||||
import com.intellij.openapi.application.invokeAndWaitIfNeeded
|
||||
import com.intellij.openapi.application.runWriteAction
|
||||
import com.intellij.openapi.file.CanonicalPathUtil.getAbsoluteNioPath
|
||||
import com.intellij.openapi.file.CanonicalPathUtil.toNioPath
|
||||
import com.intellij.openapi.file.getResolvedNioPath
|
||||
import com.intellij.openapi.file.toNioPath
|
||||
import com.intellij.openapi.file.findVirtualFile
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager
|
||||
import com.intellij.openapi.project.Project
|
||||
@@ -58,7 +58,7 @@ abstract class AssetsNewProjectWizardStep(parent: NewProjectWizardStep) : Abstra
|
||||
|
||||
private fun addFilesToOpen(relativeCanonicalPaths: Iterable<String>) {
|
||||
for (relativePath in relativeCanonicalPaths) {
|
||||
filesToOpen.add(outputDirectory.getAbsoluteNioPath(relativePath))
|
||||
filesToOpen.add(outputDirectory.getResolvedNioPath(relativePath))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.application.ModalityState
|
||||
import com.intellij.openapi.application.WriteAction
|
||||
import com.intellij.openapi.application.runWriteAction
|
||||
import com.intellij.openapi.components.service
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.extensions.ExtensionPointName
|
||||
import com.intellij.openapi.externalSystem.service.project.manage.ExternalProjectsManagerImpl
|
||||
@@ -52,7 +51,6 @@ import com.intellij.openapi.util.Version
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.vfs.LocalFileSystem
|
||||
import com.intellij.openapi.vfs.VfsUtil
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.pom.java.LanguageLevel
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import com.intellij.util.ModalityUiUtil
|
||||
@@ -61,7 +59,6 @@ import org.jetbrains.annotations.Nullable
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import java.io.IOException
|
||||
import java.net.URL
|
||||
import java.nio.file.Path
|
||||
import javax.swing.Icon
|
||||
|
||||
abstract class StarterModuleBuilder : ModuleBuilder() {
|
||||
|
||||
@@ -86,12 +86,14 @@ open class AssetsProcessorImpl : AssetsProcessor {
|
||||
|
||||
protected open fun findOrCreateFile(outputDirectory: Path, relativePath: String): Path {
|
||||
LOG.info("Creating file $relativePath in $outputDirectory")
|
||||
return NioPathUtil.findOrCreateFile(outputDirectory, relativePath)
|
||||
val filePath = outputDirectory.getResolvedNioPath(relativePath)
|
||||
return filePath.findOrCreateNioFile()
|
||||
}
|
||||
|
||||
protected open fun findOrCreateDirectory(outputDirectory: Path, relativePath: String): Path {
|
||||
LOG.info("Creating directory $relativePath in $outputDirectory")
|
||||
return NioPathUtil.findOrCreateDirectory(outputDirectory, relativePath)
|
||||
val directoryPath = outputDirectory.getResolvedNioPath(relativePath)
|
||||
return directoryPath.findOrCreateNioDirectory()
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
+2
-3
@@ -3,7 +3,6 @@ package com.intellij.ide.starters.local.generator
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.file.*
|
||||
import com.intellij.openapi.file.NioPathUtil.getAbsoluteNioPath
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import java.nio.file.Path
|
||||
@@ -52,7 +51,7 @@ class TestAssetsProcessorImpl : AssetsProcessorImpl() {
|
||||
override fun findOrCreateFile(outputDirectory: Path, relativePath: String): Path {
|
||||
if (outputDirectory is TestFileSystemLocation) {
|
||||
val vFile = outputDirectory.virtualFile.findOrCreateVirtualFile(relativePath)
|
||||
val debugPath = outputDirectory.debugPath.getAbsoluteNioPath(relativePath)
|
||||
val debugPath = outputDirectory.debugPath.getResolvedNioPath(relativePath)
|
||||
return TestFileSystemLocation(vFile, debugPath)
|
||||
}
|
||||
return super.findOrCreateFile(outputDirectory, relativePath)
|
||||
@@ -61,7 +60,7 @@ class TestAssetsProcessorImpl : AssetsProcessorImpl() {
|
||||
override fun findOrCreateDirectory(outputDirectory: Path, relativePath: String): Path {
|
||||
if (outputDirectory is TestFileSystemLocation) {
|
||||
val vFile = outputDirectory.virtualFile.findOrCreateVirtualDirectory(relativePath)
|
||||
val debugPath = outputDirectory.debugPath.getAbsoluteNioPath(relativePath)
|
||||
val debugPath = outputDirectory.debugPath.getResolvedNioPath(relativePath)
|
||||
return TestFileSystemLocation(vFile, debugPath)
|
||||
}
|
||||
return super.findOrCreateDirectory(outputDirectory, relativePath)
|
||||
|
||||
@@ -4,7 +4,7 @@ package com.intellij.jarRepository
|
||||
import com.intellij.application.options.PathMacrosImpl
|
||||
import com.intellij.openapi.application.PathMacros
|
||||
import com.intellij.openapi.application.ex.PathManagerEx
|
||||
import com.intellij.openapi.file.CanonicalPathUtil.toNioPath
|
||||
import com.intellij.openapi.file.toNioPath
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.project.doNotEnableExternalStorageByDefaultInTests
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryEx
|
||||
|
||||
@@ -1,72 +1,54 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
@file:Suppress("MemberVisibilityCanBePrivate", "unused")
|
||||
@file:JvmName("CanonicalPathUtil")
|
||||
package com.intellij.openapi.file
|
||||
|
||||
import com.intellij.openapi.file.NioPathUtil.toCanonicalPath
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.util.PathUtil
|
||||
import com.intellij.util.text.nullize
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import org.jetbrains.annotations.SystemIndependent
|
||||
import java.io.File
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
|
||||
@ApiStatus.Experimental
|
||||
object CanonicalPathUtil {
|
||||
|
||||
@JvmStatic
|
||||
fun String.toNioPath(): Path {
|
||||
return Paths.get(FileUtil.toSystemDependentName(this))
|
||||
}
|
||||
fun @SystemIndependent String.toNioPath(): Path {
|
||||
return Paths.get(FileUtil.toSystemDependentName(this))
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun String.toIoFile(): File {
|
||||
return toNioPath().toFile()
|
||||
}
|
||||
fun @SystemIndependent String.toIoFile(): File {
|
||||
return toNioPath().toFile()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun String.getFileName(): String {
|
||||
return PathUtil.getFileName(this)
|
||||
}
|
||||
fun @SystemIndependent String.getFileName(): String {
|
||||
return PathUtil.getFileName(this)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun String.getParentPath(): String? {
|
||||
return PathUtil.getParentPath(this).nullize()
|
||||
}
|
||||
fun @SystemIndependent String.getParentPath(): @SystemIndependent String? {
|
||||
return PathUtil.getParentPath(this).nullize()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun String.getParentNioPath(): Path? {
|
||||
return getParentPath()?.toNioPath()
|
||||
}
|
||||
fun @SystemIndependent String.getParentNioPath(): Path? {
|
||||
return getParentPath()?.toNioPath()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun String.getAbsolutePath(relativePath: String): String {
|
||||
val path = "$this/$relativePath"
|
||||
return FileUtil.toCanonicalPath(path) // resolve simple symlinks . and ..
|
||||
}
|
||||
fun @SystemIndependent String.getResolvedPath(relativePath: @SystemIndependent String): @SystemIndependent String {
|
||||
val path = "$this/$relativePath"
|
||||
return FileUtil.toCanonicalPath(path) // resolve simple symlinks . and ..
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun String.getAbsoluteNioPath(relativePath: String): Path {
|
||||
return getAbsolutePath(relativePath).toNioPath()
|
||||
}
|
||||
fun @SystemIndependent String.getResolvedNioPath(relativePath: @SystemIndependent String): Path {
|
||||
return getResolvedPath(relativePath).toNioPath()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun String.getRelativePath(path: String): String? {
|
||||
return FileUtil.getRelativePath(this, path, '/')
|
||||
}
|
||||
fun @SystemIndependent String.getRelativePath(path: @SystemIndependent String): @SystemIndependent String? {
|
||||
return FileUtil.getRelativePath(this, path, '/')
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun String.getRelativeNioPath(path: String): Path? {
|
||||
return getRelativePath(path)?.toNioPath()
|
||||
}
|
||||
fun @SystemIndependent String.getRelativeNioPath(path: @SystemIndependent String): Path? {
|
||||
return getRelativePath(path)?.toNioPath()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun String.isAncestor(path: String, strict: Boolean): Boolean {
|
||||
return FileUtil.isAncestor(this, path, strict)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun String.isAncestor(path: Path, strict: Boolean): Boolean {
|
||||
return isAncestor(path.toCanonicalPath(), strict)
|
||||
}
|
||||
}
|
||||
fun @SystemIndependent String.isAncestor(path: @SystemIndependent String, strict: Boolean): Boolean {
|
||||
return FileUtil.isAncestor(this, path, strict)
|
||||
}
|
||||
|
||||
@@ -1,119 +1,113 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
@file:Suppress("MemberVisibilityCanBePrivate", "unused")
|
||||
|
||||
@file:JvmName("NioPathUtil")
|
||||
package com.intellij.openapi.file
|
||||
|
||||
import com.intellij.openapi.file.CanonicalPathUtil.getAbsoluteNioPath
|
||||
import com.intellij.openapi.file.CanonicalPathUtil.getAbsolutePath
|
||||
import com.intellij.openapi.file.CanonicalPathUtil.getRelativeNioPath
|
||||
import com.intellij.openapi.file.CanonicalPathUtil.getRelativePath
|
||||
import com.intellij.openapi.file.CanonicalPathUtil.isAncestor
|
||||
import com.intellij.openapi.file.system.NioPathSystemUtil
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import com.intellij.util.io.createDirectories
|
||||
import com.intellij.util.io.createFile
|
||||
import com.intellij.util.io.delete
|
||||
import org.jetbrains.annotations.SystemIndependent
|
||||
import java.io.File
|
||||
import java.nio.file.DirectoryStream
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.exists
|
||||
import kotlin.io.path.isDirectory
|
||||
import kotlin.io.path.isRegularFile
|
||||
|
||||
@ApiStatus.Experimental
|
||||
object NioPathUtil {
|
||||
fun Path.toCanonicalPath(): @SystemIndependent String {
|
||||
return FileUtil.toCanonicalPath(toString())
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun findFileOrDirectory(path: Path, relativePath: String): Path? {
|
||||
return NioPathSystemUtil.findFileOrDirectory(path.getAbsoluteNioPath(relativePath))
|
||||
fun Path.toIoFile(): File {
|
||||
return toFile()
|
||||
}
|
||||
|
||||
fun Path.getResolvedPath(relativePath: @SystemIndependent String): String {
|
||||
return toCanonicalPath().getResolvedPath(relativePath)
|
||||
}
|
||||
|
||||
fun Path.getResolvedNioPath(relativePath: @SystemIndependent String): Path {
|
||||
return toCanonicalPath().getResolvedNioPath(relativePath)
|
||||
}
|
||||
|
||||
fun Path.getRelativePath(path: Path): @SystemIndependent String? {
|
||||
return toCanonicalPath().getRelativePath(path.toCanonicalPath())
|
||||
}
|
||||
|
||||
fun Path.getRelativeNioPath(path: Path): Path? {
|
||||
return toCanonicalPath().getRelativeNioPath(path.toCanonicalPath())
|
||||
}
|
||||
|
||||
fun Path.isAncestor(path: Path, strict: Boolean): Boolean {
|
||||
return FileUtil.isAncestor(this, path, strict)
|
||||
}
|
||||
|
||||
fun Path.findNioFileOrDirectory(): Path? {
|
||||
if (!exists()) {
|
||||
return null
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getFileOrDirectory(path: Path, relativePath: String): Path {
|
||||
return NioPathSystemUtil.getFileOrDirectory(path.getAbsoluteNioPath(relativePath))
|
||||
fun Path.getNioFileOrDirectory(): Path {
|
||||
return checkNotNull(findNioFileOrDirectory()) {
|
||||
"File or directory doesn't exist: $this"
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun findFile(path: Path, relativePath: String): Path? {
|
||||
return NioPathSystemUtil.findFile(path.getAbsoluteNioPath(relativePath))
|
||||
fun Path.findNioFile(): Path? {
|
||||
val filePath = findNioFileOrDirectory() ?: return null
|
||||
check(filePath.isRegularFile()) {
|
||||
"Expected file instead directory: $filePath"
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getFile(path: Path, relativePath: String): Path {
|
||||
return NioPathSystemUtil.getFile(path.getAbsoluteNioPath(relativePath))
|
||||
fun Path.getNioFile(): Path {
|
||||
return checkNotNull(findNioFile()) {
|
||||
"File doesn't exist: $this"
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun findDirectory(path: Path, relativePath: String): Path? {
|
||||
return NioPathSystemUtil.findDirectory(path.getAbsoluteNioPath(relativePath))
|
||||
fun Path.findNioDirectory(): Path? {
|
||||
val filePath = findNioFileOrDirectory() ?: return null
|
||||
check(filePath.isDirectory()) {
|
||||
"Expected directory instead file: $filePath"
|
||||
}
|
||||
return filePath
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getDirectory(path: Path, relativePath: String): Path {
|
||||
return NioPathSystemUtil.getDirectory(path.getAbsoluteNioPath(relativePath))
|
||||
fun Path.getNioDirectory(): Path {
|
||||
return checkNotNull(findNioDirectory()) {
|
||||
"Directory doesn't exist: $this"
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun findOrCreateFile(path: Path, relativePath: String): Path {
|
||||
return NioPathSystemUtil.findOrCreateFile(path.getAbsoluteNioPath(relativePath))
|
||||
}
|
||||
fun Path.createNioFile(): Path {
|
||||
return createFile()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun findOrCreateDirectory(path: Path, relativePath: String): Path {
|
||||
return NioPathSystemUtil.findOrCreateDirectory(path.getAbsoluteNioPath(relativePath))
|
||||
}
|
||||
fun Path.createNioDirectory(): Path {
|
||||
return createDirectories()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun createFile(path: Path, relativePath: String): Path {
|
||||
return NioPathSystemUtil.createFile(path.getAbsoluteNioPath(relativePath))
|
||||
}
|
||||
fun Path.findOrCreateNioFile(): Path {
|
||||
return findNioFile() ?: createNioFile()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun createDirectory(path: Path, relativePath: String): Path {
|
||||
return NioPathSystemUtil.createDirectory(path.getAbsoluteNioPath(relativePath))
|
||||
}
|
||||
fun Path.findOrCreateNioDirectory(): Path {
|
||||
return findNioDirectory() ?: createNioDirectory()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun deleteFileOrDirectory(path: Path, relativePath: String = ".") {
|
||||
NioPathSystemUtil.deleteFileOrDirectory(path.getAbsoluteNioPath(relativePath))
|
||||
}
|
||||
fun Path.deleteNioFileOrDirectory() {
|
||||
delete(recursively = true)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun deleteChildren(path: Path, relativePath: String = ".", predicate: (Path) -> Boolean = { true }) {
|
||||
NioPathSystemUtil.deleteChildren(path.getAbsoluteNioPath(relativePath), predicate)
|
||||
fun Path.deleteNioChildren(predicate: (Path) -> Boolean = { true }) {
|
||||
val filter = DirectoryStream.Filter(predicate)
|
||||
Files.newDirectoryStream(this, filter).use { stream ->
|
||||
stream.forEach { it.deleteNioFileOrDirectory() }
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun Path.toCanonicalPath(): String {
|
||||
return FileUtil.toCanonicalPath(toString())
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun Path.toIoFile(): File {
|
||||
return toFile()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun Path.getAbsolutePath(relativePath: String): String {
|
||||
return toCanonicalPath().getAbsolutePath(relativePath)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun Path.getAbsoluteNioPath(relativePath: String): Path {
|
||||
return toCanonicalPath().getAbsoluteNioPath(relativePath)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun Path.getRelativePath(path: Path): String? {
|
||||
return toCanonicalPath().getRelativePath(path.toCanonicalPath())
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun Path.getRelativeNioPath(path: Path): Path? {
|
||||
return toCanonicalPath().getRelativeNioPath(path.toCanonicalPath())
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun Path.isAncestor(canonicalPath: String, strict: Boolean): Boolean {
|
||||
return toCanonicalPath().isAncestor(canonicalPath, strict)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun Path.isAncestor(path: Path, strict: Boolean): Boolean {
|
||||
return FileUtil.isAncestor(this, path, strict)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
@file:Suppress("MemberVisibilityCanBePrivate", "unused")
|
||||
|
||||
@file:JvmName("VirtualFileUtil")
|
||||
package com.intellij.openapi.file
|
||||
|
||||
import com.intellij.openapi.editor.Document
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.vfs.*
|
||||
import com.intellij.openapi.file.CanonicalPathUtil.getAbsolutePath
|
||||
import com.intellij.openapi.file.CanonicalPathUtil.getFileName
|
||||
import com.intellij.openapi.file.CanonicalPathUtil.getParentPath
|
||||
import com.intellij.openapi.file.NioPathUtil.toCanonicalPath
|
||||
import com.intellij.openapi.vfs.newvfs.RefreshQueue
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import com.intellij.psi.PsiFile
|
||||
@@ -48,7 +44,9 @@ fun VirtualFile.findDocument(): Document? {
|
||||
}
|
||||
|
||||
fun VirtualFile.getDocument(): Document {
|
||||
return requireNotNull(findDocument()) { "Cannot find Document for $path" }
|
||||
return checkNotNull(findDocument()) {
|
||||
"Cannot find Document for $path"
|
||||
}
|
||||
}
|
||||
|
||||
fun VirtualFile.reloadDocument() {
|
||||
@@ -72,7 +70,9 @@ fun VirtualFile.findPsiFile(project: Project): PsiFile? {
|
||||
}
|
||||
|
||||
fun VirtualFile.getPsiFile(project: Project): PsiFile {
|
||||
return requireNotNull(findPsiFile(project)) { "Cannot find PSI file for $path" }
|
||||
return checkNotNull(findPsiFile(project)) {
|
||||
"Cannot find PSI file for $path"
|
||||
}
|
||||
}
|
||||
|
||||
fun refreshVirtualFiles(vararg paths: Path, async: Boolean = false, recursive: Boolean = true, callback: () -> Unit = {}) {
|
||||
@@ -84,51 +84,51 @@ fun refreshVirtualFiles(vararg files: VirtualFile, async: Boolean = false, recur
|
||||
}
|
||||
|
||||
fun VirtualFile.findVirtualFileOrDirectory(relativePath: @SystemIndependent String): VirtualFile? {
|
||||
return fileSystem.findVirtualFileOrDirectory(path.getAbsolutePath(relativePath))
|
||||
return fileSystem.findVirtualFileOrDirectory(path.getResolvedPath(relativePath))
|
||||
}
|
||||
|
||||
fun VirtualFile.getVirtualFileOrDirectory(relativePath: @SystemIndependent String): VirtualFile {
|
||||
return fileSystem.getVirtualFileOrDirectory(path.getAbsolutePath(relativePath))
|
||||
return fileSystem.getVirtualFileOrDirectory(path.getResolvedPath(relativePath))
|
||||
}
|
||||
|
||||
fun VirtualFile.findVirtualFile(relativePath: @SystemIndependent String): VirtualFile? {
|
||||
return fileSystem.findVirtualFile(path.getAbsolutePath(relativePath))
|
||||
return fileSystem.findVirtualFile(path.getResolvedPath(relativePath))
|
||||
}
|
||||
|
||||
fun VirtualFile.getVirtualFile(relativePath: @SystemIndependent String): VirtualFile {
|
||||
return fileSystem.getVirtualFile(path.getAbsolutePath(relativePath))
|
||||
return fileSystem.getVirtualFile(path.getResolvedPath(relativePath))
|
||||
}
|
||||
|
||||
fun VirtualFile.findVirtualDirectory(relativePath: @SystemIndependent String): VirtualFile? {
|
||||
return fileSystem.findVirtualDirectory(path.getAbsolutePath(relativePath))
|
||||
return fileSystem.findVirtualDirectory(path.getResolvedPath(relativePath))
|
||||
}
|
||||
|
||||
fun VirtualFile.getVirtualDirectory(relativePath: @SystemIndependent String): VirtualFile {
|
||||
return fileSystem.getVirtualDirectory(path.getAbsolutePath(relativePath))
|
||||
}
|
||||
|
||||
fun VirtualFile.findOrCreateVirtualFile(relativePath: @SystemIndependent String): VirtualFile {
|
||||
return fileSystem.findOrCreateVirtualFile(path.getAbsolutePath(relativePath))
|
||||
}
|
||||
|
||||
fun VirtualFile.findOrCreateVirtualDirectory(relativePath: @SystemIndependent String): VirtualFile {
|
||||
return fileSystem.findOrCreateVirtualDirectory(path.getAbsolutePath(relativePath))
|
||||
return fileSystem.getVirtualDirectory(path.getResolvedPath(relativePath))
|
||||
}
|
||||
|
||||
fun VirtualFile.createVirtualFile(relativePath: @SystemIndependent String): VirtualFile {
|
||||
return fileSystem.createVirtualFile(path.getAbsolutePath(relativePath))
|
||||
return fileSystem.createVirtualFile(path.getResolvedPath(relativePath))
|
||||
}
|
||||
|
||||
fun VirtualFile.createVirtualDirectory(relativePath: @SystemIndependent String): VirtualFile {
|
||||
return fileSystem.createVirtualDirectory(path.getAbsolutePath(relativePath))
|
||||
return fileSystem.createVirtualDirectory(path.getResolvedPath(relativePath))
|
||||
}
|
||||
|
||||
fun VirtualFile.findOrCreateVirtualFile(relativePath: @SystemIndependent String): VirtualFile {
|
||||
return fileSystem.findOrCreateVirtualFile(path.getResolvedPath(relativePath))
|
||||
}
|
||||
|
||||
fun VirtualFile.findOrCreateVirtualDirectory(relativePath: @SystemIndependent String): VirtualFile {
|
||||
return fileSystem.findOrCreateVirtualDirectory(path.getResolvedPath(relativePath))
|
||||
}
|
||||
|
||||
fun VirtualFile.deleteVirtualFileOrDirectory(relativePath: @SystemIndependent String = ".") {
|
||||
fileSystem.deleteVirtualFileOrDirectory(path.getAbsolutePath(relativePath))
|
||||
fileSystem.deleteVirtualFileOrDirectory(path.getResolvedPath(relativePath))
|
||||
}
|
||||
|
||||
fun VirtualFile.deleteVirtualChildren(relativePath: @SystemIndependent String = ".", predicate: (VirtualFile) -> Boolean = { true }) {
|
||||
fileSystem.deleteVirtualChildren(path.getAbsolutePath(relativePath), predicate)
|
||||
fileSystem.deleteVirtualChildren(path.getResolvedPath(relativePath), predicate)
|
||||
}
|
||||
|
||||
fun Path.findVirtualFileOrDirectory(): VirtualFile? {
|
||||
@@ -159,10 +159,6 @@ fun Path.findOrCreateVirtualFile(): VirtualFile {
|
||||
return getVirtualFileSystem().findOrCreateVirtualFile(toCanonicalPath())
|
||||
}
|
||||
|
||||
fun Path.findOrCreateVirtualDirectory(): VirtualFile {
|
||||
return getVirtualFileSystem().findOrCreateVirtualDirectory(toCanonicalPath())
|
||||
}
|
||||
|
||||
fun Path.createVirtualFile(): VirtualFile {
|
||||
return getVirtualFileSystem().createVirtualFile(toCanonicalPath())
|
||||
}
|
||||
@@ -171,6 +167,10 @@ fun Path.createVirtualDirectory(): VirtualFile {
|
||||
return getVirtualFileSystem().createVirtualDirectory(toCanonicalPath())
|
||||
}
|
||||
|
||||
fun Path.findOrCreateVirtualDirectory(): VirtualFile {
|
||||
return getVirtualFileSystem().findOrCreateVirtualDirectory(toCanonicalPath())
|
||||
}
|
||||
|
||||
fun Path.deleteVirtualFileOrDirectory() {
|
||||
getVirtualFileSystem().deleteVirtualFileOrDirectory(toCanonicalPath())
|
||||
}
|
||||
@@ -209,7 +209,9 @@ fun VirtualFileSystem.findVirtualFile(path: @SystemIndependent String): VirtualF
|
||||
}
|
||||
|
||||
fun VirtualFileSystem.getVirtualFile(path: @SystemIndependent String): VirtualFile {
|
||||
return requireNotNull(findVirtualFile(path)) { "File doesn't exist: $path" }
|
||||
return checkNotNull(findVirtualFile(path)) {
|
||||
"File doesn't exist: $path"
|
||||
}
|
||||
}
|
||||
|
||||
fun VirtualFileSystem.findVirtualDirectory(path: @SystemIndependent String): VirtualFile? {
|
||||
@@ -226,14 +228,6 @@ fun VirtualFileSystem.getVirtualDirectory(path: @SystemIndependent String): Virt
|
||||
}
|
||||
}
|
||||
|
||||
fun VirtualFileSystem.findOrCreateVirtualFile(path: @SystemIndependent String): VirtualFile {
|
||||
return findVirtualFile(path) ?: createVirtualFile(path)
|
||||
}
|
||||
|
||||
fun VirtualFileSystem.findOrCreateVirtualDirectory(path: @SystemIndependent String): VirtualFile {
|
||||
return findVirtualDirectory(path) ?: createVirtualDirectory(path)
|
||||
}
|
||||
|
||||
fun VirtualFileSystem.createVirtualFile(path: @SystemIndependent String): VirtualFile {
|
||||
val parentFile = findOrCreateParentDirectory(path)
|
||||
return parentFile.createChildData(null, path.getFileName())
|
||||
@@ -244,6 +238,14 @@ fun VirtualFileSystem.createVirtualDirectory(path: @SystemIndependent String): V
|
||||
return parentFile.createChildDirectory(null, path.getFileName())
|
||||
}
|
||||
|
||||
fun VirtualFileSystem.findOrCreateVirtualFile(path: @SystemIndependent String): VirtualFile {
|
||||
return findVirtualFile(path) ?: createVirtualFile(path)
|
||||
}
|
||||
|
||||
fun VirtualFileSystem.findOrCreateVirtualDirectory(path: @SystemIndependent String): VirtualFile {
|
||||
return findVirtualDirectory(path) ?: createVirtualDirectory(path)
|
||||
}
|
||||
|
||||
fun VirtualFileSystem.deleteVirtualFileOrDirectory(path: @SystemIndependent String) {
|
||||
val file = findVirtualFileOrDirectory(path) ?: return
|
||||
file.delete(this)
|
||||
|
||||
+3
-2
@@ -2,10 +2,11 @@
|
||||
package com.intellij.openapi.file.converter
|
||||
|
||||
import com.intellij.util.containers.prefix.map.AbstractPrefixTreeFactory
|
||||
import org.jetbrains.annotations.SystemIndependent
|
||||
|
||||
object CanonicalPathPrefixTreeFactory : AbstractPrefixTreeFactory<String, String>() {
|
||||
object CanonicalPathPrefixTreeFactory : AbstractPrefixTreeFactory<@SystemIndependent String, String>() {
|
||||
|
||||
override fun convertToList(element: String): List<String> {
|
||||
override fun convertToList(element: @SystemIndependent String): List<String> {
|
||||
return element.removeSuffix("/").split("/")
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
|
||||
package com.intellij.openapi.file.converter
|
||||
|
||||
import com.intellij.openapi.file.NioPathUtil.toCanonicalPath
|
||||
import com.intellij.openapi.file.toCanonicalPath
|
||||
import com.intellij.util.containers.prefix.map.AbstractPrefixTreeFactory
|
||||
import java.nio.file.Path
|
||||
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
@file:Suppress("MemberVisibilityCanBePrivate", "unused")
|
||||
package com.intellij.openapi.file.system
|
||||
|
||||
import com.intellij.util.io.*
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import java.nio.file.DirectoryStream
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.exists
|
||||
import kotlin.io.path.isDirectory
|
||||
import kotlin.io.path.isRegularFile
|
||||
|
||||
@ApiStatus.Experimental
|
||||
object NioPathSystemUtil {
|
||||
|
||||
@JvmStatic
|
||||
fun findFileOrDirectory(path: Path): Path? {
|
||||
if (!path.exists()) {
|
||||
return null
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getFileOrDirectory(path: Path): Path {
|
||||
return requireNotNull(findFileOrDirectory(path)) { "File or directory doesn't exist: $path" }
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun findFile(path: Path): Path? {
|
||||
val filePath = findFileOrDirectory(path) ?: return null
|
||||
require(filePath.isRegularFile()) { "Expected file instead directory: $filePath" }
|
||||
return path
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getFile(path: Path): Path {
|
||||
return requireNotNull(findFile(path)) { "File doesn't exist: $path" }
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun findDirectory(path: Path): Path? {
|
||||
val filePath = findFileOrDirectory(path) ?: return null
|
||||
require(filePath.isDirectory()) { "Expected directory instead file: $filePath" }
|
||||
return filePath
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getDirectory(path: Path): Path {
|
||||
return requireNotNull(findDirectory(path)) { "Directory doesn't exist: $path" }
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun findOrCreateFile(path: Path): Path {
|
||||
return findFile(path) ?: createFile(path)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun findOrCreateDirectory(path: Path): Path {
|
||||
return findDirectory(path) ?: createDirectory(path)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun createFile(path: Path): Path {
|
||||
return path.createFile()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun createDirectory(path: Path): Path {
|
||||
return path.createDirectories()
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun deleteFileOrDirectory(path: Path) {
|
||||
path.delete(recursively = true)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun deleteChildren(path: Path, predicate: (Path) -> Boolean = { true }) {
|
||||
val filter = DirectoryStream.Filter(predicate)
|
||||
Files.newDirectoryStream(path, filter).use { stream ->
|
||||
stream.forEach { deleteFileOrDirectory(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -3,7 +3,7 @@ package com.intellij.openapi.externalSystem.service.project.trusted
|
||||
|
||||
import com.intellij.ide.impl.trustedProjects.ProjectLocator
|
||||
import com.intellij.openapi.externalSystem.ExternalSystemManager
|
||||
import com.intellij.openapi.file.CanonicalPathUtil.toNioPath
|
||||
import com.intellij.openapi.file.toNioPath
|
||||
import com.intellij.openapi.file.converter.NioPathPrefixTreeFactory
|
||||
import com.intellij.openapi.project.Project
|
||||
import java.nio.file.Path
|
||||
|
||||
+1
-2
@@ -16,7 +16,6 @@ import com.intellij.openapi.externalSystem.autoimport.MockProjectAware.ReloadCol
|
||||
import com.intellij.openapi.externalSystem.importing.ProjectResolverPolicy
|
||||
import com.intellij.openapi.externalSystem.service.project.autoimport.ProjectAware
|
||||
import com.intellij.openapi.file.*
|
||||
import com.intellij.openapi.file.CanonicalPathUtil.getAbsoluteNioPath
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager
|
||||
import com.intellij.openapi.progress.util.BackgroundTaskUtil
|
||||
import com.intellij.openapi.project.Project
|
||||
@@ -62,7 +61,7 @@ abstract class AutoReloadTestCase : ExternalSystemTestCase() {
|
||||
"$projectPath/$relativePath"
|
||||
|
||||
private fun getAbsoluteNioPath(relativePath: String) =
|
||||
projectRoot.path.getAbsoluteNioPath(relativePath)
|
||||
projectRoot.path.getResolvedNioPath(relativePath)
|
||||
|
||||
protected fun createFile(relativePath: String) =
|
||||
runWriteAction { projectRoot.createVirtualFile(relativePath) }
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// 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.ide.impl.trustedProjects
|
||||
|
||||
import com.intellij.openapi.file.CanonicalPathUtil.toNioPath
|
||||
import com.intellij.openapi.file.toNioPath
|
||||
import com.intellij.openapi.project.Project
|
||||
import java.nio.file.Path
|
||||
|
||||
|
||||
+3
-3
@@ -5,8 +5,8 @@ import com.intellij.ide.impl.trustedProjects.LocatedProject
|
||||
import com.intellij.ide.impl.trustedProjects.ProjectLocator
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.application.writeAction
|
||||
import com.intellij.openapi.file.CanonicalPathUtil.getAbsoluteNioPath
|
||||
import com.intellij.openapi.file.CanonicalPathUtil.toNioPath
|
||||
import com.intellij.openapi.file.getResolvedNioPath
|
||||
import com.intellij.openapi.file.toNioPath
|
||||
import com.intellij.openapi.file.converter.NioPathPrefixTreeFactory
|
||||
import com.intellij.openapi.file.createVirtualDirectory
|
||||
import com.intellij.openapi.file.findOrCreateVirtualDirectory
|
||||
@@ -160,7 +160,7 @@ abstract class TrustedProjectsHeavyTestCase {
|
||||
) {
|
||||
val locatedProject = LocatedProject.locateProject(project)
|
||||
Assertions.assertEquals(
|
||||
relativeRoots.map { testRoot.path.getAbsoluteNioPath(it) }.toSet(),
|
||||
relativeRoots.map { testRoot.path.getResolvedNioPath(it) }.toSet(),
|
||||
locatedProject.projectRoots.toSet()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@ import com.intellij.ide.impl.trustedProjects.TrustedProjectsListener
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.application.EDT
|
||||
import com.intellij.openapi.application.writeAction
|
||||
import com.intellij.openapi.file.CanonicalPathUtil.getAbsoluteNioPath
|
||||
import com.intellij.openapi.file.CanonicalPathUtil.getAbsolutePath
|
||||
import com.intellij.openapi.file.CanonicalPathUtil.toNioPath
|
||||
import com.intellij.openapi.file.getResolvedNioPath
|
||||
import com.intellij.openapi.file.getResolvedPath
|
||||
import com.intellij.openapi.file.toNioPath
|
||||
import com.intellij.openapi.file.findOrCreateVirtualDirectory
|
||||
import com.intellij.openapi.file.getVirtualDirectory
|
||||
import com.intellij.openapi.project.Project
|
||||
@@ -97,7 +97,7 @@ abstract class GradleUntrustedProjectTestCase {
|
||||
|
||||
suspend fun linkProjectAsyncAndWait(project: Project, relativePath: String) {
|
||||
val deferred = getProjectDataLoadPromise()
|
||||
linkAndRefreshGradleProject(testRoot.path.getAbsolutePath(relativePath), project)
|
||||
linkAndRefreshGradleProject(testRoot.path.getResolvedPath(relativePath), project)
|
||||
withContext(Dispatchers.EDT) {
|
||||
withTimeout(10.minutes) {
|
||||
deferred.asDeferred().join()
|
||||
@@ -111,7 +111,7 @@ abstract class GradleUntrustedProjectTestCase {
|
||||
|
||||
fun assertTrustedLocations(relativePaths: List<String>) {
|
||||
Assertions.assertEquals(
|
||||
relativePaths.map { testRoot.path.getAbsoluteNioPath(it) }.toSet(),
|
||||
relativePaths.map { testRoot.path.getResolvedNioPath(it) }.toSet(),
|
||||
trustedLocations.toSet()
|
||||
)
|
||||
}
|
||||
@@ -122,7 +122,7 @@ abstract class GradleUntrustedProjectTestCase {
|
||||
) {
|
||||
val locatedProject = LocatedProject.locateProject(project)
|
||||
Assertions.assertEquals(
|
||||
relativePaths.map { testRoot.path.getAbsoluteNioPath(it) }.toSet(),
|
||||
relativePaths.map { testRoot.path.getResolvedNioPath(it) }.toSet(),
|
||||
locatedProject.projectRoots.toSet()
|
||||
)
|
||||
}
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ package org.jetbrains.plugins.gradle.service.project.open
|
||||
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemBundle
|
||||
import com.intellij.openapi.file.NioPathUtil.toCanonicalPath
|
||||
import com.intellij.openapi.file.toCanonicalPath
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.ui.Messages
|
||||
import com.intellij.openapi.ui.ValidationInfo
|
||||
|
||||
+4
-7
@@ -7,13 +7,10 @@ import com.intellij.openapi.externalSystem.autoimport.changes.vfs.VirtualFileCha
|
||||
import com.intellij.openapi.externalSystem.autoimport.changes.vfs.VirtualFileChangesListener.Companion.installBulkVirtualFileListener
|
||||
import com.intellij.openapi.externalSystem.util.*
|
||||
import com.intellij.openapi.file.*
|
||||
import com.intellij.openapi.file.CanonicalPathUtil.getAbsoluteNioPath
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.util.JDOMUtil
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.vfs.*
|
||||
import com.intellij.openapi.file.CanonicalPathUtil.getRelativePath
|
||||
import com.intellij.openapi.file.NioPathUtil.toCanonicalPath
|
||||
import com.intellij.openapi.vfs.newvfs.events.VFileEvent
|
||||
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess
|
||||
import com.intellij.testFramework.common.runAll
|
||||
@@ -61,7 +58,7 @@ internal class FileTestFixtureImpl(
|
||||
val configuration = createFixtureConfiguration()
|
||||
|
||||
excludedFiles = configuration.excludedFiles
|
||||
.map { root.path.getAbsoluteNioPath(it) }
|
||||
.map { root.path.getResolvedNioPath(it) }
|
||||
.toSet()
|
||||
|
||||
withSuppressedErrors {
|
||||
@@ -174,7 +171,7 @@ internal class FileTestFixtureImpl(
|
||||
}
|
||||
|
||||
override fun snapshot(relativePath: String) {
|
||||
snapshot(root.path.getAbsoluteNioPath(relativePath))
|
||||
snapshot(root.path.getResolvedNioPath(relativePath))
|
||||
}
|
||||
|
||||
private fun snapshot(path: Path) {
|
||||
@@ -191,7 +188,7 @@ internal class FileTestFixtureImpl(
|
||||
}
|
||||
|
||||
override fun rollback(relativePath: String) {
|
||||
rollback(root.path.getAbsoluteNioPath(relativePath))
|
||||
rollback(root.path.getResolvedNioPath(relativePath))
|
||||
}
|
||||
|
||||
private fun rollback(path: Path) {
|
||||
@@ -202,7 +199,7 @@ internal class FileTestFixtureImpl(
|
||||
}
|
||||
|
||||
private fun revertFile(relativePath: String, text: String?) {
|
||||
revertFile(root.path.getAbsoluteNioPath(relativePath), text)
|
||||
revertFile(root.path.getResolvedNioPath(relativePath), text)
|
||||
}
|
||||
|
||||
private fun revertFile(path: Path, text: String?) {
|
||||
|
||||
Reference in New Issue
Block a user