### Eclipse Workspace Patch 1.0
#P org.eclipse.core.net
Index: plugin.xml
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.core.net/plugin.xml,v
retrieving revision 1.3
diff -u -r1.3 plugin.xml
--- plugin.xml 14 May 2009 10:31:50 -0000 1.3
+++ plugin.xml 19 Nov 2010 12:10:31 -0000
@@ -2,6 +2,7 @@
+
+
+
+
+
+
+
Index: schema/proxyProvider.exsd
===================================================================
RCS file: schema/proxyProvider.exsd
diff -N schema/proxyProvider.exsd
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ schema/proxyProvider.exsd 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,102 @@
+
+
+
+
+
+
+
+
+ [Enter description of this extension point.]
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ [Enter the first release in which this extension point appears.]
+
+
+
+
+
+
+
+
+ [Enter extension point usage example here.]
+
+
+
+
+
+
+
+
+ [Enter API information here.]
+
+
+
+
+
+
+
+
+ [Enter information about supplied implementation of this extension point.]
+
+
+
+
+
Index: src/org/eclipse/core/internal/net/AbstractProxyProvider.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.core.net/src/org/eclipse/core/internal/net/AbstractProxyProvider.java,v
retrieving revision 1.6
diff -u -r1.6 AbstractProxyProvider.java
--- src/org/eclipse/core/internal/net/AbstractProxyProvider.java 7 Oct 2010 11:31:02 -0000 1.6
+++ src/org/eclipse/core/internal/net/AbstractProxyProvider.java 19 Nov 2010 12:10:31 -0000
@@ -20,6 +20,10 @@
*/
public abstract class AbstractProxyProvider {
+ public abstract String getName();
+
+ public abstract String getLocalizedName();
+
/**
* Returns proxies to use with the given URI. Returns empty array
* when there is no appropriate proxy.
Index: src/org/eclipse/core/internal/net/Activator.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.core.net/src/org/eclipse/core/internal/net/Activator.java,v
retrieving revision 1.7
diff -u -r1.7 Activator.java
--- src/org/eclipse/core/internal/net/Activator.java 7 Oct 2010 11:24:26 -0000 1.7
+++ src/org/eclipse/core/internal/net/Activator.java 19 Nov 2010 12:10:31 -0000
@@ -49,6 +49,8 @@
private static final String PROP_REGISTER_SERVICE = "org.eclipse.net.core.enableProxyService"; //$NON-NLS-1$
public static final String PT_AUTHENTICATOR = "authenticator"; //$NON-NLS-1$
+
+ public static final String PT_PROXYPROVIDER = "proxyProvider"; //$NON-NLS-1$
private BundleContext bundleContext;
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.9
diff -u -r1.9 ProxyData.java
--- src/org/eclipse/core/internal/net/ProxyData.java 24 Feb 2009 10:04:25 -0000 1.9
+++ src/org/eclipse/core/internal/net/ProxyData.java 19 Nov 2010 12:10:31 -0000
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2009 IBM Corporation and others.
+ * Copyright (c) 2007, 2010 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
@@ -25,7 +25,7 @@
public ProxyData(String type, String host, int port,
boolean requiresAuthentication, String source) {
- this.type = type;
+ this.type = resolveType(type);
this.host = host;
this.port = port;
this.requiresAuthentication = requiresAuthentication;
@@ -33,7 +33,7 @@
}
public ProxyData(String type) {
- this.type = type;
+ this.type = resolveType(type);
}
public String getHost() {
@@ -57,7 +57,7 @@
}
public void setType(String type) {
- this.type = type;
+ this.type = resolveType(type);
}
public void setHost(String host) {
@@ -184,5 +184,16 @@
return false;
return true;
}
+
+ private String resolveType(String proxyType) {
+ if (IProxyData.HTTP_PROXY_TYPE.equalsIgnoreCase(proxyType)) {
+ return IProxyData.HTTP_PROXY_TYPE;
+ } else if (IProxyData.HTTPS_PROXY_TYPE.equalsIgnoreCase(proxyType)) {
+ return IProxyData.HTTPS_PROXY_TYPE;
+ } else if (IProxyData.SOCKS_PROXY_TYPE.equalsIgnoreCase(proxyType)) {
+ return IProxyData.SOCKS_PROXY_TYPE;
+ }
+ throw new IllegalArgumentException("Incorrect proxy data type."); //$NON-NLS-1$
+ }
}
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.28
diff -u -r1.28 ProxyManager.java
--- src/org/eclipse/core/internal/net/ProxyManager.java 25 Oct 2010 14:25:05 -0000 1.28
+++ src/org/eclipse/core/internal/net/ProxyManager.java 19 Nov 2010 12:10:32 -0000
@@ -16,7 +16,9 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
+import java.util.TreeMap;
import org.eclipse.core.net.proxy.IProxyChangeEvent;
import org.eclipse.core.net.proxy.IProxyChangeListener;
@@ -42,10 +44,11 @@
static final String PREF_NON_PROXIED_HOSTS = "nonProxiedHosts"; //$NON-NLS-1$
static final String PREF_ENABLED = "proxiesEnabled"; //$NON-NLS-1$
static final String PREF_OS = "systemProxiesEnabled"; //$NON-NLS-1$
+ static final String PREF_CUSTOM_PROVIDER = "customProxyProvider"; //$NON-NLS-1$
private static IProxyService proxyManager;
-
- private AbstractProxyProvider nativeProxyProvider;
+
+ private Map providers;
private PreferenceManager preferenceManager;
@@ -58,16 +61,51 @@
};
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$
- }
+ providers = new TreeMap();
preferenceManager = Activator.getInstance().getPreferenceManager();
}
+
+ private void initializeProxyProviders() {
+ IExtension[] extensions = RegistryFactory.getRegistry().getExtensionPoint(Activator.ID, Activator.PT_PROXYPROVIDER).getExtensions();
+ if (extensions.length == 0) {
+ return;
+ }
+ for (int i = 0; i < extensions.length; i++) {
+ IConfigurationElement[] configs = extensions[i].getConfigurationElements();
+ for (int j = 0; j < configs.length; j++) {
+ try {
+ Object object = configs[j].createExecutableExtension("class"); //$NON-NLS-1$
+ if (object instanceof AbstractProxyProvider) {
+ AbstractProxyProvider provider = (AbstractProxyProvider) object;
+ if (!providers.containsKey(provider.getName())) {
+ providers.put(provider.getName(), provider);
+ }
+ }
+ } catch (CoreException e) {
+ Activator.logError("Cannot initialize proxy provider", e); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+
+ AbstractProxyProvider getProviderByName(String name) {
+ AbstractProxyProvider provider = (AbstractProxyProvider) providers.get(name);
+ if (provider == null) {
+ throw new IllegalArgumentException("Provider not supported"); //$NON-NLS-1$
+ }
+ return provider;
+ }
+
+ String getCustomProxyProvider() {
+ String provider = preferenceManager.getString(PreferenceManager.ROOT, PREF_CUSTOM_PROVIDER);
+ if (provider != null && providers.containsKey(provider)) {
+ return provider;
+ }
+ if (hasSystemProxies()) {
+ return "Native"; //$NON-NLS-1$
+ }
+ return null;
+ }
/**
* Return the proxy manager.
@@ -123,14 +161,7 @@
System.arraycopy(nonProxiedHosts, 0, result, 0, nonProxiedHosts.length );
return result;
}
-
- public String[] getNativeNonProxiedHosts() {
- if (hasSystemProxies()) {
- return nativeProxyProvider.getNonProxiedHosts();
- }
- return new String[0];
- }
-
+
/* (non-Javadoc)
* @see org.eclipse.core.net.IProxyManager#setNonProxiedHosts(java.lang.String[])
*/
@@ -168,31 +199,20 @@
ProxyType type = proxies[i];
result[i] = type.getProxyData(ProxyType.VERIFY_EQUAL);
}
- return resolveType(result);
- }
-
- public IProxyData[] getNativeProxyData() {
- if (hasSystemProxies()) {
- return resolveType(nativeProxyProvider.getProxyData());
- }
- return new IProxyData[0];
+ return result;
}
public void setProxyData(IProxyData[] proxies) {
checkMigrated();
- doSetProxyData(proxies);
- }
-
- private void doSetProxyData(IProxyData[] proxyDatas) {
IProxyData[] oldData = getProxyData();
String[] hosts = getNonProxiedHosts();
- IProxyData[] changedProxies = internalSetProxyData(proxyDatas);
+ IProxyData[] changedProxies = internalSetProxyData(proxies);
if (changedProxies.length > 0) {
IProxyChangeEvent event = new ProxyChangeEvent(IProxyChangeEvent.PROXY_SERVICE_ENABLEMENT_CHANGE, hosts, hosts, oldData, changedProxies);
fireChange(event);
}
}
-
+
private IProxyData[] internalSetProxyData(IProxyData[] proxyDatas) {
List result = new ArrayList();
for (int i = 0; i < proxyDatas.length; i++) {
@@ -266,6 +286,7 @@
}
public void initialize() {
+ initializeProxyProviders();
checkMigrated();
preferenceManager.addPreferenceChangeListener(PreferenceManager.ROOT, this);
// Now initialize each proxy type
@@ -278,7 +299,7 @@
public IProxyData getProxyData(String type) {
checkMigrated();
- return resolveType(internalGetProxyData(type, ProxyType.VERIFY_EQUAL));
+ return internalGetProxyData(type, ProxyType.VERIFY_EQUAL);
}
private IProxyData internalGetProxyData(String type, int verifySystemProperties) {
@@ -293,28 +314,8 @@
public IProxyData[] getProxyDataForHost(String host) {
checkMigrated();
- if (!internalIsProxiesEnabled()) {
- return new IProxyData[0];
- }
URI uri = tryGetURI(host);
- if (uri == null) {
- return new IProxyData[0];
- }
- if (hasSystemProxies() && isSystemProxiesEnabled()) {
- return resolveType(nativeProxyProvider.select(uri));
- }
-
- if (isHostFiltered(uri))
- return new IProxyData[0];
- IProxyData[] data = getProxyData();
- List result = new ArrayList();
- for (int i = 0; i < data.length; i++) {
- IProxyData proxyData = data[i];
- if (proxyData.getHost() != null)
- result.add(proxyData);
- }
- IProxyData ret[] = (IProxyData[]) result.toArray(new IProxyData[result.size()]);
- return resolveType(ret);
+ return select(uri);
}
public static URI tryGetURI(String host) {
@@ -329,46 +330,18 @@
}
}
- private boolean isHostFiltered(URI uri) {
- String[] filters = getNonProxiedHosts();
- for (int i = 0; i < filters.length; i++) {
- String filter = filters[i];
- if (matchesFilter(uri.getHost(), filter))
- return true;
- }
- return false;
- }
-
- private boolean matchesFilter(String host, String filter) {
- StringMatcher matcher = new StringMatcher(filter, true, false);
- return matcher.match(host);
- }
-
/* (non-Javadoc)
* @see org.eclipse.net.core.IProxyManager#getProxyDataForHost(java.lang.String, java.lang.String)
*/
public IProxyData getProxyDataForHost(String host, String type) {
checkMigrated();
- if (!internalIsProxiesEnabled()) {
+ try {
+ URI uri = new URI(type, "//" + host, null); //$NON-NLS-1$
+ IProxyData[] proxyDatas = select(uri);
+ return proxyDatas.length > 0 ? proxyDatas[0] : null;
+ } catch (URISyntaxException e) {
return null;
}
- if (hasSystemProxies() && isSystemProxiesEnabled())
- try {
- URI uri = new URI(type, "//" + host, null); //$NON-NLS-1$
- IProxyData[] proxyDatas = nativeProxyProvider.select(uri);
- return proxyDatas.length > 0 ? resolveType(proxyDatas[0]) : null;
- } catch (URISyntaxException e) {
- return null;
- }
-
- IProxyData[] data = getProxyDataForHost(host);
- for (int i = 0; i < data.length; i++) {
- IProxyData proxyData = data[i];
- if (proxyData.getType().equalsIgnoreCase(type)
- && proxyData.getHost() != null)
- return resolveType(proxyData);
- }
- return null;
}
private void registerAuthenticator() {
@@ -411,7 +384,7 @@
}
public void preferenceChange(PreferenceChangeEvent event) {
- if (event.getKey().equals(PREF_ENABLED) || event.getKey().equals(PREF_OS)) {
+ if (event.getKey().equals(PREF_ENABLED) || event.getKey().equals(PREF_OS) || event.getKey().equals(PREF_CUSTOM_PROVIDER)) {
checkMigrated();
internalSetEnabled(preferenceManager.getBoolean(PreferenceManager.ROOT, PREF_ENABLED),
preferenceManager.getBoolean(PreferenceManager.ROOT, PREF_OS));
@@ -419,7 +392,7 @@
}
public boolean hasSystemProxies() {
- return nativeProxyProvider != null;
+ return providers.containsKey("Native") ? true : false; //$NON-NLS-1$
}
public boolean isSystemProxiesEnabled() {
@@ -438,36 +411,28 @@
}
public IProxyData[] select(URI uri) {
- IProxyData data = getProxyDataForHost(uri.getHost(), uri.getScheme());
- if (data != null) {
- return resolveType(new IProxyData[] { data });
+ if (uri == null) {
+ throw new IllegalArgumentException("Illegal argument value: " + uri); //$NON-NLS-1$
}
- return new IProxyData[0];
- }
-
- public IProxyData resolveType(IProxyData data) {
- if (data == null) {
- return null;
+ if ("file".equals(uri.getScheme())) { //$NON-NLS-1$
+ return new IProxyData[0];
}
- ProxyData d = (ProxyData) data;
- if (d.getType().equalsIgnoreCase(IProxyData.HTTP_PROXY_TYPE)) {
- d.setType(IProxyData.HTTP_PROXY_TYPE);
- } else if (d.getType().equalsIgnoreCase(IProxyData.HTTPS_PROXY_TYPE)) {
- d.setType(IProxyData.HTTPS_PROXY_TYPE);
- } else if (d.getType().equalsIgnoreCase(IProxyData.SOCKS_PROXY_TYPE)) {
- d.setType(IProxyData.SOCKS_PROXY_TYPE);
+ if (uri.getHost() == null) {
+ uri = tryGetURI(uri.toString());
}
- return d;
+ return internalIsProxiesEnabled() ? getProviderByName(getProxyProvider()).select(uri) : new IProxyData[0];
}
- public IProxyData[] resolveType(IProxyData[] data) {
- if (data == null) {
- return null;
- }
- for (int i = 0; i < data.length; i++) {
- resolveType(data[i]);
- }
- return data;
+ public void setProxyProvider(String name) {
+ preferenceManager.putString(PreferenceManager.ROOT, PREF_CUSTOM_PROVIDER, getProviderByName(name).getName());
+ }
+
+ public String getProxyProvider() {
+ return ProxySelector.getDefaultProvider();
+ }
+
+ public String[] getAvailableProxyProviders() {
+ return (String[]) providers.keySet().toArray(new String[0]);
}
}
Index: src/org/eclipse/core/internal/net/ProxySelector.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.core.net/src/org/eclipse/core/internal/net/ProxySelector.java,v
retrieving revision 1.6
diff -u -r1.6 ProxySelector.java
--- src/org/eclipse/core/internal/net/ProxySelector.java 2 Apr 2009 14:49:53 -0000 1.6
+++ src/org/eclipse/core/internal/net/ProxySelector.java 19 Nov 2010 12:10:32 -0000
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 IBM Corporation and others.
+ * Copyright (c) 2008, 2010 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,9 +11,7 @@
package org.eclipse.core.internal.net;
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;
/**
* This class adapts ProxyManager to add additional layer of providers on its
@@ -22,75 +20,69 @@
public class ProxySelector {
private static final String DIRECT_PROVIDER = "Direct"; //$NON-NLS-1$
- private static final String ECLIPSE_PROVIDER = "Manual"; //$NON-NLS-1$
- private static final String NATIVE_PROVIDER = "Native"; //$NON-NLS-1$
+ private static final String MANUAL_PROVIDER = "Manual"; //$NON-NLS-1$
+
+ private static ProxyManager manager;
+
+ static {
+ manager = (ProxyManager) ProxyManager.getProxyManager();
+ }
public static String[] getProviders() {
- return new String[] { DIRECT_PROVIDER, ECLIPSE_PROVIDER,
- NATIVE_PROVIDER };
+ return manager.getAvailableProxyProviders();
}
public static String unlocalizeProvider(String name) {
- if (Messages.ProxySelector_0.equals(name)) {
- return DIRECT_PROVIDER;
- } else if (Messages.ProxySelector_1.equals(name)) {
- return ECLIPSE_PROVIDER;
- } else if (Messages.ProxySelector_2.equals(name)) {
- return NATIVE_PROVIDER;
+ String[] providers = manager.getAvailableProxyProviders();
+ for (int i = 0; i < providers.length; i++) {
+ AbstractProxyProvider provider = manager.getProviderByName(providers[i]);
+ if (provider.getLocalizedName().equals(name)) {
+ return provider.getName();
+ }
}
Assert.isTrue(false);
return null;
}
public static String localizeProvider(String name) {
- if (DIRECT_PROVIDER.equals(name)) {
- return Messages.ProxySelector_0;
- } else if (ECLIPSE_PROVIDER.equals(name)) {
- return Messages.ProxySelector_1;
- } else if (NATIVE_PROVIDER.equals(name)) {
- return Messages.ProxySelector_2;
+ AbstractProxyProvider proxyProvider = manager.getProviderByName(name);
+ String localizedName = proxyProvider.getLocalizedName();
+ if (localizedName != null) {
+ return localizedName;
}
Assert.isTrue(false);
return null;
}
public static String getDefaultProvider() {
- IProxyService service = ProxyManager.getProxyManager();
- if (!service.isProxiesEnabled()) {
+ if (!manager.isProxiesEnabled()) {
return DIRECT_PROVIDER;
- } else if (service.isProxiesEnabled()
- && !service.isSystemProxiesEnabled()) {
- return ECLIPSE_PROVIDER;
+ }
+ if (!manager.isSystemProxiesEnabled()) {
+ return MANUAL_PROVIDER;
}
- return NATIVE_PROVIDER;
+ String provider = manager.getCustomProxyProvider();
+ return provider != null ? provider : DIRECT_PROVIDER;
}
public static void setActiveProvider(String provider) {
- IProxyService service = ProxyManager.getProxyManager();
if (provider.equals(DIRECT_PROVIDER)) {
- service.setProxiesEnabled(false);
- service.setSystemProxiesEnabled(false);
- } else if (provider.equals(ECLIPSE_PROVIDER)) {
- service.setProxiesEnabled(true);
- service.setSystemProxiesEnabled(false);
- } else if (provider.equals(NATIVE_PROVIDER)) {
- service.setProxiesEnabled(true);
- service.setSystemProxiesEnabled(true);
+ manager.setProxiesEnabled(false);
+ manager.setSystemProxiesEnabled(false);
+ } else if (provider.equals(MANUAL_PROVIDER)) {
+ manager.setProxiesEnabled(true);
+ manager.setSystemProxiesEnabled(false);
} else {
- throw new IllegalArgumentException("Provider not supported"); //$NON-NLS-1$
+ manager.setProxiesEnabled(true);
+ manager.setSystemProxiesEnabled(true);
+ manager.setProxyProvider(provider);
}
+
}
-
+
public static ProxyData[] getProxyData(String provider) {
- ProxyManager manager = (ProxyManager) ProxyManager.getProxyManager();
- if (provider.equals(DIRECT_PROVIDER)) {
- return new ProxyData[0];
- } else if (provider.equals(ECLIPSE_PROVIDER)) {
- return castArray(manager.getProxyData());
- } else if (provider.equals(NATIVE_PROVIDER)) {
- return castArray(manager.getNativeProxyData());
- }
- throw new IllegalArgumentException("Provider not supported"); //$NON-NLS-1$
+ AbstractProxyProvider proxyProvider = manager.getProviderByName(provider);
+ return castArray(proxyProvider.getProxyData());
}
private static ProxyData[] castArray(IProxyData data[]) {
@@ -100,15 +92,8 @@
}
public static void setProxyData(String provider, ProxyData proxies[]) {
- if (provider.equals(ECLIPSE_PROVIDER)) {
- IProxyService service = ProxyManager.getProxyManager();
- try {
- service.setProxyData(proxies);
- } catch (CoreException e) {
- // Should never occur since ProxyManager does not
- // declare CoreException to be thrown
- throw new RuntimeException(e);
- }
+ if (canSetProxyData(provider)) {
+ manager.setProxyData(proxies);
} else {
throw new IllegalArgumentException(
"Provider does not support setting proxy data"); //$NON-NLS-1$
@@ -116,34 +101,17 @@
}
public static boolean canSetProxyData(String provider) {
- if (provider.equals(ECLIPSE_PROVIDER)) {
- return true;
- }
- return false;
+ return provider.equals(MANUAL_PROVIDER);
}
public static String[] getBypassHosts(String provider) {
- ProxyManager manager = (ProxyManager) ProxyManager.getProxyManager();
- if (provider.equals(DIRECT_PROVIDER)) {
- return new String[0];
- } else if (provider.equals(ECLIPSE_PROVIDER)) {
- return manager.getNonProxiedHosts();
- } else if (provider.equals(NATIVE_PROVIDER)) {
- return manager.getNativeNonProxiedHosts();
- }
- throw new IllegalArgumentException("Provider not supported"); //$NON-NLS-1$
+ AbstractProxyProvider proxyProvider = manager.getProviderByName(provider);
+ return proxyProvider.getNonProxiedHosts();
}
public static void setBypassHosts(String provider, String hosts[]) {
- if (provider.equals(ECLIPSE_PROVIDER)) {
- IProxyService service = ProxyManager.getProxyManager();
- try {
- service.setNonProxiedHosts(hosts);
- } catch (CoreException e) {
- // Should never occur since ProxyManager does not
- // declare CoreException to be thrown
- throw new RuntimeException(e);
- }
+ if (canSetBypassHosts(provider)) {
+ manager.setNonProxiedHosts(hosts);
} else {
throw new IllegalArgumentException(
"Provider does not support setting bypass hosts"); //$NON-NLS-1$
@@ -151,10 +119,7 @@
}
public static boolean canSetBypassHosts(String provider) {
- if (provider.equals(ECLIPSE_PROVIDER)) {
- return true;
- }
- return false;
+ return provider.equals(MANUAL_PROVIDER);
}
}
Index: src/org/eclipse/core/internal/net/WindowsProxyProvider.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.core.net/src/org/eclipse/core/internal/net/WindowsProxyProvider.java,v
retrieving revision 1.7
diff -u -r1.7 WindowsProxyProvider.java
--- src/org/eclipse/core/internal/net/WindowsProxyProvider.java 7 Oct 2010 11:31:02 -0000 1.7
+++ src/org/eclipse/core/internal/net/WindowsProxyProvider.java 19 Nov 2010 12:10:32 -0000
@@ -18,6 +18,8 @@
public class WindowsProxyProvider extends AbstractProxyProvider {
+ private static String NAME = "Native"; //$NON-NLS-1$
+
private static final String LIBRARY_NAME = "jWinHttp-1.0.0"; //$NON-NLS-1$
private static boolean jWinHttpLoaded = false;
@@ -44,6 +46,14 @@
}
}
+ public String getName() {
+ return NAME;
+ }
+
+ public String getLocalizedName() {
+ return Messages.ProxySelector_2;
+ }
+
public IProxyData[] select(URI uri) {
IProxyData[] proxies = new IProxyData[0];
if (jWinHttpLoaded) {
Index: src/org/eclipse/core/internal/net/proxy/DirectProxyProvider.java
===================================================================
RCS file: src/org/eclipse/core/internal/net/proxy/DirectProxyProvider.java
diff -N src/org/eclipse/core/internal/net/proxy/DirectProxyProvider.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/core/internal/net/proxy/DirectProxyProvider.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.internal.net.proxy;
+
+import java.net.URI;
+
+import org.eclipse.core.internal.net.AbstractProxyProvider;
+import org.eclipse.core.internal.net.Messages;
+import org.eclipse.core.net.proxy.IProxyData;
+
+public class DirectProxyProvider extends AbstractProxyProvider {
+
+ private static String NAME = "Direct"; //$NON-NLS-1$
+
+ public String getName() {
+ return NAME;
+ }
+
+ public String getLocalizedName() {
+ return Messages.ProxySelector_0;
+ }
+
+ public IProxyData[] select(URI uri) {
+ return new IProxyData[0];
+ }
+
+ protected IProxyData[] getProxyData() {
+ return new IProxyData[0];
+ }
+
+ protected String[] getNonProxiedHosts() {
+ return new String[0];
+ }
+
+}
Index: src/org/eclipse/core/internal/net/proxy/ManualProxyProvider.java
===================================================================
RCS file: src/org/eclipse/core/internal/net/proxy/ManualProxyProvider.java
diff -N src/org/eclipse/core/internal/net/proxy/ManualProxyProvider.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/core/internal/net/proxy/ManualProxyProvider.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.internal.net.proxy;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.internal.net.AbstractProxyProvider;
+import org.eclipse.core.internal.net.Messages;
+import org.eclipse.core.internal.net.ProxyManager;
+import org.eclipse.core.internal.net.StringMatcher;
+import org.eclipse.core.net.proxy.IProxyData;
+
+public class ManualProxyProvider extends AbstractProxyProvider {
+
+ private static String NAME = "Manual"; //$NON-NLS-1$
+
+ public String getName() {
+ return NAME;
+ }
+
+ public String getLocalizedName() {
+ return Messages.ProxySelector_1;
+ }
+
+ public IProxyData[] select(URI uri) {
+ String[] nonProxyHosts = getNonProxiedHosts();
+ if (nonProxyHosts != null) {
+ String host = uri.getHost();
+ for (int npIndex = 0; npIndex < nonProxyHosts.length; npIndex++) {
+ if (matchesFilter(host, nonProxyHosts[npIndex])) {
+ return new IProxyData[0];
+ }
+ }
+ }
+
+ IProxyData[] data = getProxyData();
+ List result = new ArrayList();
+ for (int i = 0; i < data.length; i++) {
+ IProxyData proxyData = data[i];
+ if (proxyData.getHost() != null)
+ result.add(proxyData);
+ }
+ data = (IProxyData[]) result.toArray(new IProxyData[result.size()]);
+ if (uri.getScheme() == null) {
+ return data;
+ }
+ for (int i = 0; i < data.length; i++) {
+ IProxyData proxyData = data[i];
+ if (proxyData.getType().equalsIgnoreCase(uri.getScheme()) && proxyData.getHost() != null) {
+ return new IProxyData[] { proxyData };
+ }
+ }
+ return new IProxyData[0];
+ }
+
+ protected IProxyData[] getProxyData() {
+ return ProxyManager.getProxyManager().getProxyData();
+ }
+
+ protected String[] getNonProxiedHosts() {
+ return ProxyManager.getProxyManager().getNonProxiedHosts();
+ }
+
+ private boolean matchesFilter(String host, String filter) {
+ StringMatcher matcher = new StringMatcher(filter, true, false);
+ return matcher.match(host);
+ }
+
+}
Index: src/org/eclipse/core/internal/net/proxy/unix/UnixProxyProvider.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.core.net/src/org/eclipse/core/internal/net/proxy/unix/UnixProxyProvider.java,v
retrieving revision 1.22
diff -u -r1.22 UnixProxyProvider.java
--- src/org/eclipse/core/internal/net/proxy/unix/UnixProxyProvider.java 7 Oct 2010 11:31:02 -0000 1.22
+++ src/org/eclipse/core/internal/net/proxy/unix/UnixProxyProvider.java 19 Nov 2010 12:10:33 -0000
@@ -19,6 +19,7 @@
import org.eclipse.core.internal.net.AbstractProxyProvider;
import org.eclipse.core.internal.net.Activator;
+import org.eclipse.core.internal.net.Messages;
import org.eclipse.core.internal.net.Policy;
import org.eclipse.core.internal.net.ProxyData;
import org.eclipse.core.internal.net.StringMatcher;
@@ -27,6 +28,8 @@
public class UnixProxyProvider extends AbstractProxyProvider {
+ private static String NAME = "Native"; //$NON-NLS-1$
+
private static final String LIBRARY_GCONF2 = "gconf-2"; //$NON-NLS-1$
private static final String LIBRARY_NAME = "gnomeproxy-1.0.0"; //$NON-NLS-1$
@@ -49,6 +52,14 @@
// Nothing to initialize
}
+ public String getName() {
+ return NAME;
+ }
+
+ public String getLocalizedName() {
+ return Messages.ProxySelector_2;
+ }
+
public IProxyData[] select(URI uri) {
String[] nonProxyHosts = getNonProxiedHosts();
if (nonProxyHosts != null) {
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.7
diff -u -r1.7 IProxyService.java
--- src/org/eclipse/core/net/proxy/IProxyService.java 21 Nov 2008 16:00:54 -0000 1.7
+++ src/org/eclipse/core/net/proxy/IProxyService.java 19 Nov 2010 12:10:33 -0000
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 IBM Corporation and others.
+ * Copyright (c) 2007, 2010 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
@@ -260,4 +260,43 @@
* @param listener a change listener
*/
void removeProxyChangeListener(IProxyChangeListener listener);
+
+ /**
+ *
+ * Sets proxy provider that will be used to provide proxy data for methods:
+ *
{@link #select(URI)}
+ * {@link #getProxyDataForHost(String)}
+ * {@link #getProxyDataForHost(String, String)}
+ *
+ *
+ * To use provider which was set using this method,
+ * {@link #isProxiesEnabled()} and {@link #isSystemProxiesEnabled()}
+ * have to return true
. Otherwise, value set by calling this method will be ignored.
+ *
+ * @param name - proxy provider's name.
+ * To get all available providers call {@link #getAvailableProxyProviders()}
+ * @throws IllegalArgumentException - if there is no proxy provider with the given name
+ */
+ void setProxyProvider(String name) throws IllegalArgumentException;
+
+ /**
+ * Returns name of a current proxy provider which was set by calling {@link #setProxyProvider(String)}.
+ * This method returns:
+ * Direct
- if {@link #isProxiesEnabled()} returns false
+ * Manual
- if {@link #isProxiesEnabled()} returns true
and {@link #isSystemProxiesEnabled()} returns false
+ * Custom
- if {@link #isProxiesEnabled()} returns true
and {@link #isSystemProxiesEnabled()} returns true
,
+ * where Custom
is a provider set by calling {@link #setProxyProvider(String)}.
+ * If there was no call to this method it returns Native
provider.
+ * If Native is unavailable, it returns Direct
.
+ * @return name of a current proxy provider
+ */
+ String getProxyProvider();
+
+ /**
+ * Returns all available proxy providers. Name is a unique identifier of each proxy provider.
+ * This method can be used to retrive providers which can be set using {@link #setProxyProvider(String)}
+ * New proxy provider can be added by extending org.eclipse.core.net.proxyProvider extension point.
+ * @return array of available providers names
+ */
+ String[] getAvailableProxyProviders();
}
#P org.eclipse.core.net.win32.x86
Index: build.properties
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.core.net/fragments/org.eclipse.core.net.win32.x86/build.properties,v
retrieving revision 1.3
diff -u -r1.3 build.properties
--- build.properties 3 Sep 2008 14:05:42 -0000 1.3
+++ build.properties 19 Nov 2010 12:10:34 -0000
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2008 IBM Corporation and others.
+# Copyright (c) 2008, 2010 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,7 +13,8 @@
about.html,\
META-INF/,\
bin/,\
- jWinHttp-1.0.0.dll
+ jWinHttp-1.0.0.dll,\
+ fragment.xml
generateSourceBundle=false
src.includes = about.html
source.. = src/
Index: fragment.xml
===================================================================
RCS file: fragment.xml
diff -N fragment.xml
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ fragment.xml 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
Index: src/org/eclipse/core/net/ProxyProvider.java
===================================================================
RCS file: src/org/eclipse/core/net/ProxyProvider.java
diff -N src/org/eclipse/core/net/ProxyProvider.java
--- src/org/eclipse/core/net/ProxyProvider.java 10 Apr 2008 10:18:21 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,16 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 compeople AG 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:
- * compeople AG (Stefan Liebig) - initial API and implementation
- *******************************************************************************/
-package org.eclipse.core.net;
-
-import org.eclipse.core.internal.net.WindowsProxyProvider;
-
-public class ProxyProvider extends WindowsProxyProvider {
-}
#P org.eclipse.core.tests.net
Index: META-INF/MANIFEST.MF
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.core.tests.net/META-INF/MANIFEST.MF,v
retrieving revision 1.7
diff -u -r1.7 MANIFEST.MF
--- META-INF/MANIFEST.MF 20 Apr 2010 13:13:54 -0000 1.7
+++ META-INF/MANIFEST.MF 19 Nov 2010 12:10:35 -0000
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Net Tests Plug-in
-Bundle-SymbolicName: org.eclipse.core.tests.net
+Bundle-SymbolicName: org.eclipse.core.tests.net;singleton:=true
Bundle-Version: 1.2.100.qualifier
Bundle-Activator: org.eclipse.core.tests.net.Activator
Bundle-Vendor: Eclipse.org
Index: plugin.xml
===================================================================
RCS file: plugin.xml
diff -N plugin.xml
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ plugin.xml 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
Index: src/org/eclipse/core/tests/net/CustomProxyProvider.java
===================================================================
RCS file: src/org/eclipse/core/tests/net/CustomProxyProvider.java
diff -N src/org/eclipse/core/tests/net/CustomProxyProvider.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/core/tests/net/CustomProxyProvider.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.tests.net;
+
+import java.net.URI;
+
+import org.eclipse.core.internal.net.AbstractProxyProvider;
+import org.eclipse.core.internal.net.ProxyData;
+import org.eclipse.core.internal.net.StringMatcher;
+import org.eclipse.core.net.proxy.IProxyData;
+
+public class CustomProxyProvider extends AbstractProxyProvider {
+
+ private static String NAME = "Test"; //$NON-NLS-1$
+
+ private IProxyData[] proxies = {
+ new ProxyData(IProxyData.HTTP_PROXY_TYPE, "customHttp", 1, false, NAME),
+ new ProxyData(IProxyData.HTTPS_PROXY_TYPE, "customHttps", 2, false, NAME),
+ new ProxyData(IProxyData.SOCKS_PROXY_TYPE, "customSocks", 3, false, NAME),
+ };
+
+ public String getName() {
+ return NAME;
+ }
+
+ public String getLocalizedName() {
+ return NAME;
+ }
+
+ public IProxyData[] select(URI uri) {
+ String[] nonProxyHosts = getNonProxiedHosts();
+ if (nonProxyHosts != null) {
+ String host = uri.getHost();
+ for (int npIndex = 0; npIndex < nonProxyHosts.length; npIndex++) {
+ if (matchesFilter(host, nonProxyHosts[npIndex])) {
+ return new IProxyData[0];
+ }
+ }
+ }
+
+ String scheme = uri.getScheme();
+ if (scheme != null) {
+ if (scheme.equalsIgnoreCase(IProxyData.HTTP_PROXY_TYPE)) {
+ return new IProxyData[] { proxies[0] };
+ }
+ if (scheme.equalsIgnoreCase(IProxyData.HTTPS_PROXY_TYPE)) {
+ return new IProxyData[] { proxies[1] };
+ }
+ if (scheme.equalsIgnoreCase(IProxyData.SOCKS_PROXY_TYPE)) {
+ return new IProxyData[] { proxies[2] };
+ }
+ }
+ return proxies;
+ }
+
+ protected IProxyData[] getProxyData() {
+ return proxies;
+ }
+
+ protected String[] getNonProxiedHosts() {
+ return new String[] { "customBypass" };
+ }
+
+ private boolean matchesFilter(String host, String filter) {
+ StringMatcher matcher = new StringMatcher(filter, true, false);
+ return matcher.match(host);
+ }
+
+}
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.13
diff -u -r1.13 NetTest.java
--- src/org/eclipse/core/tests/net/NetTest.java 20 Apr 2010 13:13:54 -0000 1.13
+++ src/org/eclipse/core/tests/net/NetTest.java 19 Nov 2010 12:10:36 -0000
@@ -15,6 +15,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -431,6 +432,95 @@
this.getProxyManager().setNonProxiedHosts(oldHosts);
}
+
+ public void testCustomProxyProvider() {
+ List providers = Arrays.asList(getProxyManager().getAvailableProxyProviders());
+ assertEquals(4, providers.size());
+ assertTrue(providers.contains("Direct"));
+ assertTrue(providers.contains("Manual"));
+ assertTrue(providers.contains("Native"));
+ assertTrue(providers.contains("Test"));
+ }
+
+ public void testSetCustomProxyProvider() throws CoreException {
+ setDataTest(IProxyData.HTTP_PROXY_TYPE);
+ setDataTest(IProxyData.HTTPS_PROXY_TYPE);
+ setDataTest(IProxyData.SOCKS_PROXY_TYPE);
+
+ IProxyService service = getProxyManager();
+ service.setProxyProvider("Test");
+
+ setSystemProxiesEnabled(false);
+ setProxiesEnabled(false);
+ assertEquals("Direct", service.getProxyProvider());
+ validateSystemProperties(false);
+
+ setSystemProxiesEnabled(false);
+ setProxiesEnabled(true);
+ assertEquals("Manual", service.getProxyProvider());
+ validateSystemProperties(true);
+
+ setSystemProxiesEnabled(true);
+ setProxiesEnabled(true);
+ assertEquals("Test", service.getProxyProvider());
+
+ setSystemProxiesEnabled(false);
+ setProxiesEnabled(false);
+ assertEquals("Direct", service.getProxyProvider());
+ validateSystemProperties(false);
+ }
+
+ public void testSelectCustomProxyProvider() throws CoreException, URISyntaxException {
+ IProxyService service = getProxyManager();
+ service.setProxyProvider("Test");
+ setSystemProxiesEnabled(true);
+
+ IProxyData[] proxies = service.select(new URI("eclipse.org"));
+ assertEquals(3, proxies.length);
+
+ IProxyData[] httpProxy = service.select(new URI("http://eclipse.org"));
+ assertEquals(1, httpProxy.length);
+ assertEquals(proxies[0], httpProxy[0]);
+
+ IProxyData[] httpsProxy = service.select(new URI("https://eclipse.org"));
+ assertEquals(1, httpsProxy.length);
+ assertEquals(proxies[1], httpsProxy[0]);
+
+ IProxyData[] socksProxy = service.select(new URI("socks://eclipse.org"));
+ assertEquals(1, socksProxy.length);
+ assertEquals(proxies[2], socksProxy[0]);
+ }
+
+ public void testChangeCustomProxyProvider() throws CoreException, URISyntaxException {
+ IProxyService service = getProxyManager();
+ service.setProxyProvider("Test");
+ setSystemProxiesEnabled(true);
+
+ IProxyData[] proxies = service.select(new URI("eclipse.org"));
+ assertEquals(3, proxies.length);
+
+ service.setProxyProvider("Native");
+ proxies = service.select(new URI("eclipse.org"));
+ assertEquals(0, proxies.length);
+ }
+
+ public void testBypassProxyProvider() throws CoreException, URISyntaxException {
+ IProxyService service = getProxyManager();
+ service.setProxyProvider("Test");
+ setSystemProxiesEnabled(true);
+
+ IProxyData[] proxies = service.select(new URI("customBypass"));
+ assertEquals(0, proxies.length);
+
+ IProxyData[] httpProxy = service.select(new URI("http://customBypass"));
+ assertEquals(0, httpProxy.length);
+
+ IProxyData[] httpsProxy = service.select(new URI("https://customBypass"));
+ assertEquals(0, httpsProxy.length);
+
+ IProxyData[] socksProxy = service.select(new URI("socks://customBypass"));
+ assertEquals(0, socksProxy.length);
+ }
private void validateSystemProperties(boolean present) {
validateProperty("http.proxySet", "true", present);