[platform] dropping obsolete/repetitive/needlessly exposed parts of PathManager API

GitOrigin-RevId: 515de04f933baefb7591bbf4d548b0a27ed2ca24
This commit is contained in:
Roman Shevchenko
2025-07-30 22:05:22 +00:00
committed by intellij-monorepo-bot
parent 3b71faab99
commit f0396467f7
7 changed files with 53 additions and 113 deletions
@@ -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);
}
}
@@ -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 <reified T : Throwable> runCatching(vararg blocks: () -> Unit
}
}
}
}
}
@@ -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<CpuArch, EelPlatform.Arch>().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())
}
}
}
@@ -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 {
}
});
}
}
}
-1
View File
@@ -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
@@ -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<Path> 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<String, String> 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() {
@@ -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<El
}
// probably running from source
File antFile = PathManager.findFileInLibDirectory(ANT_FILE);
File antFile = new File(PathManager.getLibPath(), ANT_FILE);
if (!antFile.exists()) {
antFile = new File(PathManager.getHomePath() + "/community/lib", ANT_FILE);
}
if (antFile.exists()) {
return antFile;
}