From f0396467f72618c314b69717eca3bcdf6d16b6c2 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 30 Jul 2025 20:19:58 +0200 Subject: [PATCH] [platform] dropping obsolete/repetitive/needlessly exposed parts of `PathManager` API GitOrigin-RevId: 515de04f933baefb7591bbf4d548b0a27ed2ca24 --- .../server/WslBuildCommandLineBuilder.java | 5 +- .../eel/provider/utils/eelPathUtils.kt | 10 +- .../platform/eel/provider/utils/eelUtils.kt | 13 +- .../download/impl/FileDownloaderImpl.java | 6 +- platform/util/api-dump-unreviewed.txt | 1 - .../openapi/application/PathManager.java | 124 ++++++------------ .../config/impl/GlobalAntConfiguration.java | 7 +- 7 files changed, 53 insertions(+), 113 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/server/WslBuildCommandLineBuilder.java b/java/compiler/impl/src/com/intellij/compiler/server/WslBuildCommandLineBuilder.java index 1a6a55df730c..dbd70ceb501f 100644 --- a/java/compiler/impl/src/com/intellij/compiler/server/WslBuildCommandLineBuilder.java +++ b/java/compiler/impl/src/com/intellij/compiler/server/WslBuildCommandLineBuilder.java @@ -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.compiler.server; import com.intellij.compiler.YourKitProfilerService; @@ -14,6 +14,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.io.FileUtil; +import com.intellij.util.system.OS; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.api.GlobalOptions; @@ -186,7 +187,7 @@ final class WslBuildCommandLineBuilder implements BuildCommandLineBuilder { if (wslUserHome == null) return null; String windowsUserHomePath = distribution.getWindowsPath(wslUserHome); if (pathsSelector == null) pathsSelector = "." + ApplicationNamesInfo.getInstance().getScriptName(); - String workingDirectory = PathManager.getDefaultUnixSystemPath(windowsUserHomePath, pathsSelector) + "/" + BuildManager.SYSTEM_ROOT; + String workingDirectory = PathManager.getDefaultSystemPathFor(OS.Linux, windowsUserHomePath, pathsSelector)+ "/" + BuildManager.SYSTEM_ROOT; return Paths.get(workingDirectory); } } diff --git a/platform/eel-provider/src/com/intellij/platform/eel/provider/utils/eelPathUtils.kt b/platform/eel-provider/src/com/intellij/platform/eel/provider/utils/eelPathUtils.kt index e0d8c2bf72d7..0bb33dfc8a6a 100644 --- a/platform/eel-provider/src/com/intellij/platform/eel/provider/utils/eelPathUtils.kt +++ b/platform/eel-provider/src/com/intellij/platform/eel/provider/utils/eelPathUtils.kt @@ -1,19 +1,15 @@ // 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.provider.utils -import com.dynatrace.hash4j.hashing.Hashing import com.intellij.openapi.application.PathManager import com.intellij.openapi.components.Service import com.intellij.openapi.components.service -import com.intellij.openapi.progress.runBlockingCancellable import com.intellij.openapi.progress.runBlockingMaybeCancellable import com.intellij.openapi.project.Project -import com.intellij.openapi.util.registry.Registry import com.intellij.openapi.util.io.NioFiles +import com.intellij.openapi.util.registry.Registry import com.intellij.platform.eel.EelApi import com.intellij.platform.eel.EelDescriptor -import com.intellij.platform.eel.EelPlatform -import com.intellij.platform.eel.EelResult import com.intellij.platform.eel.fs.EelFileSystemApi import com.intellij.platform.eel.fs.createTemporaryDirectory import com.intellij.platform.eel.fs.createTemporaryFile @@ -125,7 +121,7 @@ object EelPathUtils { fun getSystemFolder(eel: EelApi): Path { val selector = PathManager.getPathsSelector() ?: "IJ-Platform" val userHomeFolder = eel.userInfo.home.asNioPath().toString() - return PathManager.getDefaultSystemPathFor(eel.platform.toPathManagerOs(), userHomeFolder, selector, eel.exec.fetchLoginShellEnvVariablesBlocking()) + return PathManager.getDefaultSystemPathFor(eel.platform.toOs(), userHomeFolder, selector, eel.exec.fetchLoginShellEnvVariablesBlocking()) } @JvmStatic @@ -978,4 +974,4 @@ private inline fun runCatching(vararg blocks: () -> Unit } } } -} \ No newline at end of file +} diff --git a/platform/eel-provider/src/com/intellij/platform/eel/provider/utils/eelUtils.kt b/platform/eel-provider/src/com/intellij/platform/eel/provider/utils/eelUtils.kt index 50ff1d15b125..b931570a2901 100644 --- a/platform/eel-provider/src/com/intellij/platform/eel/provider/utils/eelUtils.kt +++ b/platform/eel-provider/src/com/intellij/platform/eel/provider/utils/eelUtils.kt @@ -1,8 +1,6 @@ // 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.provider.utils -import com.intellij.openapi.application.PathManager -import com.intellij.openapi.extensions.ExtensionDescriptor import com.intellij.openapi.progress.runBlockingMaybeCancellable import com.intellij.platform.eel.EelExecApi import com.intellij.platform.eel.EelPlatform @@ -34,15 +32,6 @@ fun EelPlatform.toOs(): OS { } } -@ApiStatus.Internal -fun EelPlatform.toPathManagerOs(): PathManager.OS = - when (this) { - is EelPlatform.Windows -> PathManager.OS.WINDOWS - is EelPlatform.Darwin -> PathManager.OS.MACOS - is EelPlatform.Linux -> PathManager.OS.LINUX - is EelPlatform.FreeBSD -> PathManager.OS.GENERIC_UNIX - } - private val archMap by lazy { BidirectionalMap().apply { put(CpuArch.X86, EelPlatform.Arch.X86) @@ -100,4 +89,4 @@ fun EelFsError.throwFileSystemException(): Nothing { is EelFileSystemApi.DeleteError.UnresolvedLink -> throw FileSystemException(where.toString(), null, message) is EelFsError.Other -> FileSystemException(where.toString(), null, message.nullize()) } -} \ No newline at end of file +} diff --git a/platform/ide-core-impl/src/com/intellij/util/download/impl/FileDownloaderImpl.java b/platform/ide-core-impl/src/com/intellij/util/download/impl/FileDownloaderImpl.java index 622f7255098e..23ea9b938728 100644 --- a/platform/ide-core-impl/src/com/intellij/util/download/impl/FileDownloaderImpl.java +++ b/platform/ide-core-impl/src/com/intellij/util/download/impl/FileDownloaderImpl.java @@ -1,4 +1,4 @@ -// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license 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.util.download.impl; import com.intellij.ide.IdeCoreBundle; @@ -209,7 +209,7 @@ final class FileDownloaderImpl implements FileDownloader { final String url = description.getDownloadUrl(); if (url.startsWith(LIB_SCHEMA)) { final String path = FileUtil.toSystemDependentName(StringUtil.trimStart(url, LIB_SCHEMA)); - final File file = PathManager.findFileInLibDirectory(path); + final File file = new File(PathManager.getLibPath(), path); existingFiles.add(Pair.create(file, description)); } else if (url.startsWith(LocalFileSystem.PROTOCOL_PREFIX)) { @@ -336,4 +336,4 @@ final class FileDownloaderImpl implements FileDownloader { } }); } -} \ No newline at end of file +} diff --git a/platform/util/api-dump-unreviewed.txt b/platform/util/api-dump-unreviewed.txt index cc009ebaa2e4..f115437b6a69 100644 --- a/platform/util/api-dump-unreviewed.txt +++ b/platform/util/api-dump-unreviewed.txt @@ -244,7 +244,6 @@ f:com.intellij.openapi.application.PathManager - s:getBinPath():java.lang.String - s:getBundledRuntimePath():java.lang.String - s:getCommonDataPath():java.nio.file.Path -- s:getCommunityHomePath():java.lang.String - s:getConfigDir():java.nio.file.Path - s:getConfigPath():java.lang.String - s:getCustomOptionsDirectory():java.lang.String diff --git a/platform/util/src/com/intellij/openapi/application/PathManager.java b/platform/util/src/com/intellij/openapi/application/PathManager.java index 0e24508bf828..61a836195d5d 100644 --- a/platform/util/src/com/intellij/openapi/application/PathManager.java +++ b/platform/util/src/com/intellij/openapi/application/PathManager.java @@ -6,6 +6,7 @@ import com.intellij.openapi.util.SystemInfoRt; import com.intellij.openapi.util.text.StringUtilRt; import com.intellij.util.io.URLUtil; import com.intellij.util.system.CpuArch; +import com.intellij.util.system.OS; import org.jetbrains.annotations.*; import java.io.File; @@ -479,35 +480,7 @@ public final class PathManager { * Returns the path to the directory where caches are stored by default for IDE with the given path selector. */ public static @NotNull String getDefaultSystemPathFor(@NotNull String selector) { - return getDefaultSystemPathFor(getLocalOS(), System.getProperty("user.home"), selector, System.getenv()).toString(); - } - - @ApiStatus.Internal - public enum OS { - LINUX, - WINDOWS, - MACOS, - // placeholder for BSD-like systems - GENERIC_UNIX, - } - - @ApiStatus.Internal - public static @NotNull OS getLocalOS() { - if (SystemInfoRt.isMac) { - return OS.MACOS; - } - else if (SystemInfoRt.isWindows) { - return OS.WINDOWS; - } - else if (SystemInfoRt.isLinux) { - return OS.LINUX; - } - else if (SystemInfoRt.isUnix) { - return OS.GENERIC_UNIX; - } - else { - throw new UnsupportedOperationException("Unsupported OS:" + SystemInfoRt.OS_NAME); - } + return getDefaultSystemPathFor(OS.CURRENT, System.getProperty("user.home"), selector, System.getenv()).toString(); } @ApiStatus.Internal @@ -520,11 +493,6 @@ public final class PathManager { return Paths.get(platformPath(os, env, userHome, selector, "Caches", "", "LOCALAPPDATA", "", "XDG_CACHE_HOME", ".cache", "")); } - @ApiStatus.Internal - public static @NotNull String getDefaultUnixSystemPath(@NotNull String userHome, @NotNull String selector) { - return getUnixPlatformPath(userHome, System.getenv(), selector, null, ".cache", ""); - } - /** * Returns the path to the directory to store temporary files. */ @@ -854,34 +822,25 @@ public final class PathManager { return s; } - @ApiStatus.Internal - public static @NotNull File findFileInLibDirectory(@NotNull String relativePath) { - Path file = Paths.get(getLibPath(), relativePath); - if (!Files.exists(file)) file = Paths.get(getHomePath(), "community/lib/" + relativePath); - return file.toFile(); - } - /** * @return path to 'community' project home irrespective of the current project */ + @ApiStatus.Internal public static @NotNull String getCommunityHomePath() { return getCommunityHomePath(getHomePath()); } - private static boolean isDevServer() { - return Boolean.getBoolean("idea.use.dev.build.server"); - } - - private static @NotNull String getCommunityHomePath(@NotNull String homePath) { - boolean isRunningFromSources = Files.isDirectory(Paths.get(homePath, ".idea")); - if (!isRunningFromSources && !isDevServer()) return homePath; - ArrayList possibleCommunityPathList = new ArrayList<>(); - possibleCommunityPathList.add(Paths.get(homePath, "community")); - possibleCommunityPathList.add(Paths.get(homePath, "..", "..", "..", "community")); - possibleCommunityPathList.add(Paths.get(homePath, "..", "..", "..", "..", "community")); - for (Path possibleCommunityPath : possibleCommunityPathList) { - if (Files.isRegularFile(possibleCommunityPath.resolve(COMMUNITY_MARKER))) { - return possibleCommunityPath.normalize().toString(); + private static String getCommunityHomePath(String homePath) { + if (Boolean.getBoolean("idea.use.dev.build.server") || Files.isDirectory(Paths.get(homePath, ".idea"))) { + Path[] possibleCommunityPathList = { + Paths.get(homePath, "community"), + Paths.get(homePath, "..", "..", "..", "community"), + Paths.get(homePath, "..", "..", "..", "..", "community") + }; + for (Path possibleCommunityPath : possibleCommunityPathList) { + if (Files.isRegularFile(possibleCommunityPath.resolve(COMMUNITY_MARKER))) { + return possibleCommunityPath.normalize().toString(); + } } } return homePath; @@ -939,7 +898,7 @@ public final class PathManager { String winVar, String winSub, String xdgVar, String xdgDfl, String xdgSub ) { - return platformPath(getLocalOS(), System.getenv(), System.getProperty("user.home"), selector, macDir, macSub, winVar, winSub, xdgVar, xdgDfl, xdgSub); + return platformPath(OS.CURRENT, System.getenv(), System.getProperty("user.home"), selector, macDir, macSub, winVar, winSub, xdgVar, xdgDfl, xdgSub); } private static String platformPath( @@ -952,37 +911,30 @@ public final class PathManager { String xdgVar, String xdgDfl, String xdgSub ) { String vendorName = vendorName(); - - if (os == OS.MACOS) { - String dir = userHome + "/Library/" + macDir + '/' + vendorName; - if (!selector.isEmpty()) dir = dir + '/' + selector; - if (!macSub.isEmpty()) dir = dir + '/' + macSub; - return dir; + switch (os) { + case Windows: { + String dir = env.get(winVar); + if (dir == null || dir.isEmpty()) dir = userHome + "\\AppData\\" + (winVar.startsWith("LOCAL") ? "Local" : "Roaming"); + dir = dir + '\\' + vendorName; + if (!selector.isEmpty()) dir = dir + '\\' + selector; + if (!winSub.isEmpty()) dir = dir + '\\' + winSub; + return dir; + } + case macOS: { + String dir = userHome + "/Library/" + macDir + '/' + vendorName; + if (!selector.isEmpty()) dir = dir + '/' + selector; + if (!macSub.isEmpty()) dir = dir + '/' + macSub; + return dir; + } + default: { + String dir = xdgVar != null ? env.get(xdgVar) : null; + if (dir == null || dir.isEmpty()) dir = userHome + '/' + xdgDfl; + dir = dir + '/' + vendorName(); + if (!selector.isEmpty()) dir = dir + '/' + selector; + if (!xdgSub.isEmpty()) dir = dir + '/' + xdgSub; + return dir; + } } - - if (os == OS.WINDOWS) { - String dir = env.get(winVar); - if (dir == null || dir.isEmpty()) dir = userHome + "\\AppData\\" + (winVar.startsWith("LOCAL") ? "Local" : "Roaming"); - dir = dir + '\\' + vendorName; - if (!selector.isEmpty()) dir = dir + '\\' + selector; - if (!winSub.isEmpty()) dir = dir + '\\' + winSub; - return dir; - } - - if (os == OS.LINUX || os == OS.GENERIC_UNIX) { - return getUnixPlatformPath(userHome, env, selector, xdgVar, xdgDfl, xdgSub); - } - - throw new UnsupportedOperationException("Unsupported OS: " + SystemInfoRt.OS_NAME); - } - - private static String getUnixPlatformPath(String userHome, Map env, String selector, @Nullable String xdgVar, String xdgDfl, String xdgSub) { - String dir = xdgVar != null ? env.get(xdgVar) : null; - if (dir == null || dir.isEmpty()) dir = userHome + '/' + xdgDfl; - dir = dir + '/' + vendorName(); - if (!selector.isEmpty()) dir = dir + '/' + selector; - if (!xdgSub.isEmpty()) dir = dir + '/' + xdgSub; - return dir; } private static String vendorName() { diff --git a/plugins/ant/src/com/intellij/lang/ant/config/impl/GlobalAntConfiguration.java b/plugins/ant/src/com/intellij/lang/ant/config/impl/GlobalAntConfiguration.java index ed5899308110..696411487a8f 100644 --- a/plugins/ant/src/com/intellij/lang/ant/config/impl/GlobalAntConfiguration.java +++ b/plugins/ant/src/com/intellij/lang/ant/config/impl/GlobalAntConfiguration.java @@ -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.lang.ant.config.impl; import com.intellij.ide.macro.MacroManager; @@ -100,7 +100,10 @@ public final class GlobalAntConfiguration implements PersistentStateComponent