mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-29 11:55:40 +02:00
2005-03-30 Alain Magloire
Patch from Alex Chapiro, tentative fix for PR 89662 * utils/org/eclipse/cdt/utils/spawner/EnvironmentReader.java
This commit is contained in:
parent
6c97bf5a19
commit
9a6a9c9350
2 changed files with 107 additions and 96 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
2005-03-30 Alain Magloire
|
||||||
|
Patch from Alex Chapiro, tentative fix for PR 89662
|
||||||
|
* utils/org/eclipse/cdt/utils/spawner/EnvironmentReader.java
|
||||||
|
|
||||||
2005-03-30 Alain Magloire
|
2005-03-30 Alain Magloire
|
||||||
Delay the processing/parsing of the WorkingCopy when creating the workingcopy
|
Delay the processing/parsing of the WorkingCopy when creating the workingcopy
|
||||||
This should speed the opening of the CEditor.
|
This should speed the opening of the CEditor.
|
||||||
|
|
|
@ -1,96 +1,103 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2000, 2004 QNX Software Systems and others.
|
* Copyright (c) 2000, 2004 QNX Software Systems and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Common Public License v1.0
|
* are made available under the terms of the Common Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/cpl-v10.html
|
* http://www.eclipse.org/legal/cpl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX Software Systems - Initial API and implementation
|
* QNX Software Systems - Initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.utils.spawner;
|
package org.eclipse.cdt.utils.spawner;
|
||||||
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStreamReader;
|
||||||
import java.util.Properties;
|
import java.nio.ByteOrder;
|
||||||
import java.util.Vector;
|
import java.util.Properties;
|
||||||
|
import java.util.Vector;
|
||||||
public class EnvironmentReader {
|
|
||||||
private static Properties envVars = null;
|
public class EnvironmentReader {
|
||||||
private static Vector rawVars = null;
|
private static Properties envVars = null;
|
||||||
|
private static Vector rawVars = null;
|
||||||
public static Properties getEnvVars() {
|
|
||||||
|
public static Properties getEnvVars() {
|
||||||
if (null != envVars)
|
|
||||||
return (Properties)envVars.clone();
|
if (null != envVars)
|
||||||
|
return (Properties)envVars.clone();
|
||||||
String OS = System.getProperty("os.name").toLowerCase(); //$NON-NLS-1$
|
|
||||||
Process p = null;
|
String OS = System.getProperty("os.name").toLowerCase(); //$NON-NLS-1$
|
||||||
envVars = new Properties();
|
Process p = null;
|
||||||
rawVars = new Vector(32);
|
envVars = new Properties();
|
||||||
String command = "env"; //$NON-NLS-1$
|
rawVars = new Vector(32);
|
||||||
InputStream in = null;
|
String command = "env"; //$NON-NLS-1$
|
||||||
boolean check_ready = false;
|
InputStream in = null;
|
||||||
boolean isWin32 = false;
|
boolean check_ready = false;
|
||||||
if (OS.startsWith("windows 9") || OS.startsWith("windows me")) { // 95, 98, me //$NON-NLS-1$ //$NON-NLS-2$
|
boolean isWin32 = false;
|
||||||
command = "command.com /c set"; //$NON-NLS-1$
|
String charSet = null;
|
||||||
//The buffered stream doesn't always like windows 98
|
if (OS.startsWith("windows 9") || OS.startsWith("windows me")) { // 95, 98, me //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
check_ready = true;
|
command = "command.com /c set"; //$NON-NLS-1$
|
||||||
isWin32 = true;
|
//The buffered stream doesn't always like windows 98
|
||||||
} else
|
check_ready = true;
|
||||||
if (OS.startsWith("windows ")) { //$NON-NLS-1$
|
isWin32 = true;
|
||||||
command = "cmd.exe /c set"; //$NON-NLS-1$
|
} else
|
||||||
isWin32 = true;
|
if (OS.startsWith("windows ")) { //$NON-NLS-1$
|
||||||
}
|
command = "cmd.exe /u /c set"; //$NON-NLS-1$
|
||||||
try {
|
isWin32 = true;
|
||||||
p = ProcessFactory.getFactory().exec(command);
|
charSet = "UTF-16" + (ByteOrder.BIG_ENDIAN.equals(ByteOrder.nativeOrder()) ? "BE" : "LE"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
|
||||||
in = p.getInputStream();
|
}
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
try {
|
||||||
String line;
|
p = ProcessFactory.getFactory().exec(command);
|
||||||
while ((line = br.readLine()) != null) {
|
in = p.getInputStream();
|
||||||
rawVars.add(line);
|
BufferedReader br;
|
||||||
int idx = line.indexOf('=');
|
if(null == charSet)
|
||||||
if (idx != -1) {
|
br = new BufferedReader(new InputStreamReader(in));
|
||||||
String key = line.substring(0, idx);
|
else
|
||||||
if (isWin32) //Since windows env ignores case let normalize to Upper here.
|
br = new BufferedReader(new InputStreamReader(in, charSet));
|
||||||
key = key.toUpperCase();
|
String line;
|
||||||
String value = line.substring(idx + 1);
|
while ((line = br.readLine()) != null) {
|
||||||
envVars.setProperty(key, value);
|
rawVars.add(line);
|
||||||
} else {
|
int idx = line.indexOf('=');
|
||||||
envVars.setProperty(line, ""); //$NON-NLS-1$
|
if (idx != -1) {
|
||||||
}
|
String key = line.substring(0, idx);
|
||||||
if (check_ready && br.ready() == false) {
|
if (isWin32) //Since windows env ignores case let normalize to Upper here.
|
||||||
break;
|
key = key.toUpperCase();
|
||||||
}
|
String value = line.substring(idx + 1);
|
||||||
}
|
envVars.setProperty(key, value);
|
||||||
} catch (IOException e) {
|
} else {
|
||||||
} finally {
|
envVars.setProperty(line, ""); //$NON-NLS-1$
|
||||||
try {
|
}
|
||||||
if (in != null) {
|
if (check_ready && br.ready() == false) {
|
||||||
in.close();
|
break;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
}
|
||||||
}
|
} catch (IOException e) {
|
||||||
try {
|
} finally {
|
||||||
if (p != null)
|
try {
|
||||||
p.waitFor();
|
if (in != null) {
|
||||||
} catch (InterruptedException e) {
|
in.close();
|
||||||
}
|
}
|
||||||
}
|
} catch (IOException e) {
|
||||||
rawVars.trimToSize();
|
}
|
||||||
return (Properties)envVars.clone();
|
try {
|
||||||
}
|
if (p != null)
|
||||||
|
p.waitFor();
|
||||||
public static String getEnvVar(String key) {
|
} catch (InterruptedException e) {
|
||||||
Properties p = getEnvVars();
|
}
|
||||||
return p.getProperty(key);
|
}
|
||||||
}
|
rawVars.trimToSize();
|
||||||
|
return (Properties)envVars.clone();
|
||||||
public static String[] getRawEnvVars() {
|
}
|
||||||
getEnvVars();
|
|
||||||
return (String[]) rawVars.toArray(new String[0]);
|
public static String getEnvVar(String key) {
|
||||||
}
|
Properties p = getEnvVars();
|
||||||
}
|
return p.getProperty(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] getRawEnvVars() {
|
||||||
|
getEnvVars();
|
||||||
|
return (String[]) rawVars.toArray(new String[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue