mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
WEB-6970 nodejs — detect npm/node path automatically (brew)
This commit is contained in:
+1
-13
@@ -6,8 +6,6 @@ import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.EnvironmentUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.text.CaseInsensitiveStringHashingStrategy;
|
||||
import gnu.trove.THashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -24,19 +22,9 @@ public class PathEnvironmentVariableUtil {
|
||||
|
||||
public static final String PATH_ENV_VAR_NAME = "PATH";
|
||||
private static final Logger LOG = Logger.getInstance(PathEnvironmentVariableUtil.class);
|
||||
private static final Map<String, String> ENVIRONMENT_VARIABLES;
|
||||
private static final String FIXED_MAC_PATH_VALUE;
|
||||
|
||||
static {
|
||||
Map<String, String> envVars = EnvironmentUtil.getEnvironmentProperties();
|
||||
if (SystemInfo.isWindows) {
|
||||
THashMap<String, String> map = new THashMap<String, String>(CaseInsensitiveStringHashingStrategy.INSTANCE);
|
||||
map.putAll(envVars);
|
||||
ENVIRONMENT_VARIABLES = map;
|
||||
}
|
||||
else {
|
||||
ENVIRONMENT_VARIABLES = envVars;
|
||||
}
|
||||
String fixedPathValue = null;
|
||||
try {
|
||||
fixedPathValue = calcFixedMacPathEnvVarValue();
|
||||
@@ -89,7 +77,7 @@ public class PathEnvironmentVariableUtil {
|
||||
|
||||
@Nullable
|
||||
private static String getOriginalPathEnvVarValue() {
|
||||
return ENVIRONMENT_VARIABLES.get(PATH_ENV_VAR_NAME);
|
||||
return EnvironmentUtil.getValue(PATH_ENV_VAR_NAME);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -15,13 +15,31 @@
|
||||
*/
|
||||
package com.intellij.util;
|
||||
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.util.text.CaseInsensitiveStringHashingStrategy;
|
||||
import gnu.trove.THashMap;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
public class EnvironmentUtil {
|
||||
private static final Map<String, String> ourEnvironmentProperties = Collections.unmodifiableMap(new ProcessBuilder().environment());
|
||||
private static final Map<String, String> ourEnvironmentVariablesOsSpecific;
|
||||
|
||||
static {
|
||||
Map<String, String> envVars = ourEnvironmentProperties;
|
||||
if (SystemInfo.isWindows) {
|
||||
THashMap<String, String> map = new THashMap<String, String>(CaseInsensitiveStringHashingStrategy.INSTANCE);
|
||||
map.putAll(envVars);
|
||||
ourEnvironmentVariablesOsSpecific = map;
|
||||
}
|
||||
else {
|
||||
ourEnvironmentVariablesOsSpecific = envVars;
|
||||
}
|
||||
}
|
||||
|
||||
private EnvironmentUtil() {
|
||||
}
|
||||
@@ -38,6 +56,19 @@ public class EnvironmentUtil {
|
||||
return ourEnvironmentProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns value for the passed environment variable name.
|
||||
* The passed environment variable name is handled in a case-sensitive or case-insensitive manner depending on OS.<p>
|
||||
* For example, on Windows <code>getValue("Path")</code> will return the same result as <code>getValue("PATH")</code>.
|
||||
*
|
||||
* @param name environment variable name
|
||||
* @return value of the environment variable or null if no such variable found
|
||||
*/
|
||||
@Nullable
|
||||
public static String getValue(@NotNull String name) {
|
||||
return ourEnvironmentVariablesOsSpecific.get(name);
|
||||
}
|
||||
|
||||
public static String[] getEnvironment() {
|
||||
return flattenEnvironment(getEnvironmentProperties());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user