From 9a6a9c9350b0c8299208f895210cfabc83fe4e38 Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Thu, 31 Mar 2005 19:38:31 +0000 Subject: [PATCH] 2005-03-30 Alain Magloire Patch from Alex Chapiro, tentative fix for PR 89662 * utils/org/eclipse/cdt/utils/spawner/EnvironmentReader.java --- core/org.eclipse.cdt.core/ChangeLog | 4 + .../cdt/utils/spawner/EnvironmentReader.java | 199 +++++++++--------- 2 files changed, 107 insertions(+), 96 deletions(-) diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index e7187d7ee9f..2de7bb29cfa 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -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 Delay the processing/parsing of the WorkingCopy when creating the workingcopy This should speed the opening of the CEditor. diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/spawner/EnvironmentReader.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/spawner/EnvironmentReader.java index a20672297d3..278c76b87fc 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/spawner/EnvironmentReader.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/spawner/EnvironmentReader.java @@ -1,96 +1,103 @@ -/******************************************************************************* - * Copyright (c) 2000, 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.utils.spawner; - - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.InputStream; -import java.util.Properties; -import java.util.Vector; - -public class EnvironmentReader { - private static Properties envVars = null; - private static Vector rawVars = null; - - public static Properties getEnvVars() { - - if (null != envVars) - return (Properties)envVars.clone(); - - String OS = System.getProperty("os.name").toLowerCase(); //$NON-NLS-1$ - Process p = null; - envVars = new Properties(); - rawVars = new Vector(32); - String command = "env"; //$NON-NLS-1$ - InputStream in = null; - boolean check_ready = false; - boolean isWin32 = false; - if (OS.startsWith("windows 9") || OS.startsWith("windows me")) { // 95, 98, me //$NON-NLS-1$ //$NON-NLS-2$ - command = "command.com /c set"; //$NON-NLS-1$ - //The buffered stream doesn't always like windows 98 - check_ready = true; - isWin32 = true; - } else - if (OS.startsWith("windows ")) { //$NON-NLS-1$ - command = "cmd.exe /c set"; //$NON-NLS-1$ - isWin32 = true; - } - try { - p = ProcessFactory.getFactory().exec(command); - in = p.getInputStream(); - BufferedReader br = new BufferedReader(new InputStreamReader(in)); - String line; - while ((line = br.readLine()) != null) { - rawVars.add(line); - int idx = line.indexOf('='); - if (idx != -1) { - String key = line.substring(0, idx); - if (isWin32) //Since windows env ignores case let normalize to Upper here. - key = key.toUpperCase(); - String value = line.substring(idx + 1); - envVars.setProperty(key, value); - } else { - envVars.setProperty(line, ""); //$NON-NLS-1$ - } - if (check_ready && br.ready() == false) { - break; - } - } - } catch (IOException e) { - } finally { - try { - if (in != null) { - in.close(); - } - } catch (IOException e) { - } - try { - if (p != null) - p.waitFor(); - } catch (InterruptedException e) { - } - } - rawVars.trimToSize(); - return (Properties)envVars.clone(); - } - - 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]); - } -} +/******************************************************************************* + * Copyright (c) 2000, 2004 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.utils.spawner; + + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.ByteOrder; +import java.util.Properties; +import java.util.Vector; + +public class EnvironmentReader { + private static Properties envVars = null; + private static Vector rawVars = null; + + public static Properties getEnvVars() { + + if (null != envVars) + return (Properties)envVars.clone(); + + String OS = System.getProperty("os.name").toLowerCase(); //$NON-NLS-1$ + Process p = null; + envVars = new Properties(); + rawVars = new Vector(32); + String command = "env"; //$NON-NLS-1$ + InputStream in = null; + boolean check_ready = false; + boolean isWin32 = false; + String charSet = null; + if (OS.startsWith("windows 9") || OS.startsWith("windows me")) { // 95, 98, me //$NON-NLS-1$ //$NON-NLS-2$ + command = "command.com /c set"; //$NON-NLS-1$ + //The buffered stream doesn't always like windows 98 + check_ready = true; + isWin32 = true; + } else + if (OS.startsWith("windows ")) { //$NON-NLS-1$ + command = "cmd.exe /u /c set"; //$NON-NLS-1$ + isWin32 = true; + charSet = "UTF-16" + (ByteOrder.BIG_ENDIAN.equals(ByteOrder.nativeOrder()) ? "BE" : "LE"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + } + try { + p = ProcessFactory.getFactory().exec(command); + in = p.getInputStream(); + BufferedReader br; + if(null == charSet) + br = new BufferedReader(new InputStreamReader(in)); + else + br = new BufferedReader(new InputStreamReader(in, charSet)); + String line; + while ((line = br.readLine()) != null) { + rawVars.add(line); + int idx = line.indexOf('='); + if (idx != -1) { + String key = line.substring(0, idx); + if (isWin32) //Since windows env ignores case let normalize to Upper here. + key = key.toUpperCase(); + String value = line.substring(idx + 1); + envVars.setProperty(key, value); + } else { + envVars.setProperty(line, ""); //$NON-NLS-1$ + } + if (check_ready && br.ready() == false) { + break; + } + } + } catch (IOException e) { + } finally { + try { + if (in != null) { + in.close(); + } + } catch (IOException e) { + } + try { + if (p != null) + p.waitFor(); + } catch (InterruptedException e) { + } + } + rawVars.trimToSize(); + return (Properties)envVars.clone(); + } + + 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]); + } +}