View | Details | Raw Unified | Return to bug 257443 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/core/internal/net/ProxyType.java (-2 / +7 lines)
Lines 30-35 Link Here
30
30
31
public class ProxyType implements INodeChangeListener, IPreferenceChangeListener {
31
public class ProxyType implements INodeChangeListener, IPreferenceChangeListener {
32
32
33
	// TODO: ProxyType should be a data container object only.
34
	// Most of the logic, including anything proxy-type specific, should be moved into the various provider implementations.
35
	
33
	/**
36
	/**
34
	 * Preference keys
37
	 * Preference keys
35
	 */
38
	 */
Lines 176-182 Link Here
176
		updatePreferences(getPreferenceNode(), proxyData);
179
		updatePreferences(getPreferenceNode(), proxyData);
177
	}
180
	}
178
	
181
	
179
	/* package */ void updatePreferencesIfMissing(Preferences node, IProxyData proxyData) {
182
	// TODO: Remove public.  Temporarily needed for child-package access from EclipseProvider.
183
	public void updatePreferencesIfMissing(Preferences node, IProxyData proxyData) {
180
		Preferences proxyNode = node.node(PREF_PROXY_DATA_NODE).node(getName());
184
		Preferences proxyNode = node.node(PREF_PROXY_DATA_NODE).node(getName());
181
		if (node.get(PREF_PROXY_HOST, null) == null)
185
		if (node.get(PREF_PROXY_HOST, null) == null)
182
			updatePreferences(proxyNode, proxyData);
186
			updatePreferences(proxyNode, proxyData);
Lines 205-211 Link Here
205
		}
209
		}
206
	}
210
	}
207
	
211
	
208
	/* package */void updateSystemProperties(IProxyData proxyData, boolean proxiesEnabled) {
212
	// TODO: Remove public.  Temporarily needed for child-package access from EclipseProvider.
213
	public void updateSystemProperties(IProxyData proxyData, boolean proxiesEnabled) {
209
		try {
214
		try {
210
			if (proxyData.getType().equals(IProxyData.HTTP_PROXY_TYPE)) {
215
			if (proxyData.getType().equals(IProxyData.HTTP_PROXY_TYPE)) {
211
				updateHttpSystemProperties(proxyData, proxiesEnabled);
216
				updateHttpSystemProperties(proxyData, proxiesEnabled);
(-)src/org/eclipse/core/internal/net/PreferenceModifyListener.java (-10 / +8 lines)
Lines 10-19 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.core.internal.net;
11
package org.eclipse.core.internal.net;
12
12
13
import org.eclipse.core.runtime.preferences.ConfigurationScope;
14
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
13
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
15
import org.eclipse.core.runtime.preferences.InstanceScope;
16
import org.osgi.service.prefs.BackingStoreException;
17
14
18
public class PreferenceModifyListener extends
15
public class PreferenceModifyListener extends
19
		org.eclipse.core.runtime.preferences.PreferenceModifyListener {
16
		org.eclipse.core.runtime.preferences.PreferenceModifyListener {
Lines 23-35 Link Here
23
	}
20
	}
24
	
21
	
25
	public IEclipsePreferences preApply(IEclipsePreferences node) {
22
	public IEclipsePreferences preApply(IEclipsePreferences node) {
26
		try {
23
		// TODO: Fix and re-enable preApply if needed.
27
			if (node.nodeExists(InstanceScope.SCOPE)) {
24
//		try {
28
				((ProxyManager)ProxyManager.getProxyManager()).migrateInstanceScopePreferences(node.node(InstanceScope.SCOPE), node.node(ConfigurationScope.SCOPE), false);
25
//			if (node.nodeExists(InstanceScope.SCOPE)) {
29
			}
26
//				((ProxyManager)ProxyManager.getProxyManager()).migrateInstanceScopePreferences(node.node(InstanceScope.SCOPE), node.node(ConfigurationScope.SCOPE), false);
30
		} catch (BackingStoreException e) {
27
//			}
31
			Activator.logError("Could not access instance preferences", e); //$NON-NLS-1$
28
//		} catch (BackingStoreException e) {
32
		}
29
//			Activator.logError("Could not access instance preferences", e); //$NON-NLS-1$
30
//		}
33
		return super.preApply(node);
31
		return super.preApply(node);
34
	}
32
	}
35
33
(-)src/org/eclipse/core/internal/net/Activator.java (-2 / +2 lines)
Lines 50-55 Link Here
50
	private static final String PROP_REGISTER_SERVICE = "org.eclipse.net.core.enableProxyService"; //$NON-NLS-1$
50
	private static final String PROP_REGISTER_SERVICE = "org.eclipse.net.core.enableProxyService"; //$NON-NLS-1$
51
51
52
	public static final String PT_AUTHENTICATOR = "authenticator"; //$NON-NLS-1$
52
	public static final String PT_AUTHENTICATOR = "authenticator"; //$NON-NLS-1$
53
	public static final String PT_PROVIDER = "provider"; //$NON-NLS-1$
53
54
54
	private BundleContext bundleContext;
55
	private BundleContext bundleContext;
55
56
Lines 174-181 Link Here
174
175
175
		if (Boolean
176
		if (Boolean
176
				.valueOf(System.getProperty(PROP_REGISTER_SERVICE, "true")).booleanValue()) { //$NON-NLS-1$
177
				.valueOf(System.getProperty(PROP_REGISTER_SERVICE, "true")).booleanValue()) { //$NON-NLS-1$
177
			ProxyManager proxyManager = (ProxyManager) ProxyManager
178
			ProxyManager proxyManager = ProxyManager.getProxyManager();
178
					.getProxyManager();
179
			proxyManager.initialize();
179
			proxyManager.initialize();
180
			proxyService = context.registerService(IProxyService.class
180
			proxyService = context.registerService(IProxyService.class
181
					.getName(), proxyManager, new Hashtable());
181
					.getName(), proxyManager, new Hashtable());
(-)src/org/eclipse/core/internal/net/AbstractProxyProvider.java (-3 / +5 lines)
Lines 14-22 Link Here
14
import java.net.URI;
14
import java.net.URI;
15
15
16
import org.eclipse.core.net.proxy.IProxyData;
16
import org.eclipse.core.net.proxy.IProxyData;
17
import org.eclipse.core.net.proxy.IProxyProvider;
17
18
18
/**
19
/**
19
 * Returns proxies to use.
20
 * Returns proxies to use.
21
 * @deprecated Use {@link IProxyProvider} instead.
20
 */
22
 */
21
public abstract class AbstractProxyProvider {
23
public abstract class AbstractProxyProvider {
22
24
Lines 51-59 Link Here
51
		return proxies;
53
		return proxies;
52
	}
54
	}
53
55
54
	protected abstract IProxyData[] getProxyData(URI uri);
56
	public abstract IProxyData[] getProxyData(URI uri);
55
57
56
	protected abstract IProxyData[] getProxyData();
58
	public abstract IProxyData[] getProxyData();
57
59
58
	protected abstract String[] getNonProxiedHosts();
60
	public abstract String[] getNonProxiedHosts();
59
}
61
}
(-)src/org/eclipse/core/internal/net/WindowsProxyProvider.java (-3 / +3 lines)
Lines 37-51 Link Here
37
		winHttpProxyProvider = new WinHttpProxyProvider();
37
		winHttpProxyProvider = new WinHttpProxyProvider();
38
	}
38
	}
39
39
40
	protected IProxyData[] getProxyData(URI uri) {
40
	public IProxyData[] getProxyData(URI uri) {
41
		return winHttpProxyProvider.getProxyData(uri);
41
		return winHttpProxyProvider.getProxyData(uri);
42
	}
42
	}
43
43
44
	protected IProxyData[] getProxyData() {
44
	public IProxyData[] getProxyData() {
45
		return winHttpProxyProvider.getProxyData();
45
		return winHttpProxyProvider.getProxyData();
46
	}
46
	}
47
47
48
	protected String[] getNonProxiedHosts() {
48
	public String[] getNonProxiedHosts() {
49
		return winHttpProxyProvider.getNonProxiedHosts();
49
		return winHttpProxyProvider.getNonProxiedHosts();
50
	}
50
	}
51
51
(-)src/org/eclipse/core/internal/net/ProxyManager.java (-483 / +120 lines)
Lines 7-27 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Mark A. Ziesemer - Refactoring into seperate extensions.
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.core.internal.net;
12
package org.eclipse.core.internal.net;
12
13
13
import java.net.Authenticator;
14
import java.net.URI;
14
import java.net.URI;
15
import java.net.URISyntaxException;
15
import java.util.LinkedList;
16
import java.util.ArrayList;
17
import java.util.List;
16
import java.util.List;
18
import java.util.Properties;
19
17
18
import org.eclipse.core.internal.net.providers.DirectProvider;
20
import org.eclipse.core.net.proxy.IProxyChangeEvent;
19
import org.eclipse.core.net.proxy.IProxyChangeEvent;
21
import org.eclipse.core.net.proxy.IProxyChangeListener;
20
import org.eclipse.core.net.proxy.IProxyChangeListener;
22
import org.eclipse.core.net.proxy.IProxyData;
21
import org.eclipse.core.net.proxy.IProxyData;
22
import org.eclipse.core.net.proxy.IProxyProvider;
23
import org.eclipse.core.net.proxy.IProxyService;
23
import org.eclipse.core.net.proxy.IProxyService;
24
import org.eclipse.core.runtime.Assert;
25
import org.eclipse.core.runtime.CoreException;
24
import org.eclipse.core.runtime.CoreException;
26
import org.eclipse.core.runtime.IConfigurationElement;
25
import org.eclipse.core.runtime.IConfigurationElement;
27
import org.eclipse.core.runtime.IExtension;
26
import org.eclipse.core.runtime.IExtension;
Lines 30-94 Link Here
30
import org.eclipse.core.runtime.ListenerList;
29
import org.eclipse.core.runtime.ListenerList;
31
import org.eclipse.core.runtime.RegistryFactory;
30
import org.eclipse.core.runtime.RegistryFactory;
32
import org.eclipse.core.runtime.SafeRunner;
31
import org.eclipse.core.runtime.SafeRunner;
33
import org.eclipse.core.runtime.preferences.ConfigurationScope;
34
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
32
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
35
import org.eclipse.core.runtime.preferences.InstanceScope;
36
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
33
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
37
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
34
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
38
import org.eclipse.osgi.util.NLS;
35
import org.eclipse.osgi.util.NLS;
39
import org.osgi.service.prefs.BackingStoreException;
40
import org.osgi.service.prefs.Preferences;
41
36
42
public class ProxyManager implements IProxyService, IPreferenceChangeListener {
37
public class ProxyManager implements IProxyService, IPreferenceChangeListener {
43
38
44
	private static final String PREF_HAS_MIGRATED = "org.eclipse.core.net.hasMigrated"; //$NON-NLS-1$
39
	private static final String PREF_PROVIDER = "provider"; //$NON-NLS-1$
40
	private static final String PROVIDER_DEFAULT = DirectProvider.class.getName();
45
	
41
	
46
	/**
42
	private static ProxyManager proxyManager;
47
	 * Preference constants used by Update to record the HTTP proxy
48
	 */
49
	private static String HTTP_PROXY_HOST = "org.eclipse.update.core.proxy.host"; //$NON-NLS-1$
50
	private static String HTTP_PROXY_PORT = "org.eclipse.update.core.proxy.port"; //$NON-NLS-1$
51
	private static String HTTP_PROXY_ENABLE = "org.eclipse.update.core.proxy.enable"; //$NON-NLS-1$
52
	
53
	private static final String PREF_NON_PROXIED_HOSTS = "nonProxiedHosts"; //$NON-NLS-1$
54
	private static final String PREF_ENABLED = "proxiesEnabled"; //$NON-NLS-1$
55
	private static final String PREF_OS = "systemProxiesEnabled"; //$NON-NLS-1$
56
	
57
	private static IProxyService proxyManager;
58
	
43
	
59
	private AbstractProxyProvider nativeProxyProvider;
44
	private IProxyProvider provider;
60
	
45
	
61
	ListenerList listeners = new ListenerList(ListenerList.IDENTITY);
46
	ListenerList listeners = new ListenerList(ListenerList.IDENTITY);
62
	private String[] nonProxiedHosts;
63
	private final ProxyType[] proxies = new ProxyType[] {
64
			new ProxyType(IProxyData.HTTP_PROXY_TYPE),
65
			new ProxyType(IProxyData.HTTPS_PROXY_TYPE),
66
			new ProxyType(IProxyData.SOCKS_PROXY_TYPE)
67
		};
68
69
	private boolean migrated = false;
70
71
	private ProxyManager() {
72
		try {
73
			nativeProxyProvider = (AbstractProxyProvider) Class.forName(
74
					"org.eclipse.core.net.ProxyProvider").newInstance(); //$NON-NLS-1$
75
		} catch (ClassNotFoundException e) {
76
			// no class found
77
		} catch (Exception e) {
78
			Activator.logInfo("Problems occured during the proxy provider initialization.", e); //$NON-NLS-1$
79
		}
80
	}
81
47
82
	/**
48
	/**
83
	 * Return the proxy manager.
49
	 * Return the proxy manager.
84
	 * @return the proxy manager
50
	 * @return the proxy manager
85
	 */
51
	 */
86
	public synchronized static IProxyService getProxyManager() {
52
	public synchronized static ProxyManager getProxyManager() {
87
		if (proxyManager == null)
53
		if (proxyManager == null)
88
			proxyManager = new ProxyManager();
54
			proxyManager = new ProxyManager();
89
		return proxyManager;
55
		return proxyManager;
90
	}
56
	}
91
	
57
	
58
	public void initialize() {
59
		((IEclipsePreferences)Activator.getInstance().getPreferences())
60
			.addPreferenceChangeListener(this);
61
		registerProvider();
62
	}
63
	
64
	/* (non-Javadoc)
65
	 * @see org.eclipse.core.net.proxy.IProxyService#getProviders()
66
	 */
67
	public IProxyProvider[] getProviders(){
68
		List resultList = new LinkedList();
69
		IExtension[] extensions = RegistryFactory.getRegistry().getExtensionPoint(Activator.ID, Activator.PT_PROVIDER).getExtensions();
70
		for(int i=0; i<extensions.length; i++){
71
			IExtension extension = extensions[i];
72
			IConfigurationElement[] configs = extension.getConfigurationElements();
73
			if(configs.length == 0){
74
				Activator.log(IStatus.ERROR, NLS.bind("Provider {0} is missing required fields", //$NON-NLS-1$
75
					(new Object[]{extension.getUniqueIdentifier()})), null);
76
			}else{
77
				try{
78
					IConfigurationElement config = configs[0];
79
					IProxyProvider ipp = (IProxyProvider)config.createExecutableExtension("class"); //$NON-NLS-1$
80
					resultList.add(ipp);
81
				}catch(CoreException ex){
82
					Activator.log(IStatus.ERROR, NLS.bind("Unable to instantiate provider {0}", //$NON-NLS-1$
83
						(new Object[]{extension.getUniqueIdentifier()})), ex); 
84
				}
85
			}
86
		}
87
		IProxyProvider[] result = new IProxyProvider[resultList.size()];
88
		resultList.toArray(result);
89
		return result;
90
	}
91
	
92
	/* (non-Javadoc)
93
	 * @see org.eclipse.core.net.proxy.IProxyService#getProvider()
94
	 */
95
	public IProxyProvider getProvider(){
96
		return provider;
97
	}
98
	
99
	/* (non-Javadoc)
100
	 * @see org.eclipse.core.net.proxy.IProxyService#setProvider(org.eclipse.core.net.proxy.IProxyProvider)
101
	 */
102
	public void setProvider(IProxyProvider provider){
103
		if(provider == null){
104
			throw new IllegalArgumentException("Provider must not be null."); //$NON-NLS-1$
105
		}
106
		this.provider = provider;
107
		Activator.getInstance().getPreferences().put(PREF_PROVIDER, provider.getClass().getName());
108
		// TODO: Remove log statement.
109
		Activator.logInfo("Loaded provider: " + provider.getClass().getName(), null); //$NON-NLS-1$
110
	}
111
	
92
	/* (non-Javadoc)
112
	/* (non-Javadoc)
93
	 * @see org.eclipse.core.net.IProxyManager#addProxyChangeListener(org.eclipse.core.net.IProxyChangeListener)
113
	 * @see org.eclipse.core.net.IProxyManager#addProxyChangeListener(org.eclipse.core.net.IProxyChangeListener)
94
	 */
114
	 */
Lines 103-109 Link Here
103
		listeners.remove(listener);
123
		listeners.remove(listener);
104
	}
124
	}
105
	
125
	
106
	private void fireChange(final IProxyChangeEvent event) {
126
	public void fireChange(final IProxyChangeEvent event) {
107
		Object[] l = listeners.getListeners();
127
		Object[] l = listeners.getListeners();
108
		for (int i = 0; i < l.length; i++) {
128
		for (int i = 0; i < l.length; i++) {
109
			final IProxyChangeListener listener = (IProxyChangeListener)l[i];
129
			final IProxyChangeListener listener = (IProxyChangeListener)l[i];
Lines 117-593 Link Here
117
			});
137
			});
118
		}
138
		}
119
	}
139
	}
120
121
	/* (non-Javadoc)
122
	 * @see org.eclipse.core.net.IProxyManager#getNonProxiedHosts()
123
	 */
124
	public synchronized String[] getNonProxiedHosts() {
125
		checkMigrated();
126
		if (nonProxiedHosts == null) {
127
			String prop = Activator.getInstance().getPreferences().get(PREF_NON_PROXIED_HOSTS, "localhost|127.0.0.1"); //$NON-NLS-1$
128
			nonProxiedHosts = ProxyType.convertPropertyStringToHosts(prop);
129
		}
130
		if (nonProxiedHosts.length == 0)
131
			return nonProxiedHosts;
132
		String[] result = new String[nonProxiedHosts.length];
133
		System.arraycopy(nonProxiedHosts, 0, result, 0, nonProxiedHosts.length );
134
		return result;
135
	}
136
137
	public String[] getNativeNonProxiedHosts() {
138
		if (hasSystemProxies()) {
139
			return nativeProxyProvider.getNonProxiedHosts();
140
		}
141
		return new String[0];
142
	}
143
144
	/* (non-Javadoc)
145
	 * @see org.eclipse.core.net.IProxyManager#setNonProxiedHosts(java.lang.String[])
146
	 */
147
	public void setNonProxiedHosts(String[] hosts) {
148
		checkMigrated();
149
		Assert.isNotNull(hosts);
150
		for (int i = 0; i < hosts.length; i++) {
151
			String host = hosts[i];
152
			Assert.isNotNull(host);
153
			Assert.isTrue(host.length() > 0);
154
		}
155
		String[] oldHosts = nonProxiedHosts;
156
		nonProxiedHosts = hosts;
157
		Activator.getInstance().getPreferences().put(PREF_NON_PROXIED_HOSTS, ProxyType.convertHostsToPropertyString(nonProxiedHosts));
158
		try {
159
			Activator.getInstance().getPreferences().flush();
160
		} catch (BackingStoreException e) {
161
			Activator.logError(
162
					"An error occurred while writing out the non-proxied hosts list", e); //$NON-NLS-1$
163
		}
164
		IProxyData[] data = getProxyData();
165
		IProxyChangeEvent event = new ProxyChangeEvent(IProxyChangeEvent.NONPROXIED_HOSTS_CHANGED, oldHosts, getNonProxiedHosts(), data, new IProxyData[0]);
166
		fireChange(event);
167
	}
168
169
	
140
	
170
	public IProxyData[] getProxyData() {
141
	private void registerProvider(){
171
		checkMigrated();
142
		String configuredProviderId = Activator.getInstance().getPreferences().get(PREF_PROVIDER, PROVIDER_DEFAULT);
172
		IProxyData[] result = new IProxyData[proxies.length];
143
		IProxyProvider[] providers = getProviders();
173
		for (int i = 0; i < proxies.length; i++) {
144
		IProxyProvider resultProvider = null;
174
			ProxyType type = proxies[i];
145
		for(int i=0; resultProvider == null && i<providers.length; i++){
175
			result[i] = type.getProxyData(ProxyType.VERIFY_EQUAL);
146
			IProxyProvider ipp = providers[i];
176
		}
147
			if(configuredProviderId.equals(ipp.getClass().getName())){
177
		return resolveType(result);
148
				resultProvider = ipp;
178
	}
179
180
	public IProxyData[] getNativeProxyData() {
181
		if (hasSystemProxies()) {
182
			return resolveType(nativeProxyProvider.getProxyData());
183
		}
184
		return new IProxyData[0];
185
	}
186
187
	public void setProxyData(IProxyData[] proxies) {
188
		checkMigrated();
189
		doSetProxyData(proxies);
190
	}
191
	
192
	private void doSetProxyData(IProxyData[] proxyDatas) {
193
		IProxyData[] oldData = getProxyData();
194
		String[] hosts = getNonProxiedHosts();
195
		IProxyData[] changedProxies = internalSetProxyData(proxyDatas);
196
		if (changedProxies.length > 0) {
197
			IProxyChangeEvent event = new ProxyChangeEvent(IProxyChangeEvent.PROXY_SERVICE_ENABLEMENT_CHANGE, hosts, hosts, oldData, changedProxies);
198
			fireChange(event);
199
		}
200
	}
201
202
	private IProxyData[] internalSetProxyData(IProxyData[] proxyDatas) {
203
		List result = new ArrayList();
204
		for (int i = 0; i < proxyDatas.length; i++) {
205
			IProxyData proxyData = proxyDatas[i];
206
			ProxyType type = getType(proxyData);
207
			if (type != null && type.setProxyData(proxyData, internalIsProxiesEnabled())) {
208
				result.add(proxyData);
209
			}
149
			}
210
		}
150
		}
211
		return (IProxyData[]) result.toArray(new IProxyData[result.size()]);
151
		if(resultProvider != null){
212
	}
152
			setProvider(resultProvider);
213
153
		}else{
214
	private ProxyType getType(IProxyData proxyData) {
154
			Activator.logError("Unable to find and load a proxy provider.", null); //$NON-NLS-1$
215
		for (int i = 0; i < proxies.length; i++) {
216
			ProxyType type = proxies[i];
217
			if (type.getName().equals(proxyData.getType())) {
218
				return type;
219
			}
220
		}
155
		}
221
		return null;
222
	}
156
	}
223
157
	
224
	/* (non-Javadoc)
158
	/* (non-Javadoc)
225
	 * @see org.eclipse.core.net.IProxyManager#isProxiesEnabled()
159
	 * @see org.eclipse.core.net.proxy.IProxyService#select(java.net.URI)
226
	 */
160
	 */
227
	public boolean isProxiesEnabled() {
161
	public IProxyData[] select(URI uri){
228
		checkMigrated();
162
		return provider.select(uri);
229
		return internalIsProxiesEnabled()
230
				&& (!isSystemProxiesEnabled() || (isSystemProxiesEnabled() && hasSystemProxies()));
231
	}
232
233
	private boolean internalIsProxiesEnabled() {
234
		return Activator.getInstance().getPreferences().getBoolean(
235
				PREF_ENABLED, true);
236
	}
163
	}
237
164
	
238
	/* (non-Javadoc)
165
	public void preferenceChange(PreferenceChangeEvent event){
239
	 * @see org.eclipse.core.net.IProxyManager#setProxiesEnabled(boolean)
166
		// Nothing to do.
240
	 */
167
		// TODO: Is this even needed?  Remove preference listener, and let implementing providers register for? 
241
	public void setProxiesEnabled(boolean enabled) {
242
		checkMigrated();
243
		boolean current = internalIsProxiesEnabled();
244
		if (current == enabled)
245
			return;
246
		// Setting the preference will trigger the system property update
247
		// (see preferenceChange)
248
		Activator.getInstance().getPreferences().putBoolean(PREF_ENABLED, enabled);
249
	}
250
251
	private void internalSetEnabled(boolean enabled, boolean systemEnabled) {
252
		Properties sysProps = System.getProperties();
253
		sysProps.put("proxySet", enabled ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
254
		sysProps.put("systemProxySet", systemEnabled ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
255
		updateSystemProperties();
256
		try {
257
			Activator.getInstance().getPreferences().flush();
258
		} catch (BackingStoreException e) {
259
			Activator.logError(
260
					"An error occurred while writing out the enablement state", e); //$NON-NLS-1$
261
		}
262
		String[] hosts = getNonProxiedHosts();
263
		IProxyData[] data = getProxyData();
264
		IProxyChangeEvent event = new ProxyChangeEvent(IProxyChangeEvent.PROXY_DATA_CHANGED, hosts, hosts, data, data);
265
		fireChange(event);
266
	}
267
268
	private void updateSystemProperties() {
269
		for (int i = 0; i < proxies.length; i++) {
270
			ProxyType type = proxies[i];
271
			type.updateSystemProperties(internalGetProxyData(type.getName(), ProxyType.DO_NOT_VERIFY), internalIsProxiesEnabled());
272
		}
273
	}
274
275
	public void initialize() {
276
		checkMigrated();
277
		((IEclipsePreferences)Activator.getInstance().getPreferences()).addPreferenceChangeListener(this);
278
		// Now initialize each proxy type
279
		for (int i = 0; i < proxies.length; i++) {
280
			ProxyType type = proxies[i];
281
			type.initialize(internalIsProxiesEnabled());
282
		}
283
		registerAuthenticator();
284
	}
285
286
	public IProxyData getProxyData(String type) {
287
		checkMigrated();
288
		return resolveType(internalGetProxyData(type, ProxyType.VERIFY_EQUAL));
289
	}
290
291
	private IProxyData internalGetProxyData(String type, int verifySystemProperties) {
292
		for (int i = 0; i < proxies.length; i++) {
293
			ProxyType pt = proxies[i];
294
			if (pt.getName().equals(type)) {
295
				return pt.getProxyData(verifySystemProperties);
296
			}
297
		}
298
		return null;
299
	}
300
301
	public IProxyData[] getProxyDataForHost(String host) {
302
		checkMigrated();
303
		if (!internalIsProxiesEnabled()) {
304
			return new IProxyData[0];
305
		}
306
		URI uri = tryGetURI(host);
307
		if (uri == null) {
308
			return new IProxyData[0];
309
		}
310
		if (hasSystemProxies() && isSystemProxiesEnabled()) {
311
			return resolveType(nativeProxyProvider.select(uri));
312
		}
313
314
		if (isHostFiltered(uri))
315
			return new IProxyData[0];
316
		IProxyData[] data = getProxyData();
317
		List result = new ArrayList();
318
		for (int i = 0; i < data.length; i++) {
319
			IProxyData proxyData = data[i];
320
			if (proxyData.getHost() != null)
321
				result.add(proxyData);
322
		}
323
		IProxyData ret[] = (IProxyData[]) result.toArray(new IProxyData[result.size()]);
324
		return resolveType(ret);
325
	}
326
327
	public static URI tryGetURI(String host) {
328
		try {
329
			int i = host.indexOf(":"); //$NON-NLS-1$
330
			if (i == -1) {
331
				return new URI("//" + host); //$NON-NLS-1$
332
			}
333
			return new URI(host.substring(i + 1));
334
		} catch (URISyntaxException e) {
335
			return null;
336
		}
337
	}
168
	}
338
169
339
	private boolean isHostFiltered(URI uri) {
170
	/** @deprecated */
340
		String[] filters = getNonProxiedHosts();
171
	public String[] getNonProxiedHosts(){
341
		for (int i = 0; i < filters.length; i++) {
172
		throw new UnsupportedOperationException();
342
			String filter = filters[i];
343
			if (matchesFilter(uri.getHost(), filter))
344
				return true;
345
		}
346
		return false;
347
	}
173
	}
348
174
349
	private boolean matchesFilter(String host, String filter) {
175
	/** @deprecated */
350
		StringMatcher matcher = new StringMatcher(filter, true, false);
176
	public IProxyData[] getProxyData(){
351
		return matcher.match(host);
177
		throw new UnsupportedOperationException();
352
	}
178
	}
353
179
354
	/* (non-Javadoc)
180
	/** @deprecated */
355
	 * @see org.eclipse.net.core.IProxyManager#getProxyDataForHost(java.lang.String, java.lang.String)
181
	public IProxyData getProxyData(String type){
356
	 */
182
		throw new UnsupportedOperationException();
357
	public IProxyData getProxyDataForHost(String host, String type) {
358
		checkMigrated();
359
		if (!internalIsProxiesEnabled()) {
360
			return null;
361
		}
362
		if (hasSystemProxies() && isSystemProxiesEnabled())
363
			try {
364
				URI uri = new URI(type, "//" + host, null); //$NON-NLS-1$
365
				IProxyData[] proxyDatas = nativeProxyProvider.select(uri);
366
				return proxyDatas.length > 0 ? resolveType(nativeProxyProvider.select(uri)[0]) : null;
367
			} catch (URISyntaxException e) {
368
				return null;
369
			}
370
			
371
		IProxyData[] data = getProxyDataForHost(host);
372
		for (int i = 0; i < data.length; i++) {
373
			IProxyData proxyData = data[i];
374
			if (proxyData.getType().equalsIgnoreCase(type)
375
					&& proxyData.getHost() != null)
376
				return resolveType(proxyData);
377
		}
378
		return null;
379
	}
380
	
381
	private void registerAuthenticator() {
382
		Authenticator a = getPluggedInAuthenticator();
383
		if (a != null) {
384
			Authenticator.setDefault(a);
385
		}
386
	}
387
	
388
	private Authenticator getPluggedInAuthenticator() {
389
		IExtension[] extensions = RegistryFactory.getRegistry().getExtensionPoint(Activator.ID, Activator.PT_AUTHENTICATOR).getExtensions();
390
		if (extensions.length == 0)
391
			return null;
392
		IExtension extension = extensions[0];
393
		IConfigurationElement[] configs = extension.getConfigurationElements();
394
		if (configs.length == 0) {
395
			Activator.log(IStatus.ERROR, NLS.bind("Authenticator {0} is missing required fields", (new Object[] {extension.getUniqueIdentifier()})), null);//$NON-NLS-1$ 
396
			return null;
397
		}
398
		try {
399
			IConfigurationElement config = configs[0];
400
			return (Authenticator) config.createExecutableExtension("class");//$NON-NLS-1$ 
401
		} catch (CoreException ex) {
402
			Activator.log(IStatus.ERROR, NLS.bind("Unable to instantiate authenticator {0}", (new Object[] {extension.getUniqueIdentifier()})), ex);//$NON-NLS-1$ 
403
			return null;
404
		}
405
	}
183
	}
406
184
407
	
185
	/** @deprecated */
408
	private synchronized void checkMigrated() {
186
	public IProxyData[] getProxyDataForHost(String host){
409
		if (migrated || !Activator.getInstance().instanceLocationAvailable())
187
		throw new UnsupportedOperationException();
410
			return;
411
		
412
		migrated = true;
413
		if (Activator.getInstance().getPreferences().getBoolean(PREF_HAS_MIGRATED, false))
414
			return;
415
		
416
		Activator.getInstance().getPreferences().putBoolean(PREF_HAS_MIGRATED, true);
417
		migrateInstanceScopePreferences(new InstanceScope().getNode(""), new ConfigurationScope().getNode(""), true);  //$NON-NLS-1$//$NON-NLS-2$
418
	}
419
	
420
	void migrateInstanceScopePreferences(Preferences instanceNode, Preferences configurationNode, boolean isInitialize) {
421
		migrateUpdateHttpProxy(instanceNode, isInitialize);
422
		
423
		Preferences netInstancePrefs = instanceNode.node(Activator.ID);
424
		Preferences netConfigurationPrefs = configurationNode.node(Activator.ID);
425
		
426
		// migrate enabled status
427
		if (netConfigurationPrefs.get(PREF_ENABLED, null) == null) {
428
			String instanceEnabled = netInstancePrefs.get(PREF_ENABLED, null);
429
			if (instanceEnabled != null)
430
				netConfigurationPrefs.put(PREF_ENABLED, instanceEnabled);
431
		}
432
		
433
		// migrate enabled status
434
		if (netConfigurationPrefs.get(PREF_OS, null) == null) {
435
			String instanceEnabled = netInstancePrefs.get(PREF_OS, null);
436
			if (instanceEnabled != null)
437
				netConfigurationPrefs.put(PREF_OS, instanceEnabled);
438
		}
439
	
440
		// migrate non proxied hosts if not already set
441
		if (netConfigurationPrefs.get(PREF_NON_PROXIED_HOSTS, null) == null) {
442
			String instanceNonProxiedHosts = netInstancePrefs.get(PREF_NON_PROXIED_HOSTS, null);
443
			if (instanceNonProxiedHosts != null) {
444
				netConfigurationPrefs.put(PREF_NON_PROXIED_HOSTS, instanceNonProxiedHosts);
445
				nonProxiedHosts = null;
446
			}
447
		}
448
		
449
		// migrate proxy data
450
		boolean proxiesEnabled = netConfigurationPrefs.getBoolean(PREF_ENABLED, true);
451
		for (int i = 0; i < proxies.length; i++) {
452
			ProxyType type = proxies[i];
453
			IProxyData data = type.getProxyData(ProxyType.DO_NOT_VERIFY);
454
			if (data.getHost() == null) {
455
				ProxyType instanceType = new ProxyType(type.getName(),netInstancePrefs);
456
				IProxyData instanceData = instanceType.getProxyData(ProxyType.DO_NOT_VERIFY);
457
				if (instanceData.getHost() != null)
458
					type.setProxyData(instanceData, proxiesEnabled);
459
			}
460
		}
461
		
462
		// if this an import we should remove the old node
463
		if (! isInitialize) {
464
			try {
465
				netInstancePrefs.removeNode();
466
			} catch (BackingStoreException e) {
467
				// ignore
468
			}
469
		}			
470
	}
471
	
472
	private void migrateUpdateHttpProxy(Preferences node, boolean isInitialize) {
473
		Preferences netPrefs = node.node(Activator.ID);
474
		if (!netPrefs.getBoolean(PREF_HAS_MIGRATED, false)) {
475
			// Only set the migration bit when initializing
476
			if (isInitialize)
477
				netPrefs.putBoolean(PREF_HAS_MIGRATED, true);
478
			Preferences updatePrefs = node.node("org.eclipse.update.core"); //$NON-NLS-1$
479
			String httpProxyHost = getHostToMigrate(updatePrefs, isInitialize /* checkSystemProperties */);
480
			int port = getPortToMigrate(updatePrefs, isInitialize /* checkSystemProperties */);
481
			boolean httpProxyEnable = getEnablementToMigrate(updatePrefs, isInitialize /* checkSystemProperties */);
482
			if (httpProxyHost != null) {
483
				ProxyData proxyData = new ProxyData(IProxyData.HTTP_PROXY_TYPE,
484
						httpProxyHost, port, false, null);
485
				ProxyType type = getType(proxyData);
486
				type.updatePreferencesIfMissing(netPrefs, proxyData);
487
				if (httpProxyEnable) {
488
					netPrefs.putBoolean(ProxyManager.PREF_ENABLED, true);
489
				}
490
			}
491
		}
492
	}
188
	}
493
189
494
	private boolean getEnablementToMigrate(Preferences updatePrefs, boolean checkSystemProperties) {
190
	/** @deprecated */
495
		boolean httpProxyEnable = false;
191
	public IProxyData getProxyDataForHost(String host, String type){
496
		if (checkSystemProperties && updatePrefs.get(HTTP_PROXY_ENABLE, null) == null) {
192
		throw new UnsupportedOperationException();
497
			httpProxyEnable = Boolean.getBoolean("http.proxySet"); //$NON-NLS-1$
498
		} else {
499
			httpProxyEnable = updatePrefs.getBoolean(HTTP_PROXY_ENABLE, false);
500
			updatePrefs.remove(HTTP_PROXY_ENABLE);
501
		}
502
		return httpProxyEnable;
503
	}
193
	}
504
194
505
	private int getPortToMigrate(Preferences updatePrefs, boolean checkSystemProperties) {
195
	/** @deprecated */
506
		String httpProxyPort = updatePrefs.get(HTTP_PROXY_PORT, ""); //$NON-NLS-1$
196
	public boolean hasSystemProxies(){
507
		if (checkSystemProperties && "".equals(httpProxyPort)) { //$NON-NLS-1$
197
		throw new UnsupportedOperationException();
508
			httpProxyPort = System.getProperty("http.proxyPort", ""); //$NON-NLS-1$ //$NON-NLS-2$
509
		}
510
		updatePrefs.remove(HTTP_PROXY_PORT);
511
		int port = -1;
512
		if (httpProxyPort != null && !"".equals(httpProxyPort)) //$NON-NLS-1$
513
			try {
514
				port = Integer.parseInt(httpProxyPort);
515
			} catch (NumberFormatException e) {
516
				// Ignore
517
			}
518
		return port;
519
	}
198
	}
520
199
521
	private String getHostToMigrate(Preferences updatePrefs, boolean checkSystemProperties) {
200
	/** @deprecated */
522
		String httpProxyHost = updatePrefs.get(HTTP_PROXY_HOST, ""); //$NON-NLS-1$
201
	public boolean isProxiesEnabled(){
523
		if (checkSystemProperties && "".equals(httpProxyHost)) { //$NON-NLS-1$
202
		throw new UnsupportedOperationException();
524
			httpProxyHost = System.getProperty("http.proxyHost", ""); //$NON-NLS-1$ //$NON-NLS-2$
525
		}
526
		if ("".equals(httpProxyHost)) //$NON-NLS-1$
527
			httpProxyHost = null;
528
		updatePrefs.remove(HTTP_PROXY_HOST);
529
		return httpProxyHost;
530
	}
203
	}
531
204
532
	public void preferenceChange(PreferenceChangeEvent event) {
205
	/** @deprecated */
533
		if (event.getKey().equals(PREF_ENABLED) || event.getKey().equals(PREF_OS)) {
206
	public boolean isSystemProxiesEnabled(){
534
			checkMigrated();
207
		throw new UnsupportedOperationException();
535
			internalSetEnabled(Activator.getInstance().getPreferences().getBoolean(PREF_ENABLED, true),
536
					Activator.getInstance().getPreferences().getBoolean(PREF_OS, true));
537
		}
538
	}
208
	}
539
209
540
	public boolean hasSystemProxies() {
210
	/** @deprecated */
541
		return nativeProxyProvider != null;
211
	public void setNonProxiedHosts(String[] hosts) throws CoreException{
212
		throw new UnsupportedOperationException();
542
	}
213
	}
543
214
544
	public boolean isSystemProxiesEnabled() {
215
	/** @deprecated */
545
		checkMigrated();
216
	public void setProxiesEnabled(boolean enabled){
546
		return Activator.getInstance().getPreferences().getBoolean(PREF_OS,
217
		throw new UnsupportedOperationException();
547
				true);
548
	}
549
550
	public void setSystemProxiesEnabled(boolean enabled) {
551
		checkMigrated();
552
		boolean current = isSystemProxiesEnabled();
553
		if (current == enabled)
554
			return;
555
		// Setting the preference will trigger the system property update
556
		// (see preferenceChange)
557
		Activator.getInstance().getPreferences().putBoolean(PREF_OS, enabled);
558
	}
559
560
	public IProxyData[] select(URI uri) {
561
		IProxyData data = getProxyDataForHost(uri.getHost(), uri.getScheme());
562
		if (data != null) {
563
			return resolveType(new IProxyData[] { data });
564
		}
565
		return new IProxyData[0];
566
	}
218
	}
567
219
568
	public IProxyData resolveType(IProxyData data) {
220
	/** @deprecated */
569
		if (data == null) {
221
	public void setProxyData(IProxyData[] proxies) throws CoreException{
570
			return null;
222
		throw new UnsupportedOperationException();
571
		}
572
		ProxyData d = (ProxyData) data;
573
		if (d.getType().equalsIgnoreCase(IProxyData.HTTP_PROXY_TYPE)) {
574
			d.setType(IProxyData.HTTP_PROXY_TYPE);
575
		} else if (d.getType().equalsIgnoreCase(IProxyData.HTTPS_PROXY_TYPE)) {
576
			d.setType(IProxyData.HTTPS_PROXY_TYPE);
577
		} else if (d.getType().equalsIgnoreCase(IProxyData.SOCKS_PROXY_TYPE)) {
578
			d.setType(IProxyData.SOCKS_PROXY_TYPE);
579
		}
580
		return d;
581
	}
223
	}
582
224
583
	public IProxyData[] resolveType(IProxyData[] data) {
225
	/** @deprecated */
584
		if (data == null) {
226
	public void setSystemProxiesEnabled(boolean enabled){
585
			return null;
227
		throw new UnsupportedOperationException();
586
		}
587
		for (int i = 0; i < data.length; i++) {
588
			resolveType(data[i]);
589
		}
590
		return data;
591
	}
228
	}
592
229
593
}
230
}
(-)src/org/eclipse/core/internal/net/ProxySelector.java (-16 / +18 lines)
Lines 17-22 Link Here
17
/**
17
/**
18
 * This class adapts ProxyManager to add additional layer of providers on its
18
 * This class adapts ProxyManager to add additional layer of providers on its
19
 * top.
19
 * top.
20
 * 
21
 * @deprecated Converting to extension points ("org.eclipse.core.net.provider") instead.
20
 */
22
 */
21
public class ProxySelector {
23
public class ProxySelector {
22
24
Lines 57-70 Link Here
57
	}
59
	}
58
60
59
	public static ProxyData[] getProxyData(String provider) {
61
	public static ProxyData[] getProxyData(String provider) {
60
		ProxyManager manager = (ProxyManager) ProxyManager.getProxyManager();
62
//		ProxyManager manager = (ProxyManager) ProxyManager.getProxyManager();
61
		if (provider.equals(DIRECT_PROVIDER)) {
63
//		if (provider.equals(DIRECT_PROVIDER)) {
62
			return new ProxyData[0];
64
//			return new ProxyData[0];
63
		} else if (provider.equals(ECLIPSE_PROVIDER)) {
65
//		} else if (provider.equals(ECLIPSE_PROVIDER)) {
64
			return castArray(manager.getProxyData());
66
//			return castArray(manager.getProxyData());
65
		} else if (provider.equals(NATIVE_PROVIDER)) {
67
//		} else if (provider.equals(NATIVE_PROVIDER)) {
66
			return castArray(manager.getNativeProxyData());
68
//			return castArray(manager.getNativeProxyData());
67
		}
69
//		}
68
		throw new IllegalArgumentException("Provider not supported"); //$NON-NLS-1$
70
		throw new IllegalArgumentException("Provider not supported"); //$NON-NLS-1$
69
	}
71
	}
70
72
Lines 98-111 Link Here
98
	}
100
	}
99
101
100
	public static String[] getBypassHosts(String provider) {
102
	public static String[] getBypassHosts(String provider) {
101
		ProxyManager manager = (ProxyManager) ProxyManager.getProxyManager();
103
//		ProxyManager manager = (ProxyManager) ProxyManager.getProxyManager();
102
		if (provider.equals(DIRECT_PROVIDER)) {
104
//		if (provider.equals(DIRECT_PROVIDER)) {
103
			return new String[0];
105
//			return new String[0];
104
		} else if (provider.equals(ECLIPSE_PROVIDER)) {
106
//		} else if (provider.equals(ECLIPSE_PROVIDER)) {
105
			return manager.getNonProxiedHosts();
107
//			return manager.getNonProxiedHosts();
106
		} else if (provider.equals(NATIVE_PROVIDER)) {
108
//		} else if (provider.equals(NATIVE_PROVIDER)) {
107
			return manager.getNativeNonProxiedHosts();
109
//			return manager.getNativeNonProxiedHosts();
108
		}
110
//		}
109
		throw new IllegalArgumentException("Provider not supported"); //$NON-NLS-1$ 
111
		throw new IllegalArgumentException("Provider not supported"); //$NON-NLS-1$ 
110
	}
112
	}
111
113
(-)src/org/eclipse/core/net/proxy/IProxyService.java (+38 lines)
Lines 31-36 Link Here
31
public interface IProxyService {
31
public interface IProxyService {
32
	
32
	
33
	/**
33
	/**
34
	 * Returns the available {@link IProxyProvider}s.
35
	 * @return The available {@link IProxyProvider}s.
36
	 */
37
	IProxyProvider[] getProviders();
38
	
39
	/**
40
	 * Returns the current {@link IProxyProvider} implementation.
41
	 * @return The current {@link IProxyProvider} implementation.
42
	 */
43
	IProxyProvider getProvider();
44
	
45
	/**
46
	 * Sets the the current {@link IProxyProvider} implementation.
47
	 * @param provider The {@link IProxyProvider} implementation to set.
48
	 */
49
	void setProvider(IProxyProvider provider);
50
	
51
	/**
34
	 * Sets whether proxy support should be enabled. The current proxy settings
52
	 * Sets whether proxy support should be enabled. The current proxy settings
35
	 * are still kept so clients should check the enablement using
53
	 * are still kept so clients should check the enablement using
36
	 * {@link #isProxiesEnabled()} before calling the {@link #getProxyData()} or
54
	 * {@link #isProxiesEnabled()} before calling the {@link #getProxyData()} or
Lines 39-44 Link Here
39
	 * {@link #getProxyDataForHost(String, String)} method will check the
57
	 * {@link #getProxyDataForHost(String, String)} method will check the
40
	 * enablement and only return data if the service is enabled.
58
	 * enablement and only return data if the service is enabled.
41
	 * 
59
	 * 
60
	 * @deprecated Configuration should be handled through the implementation.
61
	 * 
42
	 * @param enabled
62
	 * @param enabled
43
	 *            whether proxy support should be enabled
63
	 *            whether proxy support should be enabled
44
	 */
64
	 */
Lines 53-58 Link Here
53
	 * enabled but {@link #hasSystemProxies()} returns <code>false</code>.
73
	 * enabled but {@link #hasSystemProxies()} returns <code>false</code>.
54
	 * </p>
74
	 * </p>
55
	 * 
75
	 * 
76
	 * @deprecated Configuration should be handled through the implementation.
77
	 * 
56
	 * @return whether proxy support should be enabled
78
	 * @return whether proxy support should be enabled
57
	 */
79
	 */
58
	boolean isProxiesEnabled();
80
	boolean isProxiesEnabled();
Lines 60-65 Link Here
60
	/**
82
	/**
61
	 * Returns whether system proxy support is available.
83
	 * Returns whether system proxy support is available.
62
	 * 
84
	 * 
85
	 * @deprecated Configuration should be handled through the implementation.
86
	 * 
63
	 * @return whether system proxy support is available
87
	 * @return whether system proxy support is available
64
	 * @since 1.1
88
	 * @since 1.1
65
	 */
89
	 */
Lines 69-74 Link Here
69
	 * Sets whether system proxies should be used, when the proxy support is
93
	 * Sets whether system proxies should be used, when the proxy support is
70
	 * enabled.
94
	 * enabled.
71
	 * 
95
	 * 
96
	 * @deprecated Configuration should be handled through the implementation.
97
	 * 
72
	 * @param enabled
98
	 * @param enabled
73
	 * @since 1.1
99
	 * @since 1.1
74
	 */
100
	 */
Lines 79-84 Link Here
79
	 * Returns whether system proxy should be used when the proxy support is
105
	 * Returns whether system proxy should be used when the proxy support is
80
	 * enabled.
106
	 * enabled.
81
	 * 
107
	 * 
108
	 * @deprecated Configuration should be handled through the implementation.
109
	 * 
82
	 * @return whether system proxy is used when the proxy support is enabled
110
	 * @return whether system proxy is used when the proxy support is enabled
83
	 * @since 1.1
111
	 * @since 1.1
84
	 */
112
	 */
Lines 100-105 Link Here
100
	 * This method returns the proxies set via {@link #setProxyData(IProxyData[])}
128
	 * This method returns the proxies set via {@link #setProxyData(IProxyData[])}
101
	 * </p>
129
	 * </p>
102
	 * 
130
	 * 
131
	 * @deprecated Configuration should be handled through the implementation.
132
	 * 
103
	 * @return the list of know proxy types and their settings
133
	 * @return the list of know proxy types and their settings
104
	 */
134
	 */
105
	IProxyData[] getProxyData();
135
	IProxyData[] getProxyData();
Lines 154-159 Link Here
154
	 * This method returns the proxies set via {@link #setProxyData(IProxyData[])}
184
	 * This method returns the proxies set via {@link #setProxyData(IProxyData[])}
155
	 * </p>
185
	 * </p>
156
	 * 
186
	 * 
187
	 * @deprecated Configuration should be handled through the implementation.
188
	 * 
157
	 * @param type
189
	 * @param type
158
	 *            the proxy type
190
	 *            the proxy type
159
	 * @return the proxy data for the proxy of the given type or
191
	 * @return the proxy data for the proxy of the given type or
Lines 200-205 Link Here
200
	 * is enabled).
232
	 * is enabled).
201
	 * </p>
233
	 * </p>
202
	 * 
234
	 * 
235
	 * @deprecated Configuration should be handled through the implementation.
236
	 * 
203
	 * @param proxies
237
	 * @param proxies
204
	 *            the proxy data whose information is to be set.
238
	 *            the proxy data whose information is to be set.
205
	 * @throws CoreException
239
	 * @throws CoreException
Lines 224-229 Link Here
224
	 * {@link #setNonProxiedHosts(String[])}
258
	 * {@link #setNonProxiedHosts(String[])}
225
	 * </p>
259
	 * </p>
226
	 * 
260
	 * 
261
	 * @deprecated Configuration should be handled through the implementation.
262
	 * 
227
	 * @return the list of hosts for which non proxy should be used.
263
	 * @return the list of hosts for which non proxy should be used.
228
	 * @see #getProxyDataForHost(String)
264
	 * @see #getProxyDataForHost(String)
229
	 * @see #getProxyDataForHost(String, String)
265
	 * @see #getProxyDataForHost(String, String)
Lines 239-244 Link Here
239
	 * support is enabled).
275
	 * support is enabled).
240
	 * </p>
276
	 * </p>
241
	 * 
277
	 * 
278
	 * @deprecated Configuration should be handled through the implementation.
279
	 * 
242
	 * @param hosts
280
	 * @param hosts
243
	 *            the list of hosts for which non proxy should be used
281
	 *            the list of hosts for which non proxy should be used
244
	 * @throws CoreException
282
	 * @throws CoreException
(-)META-INF/MANIFEST.MF (+1 lines)
Lines 13-18 Link Here
13
 org.eclipse.equinox.registry;bundle-version="3.4.0"
13
 org.eclipse.equinox.registry;bundle-version="3.4.0"
14
Bundle-ActivationPolicy: lazy
14
Bundle-ActivationPolicy: lazy
15
Export-Package: org.eclipse.core.internal.net;x-friends:="org.eclipse.ui.net",
15
Export-Package: org.eclipse.core.internal.net;x-friends:="org.eclipse.ui.net",
16
 org.eclipse.core.internal.net.providers;x-friends:="org.eclipse.ui.net",
16
 org.eclipse.core.net.proxy
17
 org.eclipse.core.net.proxy
17
Bundle-RequiredExecutionEnvironment: J2SE-1.4,
18
Bundle-RequiredExecutionEnvironment: J2SE-1.4,
18
 CDC-1.1/Foundation-1.1
19
 CDC-1.1/Foundation-1.1
(-)plugin.xml (+19 lines)
Lines 2-7 Link Here
2
<?eclipse version="3.2"?>
2
<?eclipse version="3.2"?>
3
<plugin>
3
<plugin>
4
   <extension-point id="authenticator" name="Authenticator" schema="schema/authenticator.exsd"/>
4
   <extension-point id="authenticator" name="Authenticator" schema="schema/authenticator.exsd"/>
5
   <extension-point id="provider" name="Provider" schema="schema/provider.exsd"/>
5
   <extension
6
   <extension
6
         point="org.eclipse.core.runtime.preferences">
7
         point="org.eclipse.core.runtime.preferences">
7
      <initializer
8
      <initializer
Lines 11-15 Link Here
11
            class="org.eclipse.core.internal.net.PreferenceModifyListener">
12
            class="org.eclipse.core.internal.net.PreferenceModifyListener">
12
      </modifier>
13
      </modifier>
13
   </extension>
14
   </extension>
15
   <extension
16
         point="org.eclipse.core.net.provider">
17
      <provider
18
            class="org.eclipse.core.internal.net.providers.DirectProvider">
19
      </provider>
20
   </extension>
21
   <extension
22
         point="org.eclipse.core.net.provider">
23
      <provider
24
            class="org.eclipse.core.internal.net.providers.EclipseProvider">
25
      </provider>
26
   </extension>
27
   <extension
28
         point="org.eclipse.core.net.provider">
29
      <provider
30
            class="org.eclipse.core.internal.net.providers.NativeProvider">
31
      </provider>
32
   </extension>
14
33
15
</plugin>
34
</plugin>
(-)src/org/eclipse/core/net/proxy/IProxyProvider.java (+32 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Mark A. Ziesemer and others
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *		Mark A. Ziesemer - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.core.net.proxy;
12
13
import java.net.URI;
14
15
public interface IProxyProvider{
16
	
17
	/**
18
	 * Returns the display name of the provider.
19
	 * @return The display name of the provider.
20
	 */
21
	String getName();
22
	
23
	/**
24
	 * <p>Returns all the applicable proxy data to access the specified URI.</p>
25
	 * <p>Clients that wish to make a connection and need to determine whether to
26
	 *   use a proxy should use this method.</p>
27
	 * @param uri the URI for which proxies are returned
28
	 * @return list of all applicable proxy data, if no proxy is applicable then
29
	 *         an empty array is returned
30
	 */
31
	IProxyData[] select(URI uri);
32
}
(-)src/org/eclipse/core/internal/net/providers/DirectProvider.java (+41 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Mark A. Ziesemer and others
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *		Mark A. Ziesemer - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.core.internal.net.providers;
12
13
import java.net.URI;
14
15
import org.eclipse.core.net.proxy.IProxyData;
16
import org.eclipse.core.net.proxy.IProxyProviderExtension;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IConfigurationElement;
19
20
public class DirectProvider implements IProxyProviderExtension{
21
	
22
	protected final IProxyData[] emptyData = new IProxyData[0];
23
	
24
	public DirectProvider(){
25
		// Nothing to do.
26
	}
27
28
	public void setInitializationData(IConfigurationElement config, String propertyName, Object data)
29
			throws CoreException{
30
		// Nothing to do.
31
	}
32
	
33
	public String getName(){
34
		return "Direct"; //$NON-NLS-1$
35
	}
36
37
	public IProxyData[] select(URI uri){
38
		return emptyData;
39
	}
40
41
}
(-)schema/provider.exsd (+102 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.core.net" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.core.net" id="provider" name="Provider"/>
7
      </appInfo>
8
      <documentation>
9
         Extension point to provide different proxy implementations.
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
      <annotation>
15
         <appinfo>
16
            <meta.element />
17
         </appinfo>
18
      </annotation>
19
      <complexType>
20
         <sequence>
21
            <element ref="provider"/>
22
         </sequence>
23
         <attribute name="point" type="string" use="required">
24
            <annotation>
25
               <documentation>
26
                  
27
               </documentation>
28
            </annotation>
29
         </attribute>
30
         <attribute name="id" type="string">
31
            <annotation>
32
               <documentation>
33
                  
34
               </documentation>
35
            </annotation>
36
         </attribute>
37
         <attribute name="name" type="string">
38
            <annotation>
39
               <documentation>
40
                  
41
               </documentation>
42
               <appinfo>
43
                  <meta.attribute translatable="true"/>
44
               </appinfo>
45
            </annotation>
46
         </attribute>
47
      </complexType>
48
   </element>
49
50
   <element name="provider">
51
      <complexType>
52
         <attribute name="class" type="string" use="required">
53
            <annotation>
54
               <documentation>
55
                  
56
               </documentation>
57
               <appinfo>
58
                  <meta.attribute kind="java" basedOn=":org.eclipse.core.net.proxy.IProxyProviderExtension"/>
59
               </appinfo>
60
            </annotation>
61
         </attribute>
62
      </complexType>
63
   </element>
64
65
   <annotation>
66
      <appinfo>
67
         <meta.section type="since"/>
68
      </appinfo>
69
      <documentation>
70
         [Enter the first release in which this extension point appears.]
71
      </documentation>
72
   </annotation>
73
74
   <annotation>
75
      <appinfo>
76
         <meta.section type="examples"/>
77
      </appinfo>
78
      <documentation>
79
         [Enter extension point usage example here.]
80
      </documentation>
81
   </annotation>
82
83
   <annotation>
84
      <appinfo>
85
         <meta.section type="apiinfo"/>
86
      </appinfo>
87
      <documentation>
88
         [Enter API information here.]
89
      </documentation>
90
   </annotation>
91
92
   <annotation>
93
      <appinfo>
94
         <meta.section type="implementation"/>
95
      </appinfo>
96
      <documentation>
97
         [Enter information about supplied implementation of this extension point.]
98
      </documentation>
99
   </annotation>
100
101
102
</schema>
(-)src/org/eclipse/core/internal/net/providers/NativeProvider.java (+89 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Mark A. Ziesemer and others All rights reserved. This program and the
3
 * accompanying materials are made available under the terms of the Eclipse Public License v1.0
4
 * which accompanies this distribution, and is available at
5
 * http://www.eclipse.org/legal/epl-v10.html Contributors: Mark A. Ziesemer - initial API and
6
 * implementation
7
 *******************************************************************************/
8
package org.eclipse.core.internal.net.providers;
9
10
import java.net.URI;
11
12
import org.eclipse.core.internal.net.AbstractProxyProvider;
13
import org.eclipse.core.internal.net.Activator;
14
import org.eclipse.core.internal.net.ProxyData;
15
import org.eclipse.core.net.proxy.IProxyData;
16
import org.eclipse.core.net.proxy.IProxyProviderExtension;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IConfigurationElement;
19
20
public class NativeProvider implements IProxyProviderExtension{
21
	
22
	private AbstractProxyProvider nativeProxyProvider;
23
24
	public NativeProvider(){
25
		try{
26
			nativeProxyProvider = (AbstractProxyProvider) Class.forName(
27
				"org.eclipse.core.net.ProxyProvider").newInstance(); //$NON-NLS-1$
28
		}catch(ClassNotFoundException e){
29
			// no class found
30
		}catch(Exception e){
31
			Activator.logInfo("Problems occured during the proxy provider initialization.", e); //$NON-NLS-1$
32
		}
33
	}
34
35
	public void setInitializationData(IConfigurationElement config, String propertyName, Object data)
36
			throws CoreException{
37
	// Nothing to do.
38
	}
39
40
	public String getName(){
41
		return "Native"; //$NON-NLS-1$
42
	}
43
44
	public IProxyData[] select(URI uri){
45
		return nativeProxyProvider.getProxyData(uri);
46
	}
47
48
	public String[] getNativeNonProxiedHosts(){
49
		//if(hasSystemProxies()){
50
			return nativeProxyProvider.getNonProxiedHosts();
51
		//}
52
		//return new String[0];
53
	}
54
	
55
	public IProxyData[] getNativeProxyData() {
56
		//if (hasSystemProxies()) {
57
			return resolveType(nativeProxyProvider.getProxyData());
58
		//}
59
		//return new IProxyData[0];
60
	}
61
	
62
	// TODO: Factor out duplication with EclipseProvider.
63
	public IProxyData resolveType(IProxyData data) {
64
		if (data == null) {
65
			return null;
66
		}
67
		ProxyData d = (ProxyData) data;
68
		if (d.getType().equalsIgnoreCase(IProxyData.HTTP_PROXY_TYPE)) {
69
			d.setType(IProxyData.HTTP_PROXY_TYPE);
70
		} else if (d.getType().equalsIgnoreCase(IProxyData.HTTPS_PROXY_TYPE)) {
71
			d.setType(IProxyData.HTTPS_PROXY_TYPE);
72
		} else if (d.getType().equalsIgnoreCase(IProxyData.SOCKS_PROXY_TYPE)) {
73
			d.setType(IProxyData.SOCKS_PROXY_TYPE);
74
		}
75
		return d;
76
	}
77
78
	// TODO: Factor out duplication with EclipseProvider.
79
	public IProxyData[] resolveType(IProxyData[] data) {
80
		if (data == null) {
81
			return null;
82
		}
83
		for (int i = 0; i < data.length; i++) {
84
			resolveType(data[i]);
85
		}
86
		return data;
87
	}
88
89
}
(-)src/org/eclipse/core/internal/net/providers/EclipseProvider.java (+516 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *     Mark A. Ziesemer - Refactor from ProxyManager to separate extension.
11
 *******************************************************************************/
12
package org.eclipse.core.internal.net.providers;
13
14
import java.net.Authenticator;
15
import java.net.URI;
16
import java.net.URISyntaxException;
17
import java.util.ArrayList;
18
import java.util.List;
19
import java.util.Properties;
20
21
import org.eclipse.core.internal.net.Activator;
22
import org.eclipse.core.internal.net.ProxyChangeEvent;
23
import org.eclipse.core.internal.net.ProxyData;
24
import org.eclipse.core.internal.net.ProxyManager;
25
import org.eclipse.core.internal.net.ProxyType;
26
import org.eclipse.core.internal.net.StringMatcher;
27
import org.eclipse.core.net.proxy.IProxyChangeEvent;
28
import org.eclipse.core.net.proxy.IProxyData;
29
import org.eclipse.core.net.proxy.IProxyProviderExtension;
30
import org.eclipse.core.runtime.Assert;
31
import org.eclipse.core.runtime.CoreException;
32
import org.eclipse.core.runtime.IConfigurationElement;
33
import org.eclipse.core.runtime.IExtension;
34
import org.eclipse.core.runtime.IStatus;
35
import org.eclipse.core.runtime.RegistryFactory;
36
import org.eclipse.core.runtime.preferences.ConfigurationScope;
37
import org.eclipse.core.runtime.preferences.InstanceScope;
38
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
39
import org.eclipse.osgi.util.NLS;
40
import org.osgi.service.prefs.BackingStoreException;
41
import org.osgi.service.prefs.Preferences;
42
43
public class EclipseProvider implements IProxyProviderExtension{
44
	
45
private static final String PREF_HAS_MIGRATED = "org.eclipse.core.net.hasMigrated"; //$NON-NLS-1$
46
	
47
	/**
48
	 * Preference constants used by Update to record the HTTP proxy
49
	 */
50
	private static String HTTP_PROXY_HOST = "org.eclipse.update.core.proxy.host"; //$NON-NLS-1$
51
	private static String HTTP_PROXY_PORT = "org.eclipse.update.core.proxy.port"; //$NON-NLS-1$
52
	private static String HTTP_PROXY_ENABLE = "org.eclipse.update.core.proxy.enable"; //$NON-NLS-1$
53
	
54
	private static final String PREF_ENABLED = "proxiesEnabled"; //$NON-NLS-1$
55
	private static final String PREF_NON_PROXIED_HOSTS = "nonProxiedHosts"; //$NON-NLS-1$
56
	
57
	private final ProxyType[] proxies = new ProxyType[] {
58
		new ProxyType(IProxyData.HTTP_PROXY_TYPE),
59
		new ProxyType(IProxyData.HTTPS_PROXY_TYPE),
60
		new ProxyType(IProxyData.SOCKS_PROXY_TYPE)
61
	};
62
	
63
	private String[] nonProxiedHosts;
64
	
65
	private boolean migrated = false;
66
	
67
	public EclipseProvider(){
68
		checkMigrated();
69
		// Now initialize each proxy type
70
		for (int i = 0; i < proxies.length; i++) {
71
			ProxyType type = proxies[i];
72
			type.initialize(internalIsProxiesEnabled());
73
		}
74
		registerAuthenticator();
75
	}
76
	
77
	public void setInitializationData(IConfigurationElement config, String propertyName, Object data)
78
			throws CoreException{
79
		// Nothing to do.
80
	}
81
	
82
	public String getName(){
83
		return "Eclipse"; //$NON-NLS-1$
84
	}
85
86
	public IProxyData[] select(URI uri){
87
		IProxyData data = getProxyDataForHost(uri.getHost(), uri.getScheme());
88
		if(data != null){
89
			return resolveType(new IProxyData[]{data});
90
		}
91
		return new IProxyData[0];
92
	}
93
	
94
	private void fireChange(IProxyChangeEvent event){
95
		// TODO: Cleanup call to fireChange.
96
		ProxyManager.getProxyManager().fireChange(event);
97
	}
98
	
99
	/* (non-Javadoc)
100
	 * @see org.eclipse.core.net.IProxyManager#getNonProxiedHosts()
101
	 */
102
	public synchronized String[] getNonProxiedHosts() {
103
		checkMigrated();
104
		if (nonProxiedHosts == null) {
105
			String prop = Activator.getInstance().getPreferences().get(PREF_NON_PROXIED_HOSTS, "localhost|127.0.0.1"); //$NON-NLS-1$
106
			nonProxiedHosts = ProxyType.convertPropertyStringToHosts(prop);
107
		}
108
		if (nonProxiedHosts.length == 0)
109
			return nonProxiedHosts;
110
		String[] result = new String[nonProxiedHosts.length];
111
		System.arraycopy(nonProxiedHosts, 0, result, 0, nonProxiedHosts.length );
112
		return result;
113
	}
114
	
115
	/* (non-Javadoc)
116
	 * @see org.eclipse.core.net.IProxyManager#setNonProxiedHosts(java.lang.String[])
117
	 */
118
	public void setNonProxiedHosts(String[] hosts) {
119
		checkMigrated();
120
		Assert.isNotNull(hosts);
121
		for (int i = 0; i < hosts.length; i++) {
122
			String host = hosts[i];
123
			Assert.isNotNull(host);
124
			Assert.isTrue(host.length() > 0);
125
		}
126
		String[] oldHosts = nonProxiedHosts;
127
		nonProxiedHosts = hosts;
128
		Activator.getInstance().getPreferences().put(PREF_NON_PROXIED_HOSTS, ProxyType.convertHostsToPropertyString(nonProxiedHosts));
129
		try {
130
			Activator.getInstance().getPreferences().flush();
131
		} catch (BackingStoreException e) {
132
			Activator.logError(
133
					"An error occurred while writing out the non-proxied hosts list", e); //$NON-NLS-1$
134
		}
135
		IProxyData[] data = getProxyData();
136
		IProxyChangeEvent event = new ProxyChangeEvent(IProxyChangeEvent.NONPROXIED_HOSTS_CHANGED, oldHosts, getNonProxiedHosts(), data, new IProxyData[0]);
137
		fireChange(event);
138
	}
139
	
140
	public IProxyData[] getProxyData() {
141
		checkMigrated();
142
		IProxyData[] result = new IProxyData[proxies.length];
143
		for (int i = 0; i < proxies.length; i++) {
144
			ProxyType type = proxies[i];
145
			result[i] = type.getProxyData(ProxyType.VERIFY_EQUAL);
146
		}
147
		return resolveType(result);
148
	}
149
	
150
	public void setProxyData(IProxyData[] proxies) {
151
		checkMigrated();
152
		doSetProxyData(proxies);
153
	}
154
	
155
	private void doSetProxyData(IProxyData[] proxyDatas) {
156
		IProxyData[] oldData = getProxyData();
157
		String[] hosts = getNonProxiedHosts();
158
		IProxyData[] changedProxies = internalSetProxyData(proxyDatas);
159
		if (changedProxies.length > 0) {
160
			IProxyChangeEvent event = new ProxyChangeEvent(IProxyChangeEvent.PROXY_SERVICE_ENABLEMENT_CHANGE, hosts, hosts, oldData, changedProxies);
161
			fireChange(event);
162
		}
163
	}
164
165
	private IProxyData[] internalSetProxyData(IProxyData[] proxyDatas) {
166
		List result = new ArrayList();
167
		for (int i = 0; i < proxyDatas.length; i++) {
168
			IProxyData proxyData = proxyDatas[i];
169
			ProxyType type = getType(proxyData);
170
			if (type != null && type.setProxyData(proxyData, internalIsProxiesEnabled())) {
171
				result.add(proxyData);
172
			}
173
		}
174
		return (IProxyData[]) result.toArray(new IProxyData[result.size()]);
175
	}
176
	
177
	private ProxyType getType(IProxyData proxyData) {
178
		for (int i = 0; i < proxies.length; i++) {
179
			ProxyType type = proxies[i];
180
			if (type.getName().equals(proxyData.getType())) {
181
				return type;
182
			}
183
		}
184
		return null;
185
	}
186
	
187
	/* (non-Javadoc)
188
	 * @see org.eclipse.core.net.IProxyManager#isProxiesEnabled()
189
	 */
190
	public boolean isProxiesEnabled() {
191
		checkMigrated();
192
		return internalIsProxiesEnabled();
193
	}
194
	
195
	private boolean internalIsProxiesEnabled() {
196
		return Activator.getInstance().getPreferences().getBoolean(
197
				PREF_ENABLED, true);
198
	}
199
	
200
	/* (non-Javadoc)
201
	 * @see org.eclipse.core.net.IProxyManager#setProxiesEnabled(boolean)
202
	 */
203
	public void setProxiesEnabled(boolean enabled) {
204
		checkMigrated();
205
		boolean current = internalIsProxiesEnabled();
206
		if (current == enabled)
207
			return;
208
		// Setting the preference will trigger the system property update
209
		// (see preferenceChange)
210
		Activator.getInstance().getPreferences().putBoolean(PREF_ENABLED, enabled);
211
	}
212
213
	private void internalSetEnabled(boolean enabled) {
214
		Properties sysProps = System.getProperties();
215
		sysProps.put("proxySet", enabled ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
216
		updateSystemProperties();
217
		try {
218
			Activator.getInstance().getPreferences().flush();
219
		} catch (BackingStoreException e) {
220
			Activator.logError(
221
					"An error occurred while writing out the enablement state", e); //$NON-NLS-1$
222
		}
223
		String[] hosts = getNonProxiedHosts();
224
		IProxyData[] data = getProxyData();
225
		IProxyChangeEvent event = new ProxyChangeEvent(IProxyChangeEvent.PROXY_DATA_CHANGED, hosts, hosts, data, data);
226
		fireChange(event);
227
	}
228
	
229
	private void updateSystemProperties() {
230
		for (int i = 0; i < proxies.length; i++) {
231
			ProxyType type = proxies[i];
232
			type.updateSystemProperties(internalGetProxyData(type.getName(), ProxyType.DO_NOT_VERIFY), internalIsProxiesEnabled());
233
		}
234
	}
235
	
236
	public IProxyData getProxyData(String type) {
237
		checkMigrated();
238
		return resolveType(internalGetProxyData(type, ProxyType.VERIFY_EQUAL));
239
	}
240
241
	private IProxyData internalGetProxyData(String type, int verifySystemProperties) {
242
		for (int i = 0; i < proxies.length; i++) {
243
			ProxyType pt = proxies[i];
244
			if (pt.getName().equals(type)) {
245
				return pt.getProxyData(verifySystemProperties);
246
			}
247
		}
248
		return null;
249
	}
250
251
	public IProxyData[] getProxyDataForHost(String host) {
252
		checkMigrated();
253
		if (!internalIsProxiesEnabled()) {
254
			return new IProxyData[0];
255
		}
256
		URI uri = tryGetURI(host);
257
		if (uri == null) {
258
			return new IProxyData[0];
259
		}
260
		// TODO: Should probably remove - now in NativeProvider.
261
//		if (hasSystemProxies() && isSystemProxiesEnabled()) {
262
//			return resolveType(nativeProxyProvider.select(uri));
263
//		}
264
265
		if (isHostFiltered(uri))
266
			return new IProxyData[0];
267
		IProxyData[] data = getProxyData();
268
		List result = new ArrayList();
269
		for (int i = 0; i < data.length; i++) {
270
			IProxyData proxyData = data[i];
271
			if (proxyData.getHost() != null)
272
				result.add(proxyData);
273
		}
274
		IProxyData ret[] = (IProxyData[]) result.toArray(new IProxyData[result.size()]);
275
		return resolveType(ret);
276
	}
277
278
	public static URI tryGetURI(String host) {
279
		try {
280
			int i = host.indexOf(":"); //$NON-NLS-1$
281
			if (i == -1) {
282
				return new URI("//" + host); //$NON-NLS-1$
283
			}
284
			return new URI(host.substring(i + 1));
285
		} catch (URISyntaxException e) {
286
			return null;
287
		}
288
	}
289
290
	private boolean isHostFiltered(URI uri) {
291
		String[] filters = getNonProxiedHosts();
292
		for (int i = 0; i < filters.length; i++) {
293
			String filter = filters[i];
294
			if (matchesFilter(uri.getHost(), filter))
295
				return true;
296
		}
297
		return false;
298
	}
299
300
	private boolean matchesFilter(String host, String filter) {
301
		StringMatcher matcher = new StringMatcher(filter, true, false);
302
		return matcher.match(host);
303
	}
304
305
	/* (non-Javadoc)
306
	 * @see org.eclipse.net.core.IProxyManager#getProxyDataForHost(java.lang.String, java.lang.String)
307
	 */
308
	public IProxyData getProxyDataForHost(String host, String type) {
309
		checkMigrated();
310
		if (!internalIsProxiesEnabled()) {
311
			return null;
312
		}
313
	// TODO: Should probably remove - now in NativeProvider.
314
//		if (hasSystemProxies() && isSystemProxiesEnabled())
315
//			try {
316
//				URI uri = new URI(type, "//" + host, null); //$NON-NLS-1$
317
//				IProxyData[] proxyDatas = nativeProxyProvider.select(uri);
318
//				return proxyDatas.length > 0 ? resolveType(nativeProxyProvider.select(uri)[0]) : null;
319
//			} catch (URISyntaxException e) {
320
//				return null;
321
//			}
322
			
323
		IProxyData[] data = getProxyDataForHost(host);
324
		for (int i = 0; i < data.length; i++) {
325
			IProxyData proxyData = data[i];
326
			if (proxyData.getType().equalsIgnoreCase(type)
327
					&& proxyData.getHost() != null)
328
				return resolveType(proxyData);
329
		}
330
		return null;
331
	}
332
	
333
	private void registerAuthenticator() {
334
		Authenticator a = getPluggedInAuthenticator();
335
		if (a != null) {
336
			Authenticator.setDefault(a);
337
		}
338
	}
339
	
340
	private Authenticator getPluggedInAuthenticator() {
341
		IExtension[] extensions = RegistryFactory.getRegistry().getExtensionPoint(Activator.ID, Activator.PT_AUTHENTICATOR).getExtensions();
342
		if (extensions.length == 0)
343
			return null;
344
		IExtension extension = extensions[0];
345
		IConfigurationElement[] configs = extension.getConfigurationElements();
346
		if (configs.length == 0) {
347
			Activator.log(IStatus.ERROR, NLS.bind("Authenticator {0} is missing required fields", (new Object[] {extension.getUniqueIdentifier()})), null);//$NON-NLS-1$ 
348
			return null;
349
		}
350
		try {
351
			IConfigurationElement config = configs[0];
352
			return (Authenticator) config.createExecutableExtension("class");//$NON-NLS-1$ 
353
		} catch (CoreException ex) {
354
			Activator.log(IStatus.ERROR, NLS.bind("Unable to instantiate authenticator {0}", (new Object[] {extension.getUniqueIdentifier()})), ex);//$NON-NLS-1$ 
355
			return null;
356
		}
357
	}
358
	
359
	private synchronized void checkMigrated() {
360
		if (migrated || !Activator.getInstance().instanceLocationAvailable())
361
			return;
362
		
363
		migrated = true;
364
		if (Activator.getInstance().getPreferences().getBoolean(PREF_HAS_MIGRATED, false))
365
			return;
366
		
367
		Activator.getInstance().getPreferences().putBoolean(PREF_HAS_MIGRATED, true);
368
		migrateInstanceScopePreferences(new InstanceScope().getNode(""), new ConfigurationScope().getNode(""), true);  //$NON-NLS-1$//$NON-NLS-2$
369
	}
370
	
371
	void migrateInstanceScopePreferences(Preferences instanceNode, Preferences configurationNode, boolean isInitialize) {
372
		migrateUpdateHttpProxy(instanceNode, isInitialize);
373
		
374
		Preferences netInstancePrefs = instanceNode.node(Activator.ID);
375
		Preferences netConfigurationPrefs = configurationNode.node(Activator.ID);
376
		
377
		// migrate enabled status
378
		if (netConfigurationPrefs.get(PREF_ENABLED, null) == null) {
379
			String instanceEnabled = netInstancePrefs.get(PREF_ENABLED, null);
380
			if (instanceEnabled != null)
381
				netConfigurationPrefs.put(PREF_ENABLED, instanceEnabled);
382
		}
383
		
384
		// TODO: Should probably remove - now in NativeProvider.
385
		// migrate enabled status
386
//		if (netConfigurationPrefs.get(PREF_OS, null) == null) {
387
//			String instanceEnabled = netInstancePrefs.get(PREF_OS, null);
388
//			if (instanceEnabled != null)
389
//				netConfigurationPrefs.put(PREF_OS, instanceEnabled);
390
//		}
391
	
392
		// migrate non proxied hosts if not already set
393
		if (netConfigurationPrefs.get(PREF_NON_PROXIED_HOSTS, null) == null) {
394
			String instanceNonProxiedHosts = netInstancePrefs.get(PREF_NON_PROXIED_HOSTS, null);
395
			if (instanceNonProxiedHosts != null) {
396
				netConfigurationPrefs.put(PREF_NON_PROXIED_HOSTS, instanceNonProxiedHosts);
397
				nonProxiedHosts = null;
398
			}
399
		}
400
		
401
		// migrate proxy data
402
		boolean proxiesEnabled = netConfigurationPrefs.getBoolean(PREF_ENABLED, true);
403
		for (int i = 0; i < proxies.length; i++) {
404
			ProxyType type = proxies[i];
405
			IProxyData data = type.getProxyData(ProxyType.DO_NOT_VERIFY);
406
			if (data.getHost() == null) {
407
				ProxyType instanceType = new ProxyType(type.getName(),netInstancePrefs);
408
				IProxyData instanceData = instanceType.getProxyData(ProxyType.DO_NOT_VERIFY);
409
				if (instanceData.getHost() != null)
410
					type.setProxyData(instanceData, proxiesEnabled);
411
			}
412
		}
413
		
414
		// if this an import we should remove the old node
415
		if (! isInitialize) {
416
			try {
417
				netInstancePrefs.removeNode();
418
			} catch (BackingStoreException e) {
419
				// ignore
420
			}
421
		}			
422
	}
423
	
424
	private void migrateUpdateHttpProxy(Preferences node, boolean isInitialize) {
425
		Preferences netPrefs = node.node(Activator.ID);
426
		if (!netPrefs.getBoolean(PREF_HAS_MIGRATED, false)) {
427
			// Only set the migration bit when initializing
428
			if (isInitialize)
429
				netPrefs.putBoolean(PREF_HAS_MIGRATED, true);
430
			Preferences updatePrefs = node.node("org.eclipse.update.core"); //$NON-NLS-1$
431
			String httpProxyHost = getHostToMigrate(updatePrefs, isInitialize /* checkSystemProperties */);
432
			int port = getPortToMigrate(updatePrefs, isInitialize /* checkSystemProperties */);
433
			boolean httpProxyEnable = getEnablementToMigrate(updatePrefs, isInitialize /* checkSystemProperties */);
434
			if (httpProxyHost != null) {
435
				ProxyData proxyData = new ProxyData(IProxyData.HTTP_PROXY_TYPE,
436
						httpProxyHost, port, false, null);
437
				ProxyType type = getType(proxyData);
438
				type.updatePreferencesIfMissing(netPrefs, proxyData);
439
				if (httpProxyEnable) {
440
					netPrefs.putBoolean(PREF_ENABLED, true);
441
				}
442
			}
443
		}
444
	}
445
446
	private boolean getEnablementToMigrate(Preferences updatePrefs, boolean checkSystemProperties) {
447
		boolean httpProxyEnable = false;
448
		if (checkSystemProperties && updatePrefs.get(HTTP_PROXY_ENABLE, null) == null) {
449
			httpProxyEnable = Boolean.getBoolean("http.proxySet"); //$NON-NLS-1$
450
		} else {
451
			httpProxyEnable = updatePrefs.getBoolean(HTTP_PROXY_ENABLE, false);
452
			updatePrefs.remove(HTTP_PROXY_ENABLE);
453
		}
454
		return httpProxyEnable;
455
	}
456
457
	private int getPortToMigrate(Preferences updatePrefs, boolean checkSystemProperties) {
458
		String httpProxyPort = updatePrefs.get(HTTP_PROXY_PORT, ""); //$NON-NLS-1$
459
		if (checkSystemProperties && "".equals(httpProxyPort)) { //$NON-NLS-1$
460
			httpProxyPort = System.getProperty("http.proxyPort", ""); //$NON-NLS-1$ //$NON-NLS-2$
461
		}
462
		updatePrefs.remove(HTTP_PROXY_PORT);
463
		int port = -1;
464
		if (httpProxyPort != null && !"".equals(httpProxyPort)) //$NON-NLS-1$
465
			try {
466
				port = Integer.parseInt(httpProxyPort);
467
			} catch (NumberFormatException e) {
468
				// Ignore
469
			}
470
		return port;
471
	}
472
473
	private String getHostToMigrate(Preferences updatePrefs, boolean checkSystemProperties) {
474
		String httpProxyHost = updatePrefs.get(HTTP_PROXY_HOST, ""); //$NON-NLS-1$
475
		if (checkSystemProperties && "".equals(httpProxyHost)) { //$NON-NLS-1$
476
			httpProxyHost = System.getProperty("http.proxyHost", ""); //$NON-NLS-1$ //$NON-NLS-2$
477
		}
478
		if ("".equals(httpProxyHost)) //$NON-NLS-1$
479
			httpProxyHost = null;
480
		updatePrefs.remove(HTTP_PROXY_HOST);
481
		return httpProxyHost;
482
	}
483
	
484
	public void preferenceChange(PreferenceChangeEvent event) {
485
		if (event.getKey().equals(PREF_ENABLED)) {
486
			checkMigrated();
487
			internalSetEnabled(Activator.getInstance().getPreferences().getBoolean(PREF_ENABLED, true));
488
		}
489
	}
490
491
	public IProxyData resolveType(IProxyData data) {
492
		if (data == null) {
493
			return null;
494
		}
495
		ProxyData d = (ProxyData) data;
496
		if (d.getType().equalsIgnoreCase(IProxyData.HTTP_PROXY_TYPE)) {
497
			d.setType(IProxyData.HTTP_PROXY_TYPE);
498
		} else if (d.getType().equalsIgnoreCase(IProxyData.HTTPS_PROXY_TYPE)) {
499
			d.setType(IProxyData.HTTPS_PROXY_TYPE);
500
		} else if (d.getType().equalsIgnoreCase(IProxyData.SOCKS_PROXY_TYPE)) {
501
			d.setType(IProxyData.SOCKS_PROXY_TYPE);
502
		}
503
		return d;
504
	}
505
506
	public IProxyData[] resolveType(IProxyData[] data) {
507
		if (data == null) {
508
			return null;
509
		}
510
		for (int i = 0; i < data.length; i++) {
511
			resolveType(data[i]);
512
		}
513
		return data;
514
	}
515
	
516
}
(-)src/org/eclipse/core/net/proxy/IProxyProviderExtension.java (+17 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Mark A. Ziesemer and others
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *		Mark A. Ziesemer - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.core.net.proxy;
12
13
import org.eclipse.core.runtime.IExecutableExtension;
14
15
public interface IProxyProviderExtension extends IExecutableExtension, IProxyProvider{
16
	// Currently parent interfaces only.
17
}
(-)src/org/eclipse/ui/internal/net/ProxyPreferencePage.java (-39 / +124 lines)
Lines 18-28 Link Here
18
 *******************************************************************************/
18
 *******************************************************************************/
19
package org.eclipse.ui.internal.net;
19
package org.eclipse.ui.internal.net;
20
20
21
import org.eclipse.core.internal.net.ProxySelector;
21
import java.util.LinkedList;
22
import java.util.List;
23
24
import org.eclipse.core.internal.net.ProxyManager;
25
import org.eclipse.core.net.proxy.IProxyProvider;
26
import org.eclipse.core.runtime.CoreException;
27
import org.eclipse.core.runtime.IConfigurationElement;
28
import org.eclipse.core.runtime.IExtension;
29
import org.eclipse.core.runtime.IStatus;
30
import org.eclipse.core.runtime.RegistryFactory;
31
import org.eclipse.core.runtime.Status;
22
import org.eclipse.jface.preference.PreferencePage;
32
import org.eclipse.jface.preference.PreferencePage;
33
import org.eclipse.osgi.util.NLS;
23
import org.eclipse.swt.SWT;
34
import org.eclipse.swt.SWT;
24
import org.eclipse.swt.events.SelectionAdapter;
35
import org.eclipse.swt.events.SelectionAdapter;
25
import org.eclipse.swt.events.SelectionEvent;
36
import org.eclipse.swt.events.SelectionEvent;
37
import org.eclipse.swt.layout.FillLayout;
26
import org.eclipse.swt.layout.GridData;
38
import org.eclipse.swt.layout.GridData;
27
import org.eclipse.swt.layout.GridLayout;
39
import org.eclipse.swt.layout.GridLayout;
28
import org.eclipse.swt.widgets.Combo;
40
import org.eclipse.swt.widgets.Combo;
Lines 35-47 Link Here
35
47
36
public class ProxyPreferencePage extends PreferencePage implements
48
public class ProxyPreferencePage extends PreferencePage implements
37
		IWorkbenchPreferencePage {
49
		IWorkbenchPreferencePage {
38
50
	
39
	private static final String PROXY_PREFERENCE_PAGE_CONTEXT_ID = "org.eclipse.ui.net.proxy_preference_page_context"; //$NON-NLS-1$
51
	private static final String PROXY_PREFERENCE_PAGE_CONTEXT_ID = "org.eclipse.ui.net.proxy_preference_page_context"; //$NON-NLS-1$
52
	
53
	protected ProxyManager proxyManager = ProxyManager.getProxyManager();
54
	
55
	// Cache as long as the page is open.
56
	protected IProxyProvider[] providers;
57
	protected IProxyProviderConfigUIExtension[] uiExtensions;
58
	protected IProxyProviderConfigUIExtension currentUiExtension;
59
	protected Composite extensionComposite;
40
60
41
	private Label providerLabel;
61
	private Label providerLabel;
42
	protected Combo providerCombo;
62
	protected Combo providerCombo;
43
	private ProxyEntriesComposite proxyEntriesComposite;
63
	
44
	private NonProxyHostsComposite nonProxyHostsComposite;
64
	public void init(IWorkbench workbench) {
65
		providers = proxyManager.getProviders();
66
		uiExtensions = getUIExtensions();
67
	}
45
68
46
	protected Control createContents(Composite parent) {
69
	protected Control createContents(Composite parent) {
47
		Composite composite = new Composite(parent, SWT.NONE);
70
		Composite composite = new Composite(parent, SWT.NONE);
Lines 51-58 Link Here
51
		composite.setLayout(layout);
74
		composite.setLayout(layout);
52
75
53
		createProviderComposite(composite);
76
		createProviderComposite(composite);
54
		createProxyEntriesComposite(composite);
77
		this.extensionComposite = new Composite(composite, SWT.NONE);
55
		createNonProxiedHostsComposite(composite);
78
		this.extensionComposite.setLayout(new FillLayout());
56
79
57
		// Adding help accessible by F1
80
		// Adding help accessible by F1
58
		PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
81
		PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
Lines 72-124 Link Here
72
		providerCombo = new Combo(composite, SWT.READ_ONLY | SWT.DROP_DOWN);
95
		providerCombo = new Combo(composite, SWT.READ_ONLY | SWT.DROP_DOWN);
73
		providerCombo.addSelectionListener(new SelectionAdapter() {
96
		providerCombo.addSelectionListener(new SelectionAdapter() {
74
			public void widgetSelected(SelectionEvent e) {
97
			public void widgetSelected(SelectionEvent e) {
75
				setProvider(providerCombo.getText());
98
				setProvider(providerCombo.getSelectionIndex());
76
			}
99
			}
77
		});
100
		});
78
	}
101
	}
79
102
80
	private void createProxyEntriesComposite(Composite parent) {
103
	protected void performApply(){
81
		proxyEntriesComposite = new ProxyEntriesComposite(parent, SWT.NONE);
104
		if(currentUiExtension != null){
82
		proxyEntriesComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
105
			currentUiExtension.performApply();
83
				true, true));
106
		}
84
	}
85
86
	private void createNonProxiedHostsComposite(Composite parent) {
87
		nonProxyHostsComposite = new NonProxyHostsComposite(parent, SWT.NONE);
88
		nonProxyHostsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
89
				true, true));
90
	}
91
92
	public void init(IWorkbench workbench) {
93
		// Nothing to do
94
	}
95
96
	protected void performApply() {
97
		int sel = providerCombo.getSelectionIndex();
107
		int sel = providerCombo.getSelectionIndex();
98
		ProxySelector.setDefaultProvider(providerCombo.getItem(sel));
108
		proxyManager.setProvider(providers[sel]);
99
		proxyEntriesComposite.performApply();
100
		nonProxyHostsComposite.performApply();
101
	}
109
	}
102
110
103
	protected void performDefaults() {
111
	protected void performDefaults(){
104
		providerCombo.select(1);
112
		//	providerCombo.select(1);
105
		setProvider(providerCombo.getItem(1));
113
		//	setProvider(1);
114
		if(currentUiExtension != null){
115
			currentUiExtension.performDefaults();
116
		}
106
	}
117
	}
107
118
108
	public boolean performOk() {
119
	public boolean performOk(){
120
		if(currentUiExtension != null){
121
			if(!currentUiExtension.performOk()){
122
				return false;
123
			}
124
		}
109
		performApply();
125
		performApply();
110
		return super.performOk();
126
		return super.performOk();
111
	}
127
	}
112
128
113
	private void initializeValues() {
129
	private void initializeValues() {
114
		providerCombo.setItems(ProxySelector.getProviders());
130
		String items[] = new String[providers.length];
115
		providerCombo.select(providerCombo.indexOf(ProxySelector
131
		int selIndex = 0;
116
				.getDefaultProvider()));
132
		IProxyProvider currentProvider = proxyManager.getProvider();
117
	}
133
		for(int i=0; i<providers.length; i++){
118
134
			items[i] = providers[i].getName();
119
	protected void setProvider(String name) {
135
			if(currentProvider.equals(providers[i])){
120
		proxyEntriesComposite.setProvider(name);
136
				selIndex = i;
121
		nonProxyHostsComposite.setProvider(name);
137
			}
138
		}
139
		providerCombo.setItems(items);
140
		providerCombo.select(selIndex);
141
		setProvider(selIndex);
142
	}
143
144
	protected void setProvider(int index){
145
		// Remove last extension control, if any.
146
		Control[] cc = extensionComposite.getChildren();
147
		for(int i=0; i<cc.length; i++){
148
			cc[i].dispose();
149
		}
150
		currentUiExtension = null;
151
		
152
		// Add new extension control, if any.
153
		IProxyProvider ipp = providers[index];
154
		for(int i=0; i<uiExtensions.length; i++){
155
			if(ipp.getClass().equals(uiExtensions[i].getProxyProviderClass())){
156
				currentUiExtension = uiExtensions[i];
157
				currentUiExtension.createProviderComposite(extensionComposite, this);
158
				extensionComposite.pack();
159
				return;
160
			}
161
		}
162
		
163
		// If no extension control provided:
164
		Label noConfigLabel = new Label(extensionComposite, SWT.NONE);
165
		// TODO: Externalize label text.
166
		noConfigLabel.setText("No configuration UI provided for the selected proxy provider."); //$NON-NLS-1$
167
		noConfigLabel.pack();
168
		
169
	}
170
	
171
	private IProxyProviderConfigUIExtension[] getUIExtensions(){
172
		List resultList = new LinkedList();
173
		IExtension[] extensions = RegistryFactory.getRegistry().getExtensionPoint(
174
			Activator.PLUGIN_ID, IProxyProviderConfigUIExtension.EXTENSION_POINT_NAME).getExtensions();
175
		for(int i=0; i<extensions.length; i++){
176
			IExtension extension = extensions[i];
177
			IConfigurationElement[] configs = extension.getConfigurationElements();
178
			if(configs.length == 0){
179
				logError(NLS.bind("Provider {0} is missing required fields", //$NON-NLS-1$
180
					(new Object[]{extension.getUniqueIdentifier()})), null);
181
			}else{
182
				try{
183
					IConfigurationElement config = configs[0];
184
					IProxyProviderConfigUIExtension ipp = (IProxyProviderConfigUIExtension)config.createExecutableExtension("class"); //$NON-NLS-1$
185
					resultList.add(ipp);
186
				}catch(CoreException ex){
187
					logError(NLS.bind("Unable to instantiate provider {0}", //$NON-NLS-1$
188
						(new Object[]{extension.getUniqueIdentifier()})), ex); 
189
				}
190
			}
191
		}
192
		IProxyProviderConfigUIExtension[] result = new IProxyProviderConfigUIExtension[resultList.size()];
193
		resultList.toArray(result);
194
		return result;
195
	}
196
	
197
	public static void logInfo(String message){
198
		log(new Status(IStatus.INFO, Activator.PLUGIN_ID, 0, message, null));
199
	}
200
	
201
	public static void logError(String message, Throwable exc){
202
		log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, message, exc));
203
	}
204
	
205
	public static void log(IStatus status){
206
		Activator.getDefault().getLog().log(status);
122
	}
207
	}
123
208
124
}
209
}
(-)plugin.xml (+7 lines)
Lines 2-7 Link Here
2
<?eclipse version="3.0"?>
2
<?eclipse version="3.0"?>
3
3
4
<plugin>
4
<plugin>
5
   <extension-point id="provider" name="Provider" schema="schema/provider.exsd"/>
5
6
6
   <extension
7
   <extension
7
   		point="org.eclipse.ui.keywords">
8
   		point="org.eclipse.ui.keywords">
Lines 25-29 Link Here
25
           class="org.eclipse.ui.internal.net.auth.NetAuthenticator">
26
           class="org.eclipse.ui.internal.net.auth.NetAuthenticator">
26
     </authenticator>
27
     </authenticator>
27
  </extension>
28
  </extension>
29
  <extension
30
        point="org.eclipse.ui.net.provider">
31
     <provider
32
           class="org.eclipse.ui.internal.net.EclipseProviderPreferencePage">
33
     </provider>
34
  </extension>
28
35
29
</plugin>
36
</plugin>
(-)src/org/eclipse/ui/internal/net/AbstractProxyProviderConfigUIExtension.java (+40 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Mark A. Ziesemer and others
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *		Mark A. Ziesemer - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.net;
12
13
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.IConfigurationElement;
15
import org.eclipse.ui.IWorkbench;
16
17
public abstract class AbstractProxyProviderConfigUIExtension implements IProxyProviderConfigUIExtension{
18
	
19
	public void setInitializationData(IConfigurationElement config, String propertyName, Object data)
20
			throws CoreException{
21
		// Nothing to do.
22
	}
23
24
	public void init(IWorkbench workbench){
25
		// Nothing to do.
26
	}
27
28
	public void performApply(){
29
		// Nothing to do.
30
	}
31
32
	public void performDefaults(){
33
		// Nothing to do.
34
	}
35
36
	public boolean performOk(){
37
		return true;
38
	}
39
40
}
(-)src/org/eclipse/ui/internal/net/IProxyProviderConfigUIExtension.java (+48 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Mark A. Ziesemer and others
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *		Mark A. Ziesemer - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.net;
12
13
import org.eclipse.core.net.proxy.IProxyProvider;
14
import org.eclipse.core.runtime.IExecutableExtension;
15
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.ui.IWorkbenchPreferencePage;
17
18
public interface IProxyProviderConfigUIExtension extends IExecutableExtension{
19
	
20
	public static final String EXTENSION_POINT_NAME = "provider"; //$NON-NLS-1$
21
	
22
	// TODO: There has to be a better way of receiving these events instead of copying relevant API.
23
	
24
	/**
25
	 * (protected) see PreferencePage#performDefaults()
26
	 */
27
	void performDefaults();
28
	
29
	/**
30
	 * (protected) see PreferencePage#performApply()
31
	 */
32
	void performApply();
33
	
34
	/**
35
	 * @see IWorkbenchPreferencePage#performOk()
36
	 * @return (see above)
37
	 */
38
	boolean performOk();
39
	
40
	
41
	/**
42
	 * Returns the {@link IProxyProvider} that this UI configures.
43
	 * @return The {@link IProxyProvider} that this UI configures.
44
	 */
45
	Class getProxyProviderClass();
46
	
47
	void createProviderComposite(Composite parentComposite, ProxyPreferencePage parentPage);
48
}
(-)src/org/eclipse/ui/internal/net/EclipseProviderPreferencePage.java (+49 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Mark A. Ziesemer and others
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *		Mark A. Ziesemer - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.net;
12
13
import org.eclipse.core.internal.net.providers.EclipseProvider;
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.layout.GridData;
16
import org.eclipse.swt.widgets.Composite;
17
18
public class EclipseProviderPreferencePage extends AbstractProxyProviderConfigUIExtension{
19
	
20
	private ProxyEntriesComposite proxyEntriesComposite;
21
	private NonProxyHostsComposite nonProxyHostsComposite;
22
	
23
	public Class getProxyProviderClass(){
24
		return EclipseProvider.class;
25
	}
26
27
	public void createProviderComposite(Composite parentComposite, ProxyPreferencePage parentPage){
28
		createProxyEntriesComposite(parentComposite);
29
		createNonProxiedHostsComposite(parentComposite);
30
	}
31
	
32
	private void createProxyEntriesComposite(Composite parent) {
33
		proxyEntriesComposite = new ProxyEntriesComposite(parent, SWT.NONE);
34
		proxyEntriesComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
35
			true, true));
36
	}
37
38
	private void createNonProxiedHostsComposite(Composite parent) {
39
		nonProxyHostsComposite = new NonProxyHostsComposite(parent, SWT.NONE);
40
		nonProxyHostsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
41
			true, true));
42
	}
43
	
44
	public void performApply(){
45
		proxyEntriesComposite.performApply();
46
		nonProxyHostsComposite.performApply();
47
	}
48
49
}
(-)schema/provider.exsd (+102 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.ui.net" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.ui.net" id="provider" name="Provider"/>
7
      </appInfo>
8
      <documentation>
9
         Extension point to provide different proxy ui configuration implementations.
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
      <annotation>
15
         <appinfo>
16
            <meta.element />
17
         </appinfo>
18
      </annotation>
19
      <complexType>
20
         <sequence>
21
            <element ref="provider"/>
22
         </sequence>
23
         <attribute name="point" type="string" use="required">
24
            <annotation>
25
               <documentation>
26
                  
27
               </documentation>
28
            </annotation>
29
         </attribute>
30
         <attribute name="id" type="string">
31
            <annotation>
32
               <documentation>
33
                  
34
               </documentation>
35
            </annotation>
36
         </attribute>
37
         <attribute name="name" type="string">
38
            <annotation>
39
               <documentation>
40
                  
41
               </documentation>
42
               <appinfo>
43
                  <meta.attribute translatable="true"/>
44
               </appinfo>
45
            </annotation>
46
         </attribute>
47
      </complexType>
48
   </element>
49
50
   <element name="provider">
51
      <complexType>
52
         <attribute name="class" type="string">
53
            <annotation>
54
               <documentation>
55
                  
56
               </documentation>
57
               <appinfo>
58
                  <meta.attribute kind="java"/>
59
               </appinfo>
60
            </annotation>
61
         </attribute>
62
      </complexType>
63
   </element>
64
65
   <annotation>
66
      <appinfo>
67
         <meta.section type="since"/>
68
      </appinfo>
69
      <documentation>
70
         [Enter the first release in which this extension point appears.]
71
      </documentation>
72
   </annotation>
73
74
   <annotation>
75
      <appinfo>
76
         <meta.section type="examples"/>
77
      </appinfo>
78
      <documentation>
79
         [Enter extension point usage example here.]
80
      </documentation>
81
   </annotation>
82
83
   <annotation>
84
      <appinfo>
85
         <meta.section type="apiinfo"/>
86
      </appinfo>
87
      <documentation>
88
         [Enter API information here.]
89
      </documentation>
90
   </annotation>
91
92
   <annotation>
93
      <appinfo>
94
         <meta.section type="implementation"/>
95
      </appinfo>
96
      <documentation>
97
         [Enter information about supplied implementation of this extension point.]
98
      </documentation>
99
   </annotation>
100
101
102
</schema>

Return to bug 257443