Introduce APPLICATION_CONFIG_DIR macro (IDEA-122001)

This commit is contained in:
Gregory.Shrago
2014-07-31 19:58:16 +04:00
parent 27b2d5d37c
commit a366ed77c5
@@ -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);
}
}