1#!/bin/bash
2#
3# This script checks the java version and bails if it's less
4# than Java6 (because we use @Override annotations on interface
5# overriding methods.  It then proceeds to do a maven build that
6# first cleans, then builds the normal lifecycle through compilation
7# unit testing (if available) up to packaging.  It then packages
8# the source, javadocs, and maven site.  It then signs the
9# artifacts with whatever pgp signature is the default of the
10# user executing it, and then deploys to the repository contained
11# in the distributionManagement section of the pom.
12#
13# author: cgruber@google.com (Christian Edward Gruber)
14#
15if [[ -n ${JAVA_HOME} ]] ; then
16  JAVA_CMD=${JAVA_HOME}/bin/java
17else
18  JAVA_CMD=java
19fi
20java_version="$(${JAVA_CMD} -version 2>&1 | grep -e 'java version' | awk '{ print $3 }')"
21
22# This test sucks, but it's short term
23# TODO(cgruber) strip the quotes and patch version and do version comparison.
24greater_than_java5="$(echo ${java_version} | grep -e '^"1.[67]')"
25
26if [[ -z ${greater_than_java5} ]] ; then
27  echo "Your java version is ${java_version}."
28  echo "You must use at least a java 6 JVM to build and deploy this software."
29  exit 1
30else
31  echo "Building with java ${java_version}"
32fi
33
34if [[ $# > 0 ]]; then
35  params+=" -Dgpg.keyname=${1}"
36  gpg_sign_plugin=" gpg:sign"
37fi
38cmd="mvn clean package source:jar site:jar javadoc:jar ${gpg_sign_plugin} deploy ${params}"
39echo "Executing ${cmd}"
40${cmd}
41