1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

2005-06-29 Alain Magloire

Fix for PR 102174 patch from Johane Woo.
	* utils/org/eclipse/cdt/utils/spawner/EnvironmentReader.java
This commit is contained in:
Alain Magloire 2005-06-30 02:57:35 +00:00
parent 7161893f55
commit fa4497f2fa
2 changed files with 37 additions and 8 deletions

View file

@ -1,3 +1,7 @@
2005-06-29 Alain Magloire
Fix for PR 102174 patch from Johane Woo.
* utils/org/eclipse/cdt/utils/spawner/EnvironmentReader.java
2005-06-29 Alain Magloire 2005-06-29 Alain Magloire
Patch From Chris Wiebe fix PR 101386 Patch From Chris Wiebe fix PR 101386
* utils/org/eclipse/cdt/utils/macho/MachO.java * utils/org/eclipse/cdt/utils/macho/MachO.java

View file

@ -25,8 +25,9 @@ public class EnvironmentReader {
public static Properties getEnvVars() { public static Properties getEnvVars() {
if (null != envVars) if (null != envVars) {
return (Properties)envVars.clone(); return (Properties)envVars.clone();
}
String OS = System.getProperty("os.name").toLowerCase(); //$NON-NLS-1$ String OS = System.getProperty("os.name").toLowerCase(); //$NON-NLS-1$
Process p = null; Process p = null;
@ -42,8 +43,7 @@ public class EnvironmentReader {
//The buffered stream doesn't always like windows 98 //The buffered stream doesn't always like windows 98
check_ready = true; check_ready = true;
isWin32 = true; isWin32 = true;
} else } else if (OS.startsWith("windows ")) { //$NON-NLS-1$
if (OS.startsWith("windows ")) { //$NON-NLS-1$
command = "cmd.exe /u /c set"; //$NON-NLS-1$ command = "cmd.exe /u /c set"; //$NON-NLS-1$
isWin32 = true; isWin32 = true;
charSet = "UTF-16" + (ByteOrder.BIG_ENDIAN.equals(ByteOrder.nativeOrder()) ? "BE" : "LE"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ charSet = "UTF-16" + (ByteOrder.BIG_ENDIAN.equals(ByteOrder.nativeOrder()) ? "BE" : "LE"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
@ -52,22 +52,46 @@ public class EnvironmentReader {
p = ProcessFactory.getFactory().exec(command); p = ProcessFactory.getFactory().exec(command);
in = p.getInputStream(); in = p.getInputStream();
BufferedReader br; BufferedReader br;
if(null == charSet) if (null == charSet) {
br = new BufferedReader(new InputStreamReader(in)); br = new BufferedReader(new InputStreamReader(in));
else } else {
br = new BufferedReader(new InputStreamReader(in, charSet)); br = new BufferedReader(new InputStreamReader(in, charSet));
}
String line; String line;
String prev_key = null; // previous key read and saved in envVars
String prev_value = null; // value of previous key
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
rawVars.add(line); rawVars.add(line);
int idx = line.indexOf('='); int idx = line.indexOf('=');
if (idx != -1) { if (idx != -1) {
String key = line.substring(0, idx); String key = line.substring(0, idx);
if (isWin32) //Since windows env ignores case let normalize to Upper here. if (isWin32) { //Since windows env ignores case let normalize to Upper here.
key = key.toUpperCase(); key = key.toUpperCase();
}
String value = line.substring(idx + 1); String value = line.substring(idx + 1);
envVars.setProperty(key, value); envVars.setProperty(key, value);
// Save key and value in case we're dealing with a variable with
// a multi-line value; i.e., it contains embedded new lines (\n).
prev_key = key;
prev_value = value;
} else { } else {
envVars.setProperty(line, ""); //$NON-NLS-1$ // Any variable setting that contains '\n' will be read as
// separate lines into the line variable. Subsequent lines
// after the first line (which contains '=') takes us to
// this else case. We try to restore the original setting
// by concatenating the value of line with previous value,
// with a \n replaced in between, and saving the new value with
// the previous key.
if (prev_key != null) {
if (prev_value != null) {
prev_value = prev_value + '\n' + line;
} else {
prev_value = line;
}
envVars.setProperty(prev_key, prev_value);
} else {
envVars.setProperty(line, ""); //$NON-NLS-1$
}
} }
if (check_ready && br.ready() == false) { if (check_ready && br.ready() == false) {
break; break;
@ -82,8 +106,9 @@ public class EnvironmentReader {
} catch (IOException e) { } catch (IOException e) {
} }
try { try {
if (p != null) if (p != null) {
p.waitFor(); p.waitFor();
}
} catch (InterruptedException e) { } catch (InterruptedException e) {
} }
} }