#!/bin/bash
######################################################################################
#
# This script calls nxm.sys.test.JunitNoGraphics to run unit tests in LIBNXM mode.
#
# Environment Variables:
#   JAVA_HOME - Java installation directory
#
# Author: Jeanette McCall
# Since:  NeXtMidas 4.1.3
# Note:   Experimental version first appeared in NeXtMidas 4.0.0
#         and was in NMROOT/swap/modularity/runNoGraphicsJunit.sh
#
######################################################################################

if [ -z "${JAVA_HOME}" ] ; then
  echo ""
  echo "JAVA_HOME is undefined, unable to run unit tests in LIBNXM mode, aborting runNoGraphicsJunit script..."
  exit 1
fi

NMROOT_TMP=`realpath ${0}`
for i in {1..4}
do
  NMROOT_TMP=`dirname ${NMROOT_TMP}`
done
NMROOT=${NMROOT_TMP}

if [ -f ${JAVAHOME}/lib/tools.jar ]; then
  nm_reflective_access = ""
else
  nm_reflective_access = "--add-opens java.logging/java.util.logging=ALL-UNNAMED --add-opens java.base/java.security=ALL-UNNAMED"
fi
# $JAVA_HOME/bin/java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n -DNONATIVE=FALSE -DNMROOT="classpath:" -Djava.library.path=$NMROOT/jars -classpath "$NMROOT/jars/*"" nxm.sys.lib.NeXtMidas
$JAVA_HOME/bin/java -DNONATIVE=FALSE $nm_reflective_access -DNMROOT="classpath:" -classpath "$NMROOT/jars/*" nxm.sys.test.JUnitNoGraphics
