#!/usr/bin/env bash
#
# this generates docs only with appropriate environment, params, etc...

set -e          # raise exception if error
set -u          # raise exception if unset
set -o pipefail # raise exceptions in pipes

BASENAME=$(basename $0)
WORKDIR=$(cd $(dirname $0);pwd -P;)
cd $WORKDIR

# check java version
expected_version=17
if [[ -n ${JAVA_HOME-} ]] && [[ -x "$JAVA_HOME/bin/java" ]];  then
    _java="$JAVA_HOME/bin/java"
elif [[ -n $(type -p java) ]]; then
    _java=java
else
    echo "Missing Java!  Set JAVA_HOME environment variable to the path to a JDK."
    exit 1
fi

version=$("$_java" -version 2>&1 | awk -F '"' '/version/ {print $2}')
if [[ "$version" < $expected_version ]]; then
    echo "This project requires Java $expected_version, but the current JDK version is $version"
    echo "Set JAVA_HOME to the directory of a $expected_version JDK."
    exit 1
fi
# end check java version

[[ $# -gt 0 ]] && {
        echo "WARN: Passing Maven options: $@" >&2
}
LOGGING="-Dlogging.level.io.netfoundry.common=warn -Dlogging.level.root=warn -Dlogging.level.io.netfoundry=warn -Dlogging.level.org.springframework=warn"
time \
(./mvnw -T 8 $LOGGING clean test verify $@)
