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

Monday, March 31, 2008

[OSGi][Equinox]the Bundle-NativeCode implementation in Equinox

OSGi Spec defines Bundle-NativeCode header to contain a specification of native code libraries contained in that bundle. All magic things are initialized by org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLibrary(String) and org.eclipse.osgi.framework.internal.core.BundleLoader.findLibrary(String). Then BundleLoader uses the org.eclipse.osgi.baseadaptor.BaseData(an implementation of BundleData) to find the library path, if the bundle is NOT a jar file, it would directly get the absolute path of library. Otherwise, the BaseData would extract the library file if it could NOT find it in OSGi bundle storage(located in ${data}/org.eclipse.osgi/bundles/[bundle_id]/.cp/). Refer to org.eclipse.osgi.baseadaptor.BaseData.findLibrary(String) for more detail.

Wednesday, March 19, 2008

[shell]Learning Note - 3/19/08

1> 是输出正确数据, 2> 则是错误数据输出项目, 若要同时写入同一个档案需要使用 2>&1 /dev/null 是什么呢?基本上,那就有点像是一个『黑洞』的垃圾桶功能!当你输入的任何东西导向到这个虚拟的垃圾桶装置时,『他就会凭空消失不见了~~』

Tuesday, March 11, 2008

[Eclipse]How to use qualifier string when exporting features and plug-ins

You must see the qualifier string property when exporting your features and plug-ins by Eclipse pde. But specified qualifier string won't appear after you export the features successfully.

If you want to use the qualifier string, you must define your feature and plug-in version like below:
1.0.0.qualifier, 2.2.2.qaulifier

:)

Tuesday, April 3, 2007

万恶的注册表

最近几天被一个注册表相关的defect搞的焦头烂额。

背景是这样的,产品在安装的时候需要通过修改注册表注册文件关联等信息。在先前安装程序基于InstallShield时工作正确,但在最近安装程序改用MSI后,我们写入注册表的信息没有被写到所期望的位置。

通过各种试验,查找资料,终于搞明白原因。我们修改注册表的进程不是当前用户进程,而是系统进程,因此写入到HKEY_CURRENT_USER下的数据不能被写入到当前登陆用户下。

We should not use "HKEY_CURRENT_USER" to retrival current user's registry key value. Because Windows Services always startup before user login. It may happen some error or loading the wrong setting profile. If you still insist on using the current user registry key setting, please refer "RegOpenCurrentUser".

最后只好将这些数据写到了Local Machine键值下。

Friday, March 9, 2007

[Eclipse]get rid of the menus of eclipse platform

When you develop a rich client application base on eclipse framework, and your application require eclipse platform feature, you would find that your application has some menu items contributed by eclipse platform. Those menu items are defined by several plug-ins' implementation of actionSet extention point. In fact Eclipse provides an activity mechanism to suppress the extension points which you don't want to use. However, you must know the identification name of extension points which you want to suppress. It's a hard work to find out all of them from dozens of plugins. so, I wrote a utility function to list all the extension points of specified name.

        IExtensionRegistry registry = Platform.getExtensionRegistry();

IExtensionPoint extensionPoint = registry.getExtensionPoint("org.eclipse.ui.actionSets");

IExtension[] extensions = extensionPoint.getExtensions();

for(int i = 0; i < extensions.length; i++){

IConfigurationElement elements[] = extensions[i ].getConfigurationElements();

for(int j = 0; j < elements.length; j++){

String pluginId = elements[j].getNamespaceIdentifier();

if(pluginId.indexOf("org.eclipse") > -1){ //$NON-NLS-1$

IConfigurationElement[] subElements = elements[j].getChildren("action");

for(int m = 0; m < subElements.length; m++){

System.out.println("Plugin: " + pluginId + " Id: " +

subElements[m].getAttribute("id"));

}

}

}

}

and the follow snippet is about the activities of menus of eclipse platform:
   <extension point="org.eclipse.ui.activities">
<activity id="activity.platform" name="hidePlatformMenus"/>
<activityPatternBinding activityId="activity.platform" pattern="org\.eclipse\.platform/org\.eclipse\.ui\.cheatsheets\.actions\.CheatSheetHelpMenuAction"/>

<activity id="activity.search" name="hideSearchMenus"/>
<activityPatternBinding activityId="activity.search" pattern="org\.eclipse\.search/org\.eclipse\.search\..*"/>
<activity
id="activity.ide"
name="hideIDEMenus">
</activity>
<activityPatternBinding
activityId="activity.ide"
pattern="org\.eclipse\.ui\.ide/org\.eclipse\.ui\.actions\.showKeyAssistHandler">
</activityPatternBinding>
<activityPatternBinding
activityId="activity.ide"
pattern="org\.eclipse\.ui\.ide/org\.eclipse\.update\.ui\..*">
</activityPatternBinding>
<activity
id="activity.editor"
name="hideEditorMenus">
</activity>
<activityPatternBinding
activityId="activity.editor"
pattern="org\.eclipse\.ui\.editors/org\.eclipse\.ui\.edit\.text\.openExternalFile">
</activityPatternBinding>
<activityPatternBinding
activityId="activity.editor"
pattern="org\.eclipse\.ui\.editors/org\.eclipse\.ui\.edit\.text\.delimiter\..*">
</activityPatternBinding>
<activity
id="activity.externaltool"
name="hideExternaltoolMenus">
</activity>
<activityPatternBinding
activityId="activity.externaltool"
pattern="org\.eclipse\.ui\.externaltools/org\.eclipse\.ui\.externaltools\.ExternalToolMenuDelegateMenu">
</activityPatternBinding>
</extension>