Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 93183 Details for
Bug 180921
[Proxy] Use system values for proxy settings
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
core.ui + updated javadocs
180921_20080321.txt (text/plain), 21.72 KB, created by
Szymon Brandys
on 2008-03-21 23:22:13 EDT
(
hide
)
Description:
core.ui + updated javadocs
Filename:
MIME Type:
Creator:
Szymon Brandys
Created:
2008-03-21 23:22:13 EDT
Size:
21.72 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.core.net >Index: src/org/eclipse/core/net/proxy/IProxyService.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.net/src/org/eclipse/core/net/proxy/IProxyService.java,v >retrieving revision 1.3 >diff -u -r1.3 IProxyService.java >--- src/org/eclipse/core/net/proxy/IProxyService.java 2 Mar 2007 15:06:22 -0000 1.3 >+++ src/org/eclipse/core/net/proxy/IProxyService.java 22 Mar 2008 03:21:11 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2007 IBM Corporation and others. >+ * Copyright (c) 2007 2008 IBM Corporation 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 >@@ -13,46 +13,110 @@ > import org.eclipse.core.runtime.CoreException; > > /** >- * Manages the proxy data and related information. The proxy service is registered as >- * an OSGi service. Clients can obtain an instance of the service from their bundle context >- * or from a service tracker. >+ * Manages the proxy data and related information. The proxy service is >+ * registered as an OSGi service. Clients can obtain an instance of the service >+ * from their bundle context or from a service tracker. >+ * > * <p> >- * This interface is not intended to be implemented by clients. >+ * Clients that wish to make a connection and need to determine whether to use a >+ * proxy or not should call either {@link #getProxyDataForHost(String)} or >+ * {@link #getProxyDataForHost(String, String)}. >+ * </p> >+ * >+ * <p> >+ * This interface is not intended to be implemented by clients. >+ * </p> >+ * > * @since 1.0 > */ > public interface IProxyService { > > /** >- * 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 service is enabled. >- * @param enabled whether proxy support should be enabled >+ * Sets 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 service is enabled. >+ * >+ * @param enabled >+ * whether proxy support should be enabled > */ > void setProxiesEnabled(boolean enabled); > > /** >- * Return whether proxy support should be enabled. When disabled, all connections >- * will be direct. >+ * Returns whether proxy support should be enabled. When disabled, all >+ * connections will be direct. >+ * >+ * <p> >+ * Returns <code>false</code>, when the system proxies support is >+ * enabled but {@link #hasSystemProxies()} returns <code>false</code>. >+ * </p> >+ * > * @return whether proxy support should be enabled > */ > boolean isProxiesEnabled(); > > /** >- * Return the list of know proxy types and their settings. >- * Some of the returned proxy types may not be enabled (i.e, >- * their hosts may be <code>null</code>. >+ * Returns whether system proxy support is available. >+ * >+ * @return whether system proxy support is available >+ * @since 3.4 >+ */ >+ boolean hasSystemProxies(); >+ >+ /** >+ * Sets whether system proxies should be used, when the proxy support is >+ * enabled. >+ * >+ * @param enabled >+ * @since 3.4 >+ */ >+ void setSystemProxiesEnabled(boolean enabled); >+ >+ >+ /** >+ * Returns whether system proxy should be used when the proxy support is >+ * enabled. >+ * >+ * @return whether system proxy is used when the proxy support is enabled >+ * @since 3.4 >+ */ >+ boolean isSystemProxiesEnabled(); >+ >+ /** >+ * Returns the list of know proxy types and their settings. Some of the >+ * returned proxy types may not be enabled (i.e, their hosts may be >+ * <code>null</code>. >+ * >+ * <p> >+ * Clients that wish to make a connection and need to determine whether to >+ * use a proxy or not should call either >+ * {@link #getProxyDataForHost(String)} or >+ * {@link #getProxyDataForHost(String, String)}. >+ * </p> >+ * >+ * <p> >+ * This method returns the proxies set via {@link #setProxyData(IProxyData[])} >+ * </p> >+ * > * @return the list of know proxy types and their settings > */ > IProxyData[] getProxyData(); > > /** >- * Return the list of known proxy types and their settings for the >+ * Returns the list of known proxy types and their settings for the > * given host. If proxies are disabled > * or if the host matches any entries in the non-proxied > * hosts lists or if a matching proxy type has no data, then > * an empty array is returned. >+ * >+ * <p> >+ * Clients that wish to make a connection and need to determine whether to >+ * use a proxy should use this method. >+ * </p> >+ * > * @param host the host for which a connection is desired > * @return the list of known proxy types and their settings for the > * given host >@@ -60,12 +124,24 @@ > IProxyData[] getProxyDataForHost(String host); > > /** >- * Return the proxy data for the proxy of the given type >- * or <code>null</code> if the proxy type is not known by this >- * service. >- * @param type the proxy type >- * @return the proxy data for the proxy of the given type >- * or <code>null</code> >+ * Returns the proxy data for the proxy of the given type or >+ * <code>null</code> if the proxy type is not known by this service. >+ * >+ * <p> >+ * Clients that wish to make a connection and need to determine whether to >+ * use a proxy or not should call either >+ * {@link #getProxyDataForHost(String)} or >+ * {@link #getProxyDataForHost(String, String)}. >+ * </p> >+ * >+ * <p> >+ * This method returns the proxies set via {@link #setProxyData(IProxyData[])} >+ * </p> >+ * >+ * @param type >+ * the proxy type >+ * @return the proxy data for the proxy of the given type or >+ * <code>null</code> > * @see IProxyData#HTTP_PROXY_TYPE > * @see IProxyData#HTTPS_PROXY_TYPE > * @see IProxyData#SOCKS_PROXY_TYPE >@@ -73,14 +149,22 @@ > IProxyData getProxyData(String type); > > /** >- * Return the proxy data for the proxy of the given type >- * or <code>null</code> if the proxy type is not known by this >- * service, the proxy data is empty for that type or the >- * host is in the non-proxied host list. >- * @param host the host for which a connection is desired >- * @param type the proxy type >- * @return the proxy data for the proxy of the given type >- * or <code>null</code> >+ * Returns the proxy data for the proxy of the given type or >+ * <code>null</code> if the proxy type is not known by this service, the >+ * proxy data is empty for that type or the host is in the non-proxied host >+ * list. >+ * >+ * <p> >+ * Clients that wish to make a connection and need to determine whether to >+ * use a proxy should use this method. >+ * </p> >+ * >+ * @param host >+ * the host for which a connection is desired >+ * @param type >+ * the proxy type >+ * @return the proxy data for the proxy of the given type or >+ * <code>null</code> > * @see IProxyData#HTTP_PROXY_TYPE > * @see IProxyData#HTTPS_PROXY_TYPE > * @see IProxyData#SOCKS_PROXY_TYPE >@@ -88,21 +172,40 @@ > IProxyData getProxyDataForHost(String host, String type); > > /** >- * 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. >- * @param proxies the proxy data whose information is to be set. >- * @throws CoreException if the proxy could not be set >+ * Sets 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. >+ * >+ * <p> >+ * This method affects only proxies defined in Eclipse by user and doesn't >+ * affect settings of the system proxies (being used when the system support >+ * is enabled). >+ * </p> >+ * >+ * @param proxies >+ * the proxy data whose information is to be set. >+ * @throws CoreException >+ * if the proxy could not be set > */ > void setProxyData(IProxyData[] proxies) throws CoreException; > > /** >- * Return the list of hosts for which non proxy should be used. >- * The values returned from this method should only be used for displaying >- * the non-proxed hosts list. Clients that which to make a connection and need >- * to determine whether to use a proxy or not shoudl call either {@link #getProxyDataForHost(String)} >- * or {@link #getProxyDataForHost(String, String)}. >+ * Returns the list of hosts for which non proxy should be used. The values >+ * returned from this method should only be used for displaying the >+ * non-proxed hosts list. >+ * >+ * <p> >+ * Clients that wish to make a connection and need to determine whether to >+ * use a proxy or not should call either >+ * {@link #getProxyDataForHost(String)} or >+ * {@link #getProxyDataForHost(String, String)}. >+ * </p> >+ * >+ * <p> >+ * This method returns the hosts set via >+ * {@link #setNonProxiedHosts(String[])} >+ * </p> >+ * > * @return the list of hosts for which non proxy should be used. > * @see #getProxyDataForHost(String) > * @see #getProxyDataForHost(String, String) >@@ -110,14 +213,23 @@ > String[] getNonProxiedHosts(); > > /** >- * Set the list of hosts for which non proxy should be used. >- * @param hosts the list of hosts for which non proxy should be used. >- * @throws CoreException if the non-proxied host list could not be set >+ * Sets the list of hosts for which non proxy should be used. >+ * >+ * <p> >+ * This method affects only non-proxied hosts defined in Eclipse by user and >+ * doesn't affect settings of the system proxies (being used when the system >+ * support is enabled). >+ * </p> >+ * >+ * @param hosts >+ * the list of hosts for which non proxy should be used >+ * @throws CoreException >+ * if the non-proxied host list could not be set > */ > void setNonProxiedHosts(String[] hosts) throws CoreException; > > /** >- * Register a listener that will be notified when proxy related >+ * Registers a listener that will be notified when proxy related > * information changes. Adding a listener that is already registered > * has no effect. > * @param listener a change listener >@@ -125,10 +237,9 @@ > void addProxyChangeListener(IProxyChangeListener listener); > > /** >- * Remove a listener. Removing a listener that is not registered >+ * Removes a listener. Removing a listener that is not registered > * has no effect. > * @param listener a change listener > */ > void removeProxyChangeListener(IProxyChangeListener listener); >- > } >Index: src/org/eclipse/core/internal/net/ProxyManager.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxyManager.java,v >retrieving revision 1.10 >diff -u -r1.10 ProxyManager.java >--- src/org/eclipse/core/internal/net/ProxyManager.java 19 Feb 2008 21:06:25 -0000 1.10 >+++ src/org/eclipse/core/internal/net/ProxyManager.java 22 Mar 2008 03:21:11 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2007 IBM Corporation and others. >+ * Copyright (c) 2007, 2008 IBM Corporation 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 >@@ -11,14 +11,30 @@ > package org.eclipse.core.internal.net; > > import java.net.Authenticator; >-import java.util.*; >- >-import org.eclipse.core.net.proxy.*; >-import org.eclipse.core.runtime.*; >+import java.net.URI; >+import java.net.URISyntaxException; >+import java.util.ArrayList; >+import java.util.List; >+import java.util.Properties; >+ >+import org.eclipse.core.net.proxy.IProxyChangeEvent; >+import org.eclipse.core.net.proxy.IProxyChangeListener; >+import org.eclipse.core.net.proxy.IProxyData; >+import org.eclipse.core.net.proxy.IProxyService; >+import org.eclipse.core.runtime.Assert; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IConfigurationElement; >+import org.eclipse.core.runtime.IExtension; >+import org.eclipse.core.runtime.ISafeRunnable; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.ListenerList; >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.core.runtime.SafeRunner; > import org.eclipse.core.runtime.preferences.ConfigurationScope; > import org.eclipse.core.runtime.preferences.IEclipsePreferences; > import org.eclipse.core.runtime.preferences.InstanceScope; >-import org.eclipse.core.runtime.preferences.IEclipsePreferences.*; >+import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; >+import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent; > import org.eclipse.osgi.util.NLS; > import org.osgi.service.prefs.BackingStoreException; > import org.osgi.service.prefs.Preferences; >@@ -36,9 +52,12 @@ > > private static final String PREF_NON_PROXIED_HOSTS = "nonProxiedHosts"; //$NON-NLS-1$ > private static final String PREF_ENABLED = "proxiesEnabled"; //$NON-NLS-1$ >+ private static final String PREF_OS = "systemProxiesEnabled"; //$NON-NLS-1$ > > private static IProxyService proxyManager; > >+ private AbstractProxyProvider nativeProxyProvider; >+ > ListenerList listeners = new ListenerList(ListenerList.IDENTITY); > private String[] nonProxiedHosts; > private final ProxyType[] proxies = new ProxyType[] { >@@ -49,6 +68,17 @@ > > private boolean migrated = false; > >+ private ProxyManager() { >+ try { >+ nativeProxyProvider = (AbstractProxyProvider) Class.forName( >+ "org.eclipse.core.net.ProxyProvider").newInstance(); //$NON-NLS-1$ >+ } catch (ClassNotFoundException e) { >+ // no class found >+ } catch (Exception e) { >+ Activator.logInfo("Problems occured during the proxy provider initialization.", e); //$NON-NLS-1$ >+ } >+ } >+ > /** > * Return the proxy manager. > * @return the proxy manager >@@ -160,7 +190,7 @@ > for (int i = 0; i < proxyDatas.length; i++) { > IProxyData proxyData = proxyDatas[i]; > ProxyType type = getType(proxyData); >- if (type != null && type.setProxyData(proxyData, isProxiesEnabled())) { >+ if (type != null && type.setProxyData(proxyData, internalIsProxiesEnabled())) { > result.add(proxyData); > } > } >@@ -182,7 +212,13 @@ > */ > public boolean isProxiesEnabled() { > checkMigrated(); >- return Activator.getInstance().getPreferences().getBoolean(PREF_ENABLED, false); >+ return internalIsProxiesEnabled() >+ && (!isSystemProxiesEnabled() || (isSystemProxiesEnabled() && hasSystemProxies())); >+ } >+ >+ private boolean internalIsProxiesEnabled() { >+ return Activator.getInstance().getPreferences().getBoolean( >+ PREF_ENABLED, false); > } > > /* (non-Javadoc) >@@ -190,7 +226,7 @@ > */ > public void setProxiesEnabled(boolean enabled) { > checkMigrated(); >- boolean current = isProxiesEnabled(); >+ boolean current = internalIsProxiesEnabled(); > if (current == enabled) > return; > // Setting the preference will trigger the system property update >@@ -198,9 +234,10 @@ > Activator.getInstance().getPreferences().putBoolean(PREF_ENABLED, enabled); > } > >- private void internalSetEnabled(boolean enabled) { >+ private void internalSetEnabled(boolean enabled, boolean systemEnabled) { > Properties sysProps = System.getProperties(); > sysProps.put("proxySet", enabled ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ >+ sysProps.put("systemProxySet", systemEnabled ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ > updateSystemProperties(); > try { > Activator.getInstance().getPreferences().flush(); >@@ -217,7 +254,7 @@ > private void updateSystemProperties() { > for (int i = 0; i < proxies.length; i++) { > ProxyType type = proxies[i]; >- type.updateSystemProperties(internalGetProxyData(type.getName(), ProxyType.DO_NOT_VERIFY), isProxiesEnabled()); >+ type.updateSystemProperties(internalGetProxyData(type.getName(), ProxyType.DO_NOT_VERIFY), internalIsProxiesEnabled()); > } > } > >@@ -227,7 +264,7 @@ > // Now initialize each proxy type > for (int i = 0; i < proxies.length; i++) { > ProxyType type = proxies[i]; >- type.initialize(isProxiesEnabled()); >+ type.initialize(internalIsProxiesEnabled()); > } > registerAuthenticator(); > } >@@ -249,6 +286,14 @@ > > public IProxyData[] getProxyDataForHost(String host) { > checkMigrated(); >+ if (hasSystemProxies() && isSystemProxiesEnabled()) >+ try { >+ System.out.println(new URI(host)); >+ return nativeProxyProvider.select(new URI(host)); >+ } catch (URISyntaxException e) { >+ return new IProxyData[0]; >+ } >+ > if (isHostFiltered(host)) > return new IProxyData[0]; > IProxyData[] data = getProxyData(); >@@ -281,6 +326,15 @@ > */ > public IProxyData getProxyDataForHost(String host, String type) { > checkMigrated(); >+ if (hasSystemProxies() && isSystemProxiesEnabled()) >+ try { >+ URI uri = new URI(type, "//" + host, null); //$NON-NLS-1$ >+ System.out.println(uri); >+ return nativeProxyProvider.select(uri)[0]; >+ } catch (URISyntaxException e) { >+ return null; >+ } >+ > IProxyData[] data = getProxyDataForHost(host); > for (int i = 0; i < data.length; i++) { > IProxyData proxyData = data[i]; >@@ -341,7 +395,14 @@ > if (instanceEnabled != null) > netConfigurationPrefs.put(PREF_ENABLED, instanceEnabled); > } >- >+ >+ // migrate enabled status >+ if (netConfigurationPrefs.get(PREF_OS, null) == null) { >+ String instanceEnabled = netInstancePrefs.get(PREF_OS, null); >+ if (instanceEnabled != null) >+ netConfigurationPrefs.put(PREF_OS, instanceEnabled); >+ } >+ > // migrate non proxied hosts if not already set > if (netConfigurationPrefs.get(PREF_NON_PROXIED_HOSTS, null) == null) { > String instanceNonProxiedHosts = netInstancePrefs.get(PREF_NON_PROXIED_HOSTS, null); >@@ -434,10 +495,30 @@ > } > > public void preferenceChange(PreferenceChangeEvent event) { >- if (event.getKey().equals(PREF_ENABLED)) { >+ if (event.getKey().equals(PREF_ENABLED) || event.getKey().equals(PREF_OS)) { > checkMigrated(); >- internalSetEnabled(Activator.getInstance().getPreferences().getBoolean(PREF_ENABLED, false)); >+ internalSetEnabled(Activator.getInstance().getPreferences().getBoolean(PREF_ENABLED, false), >+ Activator.getInstance().getPreferences().getBoolean(PREF_OS, false)); > } > } > >+ public boolean hasSystemProxies() { >+ return nativeProxyProvider != null; >+ } >+ >+ public boolean isSystemProxiesEnabled() { >+ checkMigrated(); >+ return Activator.getInstance().getPreferences().getBoolean(PREF_OS, >+ false); >+ } >+ >+ public void setSystemProxiesEnabled(boolean enabled) { >+ checkMigrated(); >+ boolean current = isSystemProxiesEnabled(); >+ if (current == enabled) >+ return; >+ // Setting the preference will trigger the system property update >+ // (see preferenceChange) >+ Activator.getInstance().getPreferences().putBoolean(PREF_OS, enabled); >+ } > } >Index: src/org/eclipse/core/internal/net/AbstractProxyProvider.java >=================================================================== >RCS file: src/org/eclipse/core/internal/net/AbstractProxyProvider.java >diff -N src/org/eclipse/core/internal/net/AbstractProxyProvider.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/core/internal/net/AbstractProxyProvider.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,49 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 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 >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Oakland Software Incorporated - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.core.internal.net; >+ >+import java.net.URI; >+ >+import org.eclipse.core.net.proxy.IProxyData; >+ >+/** >+ * Returns proxies to use. >+ */ >+public abstract class AbstractProxyProvider { >+ >+ /** >+ * Returns proxies to use with the given URI. >+ * >+ * @param uri >+ * the URI that a connection is required to >+ * @return an array of proxies for the given URI >+ */ >+ public IProxyData[] select(URI uri) { >+ String[] nonProxyHosts = getNonProxiedHosts(); >+ String host = uri.getHost(); >+ >+ if (nonProxyHosts != null) { >+ for (int npIndex = 0; npIndex < nonProxyHosts.length; npIndex++) { >+ if (host.equals(nonProxyHosts[npIndex])) { >+ return new IProxyData[0]; >+ } >+ } >+ } >+ >+ return getProxyData(uri); >+ } >+ >+ protected abstract IProxyData[] getProxyData(URI uri); >+ >+ protected String[] getNonProxiedHosts() { >+ return new String[] {}; >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 180921
:
88543
|
90245
|
90246
|
91640
|
91641
|
91739
|
91958
|
91959
|
92027
|
92028
|
92325
|
92545
| 93183 |
93367
|
94535
|
94536
|
94712
|
94713
|
95020
|
95021
|
95030
|
95187
|
95337
|
95343
|
96393