#! /bin/sh

#set the DISPLAY for running tests on Linux
DISPLAY=`$HOST`:0.0;export DISPLAY

#this value must be set when using rsh to execute this script, otherwise the script will execute from the user's home directory
dir="`pwd`"

# operating system, windowing system and architecture variables
os=
ws=
arch=

# list of tests (targets) to execute in test.xml
tests=

# default value to determine if eclipse should be reinstalled between running of tests
installmode="clean"

# name of a property file to pass to Ant
properties=

# whether or not to run the tests natively
native="no"

# where to put the results
resultdir="$dir/results"

# whether or not to run regression tests
lastregression="no"
baseregression="no"

# directories containing results to compare against
oldresultdir=
baseresultdir=

# message printed to console
usage="usage: $0 -os <osType> -ws <windowingSystemType> -arch <architecture> [-native] [-noclean] [-results <resultdir>] [-oldresults <oldresultdir>] [-baseresults <baseresultdir>] [<test target>] [-properties <path>]"


# process command line arguments
while [ $# -gt 0 ]
do
	case "$1" in
		-dir) dir="$2"; shift;;
		-os) os="$2"; shift;;
		-ws) ws="$2"; shift;;
		-arch) arch="$2"; shift;;
		-noclean) installmode="noclean";;
		-native) native="yes";;
		-results) resultdir="$2"; shift;;
		-oldresults) oldresultdir="$2"; lastregression="yes"; shift;;
		-baseresults) baseresultdir="$2"; baseregression="yes"; shift;;
		-properties) properties="-propertyfile $2";shift;;
		*) tests=$tests\ $1;;
	esac
	shift
done

# for *nix systems, os, ws and arch values must be specified
if [ "x$os" = "x" ]
then
	echo >&2 "$usage"
	exit 1
fi

if [ "x$ws" = "x" ]
then
	echo >&2 "$usage"
	exit 1
fi

if [ "x$arch" = "x" ]
then
	echo >&2 "$usage"
	exit 1
fi

#necessary when invoking this script through rsh
cd $dir

# verify os, ws and arch values passed in are valid before running tests
if [ "$os-$ws-$arch" = "linux-motif-x86" ] || [ "$os-$ws-$arch" = "linux-gtk-x86" ] || [ "$os-$ws-$arch" = "solaris-motif-sparc" ] || [ "$os-$ws-$arch" = "aix-motif-sparc" ] || [ "$os-$ws-$arch" = "hpux-motif-ppc" ] || [ "$os-$ws-$arch" = "qnx-photon-x86" ]
then

	if test -z "$JAVA_HOME"; then
		echo "You must set JAVA_HOME before running this script"
		exit 1
	fi

	# run tests
	$JAVA_HOME/bin/java -cp eclipse/startup.jar org.eclipse.core.launcher.Main -noupdate -ws $ws -os $os -arch $arch -application org.eclipse.ant.core.antRunner -file test.xml $tests -Dws=$ws -Dos=$os -Darch=$arch -D$installmode=true -Dnative=$native -Dresultdir=$resultdir -Doldresultdir=$oldresultdir -Dbaseresultdir=$baseresultdir -Dlastregression=$lastregression -Dbaseregression=$baseregression $properties -logger org.apache.tools.ant.DefaultLogger

# display message to user if os, ws and arch are invalid
else
	echo "The os, ws and arch values are either invalid or are an invalid combination"
	exit 1
fi

