if [ $# -eq 0 ]
then
  echo "Specify the release number (e.g. 5.14.2)"
  exit -1
fi

rel=testng-$1

#
# Make sure that pom.xml and pom-test.xml test the same and latest version
#

v1=`perl -ne 'BEGIN{undef $/}; print "$1" if m/(TestNG.*\n.*version)/mg' pom.xml | awk -F ">" '{ print $2 }' | awk -F "<" '{ print $1 }'`

v2=`perl -ne 'BEGIN{undef $/}; print "$1" if m/(artifactId.testng.*\n.*version)/mg' pom-test.xml | grep version | awk -F ">" '{print $2}' | awk -F "<" '{print $1}'`

if [ $v1 != $v2 ]
then
  echo "Versions of pom.xml and pom-test.xml do not match: $v1 $v2"
#  exit -1
fi

#
# Maven
#

./build-with-maven

#cd $HOME/t
#rm -rf surefire
#svn co http://svn.apache.org/repos/asf/maven/surefire/trunk surefire
#cd surefire
#mvn clean install -Dtestng.version=$1

#
# Distribution
#

cd $HOME/t
rm -f *zip
rm -rf $rel
curl http://testng.org/$rel.zip >$rel.zip
unzip $rel.zip
cd $HOME/java/testng
java -Dtest.resources.dir=$HOME/java/testng/src/test/resources -classpath $HOME/t/$rel/$rel.jar:target/test-classes:lib/guice-2.0.jar org.testng.TestNG $HOME/java/testng/src/test/resources/testng.xml