How to fetch and change deployed MWS projects version at runtime

Hi Team,

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.

Please clarify the specific version of MWS and the fix level this is for.

Hi Eric,

MWS Installed Fixes: SBPPortal_9.7.1_Fix2

Project deployment method: Deploying MWS projects by using
“Software AG Designer 9.9”

Is there a way that the project version increases/changes after deployment and how to get the deployed MWS project versions runtime?

Regards,
Ashish Kumar

There are a few different version numbers in play for a CAF application.

  1. There is the portet-app version number from WEB-INF/portlet.xml (I’ve never seen this changed from 1.0)
<portlet-app version="1.0" xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd ">
  1. There is a portlet-type version number from the WEB-INF/wm-portal.xml for each portlet.
	<wm-portlet>
		<portlet-name>test</portlet-name>
		<version>2.0</version>
	</wm-portlet>
  1. There is the OSGi Bundle-Version header from the META-INF/MANIFEST.MF of the deployed component.
Bundle-Version: 0.9.0.v20160523-1913

Which of those are you interested in?

Hi Eric,

I am deploying the CAF open application and interested in 3 option.

Thanks
Ashish Kumar

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

Hi Eric,

Thanks for the detailed answer.

Regards,
Ashish Kumar