Cleanup (salvaging expandUserHome from FileUtil)

GitOrigin-RevId: 27f7b33848e0a8d20d86dfe83192cef411d03253
This commit is contained in:
Roman Shevchenko
2025-09-19 12:42:49 +00:00
committed by intellij-monorepo-bot
parent 3ee9aedd78
commit 5dfbf73d71
27 changed files with 116 additions and 105 deletions
+2 -2
View File
@@ -12,7 +12,7 @@ import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.*;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.OSAgnosticPathUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.ReadonlyStatusHandler;
@@ -92,7 +92,7 @@ public abstract class DumpDataDialog extends DialogWrapper {
}
private String getDirPath() {
return FileUtil.expandUserHome(myForm.getOutputFileOrDirectoryField().getText().trim());
return OSAgnosticPathUtil.expandUserHome(myForm.getOutputFileOrDirectoryField().getText().trim());
}
private void addDocumentListener(JTextComponent component) {
@@ -1,9 +1,10 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// 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.ide.starters.shared;
import com.intellij.ide.starters.JavaStartersBundle;
import com.intellij.openapi.observable.properties.GraphProperty;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.OSAgnosticPathUtil;
import com.intellij.psi.impl.PsiNameHelperImpl;
import java.io.File;
@@ -116,7 +117,7 @@ public final class ValidationFunctions {
public static TextValidationFunction createLocationWarningValidator(GraphProperty<String> locationProperty) {
return fieldText -> {
try {
File file = Paths.get(FileUtil.expandUserHome(FileUtil.join(locationProperty.get(), fieldText))).toFile();
File file = Paths.get(OSAgnosticPathUtil.expandUserHome(FileUtil.join(locationProperty.get(), fieldText))).toFile();
if (file.exists()) {
String[] children = file.list();
if (children != null && children.length > 0) {
@@ -133,7 +134,7 @@ public final class ValidationFunctions {
public static final TextValidationFunction CHECK_LOCATION_FOR_ERROR = fieldText -> {
Path locationPath;
try {
locationPath = Paths.get(FileUtil.expandUserHome(fieldText));
locationPath = Paths.get(OSAgnosticPathUtil.expandUserHome(fieldText));
} catch (InvalidPathException e) {
return JavaStartersBundle.message("message.specified.path.is.illegal");
}
@@ -1,9 +1,8 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// 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.util;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.util.NlsSafe;
import com.intellij.openapi.util.SystemInfoRt;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.openapi.util.io.OSAgnosticPathUtil;
@@ -11,10 +10,8 @@ import com.intellij.openapi.util.text.Strings;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.util.io.URLUtil;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.intellij.util.system.OS;
import org.jetbrains.annotations.*;
public final class PathUtil {
private PathUtil() { }
@@ -43,10 +40,10 @@ public final class PathUtil {
return getLocalPath(VirtualFileManager.extractPath(url));
}
/**
* @deprecated Use {@link FileUtil#toCanonicalPath(String)}
*/
/** @deprecated Use NIO API instead */
@Deprecated
@ApiStatus.ScheduledForRemoval
@SuppressWarnings("UsagesOfObsoleteApi")
public static String getCanonicalPath(@NonNls String path) {
return FileUtil.toCanonicalPath(path);
}
@@ -90,13 +87,11 @@ public final class PathUtil {
}
public static @NotNull String driveLetterToLowerCase(@NotNull String path) {
if (SystemInfoRt.isWindows && OSAgnosticPathUtil.isAbsoluteDosPath(path) && Character.isUpperCase(path.charAt(0))) {
return Character.toLowerCase(path.charAt(0)) + path.substring(1);
}
return path;
boolean convert = OS.CURRENT == OS.Windows && OSAgnosticPathUtil.isAbsoluteDosPath(path) && Character.isUpperCase(path.charAt(0));
return convert ? Character.toLowerCase(path.charAt(0)) + path.substring(1) : path;
}
public static @NotNull String makeFileName(@NotNull String name, @Nullable String extension) {
return extension == null || extension.isEmpty() ? name : name + '.' + extension;
}
}
}
@@ -13,7 +13,7 @@ import com.intellij.openapi.application.PathManager
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.io.OSAgnosticPathUtil
import com.intellij.platform.diagnostic.telemetry.TelemetryManager
import com.intellij.platform.diagnostic.telemetry.impl.TelemetryManagerImpl
import com.intellij.util.SystemProperties
@@ -155,7 +155,7 @@ private suspend fun logAndClearStats(projectName: String, perfFilePath: String?)
val classReport = System.getProperty("idea.log.class.list.file")
if (!classReport.isNullOrBlank()) {
generateJarAccessLog(Path.of(FileUtil.expandUserHome(classReport)))
generateJarAccessLog(Path.of(OSAgnosticPathUtil.expandUserHome(classReport)))
}
for (instantEvent in instantEvents.filter { setOf("splash shown", "splash hidden").contains(it.name) }) {
@@ -1,4 +1,4 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// 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.dvcs.ui;
import com.intellij.dvcs.DvcsRememberedInputs;
@@ -16,7 +16,7 @@ import com.intellij.openapi.ui.ValidationInfo;
import com.intellij.openapi.ui.popup.Balloon;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.OSAgnosticPathUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.*;
import com.intellij.ui.awt.RelativePoint;
@@ -231,7 +231,7 @@ public abstract class CloneDvcsDialog extends DialogWrapper {
}
private @NotNull String getCurrentUrlText() {
return FileUtil.expandUserHome(myRepositoryUrlField.getText().trim());
return OSAgnosticPathUtil.expandUserHome(myRepositoryUrlField.getText().trim());
}
/**
@@ -1,4 +1,4 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// 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.ide.util.projectWizard;
import com.intellij.BundleBase;
@@ -17,6 +17,7 @@ import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.NlsSafe;
import com.intellij.openapi.util.NotNullLazyValue;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.OSAgnosticPathUtil;
import com.intellij.openapi.util.text.HtmlChunk;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.wm.impl.welcomeScreen.AbstractActionWithPanel;
@@ -353,7 +354,7 @@ public class ProjectSettingsStepBase<T> extends AbstractActionWithPanel implemen
}
public String getProjectLocation() {
return FileUtil.expandUserHome(FileUtil.toSystemIndependentName(myLocationField.getText()));
return OSAgnosticPathUtil.expandUserHome(FileUtil.toSystemIndependentName(myLocationField.getText()));
}
public final void setLocation(final @NotNull String location) {
@@ -1,4 +1,4 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
@file:Suppress("ReplaceGetOrSet")
package com.intellij.navigation
@@ -14,7 +14,10 @@ import com.intellij.ide.impl.getProjectOriginUrl
import com.intellij.openapi.actionSystem.ActionPlaces
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.impl.SimpleDataContext
import com.intellij.openapi.application.*
import com.intellij.openapi.application.EDT
import com.intellij.openapi.application.JBProtocolCommand
import com.intellij.openapi.application.readAction
import com.intellij.openapi.application.writeIntentReadAction
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.ScrollType
import com.intellij.openapi.fileEditor.FileEditorManager
@@ -27,6 +30,7 @@ import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.startup.StartupManager
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.io.OSAgnosticPathUtil
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.VirtualFileManager
import com.intellij.openapi.wm.IdeFocusManager
@@ -194,7 +198,7 @@ class NavigatorWithinProject(
}
val locationInFile = LocationInFile(line?.toInt() ?: 0, column?.toInt() ?: 0)
path = FileUtil.expandUserHome(path)
path = OSAgnosticPathUtil.expandUserHome(path)
withBackgroundProgress(project, IdeBundle.message("navigate.command.search.reference.progress.title", pathText)) {
val virtualFile = findFileByStringPath(path) ?: return@withBackgroundProgress
val textEditor = withContext(Dispatchers.EDT) {
@@ -11,6 +11,7 @@ import com.intellij.openapi.ui.*
import com.intellij.openapi.util.NlsContexts
import com.intellij.openapi.util.NlsSafe
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.io.OSAgnosticPathUtil
import com.intellij.openapi.util.registry.Registry
import com.intellij.platform.eel.EelApi
import com.intellij.ui.CollectionComboBoxModel
@@ -45,8 +46,7 @@ class JdkDownloaderModel(
@Internal
class JdkVersionItem(
@NlsSafe
val jdkVersion: String,
val jdkVersion: @NlsSafe String,
/* we should prefer the default selected item from the JDKs.json feed,
* the list below is sorted by vendor, and default item is not necessarily first
*/
@@ -366,7 +366,7 @@ internal class JdkDownloadDialog(
private fun onTargetPathChanged(path: String) {
@Suppress("NAME_SHADOWING")
val path = FileUtil.expandUserHome(path)
val path = OSAgnosticPathUtil.expandUserHome(path)
selectedPath = path
setModel(WslPath.isWslUncPath(path))
@@ -23,6 +23,7 @@ import com.intellij.openapi.projectRoots.JdkUtil
import com.intellij.openapi.projectRoots.impl.jdkDownloader.JdkInstallerEel.unpackJdkOnEel
import com.intellij.openapi.projectRoots.impl.jdkDownloader.JdkInstallerWSL.unpackJdkOnWsl
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.io.OSAgnosticPathUtil
import com.intellij.openapi.util.registry.Registry
import com.intellij.platform.eel.*
import com.intellij.platform.eel.path.EelPath
@@ -259,7 +260,7 @@ abstract class JdkInstallerBase {
return null to ProjectBundle.message("dialog.message.error.target.path.empty")
}
val targetDir = runCatching { Path.of(FileUtil.expandUserHome(selectedPath)) }.getOrElse { t ->
val targetDir = runCatching { Path.of(OSAgnosticPathUtil.expandUserHome(selectedPath)) }.getOrElse { t ->
LOG.warn("Failed to resolve user path: $selectedPath. ${t.message}", t)
return null to ProjectBundle.message("dialog.message.error.resolving.path")
}
@@ -1,10 +1,11 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// 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.openapi.projectRoots.impl.jdkDownloader
import com.intellij.openapi.Disposable
import com.intellij.openapi.observable.properties.GraphProperty
import com.intellij.openapi.observable.properties.PropertyGraph
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.io.OSAgnosticPathUtil
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
@@ -40,7 +41,7 @@ internal class RuntimeChooserModel {
}
fun getInstallPathFromText(item: JdkItem, text: String?) : Path {
val path = text?.trim()?.takeIf { it.isNotBlank() }?.let { FileUtil.expandUserHome(it) }
val path = text?.trim()?.takeIf { it.isNotBlank() }?.let { OSAgnosticPathUtil.expandUserHome(it) }
if (path != null) {
var file = Paths.get(path)
repeat(1000) {
@@ -1,4 +1,4 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// 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.openapi.ui;
import com.intellij.openapi.Disposable;
@@ -10,7 +10,7 @@ import com.intellij.openapi.fileChooser.FileChooserFactory;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.NlsContexts;
import com.intellij.openapi.util.NlsSafe;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.OSAgnosticPathUtil;
import com.intellij.openapi.util.text.Strings;
import com.intellij.ui.TextAccessor;
import com.intellij.ui.components.JBTextField;
@@ -102,7 +102,7 @@ public class TextFieldWithBrowseButton extends ComponentWithBrowseButton<JTextFi
public @NotNull String getText() {
var text = Strings.notNullize(getTextField().getText());
if (!(this instanceof NoPathCompletion)) {
text = FileUtil.expandUserHome(text);
text = OSAgnosticPathUtil.expandUserHome(text);
}
return text;
}
@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
@file:JvmName("UiUtils")
@file:Suppress("SameParameterValue")
@@ -11,6 +11,7 @@ import com.intellij.openapi.util.Key
import com.intellij.openapi.util.NlsContexts
import com.intellij.openapi.util.NlsSafe
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.io.OSAgnosticPathUtil
import com.intellij.openapi.util.text.NaturalComparator
import com.intellij.openapi.util.text.StringUtil
import com.intellij.ui.CollectionComboBoxModel
@@ -190,9 +191,8 @@ fun getPresentablePath(path: @NonNls String): @NlsSafe String {
}
@JvmOverloads
fun getCanonicalPath(path: @NlsSafe String, removeLastSlash: Boolean = true): @NonNls String {
return FileUtil.toCanonicalPath(FileUtil.expandUserHome(path.trim()), File.separatorChar, removeLastSlash)
}
fun getCanonicalPath(path: @NlsSafe String, removeLastSlash: Boolean = true): @NonNls String =
FileUtil.toCanonicalPath(OSAgnosticPathUtil.expandUserHome(path.trim()), File.separatorChar, removeLastSlash)
/**
* Injects ellipsis into text if text width is more [maxTextWidth].
@@ -1,4 +1,4 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// 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.ide.impl
import com.intellij.ide.IdeBundle
@@ -10,7 +10,7 @@ import com.intellij.openapi.ui.DialogBuilder
import com.intellij.openapi.ui.DialogPanel
import com.intellij.openapi.ui.Messages
import com.intellij.openapi.ui.TextFieldWithBrowseButton
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.io.OSAgnosticPathUtil
import com.intellij.ui.CollectionListModel
import com.intellij.ui.ToolbarDecorator
import com.intellij.ui.components.JBList
@@ -86,7 +86,7 @@ class TrustedHostsConfigurable : BoundConfigurable(IdeBundle.message("configurab
.title(IdeBundle.message("trusted.hosts.settings.new.trusted.folder.dialog.title"))
.setNorthPanel(pathField)
.showAndGet()
return if (ok) FileUtil.expandUserHome(pathField.text) else null
return if (ok) OSAgnosticPathUtil.expandUserHome(pathField.text) else null
}
override fun getId(): String {
@@ -12,7 +12,6 @@ import com.intellij.openapi.fileChooser.ex.FileLookup.LookupFile;
import com.intellij.openapi.fileChooser.ex.FileLookup.LookupFilter;
import com.intellij.openapi.fileTypes.FileTypeRegistry;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.NioFiles;
import com.intellij.openapi.util.io.OSAgnosticPathUtil;
import com.intellij.openapi.util.text.StringUtil;
@@ -97,7 +96,7 @@ public final class LocalFsFinder implements Finder {
@Override
public String normalize(@NotNull String path) {
try {
Path file = Path.of(FileUtil.expandUserHome(path));
Path file = Path.of(OSAgnosticPathUtil.expandUserHome(path));
if (!file.isAbsolute() && myBaseDir != null) {
file = myBaseDir.resolve(path).toAbsolutePath();
}
@@ -1,4 +1,4 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// 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.openapi.fileChooser.impl;
import com.intellij.execution.process.ProcessIOExecutorService;
@@ -22,8 +22,8 @@ import com.intellij.openapi.fileTypes.FileTypeRegistry;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.util.*;
import com.intellij.openapi.util.NlsContexts.DialogMessage;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.NioFiles;
import com.intellij.openapi.util.io.OSAgnosticPathUtil;
import com.intellij.openapi.util.text.Formats;
import com.intellij.openapi.util.text.NaturalComparator;
import com.intellij.openapi.util.text.StringUtil;
@@ -254,7 +254,7 @@ final class FileChooserPanelImpl extends JBPanel<FileChooserPanelImpl> implement
return wrapper.path;
}
if (object instanceof String str && !str.isBlank()) {
var path = findByPath(FileUtil.expandUserHome(str.trim()));
var path = findByPath(OSAgnosticPathUtil.expandUserHome(str.trim()));
if (path != null && path.isAbsolute()) {
return path;
}
-9
View File
@@ -1128,15 +1128,6 @@ f:com.intellij.openapi.util.io.NioPathUtil
- sf:getResolvedPath(java.nio.file.Path,java.lang.String):java.nio.file.Path
- sf:toCanonicalPath(java.nio.file.Path):java.lang.String
- sf:toNioPathOrNull(java.lang.String):java.nio.file.Path
f:com.intellij.openapi.util.io.OSAgnosticPathUtil
- sf:COMPARATOR:java.util.Comparator
- s:getParent(java.lang.String):java.lang.String
- s:isAbsolute(java.lang.String):Z
- s:isAbsoluteDosPath(java.lang.String):Z
- s:isDriveLetter(C):Z
- s:isUncPath(java.lang.String):Z
- s:startsWith(java.lang.String,java.lang.String):Z
- s:startsWithWindowsDrive(java.lang.String):Z
f:com.intellij.openapi.util.io.StreamUtil
- sf:BUFFER_SIZE:I
- s:closeStream(java.io.Closeable):V
+10
View File
@@ -212,6 +212,16 @@ a:com.intellij.openapi.util.io.NioFiles$StatsCollectingVisitor
- visitFileFailed(java.nio.file.Path,java.io.IOException):java.nio.file.FileVisitResult
f:com.intellij.openapi.util.io.NioJarUtilKt
- sf:getJarAttribute(java.nio.file.Path,java.util.jar.Attributes$Name):java.lang.String
f:com.intellij.openapi.util.io.OSAgnosticPathUtil
- sf:COMPARATOR:java.util.Comparator
- s:expandUserHome(java.lang.String):java.lang.String
- s:getParent(java.lang.String):java.lang.String
- s:isAbsolute(java.lang.String):Z
- s:isAbsoluteDosPath(java.lang.String):Z
- s:isDriveLetter(C):Z
- s:isUncPath(java.lang.String):Z
- s:startsWith(java.lang.String,java.lang.String):Z
- s:startsWithWindowsDrive(java.lang.String):Z
com.intellij.openapi.util.registry.RegistryValueListener
- afterValueChanged(com.intellij.openapi.util.registry.RegistryValue):V
- beforeValueChanged(com.intellij.openapi.util.registry.RegistryValue):V
@@ -1310,17 +1310,12 @@ public class FileUtil {
return path;
}
/** @deprecated use {@link OSAgnosticPathUtil#expandUserHome} instead. */
@Contract(pure = true)
@Deprecated
@ApiStatus.ScheduledForRemoval
public static @NotNull String expandUserHome(@NotNull String path) {
if (path.equals("~")) {
return SystemProperties.getUserHome();
}
else if (path.startsWith("~/") || path.startsWith("~\\")) {
return SystemProperties.getUserHome() + path.substring(1);
}
else {
return path;
}
return OSAgnosticPathUtil.expandUserHome(path);
}
public static File @NotNull [] notNullize(File @Nullable [] files) {
@@ -1,10 +1,12 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// 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.openapi.util.io;
import com.intellij.openapi.util.SystemInfoRt;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.util.text.Strings;
import com.intellij.util.PathUtilRt;
import com.intellij.util.SystemProperties;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -169,4 +171,17 @@ public final class OSAgnosticPathUtil {
public static boolean isDriveLetter(char c) {
return 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z';
}
@Contract(pure = true)
public static @NotNull String expandUserHome(@NotNull String path) {
if (path.equals("~")) {
return SystemProperties.getUserHome();
}
else if (path.startsWith("~/") || path.startsWith("~\\")) {
return SystemProperties.getUserHome() + path.substring(1);
}
else {
return path;
}
}
}
@@ -1,4 +1,4 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// 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.openapi.vcs.changes.patch
import com.intellij.ide.IdeBundle
@@ -8,6 +8,7 @@ import com.intellij.openapi.fileChooser.FileSaverDescriptor
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.*
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.io.OSAgnosticPathUtil
import com.intellij.openapi.vcs.VcsBundle.message
import com.intellij.openapi.vfs.CharsetToolkit
import com.intellij.openapi.vfs.encoding.EncodingProjectManager
@@ -116,13 +117,9 @@ class CreatePatchConfigurationPanel(val project: Project) {
return panel
}
fun getFileName(): String {
return FileUtil.expandUserHome(fileNameField.text.trim())
}
fun getFileName(): String = OSAgnosticPathUtil.expandUserHome(fileNameField.text.trim())
fun getBaseDirName(): String {
return FileUtil.expandUserHome(basePathField.getText().trim())
}
fun getBaseDirName(): String = OSAgnosticPathUtil.expandUserHome(basePathField.text.trim())
fun setFileName(file: Path) {
fileNameField.text = file.toString()
@@ -185,4 +182,4 @@ class CreatePatchConfigurationPanel(val project: Project) {
}
return null
}
}
}
@@ -1,8 +1,8 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.idea.maven.wizards.archetype
import com.intellij.openapi.ui.validation.validationErrorFor
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.io.OSAgnosticPathUtil
import com.intellij.util.text.nullize
import org.jetbrains.idea.maven.indices.archetype.MavenCatalog
import org.jetbrains.idea.maven.indices.archetype.MavenCatalogManager
@@ -32,7 +32,7 @@ internal fun createCatalog(location: String): MavenCatalog? {
return null
}
internal fun getPathOrError(location: String) = runCatching { Path(FileUtil.expandUserHome(location)) }
internal fun getPathOrError(location: String) = runCatching { Path(OSAgnosticPathUtil.expandUserHome(location)) }
internal fun getUrlOrError(location: String) = runCatching { URL(location) }
internal fun getPathOrNull(location: String) = getPathOrError(location).getOrNull()
@@ -77,4 +77,4 @@ private fun validateRemoteLocation(location: String): String? {
return MavenWizardBundle.message("maven.new.project.wizard.archetype.catalog.dialog.location.error.invalid", message)
}
return null
}
}
@@ -3,7 +3,7 @@ package com.intellij.mcpserver.impl
import com.intellij.mcpserver.clientConfiguration.*
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.SystemInfo
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.io.OSAgnosticPathUtil
import com.intellij.util.containers.addIfNotNull
import kotlinx.serialization.ExperimentalSerializationApi
import java.nio.file.Path
@@ -78,7 +78,7 @@ object McpClientDetector {
else -> null
}
if (configPath == null) return null
val path = Paths.get(FileUtil.expandUserHome(configPath))
val path = Paths.get(OSAgnosticPathUtil.expandUserHome(configPath))
if (path.exists() && path.isRegularFile()) {
return VSCodeClient(path)
}
@@ -93,7 +93,7 @@ object McpClientDetector {
else -> null
}
if (configPath == null) return null
val path = Paths.get(FileUtil.expandUserHome(configPath))
val path = Paths.get(OSAgnosticPathUtil.expandUserHome(configPath))
if (path.exists() && path.isRegularFile()) {
return ClaudeCodeMcpClient(path)
@@ -109,7 +109,7 @@ object McpClientDetector {
else -> null
}
if (configPath == null) return null
val path = Paths.get(FileUtil.expandUserHome(configPath))
val path = Paths.get(OSAgnosticPathUtil.expandUserHome(configPath))
if (path.parent.exists() && path.parent.toFile().isDirectory()) {
return ClaudeMcpClient(path)
@@ -118,7 +118,7 @@ object McpClientDetector {
}
private fun detectCursorGlobal(): McpClient? {
val path = Paths.get(FileUtil.expandUserHome("~/.cursor/mcp.json"))
val path = Paths.get(OSAgnosticPathUtil.expandUserHome("~/.cursor/mcp.json"))
if (path.parent.exists() && path.parent.toFile().isDirectory()) {
return CursorClient(path)
}
@@ -126,7 +126,7 @@ object McpClientDetector {
}
private fun detectWindsurf(): McpClient? {
val path = Paths.get(FileUtil.expandUserHome("~/.codeium/windsurf/mcp_config.json"))
val path = Paths.get(OSAgnosticPathUtil.expandUserHome("~/.codeium/windsurf/mcp_config.json"))
if (path.parent.exists() && path.parent.toFile().isDirectory()) {
return WindsurfClient(path)
}
@@ -162,4 +162,4 @@ object McpClientDetector {
}
return null
}
}
}
@@ -10,9 +10,11 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ProjectManager
import com.intellij.openapi.project.guessProjectForContentFile
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.io.OSAgnosticPathUtil
import com.intellij.openapi.util.text.StringUtilRt
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.util.PathUtil
import com.intellij.util.PathUtilRt
import io.netty.channel.ChannelHandlerContext
import io.netty.handler.codec.http.*
@@ -93,12 +95,12 @@ internal class OpenFileHttpService : RestService() {
if (requestedFile == null) {
return parameterMissedErrorMessage("file")
}
if (PathUtilRt.startsWithSeparatorSeparator(FileUtil.toSystemIndependentName(requestedFile))) {
if (PathUtilRt.startsWithSeparatorSeparator(PathUtil.toSystemIndependentName(requestedFile))) {
return "UNC paths are not supported"
}
val vfsPath = FileUtil.toSystemIndependentName(FileUtil.expandUserHome(requestedFile))
val file = Path.of(FileUtil.toSystemDependentName(vfsPath))
val vfsPath = PathUtil.toSystemIndependentName(OSAgnosticPathUtil.expandUserHome(requestedFile))
val file = Path.of(PathUtil.toSystemDependentName(vfsPath))
val fileAndProject = if (!file.isAbsolute) {
findByRelativePath(FileUtil.toCanonicalPath(vfsPath, '/'))
}
@@ -1,4 +1,4 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.settingsRepository
import com.intellij.configurationStore.StreamProvider
@@ -20,7 +20,7 @@ import com.intellij.openapi.progress.runBackgroundableTask
import com.intellij.openapi.progress.runBlockingCancellable
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ProjectCloseListener
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.io.OSAgnosticPathUtil
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.channels.BufferOverflow
@@ -246,7 +246,7 @@ private class IcsManagerService(private val coroutineScope: CoroutineScope) {
fun init(app: Application, configPath: Path) {
val customPath = System.getProperty("ics.settingsRepository")
val dir = if (customPath == null) configPath.resolve("settingsRepository") else Path.of(FileUtil.expandUserHome(customPath))
val dir = if (customPath == null) configPath.resolve("settingsRepository") else Path.of(OSAgnosticPathUtil.expandUserHome(customPath))
val icsManager = IcsManager(dir = dir, coroutineScope = coroutineScope)
this.icsManager = icsManager
icsManager.beforeApplicationLoaded(app)
@@ -261,4 +261,4 @@ private class IcsApplicationLoadListener : ApplicationLoadListener {
application.serviceAsync<IcsManagerService>().init(application, configPath)
}
}
}
@@ -10,7 +10,7 @@ import com.intellij.openapi.editor.Caret;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.OSAgnosticPathUtil;
import com.intellij.patterns.StandardPatterns;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
@@ -31,7 +31,6 @@ import java.util.List;
import static com.intellij.patterns.PlatformPatterns.psiElement;
import static com.intellij.sh.ShStringUtil.quote;
import static com.intellij.sh.ShStringUtil.unquote;
public class ShFilePathCompletionContributor extends CompletionContributor implements DumbAware {
private static final InsertHandler<LookupElement> FILE_INSERT_HANDLER = (context, item) -> {
@@ -95,7 +94,7 @@ public class ShFilePathCompletionContributor extends CompletionContributor imple
if (beforeSlash.startsWith("/") || isRoot || beforeSlash.startsWith("~")) { // absolute paths
String path = beforeSlash.equals("~") ? "~/" : beforeSlash;
String maybeFilePath = FileUtil.expandUserHome(unquote(path));
String maybeFilePath = OSAgnosticPathUtil.expandUserHome(ShStringUtil.unquote(path));
File dir = isRoot ? new File("/") : new File(maybeFilePath);
if (dir.exists() && dir.isDirectory()) {
File[] files = dir.listFiles();
@@ -168,4 +167,4 @@ public class ShFilePathCompletionContributor extends CompletionContributor imple
if (index + 1 <= 0) return variable;
return variable.substring(index + 1);
}
}
}
@@ -1,10 +1,10 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.plugins.terminal.block.completion.spec
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Key
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.io.OSAgnosticPathUtil
import com.intellij.terminal.completion.spec.ShellFileInfo
import com.intellij.terminal.completion.spec.ShellRuntimeContext
import org.jetbrains.annotations.ApiStatus
@@ -51,7 +51,7 @@ suspend fun ShellRuntimeContext.getChildFiles(
private suspend fun ShellRuntimeContext.getChildFilesReworked(path: String, onlyDirectories: Boolean): List<ShellFileInfo> {
check(isReworkedTerminal)
val adjustedPath = FileUtil.expandUserHome(path)
val adjustedPath = OSAgnosticPathUtil.expandUserHome(path)
val absolutePath = try {
val nioPath = Path(adjustedPath)
if (nioPath.isAbsolute) {
@@ -92,4 +92,4 @@ private suspend fun ShellRuntimeContext.getChildFilesExp(path: String, onlyDirec
ShellFileInfoImpl(it.removeSuffix(separator.toString()), type)
}
.toList()
}
}
@@ -9,8 +9,8 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.NioFiles;
import com.intellij.openapi.util.io.OSAgnosticPathUtil;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.platform.eel.EelDescriptor;
@@ -262,7 +262,7 @@ public final class LocalShellIntegrationInjector {
if (idx >= 0) {
arguments.remove(idx);
if (idx < arguments.size()) {
String userRcFile = FileUtil.expandUserHome(arguments.get(idx));
String userRcFile = OSAgnosticPathUtil.expandUserHome(arguments.get(idx));
// do not set the same RC file path to avoid sourcing recursion
if (!userRcFile.equals(rcFilePath)) {
envs.put(JEDITERM_USER_RCFILE, userRcFile);