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

Monday, February 9, 2009

How to set default input method for GNOME

add below lines in ~/.gnomerc

export XMODIFIERS="@im=fcitx"
export GTK_IM_MODULE="xim"

Monday, December 29, 2008

[HowTo]How to set up jre environment in firefox

create symbol link under lib/plugins of firefox to link jre/plugins/i386/ns**/libjavaplugin_oji.so

Wednesday, December 10, 2008

Thursday, December 4, 2008

[HowTo][tip]How to adjust the font size of Notes editor

Close Notes
Double click c:\notes\notes.ini to open it.
Add one new line "Display_font_adjustment=n" after the third line in notes.ini file. "n" is the number.It can be 1or 2 or 3....and the font will be larger with the number increasing.
Launch note

Sunday, September 28, 2008

[OSGi][Eclipse]Add custom jar or path into Equinox Framework

Set vm arguments 'osgi.framework.extensions' and 'osgi.frameworkClassPath' when vm starts. If those value are set, those jar or path would be added into the classloader when starting EclipseStarter.

See org.eclipse.equinox.launcher.Main for more details in the source code of Eclipse 3.4.
Best Regards
Kane

Friday, August 1, 2008

[OSGi]How to acquire the fragments of specified bundle

The answer is very simple, using the service 'org.eclipse.service.PackageAdmin'.

Thursday, July 17, 2008

[Eclipse]Equinox's classloader and its URL schema

Equinox uses the adaptor hooks to implement the class loader.
See http://wiki.eclipse.org/Adaptor_Hooks for more detail

BaseClassLoadingHook would search the native code on itself. If it find the file in that jar file, it would extract the native library into its storage folder.

EclipseClassLoadingHook defines some variables to search the native library. Belows are built-in variables:

result.add("ws/" + info.getWS() + "/"); //$NON-NLS-1$ //$NON-NLS-2$
result.add("os/" + info.getOS() + "/" + info.getOSArch() + "/"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
result.add("os/" + info.getOS() + "/"); //$NON-NLS-1$ //$NON-NLS-2$

So the classloader can find your native library that under those path. If your bundle is jar file, equinox would extract your native library into its storage folder.

I prefer to use OSGi header(Bundle-NativeCode) defining the path of native code, which still works on other OSGi implementations.

Equinox defines its url schema, one of them is named as 'BundleURLConnection'. From its name, we know it's used for describing the files of bundle. You can obtain the url of file that is located on bundle by Bundle.getResource()/Bundle.getEntry()/Bundle.findEntries()/Bundle.getResources(). The return value of those functions are an object of BundleURLConnection. Once it's used as the argument of FileLocator.toFileURL(URL), the jar bundle would be unpacked into its storage folder recursively.

Tuesday, July 15, 2008

[tip][vim]排版小技巧

    1. 将要排版的文字贴到vim了
    2.  set textwidth=70
    3. visual模式下选择要排版的文字,按gq, 就变成70字母1行的格式了

Friday, May 23, 2008

[tip]convert dos format to unix

In vi/vim,

set file format=unix

or dos2unix, unix2dos

Thursday, May 22, 2008

[tip]Makefile

Build c/c++ project always need third party library on linux, such as gtk+, glib. Writing their absolute path in Makefile is not flexible way. You can use pkg-config instead of the absolute path. Below is code snippet:

GTK_LIB=$(shell pkg-config --libs gtk+-2.0)
GTK_INC=$(shell pkg-config --cflags gtk+-2.0)

gcc -o yourlibrary.so $(GTK_INC) $(GTK_LIB)

Wednesday, April 16, 2008

[OSGi][Equinox]URL Handlers Service

OSGi provides a mechanism to let user contribute custom schemes automatically. It avoid some restriction with Java facilities for extending the handlers. The more detail could be found from OSGi specification R4, which has description how OSGi implements URL Handler Service.

Use a sample to illustrate how to contribute your scheme(protocol):

1. register your URLStreamHandlerService implementation, which must contain a property named "url.handler.protocol". below register my scheme 'smb'
public void start(BundleContext context) throws Exception {
Hashtable properties = new Hashtable();
properties.put( URLConstants.URL_HANDLER_PROTOCOL, new String[] { "smb" } );
context.registerService(URLStreamHandlerService.class.getName(), new SmbURLHandler(), properties );
}
2. your URL Handler extends AbstractURLStreamHandlerService, and implements abstract function 'openConnection(URL)'
public class SmbURLHandler extends AbstractURLStreamHandlerService {

public URLConnection openConnection(URL url) throws IOException {
return new SmbURLConnection(url);
}

}
3. your URL Connection extends java.net.URLConnection
public class SmbURLConnection extends URLConnection {

protected SmbURLConnection(URL url) {
super(url);
}

public void connect() throws IOException {
}
}