### Eclipse Workspace Patch 1.0 #P org.eclipse.core.net Index: src/org/eclipse/core/internal/net/ProxyData.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxyData.java,v retrieving revision 1.7 diff -u -r1.7 ProxyData.java --- src/org/eclipse/core/internal/net/ProxyData.java 20 Nov 2008 15:50:10 -0000 1.7 +++ src/org/eclipse/core/internal/net/ProxyData.java 21 Nov 2008 15:31:11 -0000 @@ -128,4 +128,61 @@ return stringBuffer.toString(); } + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (dynamic ? 1231 : 1237); + result = prime * result + ((host == null) ? 0 : host.hashCode()); + result = prime * result + + ((password == null) ? 0 : password.hashCode()); + result = prime * result + port; + result = prime * result + (requiresAuthentication ? 1231 : 1237); + result = prime * result + ((source == null) ? 0 : source.hashCode()); + result = prime * result + ((type == null) ? 0 : type.hashCode()); + result = prime * result + ((user == null) ? 0 : user.hashCode()); + return result; + } + + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ProxyData other = (ProxyData) obj; + if (dynamic != other.dynamic) + return false; + if (host == null) { + if (other.host != null) + return false; + } else if (!host.equals(other.host)) + return false; + if (password == null) { + if (other.password != null) + return false; + } else if (!password.equals(other.password)) + return false; + if (port != other.port) + return false; + if (requiresAuthentication != other.requiresAuthentication) + return false; + if (source == null) { + if (other.source != null) + return false; + } else if (!source.equals(other.source)) + return false; + if (type == null) { + if (other.type != null) + return false; + } else if (!type.equals(other.type)) + return false; + if (user == null) { + if (other.user != null) + return false; + } else if (!user.equals(other.user)) + return false; + return true; + } + } 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.19 diff -u -r1.19 ProxyManager.java --- src/org/eclipse/core/internal/net/ProxyManager.java 18 Nov 2008 15:16:53 -0000 1.19 +++ src/org/eclipse/core/internal/net/ProxyManager.java 21 Nov 2008 15:31:11 -0000 @@ -549,4 +549,13 @@ // (see preferenceChange) Activator.getInstance().getPreferences().putBoolean(PREF_OS, enabled); } + + public IProxyData[] select(URI uri) { + IProxyData data = getProxyDataForHost(uri.getHost(), uri.getScheme()); + if (data != null) { + return new IProxyData[] { data }; + } + return new IProxyData[0]; + } + } 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.6 diff -u -r1.6 IProxyService.java --- src/org/eclipse/core/net/proxy/IProxyService.java 3 Jun 2008 13:35:40 -0000 1.6 +++ src/org/eclipse/core/net/proxy/IProxyService.java 21 Nov 2008 15:31:11 -0000 @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.core.net.proxy; +import java.net.URI; + import org.eclipse.core.runtime.CoreException; /** @@ -105,7 +107,22 @@ * @return the list of know proxy types and their settings */ IProxyData[] getProxyData(); - + + /** + * Returns all the applicable proxy data to access the specified URI. + *

+ * Clients that wish to make a connection and need to determine whether to + * use a proxy should use this method. + *

+ * @param uri + * the URI for which proxies are returned + * @return list of all applicable proxy data, if no proxy is applicable then + * an empty array is returned + * + * @since 1.2 + */ + IProxyData[] select(URI uri); + /** * Returns the list of known proxy types and their settings for the * given host. If proxies are disabled @@ -117,6 +134,8 @@ * Clients that wish to make a connection and need to determine whether to * use a proxy should use this method. *

+ * @deprecated This method is deprecated because of its ambiguity. Use + * {@link #select(URI)} instead. * * @param host the host for which a connection is desired * @return the list of known proxy types and their settings for the @@ -159,6 +178,8 @@ * Clients that wish to make a connection and need to determine whether to * use a proxy should use this method. *

+ * @deprecated This method is deprecated because of its ambiguity. Use + * {@link #select(URI)} instead. * * @param host * the host for which a connection is desired #P org.eclipse.core.tests.net Index: src/org/eclipse/core/tests/net/NetTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.tests.net/src/org/eclipse/core/tests/net/NetTest.java,v retrieving revision 1.7 diff -u -r1.7 NetTest.java --- src/org/eclipse/core/tests/net/NetTest.java 29 Sep 2008 11:10:31 -0000 1.7 +++ src/org/eclipse/core/tests/net/NetTest.java 21 Nov 2008 15:31:13 -0000 @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.core.tests.net; +import java.net.URI; +import java.net.URISyntaxException; import java.util.*; import junit.framework.*; @@ -343,4 +345,24 @@ this.getProxyManager().setNonProxiedHosts(oldHosts); } + public void testBug247408() throws CoreException, URISyntaxException { + setDataTest(IProxyData.HTTP_PROXY_TYPE); + setDataTest(IProxyData.HTTPS_PROXY_TYPE); + setDataTest(IProxyData.SOCKS_PROXY_TYPE); + + IProxyData data1 = this.getProxyManager().getProxyDataForHost( + "randomhost.com", IProxyData.HTTP_PROXY_TYPE); + IProxyData[] data2 = this.getProxyManager().select( + new URI("http://randomhost.com")); + assertEquals(data2.length, 1); + assertEquals(data1, data2[0]); + + IProxyData data3 = this.getProxyManager().getProxyDataForHost( + "randomhost.com", null); + IProxyData[] data4 = this.getProxyManager().select( + new URI(null, "randomhost.com", null, null)); + assertNull(data3); + assertEquals(data4.length, 0); + } + }