#!/bin/sh

# do a good check that java is found
which java >& /dev/null
if [ $? -ne 0 ];then
   echo "java is not configured - alter your PATH environment or set up using mayobiotools"
   exit 1
fi

# exit if any statement returns a non-zero exit code
set -e

# Fix for excessive virtual memory usage
# newer glibc will allocate 64MB per thread
# this will limit 64MB to all threads for a process  
export MALLOC_ARENA_MAX=1

# check java version
REQUIRED_MINOR_VERSION=6

# grab full version string from running "java -version"
VERSION=`java -Xmx64m -version 2>&1 | grep "java version" | awk '{ print substr($3, 2, length($3)-2); }'`

# parse out the minor version number
MINOR_VERSION=`echo $VERSION | cut -d . -f 2`

# check minor version, anything less than the required version is invalid
if [ $MINOR_VERSION -lt $REQUIRED_MINOR_VERSION ]; then
	echo "Invalid Java version $VERSION.  Java 1.$REQUIRED_MINOR_VERSION or higher is required."
	echo "You can check your java version by running: java -version"
	exit 1
fi

java -Dlog4j.defaultInitOverride=true -Xmx128m -cp $BIOR_LITE_HOME/conf:$BIOR_LITE_HOME/lib/* edu.mayo.cli.CommandLineApp edu.mayo.bior.cli.cmd.RefAlleleCommand $0 $@


