return platformPath(selector, "Library/Preferences", CONFIG_FOLDER);
}
- @NotNull
- public static String getDefaultPluginPathFor(@NotNull String selector) {
- return platformPath(selector, "Library/Application Support", PLUGINS_FOLDER);
- }
-
public static void ensureConfigFolderExists() {
checkAndCreate(getConfigPath(), true);
}
return ourPluginsPath;
}
+ @NotNull
+ public static String getDefaultPluginPathFor(@NotNull String selector) {
+ return platformPath(selector, "Library/Application Support", PLUGINS_FOLDER);
+ }
+
// runtime paths
@NotNull
return resultPath;
}
- public static String getUserPropertiesPath() {
- if (PATHS_SELECTOR != null) {
- return platformPath(PATHS_SELECTOR, "Library/Preferences", ".");
- }
- else {
- return getUserHome();
- }
- }
-
public static void loadProperties() {
String[] propFiles = {
System.getProperty(PROPERTIES_FILE),
- getUserPropertiesPath() + "/idea.properties",
+ getUserPropertiesPath(),
getHomePath() + "/bin/idea.properties",
getHomePath() + "/community/bin/idea.properties"};
Properties sysProperties = System.getProperties();
for (String key : properties.keySet()) {
- if (sysProperties.getProperty(key, null) == null) { // load the property from the property file only if it is not defined yet
+ if (sysProperties.getProperty(key, null) == null) { // do not override already defined properties
String value = substituteVars(properties.get(key));
sysProperties.setProperty(key, value);
}
}
}
+ private static String getUserPropertiesPath() {
+ if (PATHS_SELECTOR != null) {
+ // do not use getConfigPath() here - as it may be not yet defined
+ return platformPath(PATHS_SELECTOR, "Library/Preferences", /*"APPDATA", "XDG_CONFIG_HOME", ".config",*/ "") + "/idea.properties";
+ }
+ else {
+ return getUserHome() + "/.idea.properties";
+ }
+ }
+
@Contract("null -> null")
public static String substituteVars(String s) {
return substituteVars(s, getHomePath());
}
// todo[r.sh] XDG directories, Windows folders
- private static String platformPath(String selector, String macDir, String fallback) {
- if (SystemInfo.isMac) {
- return getUserHome() + File.separator + macDir + File.separator + selector;
+ // http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
+ // http://www.microsoft.com/security/portal/mmpc/shared/variables.aspx
+ private static String platformPath(@NotNull String selector, @Nullable String macPart, @NotNull String fallback) {
+ return platformPath(selector, macPart, null, null, null, fallback);
+ }
+
+ private static String platformPath(@NotNull String selector,
+ @Nullable String macPart,
+ @Nullable String winVar,
+ @Nullable String xdgVar,
+ @Nullable String xdgDir,
+ @NotNull String fallback) {
+ if (macPart != null && SystemInfo.isMac) {
+ return getUserHome() + File.separator + macPart + File.separator + selector;
+ }
+
+ if (winVar != null && SystemInfo.isWindows) {
+ String dir = System.getenv(winVar);
+ if (dir != null) {
+ return dir + File.separator + selector;
+ }
}
- else {
- return getUserHome() + File.separator + "." + selector + File.separator + fallback;
+
+ if (xdgVar != null && xdgDir != null && SystemInfo.hasXdgOpen()) {
+ String dir = System.getenv(xdgVar);
+ if (dir == null) dir = getUserHome() + File.separator + xdgDir;
+ return dir + File.separator + selector;
}
+
+ return getUserHome() + File.separator + "." + selector + (!fallback.isEmpty() ? File.separator + fallback : "");
}
private static boolean checkAndCreate(String path, boolean createIfNotExists) {