mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[platform] ConfigImportHelper API cleanup
(IDEA-149673 prerequisite)
This commit is contained in:
+36
-47
@@ -38,12 +38,8 @@ import java.util.PropertyResourceBundle;
|
||||
* @author max
|
||||
*/
|
||||
public class ConfigImportHelper {
|
||||
/**
|
||||
* Holds name of the system property that is supposed to hold <code>'true'</code> value when IDE settings have been
|
||||
* imported on the current startup
|
||||
*/
|
||||
public static final String CONFIG_IMPORTED_IN_CURRENT_SESSION_KEY = "intellij.config.imported.in.current.session";
|
||||
|
||||
private static final String CONFIG_IMPORTED_IN_CURRENT_SESSION_KEY = "intellij.config.imported.in.current.session";
|
||||
|
||||
private static final String BUILD_NUMBER_FILE = SystemInfo.isMac ? "/Resources/build.txt" : "build.txt";
|
||||
private static final String PLUGINS_PATH = "plugins";
|
||||
private static final String BIN_FOLDER = "bin";
|
||||
@@ -61,27 +57,34 @@ public class ConfigImportHelper {
|
||||
try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }
|
||||
catch (Throwable ignore) { }
|
||||
|
||||
do {
|
||||
while (true) {
|
||||
ImportOldConfigsPanel dialog = new ImportOldConfigsPanel(oldConfigDir, settings);
|
||||
dialog.setModalityType(Dialog.ModalityType.TOOLKIT_MODAL);
|
||||
AppUIUtil.updateWindowIcon(dialog);
|
||||
dialog.setVisible(true);
|
||||
if (dialog.isImportEnabled()) {
|
||||
File installationHome = dialog.getSelectedFile();
|
||||
oldConfigDir = getOldConfigDir(installationHome, settings);
|
||||
if (!validateOldConfigDir(installationHome, oldConfigDir, settings)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
assert oldConfigDir != null;
|
||||
doImport(newConfigDir, oldConfigDir, settings, installationHome);
|
||||
settings.importFinished(newConfigPath);
|
||||
System.setProperty(CONFIG_IMPORTED_IN_CURRENT_SESSION_KEY, Boolean.TRUE.toString());
|
||||
if (!dialog.isImportEnabled()) {
|
||||
break;
|
||||
}
|
||||
|
||||
File installationHome = dialog.getSelectedFile();
|
||||
oldConfigDir = getOldConfigDir(installationHome, settings);
|
||||
if (!validateOldConfigDir(installationHome, oldConfigDir, settings)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
assert oldConfigDir != null;
|
||||
doImport(newConfigDir, oldConfigDir, settings, installationHome);
|
||||
settings.importFinished(newConfigPath);
|
||||
System.setProperty(CONFIG_IMPORTED_IN_CURRENT_SESSION_KEY, Boolean.TRUE.toString());
|
||||
break;
|
||||
}
|
||||
while (true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} when the IDE is launched for the first time, and configs were imported from another installation.
|
||||
*/
|
||||
public static boolean isConfigImported() {
|
||||
return Boolean.getBoolean(CONFIG_IMPORTED_IN_CURRENT_SESSION_KEY);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -223,7 +226,7 @@ public class ConfigImportHelper {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File getOldConfigDir(@Nullable File oldInstallHome, ConfigImportSettings settings) {
|
||||
private static File getOldConfigDir(@Nullable File oldInstallHome, ConfigImportSettings settings) {
|
||||
if (oldInstallHome == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -239,7 +242,6 @@ public class ConfigImportHelper {
|
||||
int oldBuildNumber = getBuildNumber(oldInstallHome);
|
||||
|
||||
if (oldBuildNumber != -1 && oldBuildNumber <= 600) { // Pandora
|
||||
//noinspection HardCodedStringLiteral
|
||||
return new File(oldInstallHome, "config");
|
||||
}
|
||||
|
||||
@@ -251,11 +253,8 @@ public class ConfigImportHelper {
|
||||
});
|
||||
}
|
||||
|
||||
private static File getSettingsPath(final File installHome,
|
||||
final ConfigImportSettings settings,
|
||||
final String propertyName,
|
||||
final Function<String, String> fromPathSelector) {
|
||||
final File[] launchFileCandidates = getLaunchFilesCandidates(installHome, settings);
|
||||
private static File getSettingsPath(File installHome, ConfigImportSettings settings, String propertyName, Function<String, String> fromPathSelector) {
|
||||
final List<File> launchFileCandidates = getLaunchFilesCandidates(installHome, settings);
|
||||
|
||||
// custom config folder
|
||||
for (File candidate : launchFileCandidates) {
|
||||
@@ -274,10 +273,9 @@ public class ConfigImportHelper {
|
||||
if (candidate.exists()) {
|
||||
final String pathsSelector = getPropertyFromLaxFile(candidate, PathManager.PROPERTY_PATHS_SELECTOR);
|
||||
if (pathsSelector != null) {
|
||||
final String configDir = fromPathSelector.fun(pathsSelector);
|
||||
final File probableConfig = new File(configDir);
|
||||
if (probableConfig.exists()) {
|
||||
return probableConfig;
|
||||
File candidateDir = new File(fromPathSelector.fun(pathsSelector));
|
||||
if (candidateDir.exists()) {
|
||||
return candidateDir;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -286,21 +284,18 @@ public class ConfigImportHelper {
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"HardCodedStringLiteral"})
|
||||
private static File[] getLaunchFilesCandidates(@NotNull final File instHome, @NotNull final ConfigImportSettings settings) {
|
||||
private static List<File> getLaunchFilesCandidates(@NotNull File instHome, @NotNull ConfigImportSettings settings) {
|
||||
final File bin = new File(instHome, BIN_FOLDER);
|
||||
final List<File> files = new ArrayList<File>();
|
||||
if (SystemInfo.isMac) {
|
||||
// Info.plist
|
||||
files.add(new File(new File(instHome, "Contents"), "Info.plist"));
|
||||
|
||||
files.add(new File(new File(new File(bin, "idea.app"), "Contents"), "Info.plist"));
|
||||
files.add(new File(new File(new File(instHome, "idea.app"), "Contents"), "Info.plist"));
|
||||
}
|
||||
// idea.properties
|
||||
files.add(new File(bin, PathManager.PROPERTIES_FILE_NAME));
|
||||
|
||||
|
||||
// other binary scripts
|
||||
final String executableName = StringUtil.toLowerCase(settings.getExecutableName());
|
||||
// * defaults:
|
||||
@@ -312,21 +307,17 @@ public class ConfigImportHelper {
|
||||
// for compatibility with some platform-base IDEs with wrong executable names
|
||||
addLaunchExecutableScriptsCandidates(files, "idea", bin);
|
||||
}
|
||||
return files.toArray(new File[files.size()]);
|
||||
return files;
|
||||
}
|
||||
|
||||
private static void addLaunchExecutableScriptsCandidates(final List<File> files,
|
||||
final String executableName,
|
||||
final File binFolder) {
|
||||
private static void addLaunchExecutableScriptsCandidates(List<File> files, String executableName, File binFolder) {
|
||||
files.add(new File(binFolder, executableName + ".lax"));
|
||||
files.add(new File(binFolder, executableName + ".bat"));
|
||||
files.add(new File(binFolder, executableName + ".sh"));
|
||||
}
|
||||
|
||||
@SuppressWarnings({"HardCodedStringLiteral"})
|
||||
@Nullable
|
||||
public static String getPropertyFromLaxFile(@NotNull final File file,
|
||||
@NotNull final String propertyName) {
|
||||
private static String getPropertyFromLaxFile(@NotNull File file, @NotNull String propertyName) {
|
||||
if (file.getName().endsWith(".properties")) {
|
||||
try {
|
||||
PropertyResourceBundle bundle;
|
||||
@@ -359,8 +350,7 @@ public class ConfigImportHelper {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String findProperty(final String propertyName,
|
||||
final String fileContent) {
|
||||
private static String findProperty(String propertyName, String fileContent) {
|
||||
String param = propertyName + "=";
|
||||
int idx = fileContent.indexOf(param);
|
||||
if (idx == -1) {
|
||||
@@ -411,7 +401,7 @@ public class ConfigImportHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public static String fixDirName(String dir, boolean replaceUserHome) {
|
||||
private static String fixDirName(String dir, boolean replaceUserHome) {
|
||||
if (StringUtil.startsWithChar(dir, '\"') && StringUtil.endsWithChar(dir, '\"')) {
|
||||
dir = dir.substring(1, dir.length() - 1);
|
||||
}
|
||||
@@ -421,7 +411,7 @@ public class ConfigImportHelper {
|
||||
return dir;
|
||||
}
|
||||
|
||||
public static boolean isInstallationHomeOrConfig(@NotNull final String installationHome, @NotNull final ConfigImportSettings settings) {
|
||||
public static boolean isInstallationHomeOrConfig(@NotNull String installationHome, @NotNull ConfigImportSettings settings) {
|
||||
if (new File(installationHome, OPTIONS_XML).exists()) return true;
|
||||
if (new File(installationHome, CONFIG_RELATED_PATH + OPTIONS_XML).exists()) return true;
|
||||
|
||||
@@ -434,7 +424,6 @@ public class ConfigImportHelper {
|
||||
String[] mainJarNames = settings.getMainJarNames();
|
||||
for (String name : mainJarNames) {
|
||||
String mainJarName = StringUtil.toLowerCase(name) + ".jar";
|
||||
//noinspection HardCodedStringLiteral
|
||||
if (new File(libFolder, mainJarName).exists()) {
|
||||
quickTest = true;
|
||||
break;
|
||||
@@ -442,7 +431,7 @@ public class ConfigImportHelper {
|
||||
}
|
||||
if (!quickTest) return false;
|
||||
|
||||
File[] files = getLaunchFilesCandidates(new File(installationHome), settings);
|
||||
List<File> files = getLaunchFilesCandidates(new File(installationHome), settings);
|
||||
for (File file : files) {
|
||||
if (file.exists()) return true;
|
||||
}
|
||||
|
||||
+1
-1
@@ -82,7 +82,7 @@ public class UpdateCheckerComponent implements ApplicationComponent {
|
||||
notify(app, UpdateChecker.NOTIFICATIONS.createNotification(title, message, NotificationType.INFORMATION, null));
|
||||
}
|
||||
|
||||
if (!eap && current == ChannelStatus.EAP && Boolean.getBoolean(ConfigImportHelper.CONFIG_IMPORTED_IN_CURRENT_SESSION_KEY)) {
|
||||
if (!eap && current == ChannelStatus.EAP && ConfigImportHelper.isConfigImported()) {
|
||||
mySettings.setSelectedChannelStatus(ChannelStatus.RELEASE);
|
||||
LOG.info("channel set to 'release'");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -40,7 +40,7 @@ public class MainImpl {
|
||||
public void run() {
|
||||
PluginManager.installExceptionHandler();
|
||||
|
||||
if (newConfigFolder && !Boolean.getBoolean(ConfigImportHelper.CONFIG_IMPORTED_IN_CURRENT_SESSION_KEY)) {
|
||||
if (newConfigFolder && !ConfigImportHelper.isConfigImported()) {
|
||||
StartupUtil.runStartupWizard();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user