PathManager.getConfigDir

GitOrigin-RevId: cebd1816a05f5e557cbb162ad19ca6fc4e7c7621
This commit is contained in:
Vladimir Krivosheev
2020-01-30 17:11:07 +01:00
committed by intellij-monorepo-bot
parent 222f069ccc
commit 5bda8b1eab
22 changed files with 77 additions and 72 deletions

View File

@@ -1,5 +1,5 @@
// Copyright 2000-2019 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-2020 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.
package com.intellij.refactoring.migration;
import com.intellij.application.options.CodeStyle;
@@ -24,6 +24,8 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Set;
@@ -119,15 +121,17 @@ public class MigrationMapSet {
return ret;
}
@Nullable
private static File getMapDirectory() {
File dir = new File(PathManager.getConfigPath() + File.separator + "migration");
if (!dir.exists() && !dir.mkdirs()) {
LOG.error("cannot create directory: " + dir.getAbsolutePath());
Path dir = PathManager.getConfigDir().resolve("migration");
try {
Files.createDirectories(dir);
}
catch (IOException e) {
LOG.error("cannot create directory: " + dir, e);
return null;
}
return dir;
return dir.toFile();
}
private void copyPredefinedMaps(File dir) {

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2019 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-2020 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.
package com.intellij.testFramework;
import com.intellij.compiler.CompilerManagerImpl;
@@ -201,7 +201,7 @@ public class CompilerTester {
Map<String, String> userMacros = pathMacroManager.getUserMacros();
if (!userMacros.isEmpty()) {
// require to be presented on disk
Path configDir = Paths.get(PathManager.getConfigPath());
Path configDir = PathManager.getConfigDir();
Path macroFilePath = configDir.resolve("options").resolve(JpsGlobalLoader.PathVariablesSerializer.STORAGE_FILE_NAME);
if (!Files.exists(macroFilePath)) {
String message = "File " + macroFilePath + " doesn't exist, but user macros defined: " + userMacros;

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2018 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-2020 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.
package com.intellij.configurationStore
import com.intellij.ide.IdeBundle
@@ -110,7 +110,7 @@ open class ImportSettingsAction : AnAction(), DumbAware {
private fun getRelativeNamesToExtract(chosenComponents: Set<ExportableItem>): Set<String> {
val result = THashSet<String>()
val root = Paths.get(PathManager.getConfigPath())
val root = PathManager.getConfigDir()
for (item in chosenComponents) {
result.add(root.relativize(item.file).systemIndependentPath)
}

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2019 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-2020 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.
package com.intellij.configurationStore
import com.intellij.ide.highlighter.ProjectFileType
@@ -263,9 +263,9 @@ abstract class ProjectStoreBase(final override val project: Project) : Component
return FileUtil.isAncestor(PathUtil.getParentPath(projectFilePath), filePath, false)
}
override fun getDirectoryStorePath(ignoreProjectStorageScheme: Boolean): String? =
if (!ignoreProjectStorageScheme && !isDirectoryBased) null
else PathUtil.getParentPath(projectFilePath).nullize()
override fun getDirectoryStorePath(ignoreProjectStorageScheme: Boolean): String? {
return if (!ignoreProjectStorageScheme && !isDirectoryBased) null else PathUtil.getParentPath(projectFilePath).nullize()
}
override fun getDirectoryStoreFile(): VirtualFile? = directoryStorePath?.let { LocalFileSystem.getInstance().findFileByPath(it) }

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2019 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-2020 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.
package com.intellij.ide.plugins;
import com.intellij.openapi.application.ApplicationManager;
@@ -20,7 +20,6 @@ import java.io.IOException;
import java.lang.reflect.Method;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -61,7 +60,7 @@ public final class PluginManager {
*/
@Nullable
public static Path getOnceInstalledIfExists() {
Path onceInstalledFile = Paths.get(PathManager.getConfigPath(), INSTALLED_TXT);
Path onceInstalledFile = PathManager.getConfigDir().resolve(INSTALLED_TXT);
return Files.isRegularFile(onceInstalledFile) ? onceInstalledFile : null;
}

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2019 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-2020 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.
package com.intellij.credentialStore.keePass
import com.intellij.credentialStore.*
@@ -13,14 +13,13 @@ import com.intellij.util.io.exists
import com.intellij.util.io.safeOutputStream
import org.jetbrains.annotations.TestOnly
import java.nio.file.Path
import java.nio.file.Paths
import java.security.SecureRandom
import java.util.*
import java.util.concurrent.atomic.AtomicBoolean
internal const val DB_FILE_NAME = "c.kdbx"
internal fun getDefaultKeePassBaseDirectory() = Paths.get(PathManager.getConfigPath())
internal fun getDefaultKeePassBaseDirectory() = PathManager.getConfigDir()
internal fun getDefaultMasterPasswordFile() = getDefaultKeePassBaseDirectory().resolve(MASTER_KEY_FILE_NAME)

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2018 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-2020 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.
package com.intellij.ide.fileTemplates;
import com.intellij.openapi.application.PathManager;
@@ -7,18 +7,15 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import org.jetbrains.annotations.NotNull;
import java.io.File;
/**
* @author Dmitry Avdeev
*/
public abstract class FileTemplatesScheme implements Scheme {
public final static FileTemplatesScheme DEFAULT = new FileTemplatesScheme("Default") {
@NotNull
@Override
public String getTemplatesDir() {
return new File(PathManager.getConfigPath(), TEMPLATES_DIR).getPath();
return PathManager.getConfigDir().resolve(TEMPLATES_DIR).toString();
}
@NotNull

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2018 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-2020 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.
package com.intellij.ide.fileTemplates.impl;
import com.intellij.ide.fileTemplates.FileTemplateManager;
@@ -57,9 +57,14 @@ class FileTemplatesLoader {
private final URL myDefaultIncludeDescription;
FileTemplatesLoader(@Nullable Project project) {
Path configDir = Paths.get(project == null || project.isDefault()
? PathManager.getConfigPath()
: UriUtil.trimTrailingSlashes(Objects.requireNonNull(ProjectKt.getStateStore(project).getDirectoryStorePath(true))), TEMPLATES_DIR);
Path configDir;
if (project == null || project.isDefault()) {
configDir = PathManager.getConfigDir();
}
else {
String storeDirPath = Objects.requireNonNull(ProjectKt.getStateStore(project).getDirectoryStorePath(true));
configDir = Paths.get(storeDirPath, TEMPLATES_DIR);
}
myDefaultTemplatesManager = new FTManager(FileTemplateManager.DEFAULT_TEMPLATES_CATEGORY, configDir);
myInternalTemplatesManager = new FTManager(FileTemplateManager.INTERNAL_TEMPLATES_CATEGORY, configDir.resolve(INTERNAL_DIR), true);
@@ -134,7 +139,7 @@ class FileTemplatesLoader {
Set<ClassLoader> processedLoaders = new HashSet<>();
IdeaPluginDescriptor[] plugins = PluginManagerCore.getPlugins();
for (PluginDescriptor plugin : plugins) {
if (plugin instanceof IdeaPluginDescriptorImpl && ((IdeaPluginDescriptorImpl)plugin).isEnabled()) {
if (plugin instanceof IdeaPluginDescriptorImpl && plugin.isEnabled()) {
final ClassLoader loader = plugin.getPluginClassLoader();
if (loader instanceof PluginClassLoader && ((PluginClassLoader)loader).getUrls().isEmpty() ||
!processedLoaders.add(loader)) {

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2019 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-2020 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.
package com.intellij.util.indexing;
import com.intellij.openapi.application.PathManager;
@@ -6,6 +6,7 @@ import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.roots.ContentIterator;
import com.intellij.openapi.util.AtomicNullableLazyValue;
import com.intellij.openapi.util.NullableLazyValue;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.*;
import com.intellij.openapi.vfs.newvfs.ManagingFS;
import com.intellij.openapi.vfs.newvfs.NewVirtualFile;
@@ -19,7 +20,7 @@ abstract class IndexedFilesListener implements AsyncFileListener {
private final VfsEventsMerger myEventMerger = new VfsEventsMerger();
private static final NullableLazyValue<VirtualFile> myConfig = AtomicNullableLazyValue.createValue(() -> {
return LocalFileSystem.getInstance().findFileByIoFile(new File(PathManager.getConfigPath()));
return LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(PathManager.getConfigPath()));
});
private static final NullableLazyValue<VirtualFile> myLog = AtomicNullableLazyValue.createValue(() -> {

View File

@@ -82,9 +82,11 @@ public final class StartupUtil {
private StartupUtil() { }
/* called by the app after startup */
// called by the app after startup
public static synchronized void addExternalInstanceListener(@Nullable Function<List<String>, Future<CliResult>> processor) {
if (ourSocketLock == null) throw new AssertionError("Not initialized yet");
if (ourSocketLock == null) {
throw new AssertionError("Not initialized yet");
}
ourSocketLock.setCommandProcessor(processor);
}
@@ -131,8 +133,8 @@ public final class StartupUtil {
Method invokeMethod = clazz.getDeclaredMethod("invoke");
invokeMethod.invoke(null);
}
catch (Exception ex) {
log.error("Failed pre-app class init for class " + classBeforeAppProperty, ex);
catch (Exception e) {
log.error("Failed pre-app class init for class " + classBeforeAppProperty, e);
}
}
}
@@ -166,11 +168,11 @@ public final class StartupUtil {
}
activity = StartUpMeasurer.startMainActivity("config path computing");
String configPath = PathManager.getConfigPath();
Path configPath = PathManager.getConfigDir();
activity = activity.endAndStart("config path existence check");
// this check must be performed before system directories are locked
boolean configImportNeeded = !Main.isHeadless() && !Files.exists(Paths.get(configPath));
boolean configImportNeeded = !Main.isHeadless() && !Files.exists(configPath);
activity = activity.endAndStart("system dirs checking");
// note: uses config directory
@@ -221,7 +223,7 @@ public final class StartupUtil {
if (configImportNeeded) {
appStarter.beforeImportConfigs();
Path newConfigDir = Paths.get(PathManager.getConfigPath());
Path newConfigDir = PathManager.getConfigDir();
runInEdtAndWait(log, () -> ConfigImportHelper.importConfigsTo(newConfigDir, log), initUiTask);
appStarter.importFinished(newConfigDir);
}

View File

@@ -20,7 +20,6 @@ import org.junit.Test
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.attribute.FileTime
import java.util.function.Predicate
@@ -36,7 +35,7 @@ class ConfigImportHelperTest : BareTestFixtureTestCase() {
useAppConfigDir {
runBlocking { ApplicationManager.getApplication().stateStore.save(forceSavingAllSettings = true) }
assertThat(Paths.get(PathManager.getConfigPath()))
assertThat(PathManager.getConfigDir())
.isNotEmptyDirectory()
.satisfies(Condition(Predicate<Path> { ConfigImportHelper.isConfigDirectory(it) }, "A valid config directory"))
}

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2019 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-2020 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.
package com.intellij.openapi.fileEditor;
import com.intellij.ide.ui.UISettings;
@@ -23,11 +23,6 @@ import javax.swing.*;
import java.util.Arrays;
import java.util.List;
/**
* @author Dmitry Avdeev
* @author Vassiliy Kudryashov
*/
@SuppressWarnings("ConstantConditions")
public class FileEditorManagerTest extends FileEditorManagerTestCase {
public void testTabOrder() throws Exception {

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2019 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-2020 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.
package com.intellij.internal.statistic.eventLog.validator.persistence;
import com.intellij.openapi.application.PathManager;
@@ -9,7 +9,6 @@ import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
abstract public class BaseEventLogWhitelistPersistence {
public static final String FUS_WHITELIST_PATH = "event-log-whitelist";
@@ -19,8 +18,8 @@ abstract public class BaseEventLogWhitelistPersistence {
@NotNull
public static File getDefaultWhitelistFile(@NotNull String recorderId, @NotNull String whitelistFileName) throws IOException {
final Path configPath = Paths.get(PathManager.getConfigPath());
final Path whitelistDir = configPath
Path configPath = PathManager.getConfigDir();
Path whitelistDir = configPath
.resolve(FUS_WHITELIST_PATH)
.resolve(StringUtil.toLowerCase(recorderId));
return whitelistDir.

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2018 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-2020 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.
package com.intellij.internal.statistic.service.fus.collectors;
import com.intellij.openapi.application.PathManager;
@@ -40,12 +40,12 @@ public class FUStatisticsPersistence {
}
}
@Nullable
@NotNull
public static File getStatisticsCacheDirectory() {
return Paths.get(PathManager.getConfigPath()).resolve(FUS_CACHE_PATH + "/").toFile();
return PathManager.getConfigDir().resolve(FUS_CACHE_PATH + "/").toFile();
}
@Nullable
@NotNull
public static File getStatisticsLegacyCacheDirectory() {
return Paths.get(PathManager.getSystemPath()).resolve(FUS_CACHE_PATH).toFile();
}

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2019 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-2020 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.
package com.intellij.tasks.context;
@@ -158,7 +158,7 @@ public class WorkingContextManager {
}
private File getArchiveFile(String postfix) {
File tasksFolder = new File(PathManager.getConfigPath(), TASKS_FOLDER);
File tasksFolder = PathManager.getConfigDir().resolve(TASKS_FOLDER).toFile();
if (!tasksFolder.exists()) {
//noinspection ResultOfMethodCallIgnored
tasksFolder.mkdirs();

View File

@@ -1078,8 +1078,7 @@ public class PlatformTestUtil {
}
public static void useAppConfigDir(ThrowableRunnable<? extends Exception> task) throws Exception {
Path configDir = Paths.get(PathManager.getConfigPath());
Path configDir = PathManager.getConfigDir();
Path configCopy;
if (Files.exists(configDir)) {
configCopy = Files.move(configDir, Paths.get(configDir + "_bak"), StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2018 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-2020 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.
package com.intellij.testGuiFramework.impl
import com.intellij.ide.gdpr.EndUserAgreement
@@ -30,7 +30,7 @@ import org.fest.swing.timing.Timeout
import java.awt.Component
import java.awt.Container
import java.awt.Frame
import java.io.File
import java.nio.file.Files
import java.util.concurrent.atomic.AtomicReference
import javax.swing.*
import kotlin.concurrent.thread
@@ -73,7 +73,7 @@ abstract class FirstStart(val ideType: IdeType) {
private val newConfigFolder: Boolean by lazy {
if (ApplicationManager.getApplication() != null) throw Exception(
"Cannot get status (new or not) of config folder because IDE has been already started")
!File(PathManager.getConfigPath()).exists() || System.getProperty("intellij.first.ide.session") == "true"
!Files.exists(PathManager.getConfigDir()) || System.getProperty("intellij.first.ide.session") == "true"
}

View File

@@ -231,9 +231,16 @@ public class PathManager {
return PATHS_SELECTOR;
}
@NotNull
public static Path getConfigDir() {
return Paths.get(getConfigPath());
}
@NotNull
public static String getConfigPath() {
if (ourConfigPath != null) return ourConfigPath;
if (ourConfigPath != null) {
return ourConfigPath;
}
String explicit = getExplicitPath(PROPERTY_CONFIG_PATH);
if (explicit != null) {

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2019 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-2020 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.
package org.jetbrains.settingsRepository
import com.intellij.ide.IdeBundle
@@ -8,7 +8,6 @@ import com.intellij.openapi.application.PathManager
import com.intellij.openapi.options.ConfigurableBase
import com.intellij.openapi.options.ConfigurableUi
import com.intellij.ui.layout.*
import java.nio.file.Paths
import javax.swing.JCheckBox
internal class IcsConfigurable : ConfigurableBase<IcsConfigurableUi, IcsSettings>("ics", icsMessage("ics.settings"), "reference.settings.ics") {
@@ -18,7 +17,7 @@ internal class IcsConfigurable : ConfigurableBase<IcsConfigurableUi, IcsSettings
}
internal class IcsConfigurableUi : ConfigurableUi<IcsSettings>, Disposable {
private val icsManager = if (ApplicationManager.getApplication().isUnitTestMode) IcsManager(Paths.get(PathManager.getConfigPath()).resolve("settingsRepository")) else org.jetbrains.settingsRepository.icsManager
private val icsManager = if (ApplicationManager.getApplication().isUnitTestMode) IcsManager(PathManager.getConfigDir().resolve("settingsRepository")) else org.jetbrains.settingsRepository.icsManager
private val repositoryListEditor = createRepositoryListEditor(icsManager)
private val editors = listOf(repositoryListEditor, createReadOnlySourcesEditor())

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2018 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-2020 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.
package org.jetbrains.plugins.terminal.arrangement;
import com.intellij.openapi.application.PathManager;
@@ -131,7 +131,7 @@ public class TerminalArrangementManager implements PersistentStateComponent<Term
@NotNull
private static File getCommandHistoryDirectory() {
return new File(PathManager.getConfigPath() + File.separatorChar + "terminal" + File.separatorChar + "history");
return PathManager.getConfigDir().resolve("terminal/history").toFile();
}
private void deleteUnusedCommandHistoryFiles(@NotNull List<String> keepCommandHistoryFileNames) {

View File

@@ -141,7 +141,7 @@ class InstallVSCodePluginAction : AnAction(), DumbAware {
DownloadUtil.downloadAtomically(indicator, "${selectedValue.url}/Microsoft.VisualStudio.Services.VSIXPackage", temp)
indicator.text = "Unzipping $selectedValue..."
val extensionDir = File(File(PathManager.getConfigPath(), "vscode"), selectedValue.name)
val extensionDir = PathManager.getConfigDir().resolve("vscode").resolve(selectedValue.name).toFile()
ZipUtil.extract(temp, extensionDir, null)
indicator.text = "Applying $selectedValue"

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2019 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-2020 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.
package com.intellij.xml.util.documentation;
import com.intellij.lang.documentation.DocumentationMarkup;
@@ -116,7 +116,7 @@ public class MdnDocumentationUtil {
}
}
if (url == null) return null;
File targetDir = new File(PathManager.getConfigPath(), "mdn");
File targetDir = PathManager.getConfigDir().resolve("mdn").toFile();
File targetFile = new File(targetDir, makeUniqueFileName(url));
try {
String text = defaultDocProducer.get();