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 |
} |