summaryrefslogtreecommitdiff
path: root/jps/model-serialization/src/org/jetbrains/jps/model/serialization/PathMacroUtil.java
diff options
context:
space:
mode:
Diffstat (limited to 'jps/model-serialization/src/org/jetbrains/jps/model/serialization/PathMacroUtil.java')
-rw-r--r--jps/model-serialization/src/org/jetbrains/jps/model/serialization/PathMacroUtil.java37
1 files changed, 17 insertions, 20 deletions
diff --git a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/PathMacroUtil.java b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/PathMacroUtil.java
index 6214412c4a52..cf87eb5744b3 100644
--- a/jps/model-serialization/src/org/jetbrains/jps/model/serialization/PathMacroUtil.java
+++ b/jps/model-serialization/src/org/jetbrains/jps/model/serialization/PathMacroUtil.java
@@ -16,16 +16,19 @@
package org.jetbrains.jps.model.serialization;
import com.intellij.openapi.application.PathManager;
-import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.util.ObjectUtils;
import com.intellij.util.SystemProperties;
-import com.intellij.util.containers.HashMap;
+import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.util.Map;
+import static com.intellij.openapi.util.io.FileUtil.toSystemIndependentName;
+
/**
* @author nik
*/
@@ -34,9 +37,16 @@ public class PathMacroUtil {
@NonNls public static final String MODULE_DIR_MACRO_NAME = "MODULE_DIR";
@NonNls public static final String DIRECTORY_STORE_NAME = ".idea";
@NonNls public static final String APPLICATION_HOME_DIR = "APPLICATION_HOME_DIR";
+ @NonNls public static final String APPLICATION_CONFIG_DIR = "APPLICATION_CONFIG_DIR";
@NonNls public static final String APPLICATION_PLUGINS_DIR = "APPLICATION_PLUGINS_DIR";
@NonNls public static final String USER_HOME_NAME = "USER_HOME";
+ private static final Map<String, String> ourGlobalMacros = ContainerUtil.<String, String>immutableMapBuilder()
+ .put(APPLICATION_HOME_DIR, toSystemIndependentName(PathManager.getHomePath()))
+ .put(APPLICATION_CONFIG_DIR, toSystemIndependentName(PathManager.getConfigPath()))
+ .put(APPLICATION_PLUGINS_DIR, toSystemIndependentName(PathManager.getPluginsPath()))
+ .put(USER_HOME_NAME, StringUtil.trimEnd(toSystemIndependentName(SystemProperties.getUserHome()), "/")).build();
+
@Nullable
public static String getModuleDir(String moduleFilePath) {
File moduleDirFile = new File(moduleFilePath).getParentFile();
@@ -57,31 +67,18 @@ public class PathMacroUtil {
return moduleDir;
}
+ @NotNull
public static String getUserHomePath() {
- return StringUtil.trimEnd(FileUtil.toSystemIndependentName(SystemProperties.getUserHome()), "/");
+ return ObjectUtils.assertNotNull(getGlobalSystemMacroValue(USER_HOME_NAME));
}
+ @NotNull
public static Map<String, String> getGlobalSystemMacros() {
- final Map<String, String> map = new HashMap<String, String>();
- map.put(APPLICATION_HOME_DIR, getApplicationHomeDirPath());
- map.put(APPLICATION_PLUGINS_DIR, getApplicationPluginsDirPath());
- map.put(USER_HOME_NAME, getUserHomePath());
- return map;
- }
-
- private static String getApplicationHomeDirPath() {
- return FileUtil.toSystemIndependentName(PathManager.getHomePath());
- }
-
- private static String getApplicationPluginsDirPath() {
- return FileUtil.toSystemIndependentName(PathManager.getPluginsPath());
+ return ourGlobalMacros;
}
@Nullable
public static String getGlobalSystemMacroValue(String name) {
- if (APPLICATION_HOME_DIR.equals(name)) return getApplicationHomeDirPath();
- if (APPLICATION_PLUGINS_DIR.equals(name)) return getApplicationPluginsDirPath();
- if (USER_HOME_NAME.equals(name)) return getUserHomePath();
- return null;
+ return ourGlobalMacros.get(name);
}
}