Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 321753

Summary: Expose version qualifier property
Product: z_Archived Reporter: Aleksandr Kravets <aleksandr.kravets>
Component: BuckminsterAssignee: buckminster.core-inbox <buckminster.core-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: info, michael.wenz, mtaal, stefan.bolton, tamar.e.cohen, thomas
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Aleksandr Kravets CLA 2010-08-04 12:10:48 EDT
Build Identifier: 20100218-1602

When generator.last.revision.format is set, for example as Nightly-{0,number,00000} and qualifier.replacement.*=generator:lastRevision is used during components assembly, components that are build and their Manifest.mf file have this revision in the bundle name and Bundle-Version. Currently in create.product.zip action for example, my path is prodcut.${target.ws}.${target.os}.${target.arch}, the resulting zip file could be product.win32.win32.x86. However, this does not say anything about its version or what type of build was performed, as Manifest.mf does. If there was a property that could be used that was set as a result of performing qualifier.replacement.*=generator:lastRevision, user would be able to do something like prodcut.${target.ws}.${target.os}.${target.arch}_{version.qualifier}, and create more descriptive description of the product: product.win32.win32.x86_0.1.0.Nightly-56459 for example.

Discussion about this is here http://www.eclipse.org/forums/index.php?t=msg&th=172889&start=0&S=a5948dcaabb8325cb6578bb6b758c24b

Reproducible: Always
Comment 1 Aleksandr Kravets CLA 2010-08-18 11:29:08 EDT
I would really like to have this feature available and wouldn't mind implementing this. I've never worked with Buckminster code, but perhaps with some guidance I can implement this and contribute code back if somewhere can give me some pointers on where to look for relevant code?
Comment 2 Michael Wenz CLA 2010-08-26 03:27:47 EDT
I would also be interested in having this feature
Comment 3 Stef bolton CLA 2011-01-28 04:06:31 EST
This feature is pretty essential for me. 

I'm not sure how I'm supposed to publish built jars to a maven repo without knowing what the qualifier is as I have to specify an exact jars filename - which Buckminster adds the qualifier to.

Unfortunately the deploy task doesn't seem to support wildcards :/
Comment 4 Thomas Hallgren CLA 2011-01-28 06:14:27 EST
We do this already. It's not very intuitive though. The source for all of this can be found in the org.eclipse.equinox.p2.director.product project in our SVN. Here's a brief explanation.

When a cspec or cspex action executes an ant task using the ant-actor, it will set a property 'buckminster.pdetasks' to appoint the ant script bundled with Buckminsters pde support. You can import this file into another antscript using:

	<import file="${buckminster.pdetasks}"/>

That script contains macros such as 'extractFeatureVersion' and 'extractFeatureId'.

Key to all of this is that the product is defined in a feature. The product must be feature based and use one single feature (the one that it is defined within). Here is the task that builds the actual zip file for the product:

	<target name="create.product.zip">
		<extractFeatureVersion file="${sp:manifest}" property="product.version"/>
		<extractFeatureId file="${sp:manifest}" property="product.name"/>
		<dirname file="${sp:product.dir}" property="product.parent.dir"/>
		<basename file="${sp:product.dir}" property="relative.product.dir"/>
		<mkdir dir="${sp:action.output}"/>
		<exec dir="${product.parent.dir}" executable="zip" outputproperty="zip.output" failonerror="true">
			<arg value="-r"/>
			<arg value="-9"/>
			<arg value="${sp:action.output}${product.name}_${product.version}.zip"/>
			<arg value="${relative.product.dir}"/>
		</exec>
		<echo message="${zip.output}"/>
	</target>

This task is called from the cspex like so:

	<public name="create.product.zip" actor="ant">
            <actorProperties>
                <property key="buildFile" value="product.ant"/>
                <property key="targets" value="create.product.zip"/>
            </actorProperties>
			<prerequisites>
				<attribute name="create.product" alias="product.dir"/>
				<attribute name="manifest" alias="manifest"/>
			</prerequisites>
            <products alias="action.output" base="${buckminster.output}" upToDatePolicy="COUNT" fileCount="1">
            	<path path="director.zip/"/>
            </products>
	</public>

and since this cspex resides in the feature that defines the product, the 'manifest' that is defined in its auto generated cspec is referencing it's feature.xml. The extractFeatureVersion and extractFeatureId extracts the version and id from that file.
Comment 5 Stef bolton CLA 2011-01-31 05:02:33 EST
Thanks Thomas, just tried this approach and it works great!
Comment 6 Tamar Cohen CLA 2011-02-07 13:19:14 EST
Hi Thomas --

I'm trying to do the same thing and would really enjoy having access to the version & qualifier in a property I can access from ant!

I have tried following your direction and my issue is this:
In the main feature which includes the product when I call the ant task <extractFeatureVersion file="${sp:manifest}"	property="full.version"/> the full.version is set correctly.  However, my about.mappings and branding stuff are in a different plugin.  If I call that <extractFeatureVersion ... within my branding plugin, instead of just getting the version back I get the contents of the entire manifest in the property!

Given that I need to adjust the information in the about.mappings BEFORE it is jarred up etc, what would be the correct approach?

thanks
Tamar
Comment 7 Martin Taal CLA 2012-10-23 09:28:12 EDT
See here for another solution to this:
http://www.eclipse.org/forums/index.php/t/263216/

An approach I did myself was to retrieve the version from the generated jar file names. In ant you can use javascript for this:
	<macrodef name="computeVersionQualifier">
		<attribute name="directory" />
		<attribute name="pattern" />
		<sequential>

			<path id="versionQualifierFileName.id">
				<fileset dir="@{directory}">
					<include name="@{pattern}" />
				</fileset>
			</path>

			<property name="versionQualifierFileName" refid="versionQualifierFileName.id" />

			<script language="javascript">
				<![CDATA[
		 	var lastIndex = versionQualifierFileName.lastIndexOf('.');
			var version = versionQualifierFileName.substring(0, lastIndex);
			lastIndex = version.lastIndexOf('.');
			version = version.substring(lastIndex + 1);
			project.setProperty('versionQualifier', version);
  	  	]]>
			</script>
		</sequential>
	</macrodef>


See for an example file name I use to parse:
https://hudson.eclipse.org/hudson/job/emf-teneo-nightly/ws/build/output/org.eclipse.emf.teneo.hibernate.mapper_2.0.0-osgi.bundle/jar
Comment 8 Thomas Hallgren CLA 2012-11-29 16:35:41 EST
Closing this since the questions seems to have been answered. Please open a new bug or enhancement request if you feel that there are some outstanding issues.