mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Revert "Fix EnvironmentUtil.inlineParentOccurrences() for Windows (ignore case)" as it breaks clients
This reverts commit a69ef6b
This commit is contained in:
@@ -54,13 +54,6 @@ public class EnvironmentUtil {
|
||||
|
||||
private static final Future<Map<String, String>> ourEnvGetter;
|
||||
|
||||
/**
|
||||
* String that is used as a delimiter for referencing parent environment variable.
|
||||
* <code>"%"</code> on Microsoft Windows;
|
||||
* <code>"$"</code> on Unix systems
|
||||
*/
|
||||
public static final String PARENT_ENV_KEY_DELIMITER = SystemInfo.isWindows ? "%" : "$";
|
||||
|
||||
static {
|
||||
if (SystemInfo.isMac &&
|
||||
"unlocked".equals(System.getProperty("__idea.mac.env.lock")) &&
|
||||
@@ -381,7 +374,7 @@ public class EnvironmentUtil {
|
||||
}
|
||||
|
||||
public static void inlineParentOccurrences(@NotNull Map<String, String> envs) {
|
||||
inlineParentOccurrences(envs, getEnvironmentMap());
|
||||
inlineParentOccurrences(envs, new HashMap<String, String>(System.getenv()));
|
||||
}
|
||||
|
||||
public static void inlineParentOccurrences(@NotNull Map<String, String> envs, @NotNull Map<String, String> parentEnv) {
|
||||
@@ -389,26 +382,18 @@ public class EnvironmentUtil {
|
||||
String key = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
if (value != null) {
|
||||
final String parentVal = parentEnv.get(key);
|
||||
if (parentVal != null) {
|
||||
StringBuilder newValue = new StringBuilder();
|
||||
final String keySubstitution = PARENT_ENV_KEY_DELIMITER + key + PARENT_ENV_KEY_DELIMITER;
|
||||
for (String part : StringUtil.split(value, File.pathSeparator)) {
|
||||
if (SystemInfo.isWindows) {
|
||||
newValue.append(part.equalsIgnoreCase(keySubstitution) ? parentVal : part);
|
||||
}
|
||||
else {
|
||||
newValue.append(part.equals(keySubstitution) ? parentVal : part);
|
||||
}
|
||||
newValue.append(File.pathSeparator);
|
||||
}
|
||||
newValue.trimToSize();
|
||||
envs.put(key, newValue.substring(0, newValue.length() - File.pathSeparator.length()));
|
||||
String parentVal = parentEnv.get(key);
|
||||
if (parentVal != null && containsEnvKeySubstitution(key, value)) {
|
||||
envs.put(key, value.replace("$" + key + "$", parentVal));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean containsEnvKeySubstitution(final String envKey, final String val) {
|
||||
return ArrayUtil.find(val.split(File.pathSeparator), "$" + envKey + "$") != -1;
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
static Map<String, String> testLoader() {
|
||||
try {
|
||||
|
||||
@@ -3,9 +3,6 @@ package com.intellij.util;
|
||||
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.text.CaseInsensitiveStringHashingStrategy;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
@@ -49,53 +46,6 @@ public class EnvironmentUtilTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inlineParentOccurrences() {
|
||||
Map<String, String> parentEnv = SystemInfo.isWindows ?
|
||||
ContainerUtil.newTroveMap(CaseInsensitiveStringHashingStrategy.INSTANCE) :
|
||||
ContainerUtil.newHashMap();
|
||||
parentEnv.put("Foo", "foo/bar");
|
||||
parentEnv.put("smth", "another()thing");
|
||||
parentEnv.put("tmp", "tempo#rary");
|
||||
parentEnv.put("123", "50m37h1ng");
|
||||
|
||||
Map<String, String> childEnv = ContainerUtil.newHashMap();
|
||||
childEnv.put("no parent", "no parent indeed");
|
||||
childEnv.put("Foo", "have parent but no parent reference");
|
||||
childEnv.put("smth", "have parent and reference" + File.pathSeparator +
|
||||
EnvironmentUtil.PARENT_ENV_KEY_DELIMITER + "smth" + EnvironmentUtil.PARENT_ENV_KEY_DELIMITER +
|
||||
File.pathSeparator + "flavor text");
|
||||
childEnv.put("TMP", "case sensitive" +
|
||||
File.pathSeparator +
|
||||
EnvironmentUtil.PARENT_ENV_KEY_DELIMITER + "Tmp" + EnvironmentUtil.PARENT_ENV_KEY_DELIMITER);
|
||||
|
||||
EnvironmentUtil.inlineParentOccurrences(childEnv, parentEnv);
|
||||
|
||||
assertEnvVariable(childEnv, "no parent", "no parent indeed");
|
||||
assertEnvVariable(childEnv, "Foo", "have parent but no parent reference");
|
||||
assertEnvVariable(childEnv, "smth", "have parent and reference" + File.pathSeparator +
|
||||
"another()thing" +
|
||||
File.pathSeparator + "flavor text");
|
||||
if (SystemInfo.isWindows) {
|
||||
assertEnvVariable(childEnv, "TMP", "case sensitive" +
|
||||
File.pathSeparator + "tempo#rary");
|
||||
}
|
||||
else {
|
||||
assertEnvVariable(childEnv, "TMP", "case sensitive" +
|
||||
File.pathSeparator +
|
||||
EnvironmentUtil.PARENT_ENV_KEY_DELIMITER + "Tmp" + EnvironmentUtil.PARENT_ENV_KEY_DELIMITER);
|
||||
}
|
||||
assertNull(childEnv.get("123"));
|
||||
}
|
||||
|
||||
private static void assertEnvVariable(@NotNull Map<String, String> env,
|
||||
@NotNull String expectedKey,
|
||||
@NotNull String expectedValue) {
|
||||
String actualValue = env.get(expectedKey);
|
||||
assertNotNull(actualValue);
|
||||
assertEquals(expectedValue, actualValue);
|
||||
}
|
||||
|
||||
@Test(timeout = 30000)
|
||||
public void load() {
|
||||
assumeTrue(SystemInfo.isUnix);
|
||||
|
||||
Reference in New Issue
Block a user