Lines 53-63
Link Here
|
53 |
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$ |
54 |
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$ |
55 |
private static final String PREF_OS = "systemProxiesEnabled"; //$NON-NLS-1$ |
|
|
56 |
private static final String PREF_COMMAND_LINE = "commandLineProxiesEnabled"; //$NON-NLS-1$ |
56 |
|
57 |
|
57 |
private static IProxyService proxyManager; |
58 |
private static IProxyService proxyManager; |
58 |
|
59 |
|
59 |
private AbstractProxyProvider nativeProxyProvider; |
60 |
private AbstractProxyProvider nativeProxyProvider; |
60 |
|
61 |
|
|
|
62 |
private AbstractProxyProvider commandLineProxyProvider; |
63 |
|
61 |
ListenerList listeners = new ListenerList(ListenerList.IDENTITY); |
64 |
ListenerList listeners = new ListenerList(ListenerList.IDENTITY); |
62 |
private String[] nonProxiedHosts; |
65 |
private String[] nonProxiedHosts; |
63 |
private final ProxyType[] proxies = new ProxyType[] { |
66 |
private final ProxyType[] proxies = new ProxyType[] { |
Lines 70-75
Link Here
|
70 |
|
73 |
|
71 |
private ProxyManager() { |
74 |
private ProxyManager() { |
72 |
try { |
75 |
try { |
|
|
76 |
commandLineProxyProvider = new CommandLineProxyProvider(); |
73 |
nativeProxyProvider = (AbstractProxyProvider) Class.forName( |
77 |
nativeProxyProvider = (AbstractProxyProvider) Class.forName( |
74 |
"org.eclipse.core.net.ProxyProvider").newInstance(); //$NON-NLS-1$ |
78 |
"org.eclipse.core.net.ProxyProvider").newInstance(); //$NON-NLS-1$ |
75 |
} catch (ClassNotFoundException e) { |
79 |
} catch (ClassNotFoundException e) { |
Lines 141-146
Link Here
|
141 |
return new String[0]; |
145 |
return new String[0]; |
142 |
} |
146 |
} |
143 |
|
147 |
|
|
|
148 |
public String[] getCommandLineNonProxiedHosts() { |
149 |
if (hasCommandLineProxies()) { |
150 |
return commandLineProxyProvider.getNonProxiedHosts(); |
151 |
} |
152 |
return new String[0]; |
153 |
} |
154 |
|
144 |
/* (non-Javadoc) |
155 |
/* (non-Javadoc) |
145 |
* @see org.eclipse.core.net.IProxyManager#setNonProxiedHosts(java.lang.String[]) |
156 |
* @see org.eclipse.core.net.IProxyManager#setNonProxiedHosts(java.lang.String[]) |
146 |
*/ |
157 |
*/ |
Lines 184-189
Link Here
|
184 |
return new IProxyData[0]; |
195 |
return new IProxyData[0]; |
185 |
} |
196 |
} |
186 |
|
197 |
|
|
|
198 |
public IProxyData[] getCommandLineProxyData() { |
199 |
if (hasCommandLineProxies()) { |
200 |
return resolveType(commandLineProxyProvider.getProxyData()); |
201 |
} |
202 |
return new IProxyData[0]; |
203 |
} |
204 |
|
187 |
public void setProxyData(IProxyData[] proxies) { |
205 |
public void setProxyData(IProxyData[] proxies) { |
188 |
checkMigrated(); |
206 |
checkMigrated(); |
189 |
doSetProxyData(proxies); |
207 |
doSetProxyData(proxies); |
Lines 227-233
Link Here
|
227 |
public boolean isProxiesEnabled() { |
245 |
public boolean isProxiesEnabled() { |
228 |
checkMigrated(); |
246 |
checkMigrated(); |
229 |
return internalIsProxiesEnabled() |
247 |
return internalIsProxiesEnabled() |
230 |
&& (!isSystemProxiesEnabled() || (isSystemProxiesEnabled() && hasSystemProxies())); |
248 |
&& ((!isSystemProxiesEnabled() || (isSystemProxiesEnabled() && hasSystemProxies())) |
|
|
249 |
|| (!isCommandLineProxiesEnabled() || (isCommandLineProxiesEnabled() && hasCommandLineProxies()))); |
231 |
} |
250 |
} |
232 |
|
251 |
|
233 |
private boolean internalIsProxiesEnabled() { |
252 |
private boolean internalIsProxiesEnabled() { |
Lines 248-257
Link Here
|
248 |
Activator.getInstance().getPreferences().putBoolean(PREF_ENABLED, enabled); |
267 |
Activator.getInstance().getPreferences().putBoolean(PREF_ENABLED, enabled); |
249 |
} |
268 |
} |
250 |
|
269 |
|
251 |
private void internalSetEnabled(boolean enabled, boolean systemEnabled) { |
270 |
private void internalSetEnabled(boolean enabled, boolean commandLineEnabled, boolean systemEnabled) { |
252 |
Properties sysProps = System.getProperties(); |
271 |
Properties sysProps = System.getProperties(); |
253 |
sysProps.put("proxySet", enabled ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
272 |
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$ |
273 |
sysProps.put("systemProxySet", systemEnabled ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
|
|
274 |
sysProps.put("commandLineProxySet", commandLineEnabled ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ |
255 |
updateSystemProperties(); |
275 |
updateSystemProperties(); |
256 |
try { |
276 |
try { |
257 |
Activator.getInstance().getPreferences().flush(); |
277 |
Activator.getInstance().getPreferences().flush(); |
Lines 273-278
Link Here
|
273 |
} |
293 |
} |
274 |
|
294 |
|
275 |
public void initialize() { |
295 |
public void initialize() { |
|
|
296 |
boolean switchToCommandLineProxy = Boolean.getBoolean("commandLineProxySet"); //$NON-NLS-1$ |
297 |
|
276 |
checkMigrated(); |
298 |
checkMigrated(); |
277 |
((IEclipsePreferences)Activator.getInstance().getPreferences()).addPreferenceChangeListener(this); |
299 |
((IEclipsePreferences)Activator.getInstance().getPreferences()).addPreferenceChangeListener(this); |
278 |
// Now initialize each proxy type |
300 |
// Now initialize each proxy type |
Lines 281-286
Link Here
|
281 |
type.initialize(); |
303 |
type.initialize(); |
282 |
} |
304 |
} |
283 |
registerAuthenticator(); |
305 |
registerAuthenticator(); |
|
|
306 |
|
307 |
if(switchToCommandLineProxy){ |
308 |
ProxySelector.setActiveProvider(ProxySelector.COMMAND_LINE_PROVIDER); |
309 |
} |
284 |
} |
310 |
} |
285 |
|
311 |
|
286 |
public IProxyData getProxyData(String type) { |
312 |
public IProxyData getProxyData(String type) { |
Lines 307-312
Link Here
|
307 |
if (uri == null) { |
333 |
if (uri == null) { |
308 |
return new IProxyData[0]; |
334 |
return new IProxyData[0]; |
309 |
} |
335 |
} |
|
|
336 |
if (hasCommandLineProxies() && isCommandLineProxiesEnabled()) { |
337 |
return resolveType(commandLineProxyProvider.select(uri)); |
338 |
} |
310 |
if (hasSystemProxies() && isSystemProxiesEnabled()) { |
339 |
if (hasSystemProxies() && isSystemProxiesEnabled()) { |
311 |
return resolveType(nativeProxyProvider.select(uri)); |
340 |
return resolveType(nativeProxyProvider.select(uri)); |
312 |
} |
341 |
} |
Lines 359-369
Link Here
|
359 |
if (!internalIsProxiesEnabled()) { |
388 |
if (!internalIsProxiesEnabled()) { |
360 |
return null; |
389 |
return null; |
361 |
} |
390 |
} |
|
|
391 |
if (hasCommandLineProxies() && isCommandLineProxiesEnabled()) |
392 |
try { |
393 |
URI uri = new URI(type, "//" + host, null); //$NON-NLS-1$ |
394 |
IProxyData[] proxyDatas = commandLineProxyProvider.select(uri); |
395 |
return proxyDatas.length > 0 ? resolveType(proxyDatas[0]) : null; |
396 |
} catch (URISyntaxException e) { |
397 |
return null; |
398 |
} |
362 |
if (hasSystemProxies() && isSystemProxiesEnabled()) |
399 |
if (hasSystemProxies() && isSystemProxiesEnabled()) |
363 |
try { |
400 |
try { |
364 |
URI uri = new URI(type, "//" + host, null); //$NON-NLS-1$ |
401 |
URI uri = new URI(type, "//" + host, null); //$NON-NLS-1$ |
365 |
IProxyData[] proxyDatas = nativeProxyProvider.select(uri); |
402 |
IProxyData[] proxyDatas = nativeProxyProvider.select(uri); |
366 |
return proxyDatas.length > 0 ? resolveType(nativeProxyProvider.select(uri)[0]) : null; |
403 |
return proxyDatas.length > 0 ? resolveType(proxyDatas[0]) : null; |
367 |
} catch (URISyntaxException e) { |
404 |
} catch (URISyntaxException e) { |
368 |
return null; |
405 |
return null; |
369 |
} |
406 |
} |
Lines 423-428
Link Here
|
423 |
Preferences netInstancePrefs = instanceNode.node(Activator.ID); |
460 |
Preferences netInstancePrefs = instanceNode.node(Activator.ID); |
424 |
Preferences netConfigurationPrefs = configurationNode.node(Activator.ID); |
461 |
Preferences netConfigurationPrefs = configurationNode.node(Activator.ID); |
425 |
|
462 |
|
|
|
463 |
// migrate command line parameters |
464 |
|
426 |
// migrate enabled status |
465 |
// migrate enabled status |
427 |
if (netConfigurationPrefs.get(PREF_ENABLED, null) == null) { |
466 |
if (netConfigurationPrefs.get(PREF_ENABLED, null) == null) { |
428 |
String instanceEnabled = netInstancePrefs.get(PREF_ENABLED, null); |
467 |
String instanceEnabled = netInstancePrefs.get(PREF_ENABLED, null); |
Lines 474-479
Link Here
|
474 |
// Only set the migration bit when initializing |
513 |
// Only set the migration bit when initializing |
475 |
if (isInitialize) |
514 |
if (isInitialize) |
476 |
netPrefs.putBoolean(PREF_HAS_MIGRATED, true); |
515 |
netPrefs.putBoolean(PREF_HAS_MIGRATED, true); |
|
|
516 |
|
477 |
Preferences updatePrefs = node.node("org.eclipse.update.core"); //$NON-NLS-1$ |
517 |
Preferences updatePrefs = node.node("org.eclipse.update.core"); //$NON-NLS-1$ |
478 |
String httpProxyHost = getHostToMigrate(updatePrefs, isInitialize /* checkSystemProperties */); |
518 |
String httpProxyHost = getHostToMigrate(updatePrefs, isInitialize /* checkSystemProperties */); |
479 |
int port = getPortToMigrate(updatePrefs, isInitialize /* checkSystemProperties */); |
519 |
int port = getPortToMigrate(updatePrefs, isInitialize /* checkSystemProperties */); |
Lines 529-541
Link Here
|
529 |
} |
569 |
} |
530 |
|
570 |
|
531 |
public void preferenceChange(PreferenceChangeEvent event) { |
571 |
public void preferenceChange(PreferenceChangeEvent event) { |
532 |
if (event.getKey().equals(PREF_ENABLED) || event.getKey().equals(PREF_OS)) { |
572 |
if (event.getKey().equals(PREF_ENABLED) || event.getKey().equals(PREF_COMMAND_LINE) || event.getKey().equals(PREF_OS)) { |
533 |
checkMigrated(); |
573 |
checkMigrated(); |
534 |
internalSetEnabled(Activator.getInstance().getPreferences().getBoolean(PREF_ENABLED, true), |
574 |
internalSetEnabled(Activator.getInstance().getPreferences().getBoolean(PREF_ENABLED, true), |
|
|
575 |
Activator.getInstance().getPreferences().getBoolean(PREF_COMMAND_LINE, true), |
535 |
Activator.getInstance().getPreferences().getBoolean(PREF_OS, true)); |
576 |
Activator.getInstance().getPreferences().getBoolean(PREF_OS, true)); |
536 |
} |
577 |
} |
537 |
} |
578 |
} |
538 |
|
579 |
|
|
|
580 |
public boolean hasCommandLineProxies() { |
581 |
return commandLineProxyProvider != null; |
582 |
} |
583 |
|
584 |
public boolean isCommandLineProxiesEnabled() { |
585 |
checkMigrated(); |
586 |
return Activator.getInstance().getPreferences().getBoolean(PREF_COMMAND_LINE, |
587 |
true); |
588 |
} |
589 |
|
590 |
public void setCommandLineProxiesEnabled(boolean enabled) { |
591 |
checkMigrated(); |
592 |
boolean current = isCommandLineProxiesEnabled(); |
593 |
if (current == enabled) |
594 |
return; |
595 |
// Setting the preference will trigger the system property update |
596 |
// (see preferenceChange) |
597 |
Activator.getInstance().getPreferences().putBoolean(PREF_COMMAND_LINE, enabled); |
598 |
} |
599 |
|
539 |
public boolean hasSystemProxies() { |
600 |
public boolean hasSystemProxies() { |
540 |
return nativeProxyProvider != null; |
601 |
return nativeProxyProvider != null; |
541 |
} |
602 |
} |
Lines 588-592
Link Here
|
588 |
} |
649 |
} |
589 |
return data; |
650 |
return data; |
590 |
} |
651 |
} |
591 |
|
652 |
|
|
|
653 |
public boolean shouldSetSocksSystemProperties(){ |
654 |
for (int i=0; i<proxies.length; i++){ |
655 |
if(IProxyData.SOCKS_PROXY_TYPE.equals(proxies[i].getName())) |
656 |
return proxies[i].shouldSetSocksSystemProperties(); |
657 |
} |
658 |
return true; |
659 |
} |
592 |
} |
660 |
} |