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); } }