#!/bin/bash


# Find the directory where .sh File is located (also supports symlinks)
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
  DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
  SOURCE="$(readlink "$SOURCE")"
  [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

cd $DIR

JAVA_COMMAND=java

# Set Java Options 
# Which version of WinPlausi should be used? ldw, fsn oder fis:
# Sollte die GUI von Winplausi benoetigt, das Profil 'gui' mitladen (z.B. -Dspring.profiles.active=fsn,gui)
JAVA_OPTS="$JAVA_OPTS -Dspring.profiles.active=fsn"

# Reducing Spring Log Output on startup:
JAVA_OPTS="$JAVA_OPTS -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.NoOpLog"

#Performance Settings:
JAVA_OPTS="$JAVA_OPTS -Dsun.java2d.d3d=false"
JAVA_OPTS="$JAVA_OPTS -Dswing.aatext=true"
JAVA_OPTS="$JAVA_OPTS -XX:+AggressiveOpts"
JAVA_OPTS="$JAVA_OPTS -XX:+UseFastAccessorMethods"
JAVA_OPTS="$JAVA_OPTS -Xms128m"
JAVA_OPTS="$JAVA_OPTS -Xmx768m"

JAVA_OPTS="$JAVA_OPTS -XX:+UseParNewGC"
JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC"
JAVA_OPTS="$JAVA_OPTS -XX:ParallelGCThreads=20"
JAVA_OPTS="$JAVA_OPTS -XX:SurvivorRatio=8"
JAVA_OPTS="$JAVA_OPTS -XX:TargetSurvivorRatio=90"
JAVA_OPTS="$JAVA_OPTS -XX:MaxTenuringThreshold=15"
JAVA_OPTS="$JAVA_OPTS -XX:+ScavengeBeforeFullGC"
JAVA_OPTS="$JAVA_OPTS -XX:+UseNUMA"
JAVA_OPTS="$JAVA_OPTS -XX:CompileThreshold=1500"
JAVA_OPTS="$JAVA_OPTS -XX:NewRatio=3"

#task
$JAVA_COMMAND $JAVA_OPTS -jar winplausi-gui.jar "$@"
