Saturday, December 3, 2011

Access currentVersion

The currentVersion property is used to for example show the version number of your RCP in the Title line. Now it can be set via branding 
${basedir}/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties Nothing new here. The trick is if this holds information you would like to retrieve at runtime.


Naively one could try NbBundle.getMessage(Main.class, "currentVersion"); which will fail. 

I have found a way around which may not be the most obvious path - but at least a solution which might help others. I had to work around it by copying the content of that property to a Bundle.properties file which is within my access space. I do this via Ant when building the app each time. Example:

In the main build.xml add a target 
<target name="build-brand" depends="-init">
<propertyfile file="${basedir}/../moduleA/com/mycode/xyz/Bundle.properties" comment="Updated by build script for full version info">
<entry key="fullVersion" value="${app.version}" />
</propertyfile>
</target>



The target above will create a property in the Bundle.properties file in the package
/com/mycode/xyz of moduleA You could here instead of using ${app.version} use ant command to read the currentVersion property if already set. If it is in your control you can of course set the currentVersion automatically as well like adding the following into the same ant target. ${build.number} and $(app.comment} are my own properties - but you get the point.
<propertyfile file="${basedir}/branding/core/core.jar/org/netbeans/core/startup/Bundle.properties" comment="Updated by build script">
<entry key="key="currentVersion" " value="${app.title} ${app.version}.${build.number} ${app.comment}" />
</propertyfile>


If you do this first you can set the "fullVersion" (or whatever you would like to call it) property to the moduleA/com/mycode/xyz package and a method like

    public String getFullSoftwareVersion() {
        // This value is stored in the Bundle.properties of this package
        return NbBundle.getMessage(MyClassXyz.class, "fullVersion");
    }


 As this is within your code you can now read the value.

No comments:

Post a Comment