Lines 11-24
Link Here
|
11 |
package org.eclipse.core.internal.net; |
11 |
package org.eclipse.core.internal.net; |
12 |
|
12 |
|
13 |
import java.net.Authenticator; |
13 |
import java.net.Authenticator; |
14 |
import java.util.*; |
14 |
import java.net.URI; |
15 |
|
15 |
import java.net.URISyntaxException; |
16 |
import org.eclipse.core.net.proxy.*; |
16 |
import java.util.ArrayList; |
17 |
import org.eclipse.core.runtime.*; |
17 |
import java.util.List; |
|
|
18 |
import java.util.Properties; |
19 |
|
20 |
import org.eclipse.core.net.proxy.IProxyChangeEvent; |
21 |
import org.eclipse.core.net.proxy.IProxyChangeListener; |
22 |
import org.eclipse.core.net.proxy.IProxyData; |
23 |
import org.eclipse.core.net.proxy.IProxyService; |
24 |
import org.eclipse.core.runtime.Assert; |
25 |
import org.eclipse.core.runtime.CoreException; |
26 |
import org.eclipse.core.runtime.IConfigurationElement; |
27 |
import org.eclipse.core.runtime.IExtension; |
28 |
import org.eclipse.core.runtime.ISafeRunnable; |
29 |
import org.eclipse.core.runtime.IStatus; |
30 |
import org.eclipse.core.runtime.ListenerList; |
31 |
import org.eclipse.core.runtime.Platform; |
32 |
import org.eclipse.core.runtime.SafeRunner; |
18 |
import org.eclipse.core.runtime.preferences.ConfigurationScope; |
33 |
import org.eclipse.core.runtime.preferences.ConfigurationScope; |
19 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
34 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
20 |
import org.eclipse.core.runtime.preferences.InstanceScope; |
35 |
import org.eclipse.core.runtime.preferences.InstanceScope; |
21 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences.*; |
36 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; |
|
|
37 |
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent; |
22 |
import org.eclipse.osgi.util.NLS; |
38 |
import org.eclipse.osgi.util.NLS; |
23 |
import org.osgi.service.prefs.BackingStoreException; |
39 |
import org.osgi.service.prefs.BackingStoreException; |
24 |
import org.osgi.service.prefs.Preferences; |
40 |
import org.osgi.service.prefs.Preferences; |
Lines 36-44
Link Here
|
36 |
|
52 |
|
37 |
private static final String PREF_NON_PROXIED_HOSTS = "nonProxiedHosts"; //$NON-NLS-1$ |
53 |
private static final String PREF_NON_PROXIED_HOSTS = "nonProxiedHosts"; //$NON-NLS-1$ |
38 |
private static final String PREF_ENABLED = "proxiesEnabled"; //$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$ |
39 |
|
56 |
|
40 |
private static IProxyService proxyManager; |
57 |
private static IProxyService proxyManager; |
41 |
|
58 |
|
|
|
59 |
private AbstractProxyProvider nativeProxyProvider; |
60 |
|
42 |
ListenerList listeners = new ListenerList(ListenerList.IDENTITY); |
61 |
ListenerList listeners = new ListenerList(ListenerList.IDENTITY); |
43 |
private String[] nonProxiedHosts; |
62 |
private String[] nonProxiedHosts; |
44 |
private final ProxyType[] proxies = new ProxyType[] { |
63 |
private final ProxyType[] proxies = new ProxyType[] { |
Lines 49-54
Link Here
|
49 |
|
68 |
|
50 |
private boolean migrated = false; |
69 |
private boolean migrated = false; |
51 |
|
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("noNativeProxyProvider", e); //$NON-NLS-1$ |
79 |
} |
80 |
} |
81 |
|
52 |
/** |
82 |
/** |
53 |
* Return the proxy manager. |
83 |
* Return the proxy manager. |
54 |
* @return the proxy manager |
84 |
* @return the proxy manager |
Lines 160-166
Link Here
|
160 |
for (int i = 0; i < proxyDatas.length; i++) { |
190 |
for (int i = 0; i < proxyDatas.length; i++) { |
161 |
IProxyData proxyData = proxyDatas[i]; |
191 |
IProxyData proxyData = proxyDatas[i]; |
162 |
ProxyType type = getType(proxyData); |
192 |
ProxyType type = getType(proxyData); |
163 |
if (type != null && type.setProxyData(proxyData, isProxiesEnabled())) { |
193 |
if (type != null && type.setProxyData(proxyData, internalIsProxiesEnabled())) { |
164 |
result.add(proxyData); |
194 |
result.add(proxyData); |
165 |
} |
195 |
} |
166 |
} |
196 |
} |
Lines 182-188
Link Here
|
182 |
*/ |
212 |
*/ |
183 |
public boolean isProxiesEnabled() { |
213 |
public boolean isProxiesEnabled() { |
184 |
checkMigrated(); |
214 |
checkMigrated(); |
185 |
return Activator.getInstance().getPreferences().getBoolean(PREF_ENABLED, false); |
215 |
return internalIsProxiesEnabled() |
|
|
216 |
&& (!isSystemProxiesEnabled() || (isSystemProxiesEnabled() && hasSystemProxies())); |
217 |
} |
218 |
|
219 |
private boolean internalIsProxiesEnabled() { |
220 |
return Activator.getInstance().getPreferences().getBoolean( |
221 |
PREF_ENABLED, false); |
186 |
} |
222 |
} |
187 |
|
223 |
|
188 |
/* (non-Javadoc) |
224 |
/* (non-Javadoc) |
Lines 190-196
Link Here
|
190 |
*/ |
226 |
*/ |
191 |
public void setProxiesEnabled(boolean enabled) { |
227 |
public void setProxiesEnabled(boolean enabled) { |
192 |
checkMigrated(); |
228 |
checkMigrated(); |
193 |
boolean current = isProxiesEnabled(); |
229 |
boolean current = internalIsProxiesEnabled(); |
194 |
if (current == enabled) |
230 |
if (current == enabled) |
195 |
return; |
231 |
return; |
196 |
// Setting the preference will trigger the system property update |
232 |
// Setting the preference will trigger the system property update |
Lines 198-206
Link Here
|
198 |
Activator.getInstance().getPreferences().putBoolean(PREF_ENABLED, enabled); |
234 |
Activator.getInstance().getPreferences().putBoolean(PREF_ENABLED, enabled); |
199 |
} |
235 |
} |
200 |
|
236 |
|
201 |
private void internalSetEnabled(boolean enabled) { |
237 |
private void internalSetEnabled(boolean enabled, boolean systemEnabled) { |
202 |
Properties sysProps = System.getProperties(); |
238 |
Properties sysProps = System.getProperties(); |
203 |
sysProps.put("proxySet", enabled ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
239 |
sysProps.put("proxySet", enabled ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
|
240 |
sysProps.put("systemProxySet", systemEnabled ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
204 |
updateSystemProperties(); |
241 |
updateSystemProperties(); |
205 |
try { |
242 |
try { |
206 |
Activator.getInstance().getPreferences().flush(); |
243 |
Activator.getInstance().getPreferences().flush(); |
Lines 217-223
Link Here
|
217 |
private void updateSystemProperties() { |
254 |
private void updateSystemProperties() { |
218 |
for (int i = 0; i < proxies.length; i++) { |
255 |
for (int i = 0; i < proxies.length; i++) { |
219 |
ProxyType type = proxies[i]; |
256 |
ProxyType type = proxies[i]; |
220 |
type.updateSystemProperties(internalGetProxyData(type.getName(), ProxyType.DO_NOT_VERIFY), isProxiesEnabled()); |
257 |
type.updateSystemProperties(internalGetProxyData(type.getName(), ProxyType.DO_NOT_VERIFY), internalIsProxiesEnabled()); |
221 |
} |
258 |
} |
222 |
} |
259 |
} |
223 |
|
260 |
|
Lines 227-233
Link Here
|
227 |
// Now initialize each proxy type |
264 |
// Now initialize each proxy type |
228 |
for (int i = 0; i < proxies.length; i++) { |
265 |
for (int i = 0; i < proxies.length; i++) { |
229 |
ProxyType type = proxies[i]; |
266 |
ProxyType type = proxies[i]; |
230 |
type.initialize(isProxiesEnabled()); |
267 |
type.initialize(internalIsProxiesEnabled()); |
231 |
} |
268 |
} |
232 |
registerAuthenticator(); |
269 |
registerAuthenticator(); |
233 |
} |
270 |
} |
Lines 249-254
Link Here
|
249 |
|
286 |
|
250 |
public IProxyData[] getProxyDataForHost(String host) { |
287 |
public IProxyData[] getProxyDataForHost(String host) { |
251 |
checkMigrated(); |
288 |
checkMigrated(); |
|
|
289 |
if (hasSystemProxies() && isSystemProxiesEnabled()) |
290 |
try { |
291 |
System.out.println(new URI(host)); |
292 |
return nativeProxyProvider.select(new URI(host)); |
293 |
} catch (URISyntaxException e) { |
294 |
return new IProxyData[0]; |
295 |
} |
296 |
|
252 |
if (isHostFiltered(host)) |
297 |
if (isHostFiltered(host)) |
253 |
return new IProxyData[0]; |
298 |
return new IProxyData[0]; |
254 |
IProxyData[] data = getProxyData(); |
299 |
IProxyData[] data = getProxyData(); |
Lines 281-286
Link Here
|
281 |
*/ |
326 |
*/ |
282 |
public IProxyData getProxyDataForHost(String host, String type) { |
327 |
public IProxyData getProxyDataForHost(String host, String type) { |
283 |
checkMigrated(); |
328 |
checkMigrated(); |
|
|
329 |
if (hasSystemProxies() && isSystemProxiesEnabled()) |
330 |
try { |
331 |
URI uri = new URI(type, "//" + host, null); //$NON-NLS-1$ |
332 |
System.out.println(uri); |
333 |
return nativeProxyProvider.select(uri)[0]; |
334 |
} catch (URISyntaxException e) { |
335 |
return null; |
336 |
} |
337 |
|
284 |
IProxyData[] data = getProxyDataForHost(host); |
338 |
IProxyData[] data = getProxyDataForHost(host); |
285 |
for (int i = 0; i < data.length; i++) { |
339 |
for (int i = 0; i < data.length; i++) { |
286 |
IProxyData proxyData = data[i]; |
340 |
IProxyData proxyData = data[i]; |
Lines 341-347
Link Here
|
341 |
if (instanceEnabled != null) |
395 |
if (instanceEnabled != null) |
342 |
netConfigurationPrefs.put(PREF_ENABLED, instanceEnabled); |
396 |
netConfigurationPrefs.put(PREF_ENABLED, instanceEnabled); |
343 |
} |
397 |
} |
344 |
|
398 |
|
|
|
399 |
// migrate enabled status |
400 |
if (netConfigurationPrefs.get(PREF_OS, null) == null) { |
401 |
String instanceEnabled = netInstancePrefs.get(PREF_OS, null); |
402 |
if (instanceEnabled != null) |
403 |
netConfigurationPrefs.put(PREF_OS, instanceEnabled); |
404 |
} |
405 |
|
345 |
// migrate non proxied hosts if not already set |
406 |
// migrate non proxied hosts if not already set |
346 |
if (netConfigurationPrefs.get(PREF_NON_PROXIED_HOSTS, null) == null) { |
407 |
if (netConfigurationPrefs.get(PREF_NON_PROXIED_HOSTS, null) == null) { |
347 |
String instanceNonProxiedHosts = netInstancePrefs.get(PREF_NON_PROXIED_HOSTS, null); |
408 |
String instanceNonProxiedHosts = netInstancePrefs.get(PREF_NON_PROXIED_HOSTS, null); |
Lines 434-443
Link Here
|
434 |
} |
495 |
} |
435 |
|
496 |
|
436 |
public void preferenceChange(PreferenceChangeEvent event) { |
497 |
public void preferenceChange(PreferenceChangeEvent event) { |
437 |
if (event.getKey().equals(PREF_ENABLED)) { |
498 |
if (event.getKey().equals(PREF_ENABLED) || event.getKey().equals(PREF_OS)) { |
438 |
checkMigrated(); |
499 |
checkMigrated(); |
439 |
internalSetEnabled(Activator.getInstance().getPreferences().getBoolean(PREF_ENABLED, false)); |
500 |
internalSetEnabled(Activator.getInstance().getPreferences().getBoolean(PREF_ENABLED, false), |
|
|
501 |
Activator.getInstance().getPreferences().getBoolean(PREF_OS, false)); |
440 |
} |
502 |
} |
441 |
} |
503 |
} |
442 |
|
504 |
|
|
|
505 |
public boolean hasSystemProxies() { |
506 |
return nativeProxyProvider != null; |
507 |
} |
508 |
|
509 |
public boolean isSystemProxiesEnabled() { |
510 |
checkMigrated(); |
511 |
return Activator.getInstance().getPreferences().getBoolean(PREF_OS, |
512 |
false); |
513 |
} |
514 |
|
515 |
public void setSystemProxiesEnabled(boolean enabled) { |
516 |
checkMigrated(); |
517 |
boolean current = isSystemProxiesEnabled(); |
518 |
if (current == enabled) |
519 |
return; |
520 |
// Setting the preference will trigger the system property update |
521 |
// (see preferenceChange) |
522 |
Activator.getInstance().getPreferences().putBoolean(PREF_OS, enabled); |
523 |
} |
443 |
} |
524 |
} |