2010-11-23 91 views
1

我目前硬编码属性文件中的版本号,我希望能够以编程方式直接从RCP产品文件获取版本号。这样,我不需要在两个地方指定版本号。我无法找到关于这样做的文章。我正在使用Eclipse RCP 3.x.Eclipse RCP:如何以编程方式从产品文件中获取版本号?

这是可行的吗?

谢谢。

+0

这是在构建时,对不对?您是否考虑在产品文件外指定版本号,并在构建时替换产品文件中的占位符? – 2010-11-23 22:52:35

+0

@安迪,我可以知道我该如何配置它?可以从属性文件中读取版本号,并在产品文件中预先填写。谢谢。 – limc 2010-11-23 23:55:12

回答

0

您可以执行以下操作:将标记替换为buildnumber(例如$ DEVLEOPER $)到plugin.xml中,无论您需要版本号。

在你的build.properties文件,用customBuildCallbacks标签,该标签文件将包含构建回调,将做定制注明:

customBuildCallbacks = buildCustomization.xml 

文件buildCustomization.xml将包含以下内容:

<?xml version="1.0"?> 

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

这将使用“buildtag”属性的内容替换文件plugin.xml中的$ DEVELOPER $标记。

所有这一切都假设您正在构建PDE,但总体思路也适用于其他方法。

+0

-1原始海报确实指定他想从RCP产品文件中检索ID,而不是插件文件中的版本号。 – ianmayo 2012-10-09 05:41:26

0

不知道我完全理解你的问题,但你可以通过编程让您的OSGi包(即“插件版本”)的这样的版本(什么属性文件?):

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()); 

其中SomeClass是一个你的班级在插件中。

1

产品文件中的版本号是产品文件的版本。如果你想获得产品的版本,则必须在plugin.xml中设定的版本,那么你可以尝试以下的变体:

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

也可以添加属性“版本”到org.eclipse.core.runtime.products扩展名并使用此代码:System.out.println(Platform.getProduct().getProperty("version"));

相关问题