Maven + Mercurial for string numbers

I cannot figure out how to get the Mercurial version identifier that was added to my Maven assembly (ideally, I would like to do this in MANIFEST of my cans and wars).

The closest solution I could find is:

mvn -DbuildNumber=`hg id -i`

Which will not work for Windows or my Hudson server. Fortunately, Hudson marks my assemblies, but I would like to get even more confidence that the assemblies were also tagged with the Mercurial changset identifier.

+4
source share
2 answers

. , , , buildnumber:hgchangeset Mercurial, changeset hg id -i.

+4

, hg id -i . script, . . , . , . script "x.x.UNSTABLE" , .

REL_PATTERN , . , + .

#!/bin/bash
REL_PATTERN="release-[0-9]*\.[0-9]*\.[0-9]*"
BRANCH=$( hg branch )
CURR_REV=$( hg id -n )
if [  "${CURR_REV: -1}" = "+" ] ; then
  echo "ERROR: This workspace contains uncommitted code. Cannot calculate build number" >&2
  echo "UNSTABLE"
  exit 1
fi
RELEASE=$( hg log --rev="branch($BRANCH) and tag() and 1:$CURR_REV" -T "{tags} {rev}\n"|grep "${REL_PATTERN} "|tail -1 )
if [ "$RELEASE" = "" ] ; then
  echo "ERROR: Unable to locate version tag" >&2
  echo "UNSTABLE"
  exit 1
fi
RELEASE_REV=$( echo $RELEASE|cut -f 2 -d ' ' )
RELEASE_TAG=$( echo $RELEASE|cut -f 1 -d ' ' )
REVS=$( hg log -P $RELEASE_REV -b $BRANCH -T "{rev}\n"|wc -l )
BUILD=$( hg log -r1:$CURR_REV -P $RELEASE_REV -b $BRANCH -T "{rev}\n"|wc -l )
echo "BRANCH=$BRANCH" >&2
echo "CURR_REV=$CURR_REV" >&2
echo "RELEASE_REV=$RELEASE_REV" >&2
echo "RELEASE_TAG=$RELEASE_TAG" >&2
echo "BUILD=$BUILD" >&2
echo $BUILD
+1

All Articles