diff options
author | Szymon Brandys | 2011-01-11 15:09:40 +0000 |
---|---|---|
committer | Szymon Brandys | 2011-01-11 15:09:40 +0000 |
commit | ce6331139e391c12cf07edc6394b7b0c5537041c (patch) | |
tree | 8badf63bc45ef9b750a4a03515dba8fee7e1d657 /bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net | |
parent | 093cd4cef99de90204d1cfb8007aab3dc477cf72 (diff) | |
download | eclipse.platform.team-ce6331139e391c12cf07edc6394b7b0c5537041c.tar.gz eclipse.platform.team-ce6331139e391c12cf07edc6394b7b0c5537041c.tar.xz eclipse.platform.team-ce6331139e391c12cf07edc6394b7b0c5537041c.zip |
bug 332728 - [Net] UnixProxyProvider execs a process to discover whether env contains 'proxy' on each socket connect
Diffstat (limited to 'bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net')
-rw-r--r-- | bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/unix/UnixProxyProvider.java | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/unix/UnixProxyProvider.java b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/unix/UnixProxyProvider.java index fe7439f36..e479de04e 100644 --- a/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/unix/UnixProxyProvider.java +++ b/bundles/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/unix/UnixProxyProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2010 Oakland Software Incorporated and others + * Copyright (c) 2008, 2011 Oakland Software Incorporated and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -12,6 +12,7 @@ package org.eclipse.core.internal.net.proxy.unix; import java.io.IOException; +import java.lang.reflect.Method; import java.net.URI; import java.util.ArrayList; import java.util.Locale; @@ -198,32 +199,35 @@ public class UnixProxyProvider extends AbstractProxyProvider { return null; } - private synchronized String getEnv(String env) { - String cmd[] = { "/bin/sh", //$NON-NLS-1$ - "-c", //$NON-NLS-1$ - "env | grep -i proxy" }; //$NON-NLS-1$ - Properties props = new Properties(); - Process proc = null; + private static String getEnv(String env) { try { - proc = Runtime.getRuntime().exec(cmd); - props.load(proc.getInputStream()); - proc.waitFor(); - } catch (IOException e) { - Activator.logError( - "Problem during accessing system variable: " + env, e); //$NON-NLS-1$ - } catch (IllegalArgumentException e) { - Activator.logError( - "Problem during accessing system variable: " + env, e); //$NON-NLS-1$ - } catch (InterruptedException e) { - Activator.logError( - "Problem during accessing system variable: " + env, e); //$NON-NLS-1$ - } finally { - if (proc != null) { - proc.destroy(); + Method m = System.class.getMethod( + "getenv", new Class[] { String.class }); //$NON-NLS-1$ + return (String) m.invoke(null, new Object[] { env }); + } catch (Throwable t) { + // Fall-back to running 'env' directly. Warning this is very slow... + // up to 200ms + String cmd[] = { "/bin/sh", //$NON-NLS-1$ + "-c", //$NON-NLS-1$ + "env | grep -i proxy" }; //$NON-NLS-1$ + Properties props = new Properties(); + Process proc = null; + try { + proc = Runtime.getRuntime().exec(cmd); + props.load(proc.getInputStream()); + } catch (IOException e) { + Activator.logError( + "Problem during accessing system variable: " + env, e); //$NON-NLS-1$ + } catch (IllegalArgumentException e) { + Activator.logError( + "Problem during accessing system variable: " + env, e); //$NON-NLS-1$ + } finally { + if (proc != null) { + proc.destroy(); + } } + return props.getProperty(env); } - - return props.getProperty(env); } private static void loadGnomeLib() { |