From 9867126d6f36fd59b35528d6019355fabcf51423 Mon Sep 17 00:00:00 2001 From: jantje Date: Wed, 10 Jun 2020 18:20:32 +0200 Subject: [PATCH] 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 --- .../cdt/utils/spawner/EnvironmentReader.java | 45 +++++++------------ 1 file 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 rawVars = null; + private static Properties envVars; + private static List 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 envMap = System.getenv(); + for (Map.Entry curEnvVar : envMap.entrySet()) { + String key = curEnvVar.getKey(); + String value = curEnvVar.getValue(); + if (isWindows && toUppercaseEnvironmentVars.contains(key.toUpperCase())) { + key = key.toUpperCase(); } - rawVars = new ArrayList<>(); - Map 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); } }