mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-21 21:52:10 +02:00
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>
This commit is contained in:
parent
d99d06ceca
commit
9867126d6f
1 changed files with 17 additions and 28 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue