开发者

Eclipse RCP: How do I programmatically get the version number from the product file?

I currently hardcode the version number in the properties file and I'm hoping to be able to programmatically get the version number directly from the RCP product file. This way, I don't need to specify the version number in two开发者_如何学C places. I'm not able to find articles about doing so. I'm using Eclipse RCP 3.x.

Is this doable?

Thanks.


Not sure I understand fully your problem (what property file?), but you can programatically get the version of your osgi bundle (i.e. "plugin version") like this:

import org.osgi.framework.FrameworkUtil; 
import org.osgi.framework.Version; 

Version v = FrameworkUtil.getBundle(SomeClass.class).getVersion(); 
String version = String.format("Version %d.%d.%d", v.getMajor(), v.getMinor(), v.getMicro());

where SomeClass is one of your class in the plugin.


The version number from product file is version of product file. If you want to get version of product you must set version in plugin.xml, then you can try the following variants:

  1. String version = Display.getAppVersion().toString();
  2. String version = Platform.getProduct().getDefiningBundle().getVersion().toString();
  3. String version = Platform.getProduct().getDefiningBundle().getHeaders().get("Bundle-Version");

Or you can add property "version" to org.eclipse.core.runtime.products extension and use this code: System.out.println(Platform.getProduct().getProperty("version"));


You can do the following: Put a tag that will be replaced with the buildnumber (e.g. $DEVLEOPER$) into the plugin.xml, wherever you need the version number.

In your build.properties file, specify with the customBuildCallbacks tag which file will contain the build callbacks that will do the customizations:

customBuildCallbacks = buildCustomization.xml

The file buildCustomization.xml will contain the following:

 <?xml version="1.0"?>

<project name="product_customization" default="pre.@dot">
    <target name="pre.@dot" if="buildtag" description="Patch buildtag (if it exists) into plugin.xml">
        <replace file="plugin.xml" token="$DEVELOPER$" value="${buildtag}" />
    </target>
</project>

This will replace the $DEVELOPER$ token in the file plugin.xml with the contents of the "buildtag" property.

All this is assuming you are building with PDE, but the general idea applies to other methods, too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜