#!/bin/bash
set -e

# Utility script that caches the classpath from the vercors project, and
# proceeds to run a class from the arguments. Other scripts in this directory
# refer to this script to run classes from the vercors project.

SCRIPT=$(realpath $0)
BIN=$(dirname $SCRIPT)
ROOT=$(dirname $BIN)
if [ ! -f "$BIN/.classpath" ] || [ ! -s "$BIN/.classpath" ]; then
    printf "Extracting classpath from SBT. This might take a moment.\n"
    (cd $ROOT && sbt --error "Global / printMainClasspath" > "$BIN/.classpath")
    printf "Classpath extracted\n"
fi

CLASSPATH=$(cat "$BIN/.classpath" | tr -d "\n\r")
java $MORE_JAVA_OPTS -Xss128M -cp $CLASSPATH "$@"
