mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 21:05:37 +02:00
bug 285349: JUnit failure: ManagedBuildEnvironmentTests.testEnvGetParams()
This commit is contained in:
parent
a867009329
commit
152e38ddb0
1 changed files with 45 additions and 20 deletions
|
@ -10,44 +10,69 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.utils.spawner;
|
package org.eclipse.cdt.utils.spawner;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.Platform;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This class provides environment variables supplied as {@link Properties} class.
|
||||||
|
*
|
||||||
* @noextend This class is not intended to be subclassed by clients.
|
* @noextend This class is not intended to be subclassed by clients.
|
||||||
* @noinstantiate This class is not intended to be instantiated by clients.
|
* @noinstantiate This class is not intended to be instantiated by clients.
|
||||||
*/
|
*/
|
||||||
public class EnvironmentReader {
|
public class EnvironmentReader {
|
||||||
private static Properties envVars = null;
|
private static Properties envVars = null;
|
||||||
|
private static Properties envVarsNormalized = null;
|
||||||
private static ArrayList<String> rawVars = null;
|
private static ArrayList<String> rawVars = null;
|
||||||
|
|
||||||
public static synchronized Properties getEnvVars() {
|
private static synchronized void init() {
|
||||||
if (null != envVars) {
|
if (envVars==null) {
|
||||||
return (Properties)envVars.clone();
|
envVars = new Properties();
|
||||||
|
// on Windows environment variable names are case-insensitive
|
||||||
|
if (Platform.getOS().equals(Platform.OS_WIN32)) {
|
||||||
|
envVarsNormalized = new Properties();
|
||||||
|
} else {
|
||||||
|
envVarsNormalized = envVars;
|
||||||
|
}
|
||||||
|
rawVars = new ArrayList<String>();
|
||||||
|
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 = new Properties();
|
|
||||||
rawVars = new ArrayList<String>();
|
|
||||||
Map<String,String> envMap = System.getenv();
|
|
||||||
for (String var : envMap.keySet()) {
|
|
||||||
String value = envMap.get(var);
|
|
||||||
envVars.setProperty(var, value);
|
|
||||||
rawVars.add(var + "=" + value); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
rawVars.trimToSize();
|
|
||||||
return (Properties)envVars.clone();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list of environment variables.
|
||||||
|
*/
|
||||||
|
public static Properties getEnvVars() {
|
||||||
|
init();
|
||||||
|
return (Properties) envVars.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param key - name of environment variable (without $ sign).
|
||||||
|
* @return value of environment variable.
|
||||||
|
*/
|
||||||
public static String getEnvVar(String key) {
|
public static String getEnvVar(String key) {
|
||||||
Properties p = getEnvVars();
|
init();
|
||||||
return p.getProperty(key);
|
return envVarsNormalized.getProperty(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized String[] getRawEnvVars() {
|
/**
|
||||||
if (rawVars==null)
|
* @deprecated since CDT 6.1. {@link #getEnvVars()} provides all the data.
|
||||||
getEnvVars();
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static String[] getRawEnvVars() {
|
||||||
|
init();
|
||||||
return rawVars.toArray(new String[rawVars.size()]);
|
return rawVars.toArray(new String[rawVars.size()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue