Requirement: Need to fetch project versions for deployed MWS projects.
Issue : Currently there is not utility or MWS APIs available to get the MWS project versions at runtime.
When we check the version in MWS under Install Administration for the installed projects it always appears 1.0. After deploying the same project again the version doesn’t change.
We also tried to modify the project version in the “//WebContent/META-INF/MANIFEST.MF” file and tried redeploying the project. Still the project version in MWS is 1.0.
Is there a way that the project version increases/changes after deployment and how to get the deployed MWS project versions runtime?
Any help regarding to this issue will highly appreciated.
Thanks in Advance.
Your CAF application project can override the default instructions that are used for generating the META-INF/MANIFEST.MF file by adding a WebContent/OSGI-OPT/bnd.bnd file to your project.
The content of that file would need to look something like this to change the Bundle-Version from the default value:
# override the generated Bundle-Version value
Bundle-Version: 2.0.0.v${tstamp;yyyyMMdd-HHmm}
And then in the java code of the CAF application, you can lookup the Bundle-Version value using the standard OSGi APIs with something like this:
/**
* Returns the Bundle-Version value for the current java class
*/
public String getMyBundleVersion() {
//lookup the Bundle that contains the current class
org.osgi.framework.Bundle bundle = org.osgi.framework.FrameworkUtil.getBundle(getClass());
return bundle.getVersion().toString();
}
Or you can get the Bundle-Version for other bundles via the BundleContext with something like this:
/**
* Returns the Bundle-Version values for all the OSGi Bundles in the runtime
*/
public String getAllBundleVersions() {
StringBuilder buffer = new StringBuilder();
//lookup the Bundle that contains the current class
org.osgi.framework.Bundle bundle = org.osgi.framework.FrameworkUtil.getBundle(getClass());
org.osgi.framework.BundleContext bundleContext = bundle.getBundleContext();
org.osgi.framework.Bundle [] bundles = bundleContext.getBundles();
for (org.osgi.framework.Bundle bundle2 : bundles) {
if (buffer.length() > 0) {
buffer.append("\r\n");
}
buffer.append(bundle2.getSymbolicName())
.append(": ")
.append(bundle2.getVersion().toString());
}
return buffer.toString();
}