#!/bin/sh
#
# This script find the APT Libraries/classes:
#
#    lib = <Libraries location>
#
# Includes special handling for the app structure for Mac installations.
# It exists to support APT scripts and is intended to be sourced by them
#
################################################################################

if [ -z "${scriptDir}" ]; then
   echo "Error: Variable scriptDir not found";
   exit 1
fi

if [ -d "${scriptDir}/classes" ]; then
   aptDir="${scriptDir}";
elif [ -d "${scriptDir}/Libraries"  ]; then
   aptDir="${scriptDir}";
elif [ -d "${scriptDir}/APT.app"  ]; then
   aptDir="${scriptDir}/APT.app/Contents/";
elif [ -d "${scriptDir}/../classes" ]; then
   aptDir="${scriptDir}/..";
elif [ -d "${scriptDir}/../Libraries" ]; then
   aptDir="${scriptDir}/..";
elif [ -d "${scriptDir}/../APT.app"  ]; then
   aptDir="${scriptDir}/../APT.app/Contents/";
else
   echo "Error: Can't find APT installation";
   exit 1
fi

# aptDir should now the parent of the classes or Java

lib="${aptDir}/build/libs/Libraries"
if [ ! -d "$lib" ] ; then lib="${aptDir}/classes"; fi
if [ ! -d "$lib" ] ; then lib="${aptDir}/Java"; fi

if [ ! -d "$lib" ] ; then echo "Error: Can't find APT Libraries"; exit 1; fi

# Decide which Java to use...
if [ -s "${aptDir}/jre/bin/java" ] ; then
   javaCommand="${aptDir}/jre/bin/java"
elif [ -s "${aptDir}/PlugIns/Java.runtime/Contents/Home/bin/java" ] ; then
   javaCommand="${aptDir}/PlugIns/Java.runtime/Contents/Home/bin/java"
else
   javaCommand=java
fi
