void (boolean veryFirstStartOnThisComputer, @NotNull Path newConfigDir, @NotNull List<String> args, @NotNull Logger log) { log.info("Importing configs to " + newConfigDir); System.setProperty(FIRST_SESSION_KEY, Boolean.TRUE.toString()); var customMigrationOption = CustomConfigMigrationOption.readCustomConfigMigrationOptionAndRemoveMarkerFile(newConfigDir); log.info("Custom migration option: " + customMigrationOption); if (customMigrationOption instanceof CustomConfigMigrationOption.SetProperties sp) { List<String> properties = sp.getProperties(); log.info("Enabling system properties after restart: " + properties); for (String property : properties) System.setProperty(property, Boolean.TRUE.toString()); return; } ConfigImportSettings settings = findCustomConfigImportSettings(); log.info("Custom ConfigImportSettings instance: " + settings); List<String> otherProductPrefixes = settings != null ? settings.getProductsToImportFrom(args) : List.of(); ConfigDirsSearchResult guessedOldConfigDirs = findConfigDirectories(newConfigDir, settings, otherProductPrefixes); Path tempBackup = null; boolean vmOptionFileChanged = false; ImportOldConfigsState.InitialImportScenario importScenarioStatistics = null; try { Pair<Path, Path> oldConfigDirAndOldIdePath = null; if (customMigrationOption instanceof CustomConfigMigrationOption.MigrateFromCustomPlace || customMigrationOption instanceof CustomConfigMigrationOption.StartWithCleanConfig) { vmOptionFileChanged = doesVmOptionsFileExist(newConfigDir); try { if (customMigrationOption instanceof CustomConfigMigrationOption.MigrateFromCustomPlace mcp) { tempBackup = backupCurrentConfigToTempAndDelete(newConfigDir, log, false, settings); oldConfigDirAndOldIdePath = findConfigDirectoryByPath(mcp.getLocation()); importScenarioStatistics = IMPORT_SETTINGS_ACTION; } else { tempBackup = backupCurrentConfigToTempAndDelete(newConfigDir, log, true, settings); importScenarioStatistics = RESTORE_DEFAULT_ACTION; } } catch (IOException e) { log.error("Couldn't backup current config or delete current config directory", e); } } else if (IdeStartupWizardKt.isIdeStartupWizardEnabled()) { if (!guessedOldConfigDirs.isEmpty() && !shouldAskForConfig()) { Pair<Path, FileTime> bestConfigGuess = guessedOldConfigDirs.getFirstItem(); if (!isConfigOld(bestConfigGuess.second)) { oldConfigDirAndOldIdePath = findConfigDirectoryByPath(bestConfigGuess.first); if (oldConfigDirAndOldIdePath == null) { log.info("Previous config directory was detected but not accepted: " + bestConfigGuess.first); importScenarioStatistics = CONFIG_DIRECTORY_NOT_FOUND; } } } } else { boolean askForConfig = shouldAskForConfig(); if (askForConfig) { oldConfigDirAndOldIdePath = showDialogAndGetOldConfigPath(guessedOldConfigDirs.getPaths()); importScenarioStatistics = SHOW_DIALOG_REQUESTED_BY_PROPERTY; } else if (guessedOldConfigDirs.isEmpty()) { boolean importedFromCloud = false; CloudConfigProvider configProvider = CloudConfigProvider.getProvider(); if (configProvider != null) { importedFromCloud = configProvider.importSettingsSilently(newConfigDir); if (importedFromCloud) { importScenarioStatistics = IMPORTED_FROM_CLOUD; } } if (!importedFromCloud && !veryFirstStartOnThisComputer) { oldConfigDirAndOldIdePath = showDialogAndGetOldConfigPath(guessedOldConfigDirs.getPaths()); importScenarioStatistics = SHOW_DIALOG_NO_CONFIGS_FOUND; } } else { Pair<Path, FileTime> bestConfigGuess = guessedOldConfigDirs.getFirstItem(); if (isConfigOld(bestConfigGuess.second)) { log.info("The best config guess [" + bestConfigGuess.first + "] is too old, it won't be used for importing."); oldConfigDirAndOldIdePath = showDialogAndGetOldConfigPath(guessedOldConfigDirs.getPaths()); importScenarioStatistics = SHOW_DIALOG_CONFIGS_ARE_TOO_OLD; } else { oldConfigDirAndOldIdePath = findConfigDirectoryByPath(bestConfigGuess.first); if (oldConfigDirAndOldIdePath == null) { log.info("Previous config directory was detected but not accepted: " + bestConfigGuess.first); importScenarioStatistics = CONFIG_DIRECTORY_NOT_FOUND; } } } } if (oldConfigDirAndOldIdePath != null) { Path oldConfigDir = oldConfigDirAndOldIdePath.first; Path oldIdeHome = oldConfigDirAndOldIdePath.second; var configImportOptions = new ConfigImportOptions(log); configImportOptions.importSettings = settings; configImportOptions.mergeVmOptions = customMigrationOption instanceof CustomConfigMigrationOption.MergeConfigs; if (!guessedOldConfigDirs.fromSameProduct) { importScenarioStatistics = IMPORTED_FROM_OTHER_PRODUCT; } else if (importScenarioStatistics == null) { importScenarioStatistics = IMPORTED_FROM_PREVIOUS_VERSION; } System.setProperty( guessedOldConfigDirs.fromSameProduct ? CONFIG_IMPORTED_FROM_PREVIOUS_VERSION_KEY : CONFIG_IMPORTED_FROM_OTHER_PRODUCT_KEY, oldConfigDir.toString()); doImport(oldConfigDir, newConfigDir, oldIdeHome, log, configImportOptions); setConfigImportedInThisSession(); } else { log.info("No configs imported, starting with clean configs at " + newConfigDir); if (importScenarioStatistics == null) { importScenarioStatistics = CLEAN_CONFIGS; } } if (settings != null) { settings.importFinished(newConfigDir, otherProductPrefixes); } ImportOldConfigsState.Companion.getInstance().reportImportScenario(importScenarioStatistics); vmOptionFileChanged |= doesVmOptionsFileExist(newConfigDir); } finally { if (tempBackup != null) { try { moveTempBackupToStandardBackup(newConfigDir, tempBackup); } catch (IOException e) { log.warn(String.format("Couldn't move the backup of current config from temp dir [%s] to backup dir", tempBackup), e); } } } // TODO remove hack, should we support vmoptions import in per project? // TODO If so, we need to patch restarter. if (vmOptionFileChanged && !ProjectManagerEx.IS_PER_PROJECT_INSTANCE_ENABLED) { log.info("The vmoptions file has changed, restarting..."); List<String> properties = new ArrayList<>(); properties.add(FIRST_SESSION_KEY); if (isConfigImported()) { properties.add(CONFIG_IMPORTED_IN_CURRENT_SESSION_KEY); } if (settings == null || settings.shouldRestartAfterVmOptionsChange()) { new CustomConfigMigrationOption.SetProperties(properties).writeConfigMarkerFile(); restart(args); } } }