Wednesday, October 28, 2009

[tip]ssh forward

ssh -qTfnN -D LocalPort remotehost

All the added options are for a ssh session that's used for tunneling.

-q :- be very quite, we are acting only as a tunnel.
-T :- Do not allocate a pseudo tty, we are only acting a tunnel.
-f :- move the ssh process to background, as we don't want to interact with this ssh session directly.
-N :- Do not execute remote command.
-n :- redirect standard input to /dev/null.

In addition on a slow line you can gain performance by enabling compression with the -C option.

Tuesday, October 27, 2009

Simulate p2 self host in Eclipse run

-Dosgi.install.area=<launcher's folder>
-Declipse.p2.profile=<profile id>

Thursday, October 22, 2009

Eclipse/OSGi preference

The IPreferenceStore API of Eclipse is based on OSGi's preferences service. Equinox implements several scope context for different preferences, such DefaultScope, InstanceScope and ConfigurationScope. The IPreferenceStore is the wrapper of instance scope for back-compatibility. It stored the data in workspace(osgi.data.area).
The workspace folder would be created when launching RCP application if it doesn't exist. But we can use argument '-data @none' to suppress the creation of workspace. If that, the instance scope/IPreferenceStore can't store any value any more.
There is a workaround to resolve such issue. Use ConfigurationScope instead of InstanceScope. Both of them are implemented the same interface, so it's easy to migrate to use ConfigurationScope. The data of configuration scope would be stored in @config.dir/.setting folder.

Wednesday, October 21, 2009

The usage of Eclipse's Proxy API

Eclipse platform register an OSGi service 'IProxyService' to manage network connection, which has capability to set proxy setting. There are three types of proxy working mode,
  • Direct(no proxy),
  • Manual(specified by user),
  • Native(using OS's proxy setting, such as gnome-proxy, IE).

There are three types of proxy supported by IProxyService. They're http, https and socks.

It also allows to add/remove ip address from white list, which are accessed without connecting proxy.

End users can manage the proxy setting of Eclipse via Preference - General - Network Connections. Eclipse would do persistence of user's setting. Other components of Eclipse also use those proxy settings to access network, such as ECF.

Below code snippet shows how to use proxy API to manually specify proxy server,

     proxyService.setProxiesEnabled(true);
proxyService.setSystemProxiesEnabled(false);
IProxyData[] datas = proxyService.getProxyData();
IProxyData proxyData = null;
for(IProxyData data : datas) {
// clean old data
((ProxyData)data).setSource("Manual"); //$NON-NLS-1$
data.setUserid(null); //$NON-NLS-1$
data.setPassword(null); //$NON-NLS-1$
if(proxyType == SOCKSPROXY && IProxyData.SOCKS_PROXY_TYPE.equals(data.getType())) {
proxyData = data;
continue;
}else if(proxyType == WEBPROXY && IProxyData.HTTP_PROXY_TYPE.equals(data.getType())){
proxyData = data;
continue;
}
data.setHost(null); //$NON-NLS-1$
data.setPort(0);
}
if(proxyData != null){
proxyData.setHost(proxyServer);
proxyData.setPort(proxyPort);
}
try {
proxyService.setProxyData(datas);
} catch (CoreException e) {
proxyService.setProxiesEnabled(false);
proxyService.setSystemProxiesEnabled(false);
return false;
}

Official API Reference