#!/bin/bash -ex
#
# generate coverage report and upload to codacy

# extra ubuntu bionic packages: gcovr, openjdk-8-jre-headless, /usr/lib/jvm/java-8-openjdk-amd64/bin/java
# as of 6/18/2018 you must use java 8, see issue #76, #83 at https://github.com/codacy/codacy-coverage-reporter/issues
# as of 3/16/2019 with coverage reporter 4.0.3 java 8 is not required.

qmake
make -j 3 coverage

# debug tokens
"$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd)"/ci_tokens

#!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# don't leak unhashed tokens!
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!
set +x
# this shell parameter expansion also protects the token from accidental exposure
# by substituting x for the token if the token is set and not null.
if [ -n "${CODACY_PROJECT_TOKEN:+x}" ] ; then
  # upload coverate report to codacy.
  bash <(curl -Ls https://coverage.codacy.com/get.sh) report -l CPP -r gpsbabel_coverage.xml
else
  echo "Skipping codacy coverage upload as CODACY_PROJECT_TOKEN is not set."
fi
