jps: remove dependency on IntelliJ IDEA installation (IDEA-184859)

We shouldn't require idea.home.path property when running JPS from build process or a script.
This commit is contained in:
nik
2018-05-22 13:15:22 +03:00
parent ea2ac73af8
commit 625cfb6efd
3 changed files with 64 additions and 12 deletions
@@ -42,7 +42,7 @@ public class JpsModelSerializationDataService {
}
public static Map<String, String> computeAllPathVariables(JpsGlobal global) {
Map<String, String> pathVariables = new HashMap<>(PathMacroUtil.getGlobalSystemMacros());
Map<String, String> pathVariables = new HashMap<>(PathMacroUtil.getGlobalSystemMacros(false));
JpsPathVariablesConfiguration configuration = getPathVariablesConfiguration(global);
if (configuration != null) {
pathVariables.putAll(configuration.getAllUserVariables());
@@ -89,7 +89,7 @@ public class JpsModelSerializationDataService {
@Nullable
public static String getPathVariableValue(@NotNull JpsGlobal global, @NotNull String name) {
String value = PathMacroUtil.getGlobalSystemMacroValue(name);
String value = PathMacroUtil.getGlobalSystemMacroValue(name, false);
if (value != null) {
return value;
}
@@ -32,11 +32,8 @@ public class PathMacroUtil {
@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();
private static volatile Map<String, String> ourGlobalMacrosForIde;
private static volatile Map<String, String> ourGlobalMacrosForStandalone;
@Nullable
public static String getModuleDir(@NotNull String moduleFilePath) {
@@ -66,11 +63,57 @@ public class PathMacroUtil {
@NotNull
public static Map<String, String> getGlobalSystemMacros() {
return ourGlobalMacros;
return getGlobalSystemMacros(true);
}
@NotNull
public static Map<String, String> getGlobalSystemMacros(boolean insideIde) {
if (insideIde) {
if (ourGlobalMacrosForIde == null) {
ourGlobalMacrosForIde = computeGlobalPathMacrosInsideIde();
}
return ourGlobalMacrosForIde;
}
else {
if (ourGlobalMacrosForStandalone == null) {
ourGlobalMacrosForStandalone = computeGlobalPathMacrosForStandaloneCode();
}
return ourGlobalMacrosForStandalone;
}
}
private static Map<String, String> computeGlobalPathMacrosForStandaloneCode() {
ContainerUtil.ImmutableMapBuilder<String, String> builder = ContainerUtil.immutableMapBuilder();
String homePath = PathManager.getHomePath(false);
if (homePath != null) {
builder.put(APPLICATION_HOME_DIR, toSystemIndependentName(homePath))
.put(APPLICATION_CONFIG_DIR, toSystemIndependentName(PathManager.getConfigPath()))
.put(APPLICATION_PLUGINS_DIR, toSystemIndependentName(PathManager.getPluginsPath()));
}
builder.put(USER_HOME_NAME, computeUserHomePath());
return builder.build();
}
private static Map<String, String> computeGlobalPathMacrosInsideIde() {
return 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, computeUserHomePath()).build();
}
@NotNull
private static String computeUserHomePath() {
return StringUtil.trimEnd(toSystemIndependentName(SystemProperties.getUserHome()), "/");
}
@Nullable
public static String getGlobalSystemMacroValue(String name) {
return ourGlobalMacros.get(name);
return getGlobalSystemMacroValue(name, true);
}
@Nullable
public static String getGlobalSystemMacroValue(String name, boolean insideIde) {
return getGlobalSystemMacros(insideIde).get(name);
}
}
@@ -65,6 +65,15 @@ public class PathManager {
@NotNull
public static String getHomePath() {
return getHomePath(true);
}
/**
* @param insideIde {@code true} if the calling code is working inside IDE and {@code false} if it isn't (e.g. if it's running in a build
* process or a script)
*/
@Contract("true -> !null")
public static String getHomePath(boolean insideIde) {
if (ourHomePath != null) return ourHomePath;
String fromProperty = System.getProperty(PROPERTY_HOME_PATH, System.getProperty(PROPERTY_HOME));
@@ -74,7 +83,7 @@ public class PathManager {
throw new RuntimeException("Invalid home path '" + ourHomePath + "'");
}
}
else {
else if (insideIde) {
ourHomePath = getHomePathFor(PathManager.class);
if (ourHomePath == null) {
String advice = SystemInfo.isMac ? "reinstall the software." : "make sure bin/idea.properties is present in the installation directory.";
@@ -82,11 +91,11 @@ public class PathManager {
}
}
if (SystemInfo.isWindows) {
if (ourHomePath != null && SystemInfo.isWindows) {
ourHomePath = canonicalPath(ourHomePath);
}
ourBinDirectories = getBinDirectories(new File(ourHomePath));
ourBinDirectories = ourHomePath != null ? getBinDirectories(new File(ourHomePath)) : ArrayUtil.EMPTY_STRING_ARRAY;
return ourHomePath;
}