Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorjantje2020-06-10 16:20:32 +0000
committerJonah Graham2020-06-13 22:58:14 +0000
commit9867126d6f36fd59b35528d6019355fabcf51423 (patch)
treea6131ee23c441f96fd11baf7a9f51c996f6161de /core
parentd99d06cecad52476e64dc6849b30ba222baa9c37 (diff)
downloadorg.eclipse.cdt-9867126d6f36fd59b35528d6019355fabcf51423.tar.gz
org.eclipse.cdt-9867126d6f36fd59b35528d6019355fabcf51423.tar.xz
org.eclipse.cdt-9867126d6f36fd59b35528d6019355fabcf51423.zip
Bug 564123 Uppercase only special environment variables on Windows
Only uppercase the env variable names that are special (only Path for now). This is part of handling the change to keeping cdt variables case sensitive. Change-Id: Ibf22823328c8f8d57c98aa9b62763ea884164fae Signed-off-by: jantje <eclipse@baeyens.it>
Diffstat (limited to 'core')
-rw-r--r--core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/spawner/EnvironmentReader.java45
1 files changed, 17 insertions, 28 deletions
diff --git a/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/spawner/EnvironmentReader.java b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/spawner/EnvironmentReader.java
index baad1b49302..ae005dc2e7b 100644
--- a/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/spawner/EnvironmentReader.java
+++ b/core/org.eclipse.cdt.core.native/src/org/eclipse/cdt/utils/spawner/EnvironmentReader.java
@@ -13,51 +13,41 @@
*******************************************************************************/
package org.eclipse.cdt.utils.spawner;
-import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.eclipse.core.runtime.Platform;
/**
- * This class provides environment variables supplied as {@link Properties} class.
+ * This class provides OS owned environment variables supplied as {@link Properties} class.
*
* @noextend This class is not intended to be subclassed by clients.
* @noinstantiate This class is not intended to be instantiated by clients.
*/
public class EnvironmentReader {
- private static Properties envVars = null;
- private static Properties envVarsNormalized = null;
- private static ArrayList<String> rawVars = null;
+ private static Properties envVars;
+ private static List<String> toUppercaseEnvironmentVars = Arrays.asList("PATH"); //$NON-NLS-1$
- private static synchronized void init() {
- if (envVars == null) {
- envVars = new Properties();
- // on Windows environment variable names are case-insensitive
- if (Platform.getOS().equals(Platform.OS_WIN32)) {
- envVarsNormalized = new Properties();
- } else {
- envVarsNormalized = envVars;
+ static {
+ boolean isWindows = Platform.OS_WIN32.equals(Platform.getOS());
+ envVars = new Properties();
+ Map<String, String> envMap = System.getenv();
+ for (Map.Entry<String, String> curEnvVar : envMap.entrySet()) {
+ String key = curEnvVar.getKey();
+ String value = curEnvVar.getValue();
+ if (isWindows && toUppercaseEnvironmentVars.contains(key.toUpperCase())) {
+ key = key.toUpperCase();
}
- rawVars = new ArrayList<>();
- Map<String, String> envMap = System.getenv();
- for (String var : envMap.keySet()) {
- String value = envMap.get(var);
- envVars.setProperty(var, value);
- if (envVarsNormalized != envVars) {
- envVarsNormalized.setProperty(var.toUpperCase(), value);
- }
- rawVars.add(var + "=" + value); //$NON-NLS-1$
- }
- rawVars.trimToSize();
+ envVars.setProperty(key, value);
}
}
/**
- * @return list of environment variables.
+ * @return a clone of the list of environment variables.
*/
public static Properties getEnvVars() {
- init();
return (Properties) envVars.clone();
}
@@ -66,7 +56,6 @@ public class EnvironmentReader {
* @return value of environment variable.
*/
public static String getEnvVar(String key) {
- init();
- return envVarsNormalized.getProperty(key);
+ return envVars.getProperty(key);
}
}

Back to the top