[platform] refactoring: make PathManager.getOriginalConfigDir return the actual path if custom wasn't set

This simplifies code because most of the clients need to use the actual path if the custom wasn't set. PerProcessPathCustomizer.isEnabled method is added for the cases where we need to check whether a custom path was actually set.

GitOrigin-RevId: 6a2f67463cb117570cd4c9e9a6d7492b71dfff9b
This commit is contained in:
Nikolay Chashnikov
2023-10-19 16:35:23 +02:00
committed by intellij-monorepo-bot
parent 6a4313077a
commit 77ee53c4e1
4 changed files with 11 additions and 8 deletions

View File

@@ -31,6 +31,7 @@ public final class PerProcessPathCustomizer implements PathCustomizer {
// Leave the folder locked until we exit. Store reference to keep CleanerFactory from releasing the file channel.
@SuppressWarnings("unused") private static FileLock ourConfigLock;
private static volatile boolean enabled;
@Override
public CustomPaths customizePaths() {
@@ -83,10 +84,14 @@ public final class PerProcessPathCustomizer implements PathCustomizer {
e.printStackTrace();
}
Path startupScriptDir = PathManager.getSystemDir().resolve("startup-script");
enabled = true;
return new CustomPaths(newConfig.toString(), newSystem.toString(), PathManager.getPluginsPath(), newLog.toString(), startupScriptDir);
}
public static boolean isEnabled() {
return enabled;
}
private static @Nullable Path computeLogDirPath(Path baseLogDir, int directoryCounter) {
String namePrefix = DateTimeFormatter.ofPattern("yyyy-MM-dd_'at'_HH-mm-ss").format(LocalDateTime.now());
String nameSuffix = directoryCounter > 0 ? "_" + directoryCounter : "";

View File

@@ -18,7 +18,6 @@ import com.intellij.util.net.ssl.ConfirmingTrustManager.MutableTrustManager
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.jetbrains.annotations.NonNls
import java.io.File
import java.io.IOException
import java.nio.charset.StandardCharsets
import java.nio.file.FileAlreadyExistsException
@@ -97,7 +96,7 @@ class CertificateManager : PersistentStateComponent<CertificateManager.Config?>
companion object {
const val COMPONENT_NAME: @NonNls String = "Certificate Manager"
@JvmField
val DEFAULT_PATH: @NonNls String = java.lang.String.join(File.separator, PathManager.getOriginalConfigDir()?.pathString ?: PathManager.getConfigPath(), "ssl", "cacerts")
val DEFAULT_PATH: @NonNls String = PathManager.getOriginalConfigDir().resolve("ssl").resolve("cacerts").pathString
@Suppress("SpellCheckingInspection")
const val DEFAULT_PASSWORD: @NonNls String = "changeit"
private val LOG = logger<CertificateManager>()

View File

@@ -5,7 +5,6 @@ import com.intellij.openapi.application.PathManager
import com.intellij.openapi.diagnostic.Logger
import com.intellij.util.net.ssl.ConfirmingTrustManager
import com.intellij.util.net.ssl.ConfirmingTrustManager.MutableTrustManager
import java.io.File
import java.security.KeyStore
import java.security.cert.X509Certificate
import kotlin.io.path.Path
@@ -16,7 +15,7 @@ import kotlin.io.path.pathString
object PluginCertificateStore {
private val LOG = Logger.getInstance(PluginCertificateStore::class.java)
private val MANAGED_TRUSTSTORE_PATH = System.getProperty("intellij.plugin.truststore", "")
private val DEFAULT_PATH = java.lang.String.join(File.separator, PathManager.getOriginalConfigDir()?.pathString ?: PathManager.getConfigPath(), "ssl", "plugins-certs")
private val DEFAULT_PATH = PathManager.getOriginalConfigDir().resolve("ssl").resolve("plugins-certs").pathString
private const val DEFAULT_PASSWORD = "changeit"
val customTrustManager: MutableTrustManager by lazy {
ConfirmingTrustManager.createForStorage(DEFAULT_PATH, DEFAULT_PASSWORD).customManager

View File

@@ -657,11 +657,11 @@ public final class PathManager {
}
/**
* Return original value of the config path, if it was changed via {@link PathCustomizer}, or {@code null} if no custom paths were set.
* Return original value of the config path ignoring possible customizations made by {@link PathCustomizer}.
*/
@ApiStatus.Internal
public static @Nullable Path getOriginalConfigDir() {
return ourOriginalConfigDir;
public static @NotNull Path getOriginalConfigDir() {
return ourOriginalConfigDir != null ? ourOriginalConfigDir : getConfigDir();
}
private static String getCustomPropertiesFile() {