diff options
author | Michael Valenta | 2007-02-19 20:11:45 +0000 |
---|---|---|
committer | Michael Valenta | 2007-02-19 20:11:45 +0000 |
commit | d0f11de16bb0f6ffe0e69f503e7033f370edd39b (patch) | |
tree | dcc525f381d020cf5b1c15cb7c396669eff82009 /bundles/org.eclipse.core.net | |
parent | 07ece1c6e7fd0ca58ff46d67606b3f06ae3d4359 (diff) | |
download | eclipse.platform.team-d0f11de16bb0f6ffe0e69f503e7033f370edd39b.tar.gz eclipse.platform.team-d0f11de16bb0f6ffe0e69f503e7033f370edd39b.tar.xz eclipse.platform.team-d0f11de16bb0f6ffe0e69f503e7033f370edd39b.zip |
Bug 154100 Platform level proxy settings
Diffstat (limited to 'bundles/org.eclipse.core.net')
4 files changed, 48 insertions, 39 deletions
diff --git a/bundles/org.eclipse.core.net/src/org/eclipse/net/core/IProxyChangeEvent.java b/bundles/org.eclipse.core.net/src/org/eclipse/net/core/IProxyChangeEvent.java index f276fde49..17ac4bf86 100644 --- a/bundles/org.eclipse.core.net/src/org/eclipse/net/core/IProxyChangeEvent.java +++ b/bundles/org.eclipse.core.net/src/org/eclipse/net/core/IProxyChangeEvent.java @@ -32,6 +32,15 @@ public interface IProxyChangeEvent { * @see #getChangeType() */ public static final int PROXY_DATA_CHANGED = 2; + + /** + * Type constant that indicates that the enablement of the proxy + * manager has changed. Client should consult the manager to determine + * the current enablement + * @see #getChangeType() + * @see IProxyManager#isProxiesEnabled() + */ + public static final int PROXY_MANAGER_ENABLEMENT_CHANGE = 3; /** * Return the type of change this event represents. Clients diff --git a/bundles/org.eclipse.core.net/src/org/eclipse/net/core/IProxyManager.java b/bundles/org.eclipse.core.net/src/org/eclipse/net/core/IProxyManager.java index 7a01fcbde..ae6cb3124 100644 --- a/bundles/org.eclipse.core.net/src/org/eclipse/net/core/IProxyManager.java +++ b/bundles/org.eclipse.core.net/src/org/eclipse/net/core/IProxyManager.java @@ -21,10 +21,11 @@ import org.eclipse.core.runtime.CoreException; public interface IProxyManager { /** - * Set whether proxy support should be enabled. When disabled, the data for all the - * known proxy types will contain a <code>null</code> in the host field - * (see {@link IProxyData#getHost()}). When enabled, the proxy data will not have any - * values until the next time it is set (see {@link #setProxyData(IProxyData[])}). + * Set whether proxy support should be enabled. The current proxy settings are + * still kept so clients should check the enablement using {@link #isProxiesEnabled()} + * before calling the {@link #getProxyData()} or {@link #getProxyData(String)} method. + * However, the {@link #getProxyDataForHost(String)} and {@link #getProxyDataForHost(String, String)} + * method will check the enablement and only return data if the manager is enabled. * @param enabled whether proxy support should be enabled */ void setProxiesEnabled(boolean enabled); @@ -88,8 +89,7 @@ public interface IProxyManager { * Set the information associated with known proxy types. * If an unknown type is provided, it will be ignored. Any * known types that are not present in the list of the provided - * proxy data will be unaffected. Calls to this method when proxies - * are disabled will be ignored. + * proxy data will be unaffected. * @param proxies the proxy data whose information is to be set. * @throws CoreException if the proxy could not be set */ diff --git a/bundles/org.eclipse.core.net/src/org/eclipse/net/internal/core/ProxyManager.java b/bundles/org.eclipse.core.net/src/org/eclipse/net/internal/core/ProxyManager.java index c1821f039..ebc84d93f 100644 --- a/bundles/org.eclipse.core.net/src/org/eclipse/net/internal/core/ProxyManager.java +++ b/bundles/org.eclipse.core.net/src/org/eclipse/net/internal/core/ProxyManager.java @@ -108,8 +108,7 @@ public class ProxyManager implements IProxyManager { } public void setProxyData(IProxyData[] proxies) { - if (isProxiesEnabled()) - doSetProxyData(proxies); + doSetProxyData(proxies); } private void doSetProxyData(IProxyData[] proxyDatas) { @@ -117,7 +116,7 @@ public class ProxyManager implements IProxyManager { String[] hosts = getNonProxiedHosts(); IProxyData[] changedProxies = internalSetProxyData(proxyDatas); if (changedProxies.length > 0) { - IProxyChangeEvent event = new ProxyChangeEvent(IProxyChangeEvent.PROXY_DATA_CHANGED, hosts, hosts, oldData, changedProxies); + IProxyChangeEvent event = new ProxyChangeEvent(IProxyChangeEvent.PROXY_MANAGER_ENABLEMENT_CHANGE, hosts, hosts, oldData, changedProxies); fireChange(event); } } @@ -127,7 +126,7 @@ public class ProxyManager implements IProxyManager { for (int i = 0; i < proxyDatas.length; i++) { IProxyData proxyData = proxyDatas[i]; ProxyType type = getType(proxyData); - if (type != null && type.setProxyData(proxyData)) { + if (type != null && type.setProxyData(proxyData, isProxiesEnabled())) { result.add(proxyData); } } @@ -161,29 +160,30 @@ public class ProxyManager implements IProxyManager { NetCorePlugin.getInstance().getInstancePreferences().putBoolean(PREF_ENABLED, enabled); Properties sysProps = System.getProperties(); sysProps.put("proxySet", enabled ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - if (!enabled) { - // This will fire a change event - doSetProxyData(new IProxyData[] { - new ProxyData(IProxyData.HTTP_PROXY_TYPE), - new ProxyData(IProxyData.HTTPS_PROXY_TYPE), - new ProxyData(IProxyData.SOCKS_PROXY_TYPE) - }); - } + updateSystemProperties(); try { NetCorePlugin.getInstance().getInstancePreferences().flush(); } catch (BackingStoreException e) { NetCorePlugin.logError( "An error occurred while writing out the enablement state", e); //$NON-NLS-1$ } + String[] hosts = getNonProxiedHosts(); + IProxyData[] data = getProxyData(); + IProxyChangeEvent event = new ProxyChangeEvent(IProxyChangeEvent.PROXY_DATA_CHANGED, hosts, hosts, data, data); + fireChange(event); + } + + private void updateSystemProperties() { + for (int i = 0; i < proxies.length; i++) { + ProxyType type = proxies[i]; + type.updateSystemProperties(getProxyData(type.getName()), isProxiesEnabled()); + } } public void initialize() { - // Only initialize the system settings if proxies are enabled - if (isProxiesEnabled()) { - for (int i = 0; i < proxies.length; i++) { - ProxyType type = proxies[i]; - type.initialize(); - } + for (int i = 0; i < proxies.length; i++) { + ProxyType type = proxies[i]; + type.initialize(isProxiesEnabled()); } } diff --git a/bundles/org.eclipse.core.net/src/org/eclipse/net/internal/core/ProxyType.java b/bundles/org.eclipse.core.net/src/org/eclipse/net/internal/core/ProxyType.java index a56e6f39e..c93524c6c 100644 --- a/bundles/org.eclipse.core.net/src/org/eclipse/net/internal/core/ProxyType.java +++ b/bundles/org.eclipse.core.net/src/org/eclipse/net/internal/core/ProxyType.java @@ -103,7 +103,7 @@ public class ProxyType { return proxyData; } - public boolean setProxyData(IProxyData proxyData) { + public boolean setProxyData(IProxyData proxyData, boolean proxiesEnabled) { Assert.isTrue(proxyData.getType().equals(getName())); IProxyData oldData = getProxyData(); if (oldData.equals(proxyData)) @@ -130,18 +130,18 @@ public class ProxyType { "The {0} proxy node could not be written", proxyData.getType()), e); //$NON-NLS-1$ } } - updateSystemProperties(proxyData); + updateSystemProperties(proxyData, proxiesEnabled); return true; } - - private void updateSystemProperties(IProxyData proxyData) { + + /* package */void updateSystemProperties(IProxyData proxyData, boolean proxiesEnabled) { try { if (proxyData.getType().equals(IProxyData.HTTP_PROXY_TYPE)) { - updateHttpSystemProperties(proxyData); + updateHttpSystemProperties(proxyData, proxiesEnabled); } else if (proxyData.getType().equals(IProxyData.HTTPS_PROXY_TYPE)) { - updateHttpsSystemProperties(proxyData); + updateHttpsSystemProperties(proxyData, proxiesEnabled); } else if (proxyData.getType().equals(IProxyData.SOCKS_PROXY_TYPE)) { - updateSocksSystemProperties(proxyData); + updateSocksSystemProperties(proxyData, proxiesEnabled); } } catch (SecurityException e) { NetCorePlugin.logError("A security exception occurred while trying to put the proxy data into the system properties", e); //$NON-NLS-1$ @@ -152,10 +152,10 @@ public class ProxyType { return name; } - private void updateHttpSystemProperties(IProxyData data) { + private void updateHttpSystemProperties(IProxyData data, boolean proxiesEnabled) { Assert.isTrue(data.getType().equals(IProxyData.HTTP_PROXY_TYPE)); Properties sysProps = System.getProperties(); - if (data.getHost() == null) { + if (!proxiesEnabled || data.getHost() == null) { sysProps.remove("http.proxySet"); //$NON-NLS-1$ sysProps.remove("http.proxyHost"); //$NON-NLS-1$ sysProps.remove("http.proxyPort"); //$NON-NLS-1$ @@ -190,10 +190,10 @@ public class ProxyType { } } - private void updateHttpsSystemProperties(IProxyData data) { + private void updateHttpsSystemProperties(IProxyData data, boolean proxiesEnabled) { Assert.isTrue(data.getType().equals(IProxyData.HTTPS_PROXY_TYPE)); Properties sysProps = System.getProperties(); - if (data.getHost() == null) { + if (!proxiesEnabled || data.getHost() == null) { sysProps.remove("https.proxySet"); //$NON-NLS-1$ sysProps.remove("https.proxyHost"); //$NON-NLS-1$ sysProps.remove("https.proxyPort"); //$NON-NLS-1$ @@ -228,10 +228,10 @@ public class ProxyType { } } - private void updateSocksSystemProperties(IProxyData data) { + private void updateSocksSystemProperties(IProxyData data, boolean proxiesEnabled) { Assert.isTrue(data.getType().equals(IProxyData.SOCKS_PROXY_TYPE)); Properties sysProps = System.getProperties(); - if (data.getHost() == null) { + if (!proxiesEnabled || data.getHost() == null) { sysProps.remove("socksProxyHost"); //$NON-NLS-1$ sysProps.remove("socksProxyPort"); //$NON-NLS-1$ } else { @@ -248,8 +248,8 @@ public class ProxyType { } } - public void initialize() { - updateSystemProperties(getProxyData()); + public void initialize(boolean proxiesEnabled) { + updateSystemProperties(getProxyData(), proxiesEnabled); } private Map getAuthInfo() { |