cleanup: move the check that a custom config migration is needed to another class

To avoid loading unnecessary resources during startup, including CustomConfigMigrationOption.kt and paths.kt.

IDEA-CR-60006, IDEA-233305

GitOrigin-RevId: cab2644f093938df2499f38839da29c1b1050ebf
This commit is contained in:
Kirill Likhodedov
2020-03-22 16:37:41 +00:00
committed by intellij-monorepo-bot
parent 11547b6d00
commit 6efb9c7c6f
3 changed files with 17 additions and 10 deletions
@@ -20,7 +20,10 @@ import com.intellij.ide.instrument.WriteIntentLockInstrumenter;
import com.intellij.ide.plugins.PluginManagerCore;
import com.intellij.ide.ui.laf.IntelliJLaf;
import com.intellij.jna.JnaLoader;
import com.intellij.openapi.application.*;
import com.intellij.openapi.application.ApplicationInfo;
import com.intellij.openapi.application.ApplicationNamesInfo;
import com.intellij.openapi.application.ConfigImportHelper;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.application.impl.ApplicationInfoImpl;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.*;
@@ -187,7 +190,7 @@ public final class StartupUtil {
// this check must be performed before system directories are locked
boolean configImportNeeded = !Main.isHeadless() &&
(!Files.exists(configPath) ||
CustomConfigMigrationOption.needsCustomConfigMigration());
ConfigImportHelper.needsCustomConfigMigration());
activity = activity.endAndStart("system dirs checking");
// note: uses config directory
@@ -168,6 +168,15 @@ public final class ConfigImportHelper {
}
}
public static boolean needsCustomConfigMigration() {
return Files.exists(getCustomConfigMarkerFilePath());
}
@NotNull
static Path getCustomConfigMarkerFilePath() {
return Paths.get(PathManager.getConfigPath(), "migrate.config");
}
@NotNull
private static File backupCurrentConfigToTemp() throws IOException {
File tempBackupDir = FileUtil.createTempDirectory("backup", "backup");
@@ -1,6 +1,7 @@
// 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.application
import com.intellij.openapi.application.ConfigImportHelper.getCustomConfigMarkerFilePath
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.util.io.FileUtil
import com.intellij.util.io.delete
@@ -22,7 +23,7 @@ sealed class CustomConfigMigrationOption {
companion object {
@JvmStatic
fun readCustomConfigMigrationOptionAndRemoveMarkerFile(): CustomConfigMigrationOption? {
val markerFile = getMarkerFilePath()
val markerFile = getCustomConfigMarkerFilePath()
if (!markerFile.exists()) return null
try {
@@ -44,9 +45,6 @@ sealed class CustomConfigMigrationOption {
}
}
@JvmStatic
fun needsCustomConfigMigration(): Boolean = Files.exists(getMarkerFilePath())
private fun removeMarkerFile(markerFile: Path) {
try {
markerFile.delete()
@@ -60,14 +58,11 @@ sealed class CustomConfigMigrationOption {
* `null` means starts with clean configs
*/
fun writeCustomConfigMigrationFile(migrateFrom: Path?) {
val markerFile = getMarkerFilePath()
val markerFile = getCustomConfigMarkerFilePath()
if (markerFile.exists()) {
log.error("Marker file $markerFile shouldn't exist")
}
markerFile.write(migrateFrom?.systemIndependentPath ?: "")
}
private fun getMarkerFilePath() = Paths.get(PathManager.getConfigPath(), "migrate.config")
}
}