14e867904c8295537803c1c8a076e130df5674b58mikesamuel#! /bin/sh
24e867904c8295537803c1c8a076e130df5674b58mikesamuel
34e867904c8295537803c1c8a076e130df5674b58mikesamuel
44e867904c8295537803c1c8a076e130df5674b58mikesamuelprogram="$0"
54e867904c8295537803c1c8a076e130df5674b58mikesamuel
64e867904c8295537803c1c8a076e130df5674b58mikesamuel# Follow symlinks until we get to the actual file.
74e867904c8295537803c1c8a076e130df5674b58mikesamuelwhile [ -h "$program" ]; do
84e867904c8295537803c1c8a076e130df5674b58mikesamuel	link=`ls -ld "$program"`
94e867904c8295537803c1c8a076e130df5674b58mikesamuel	link=`expr "$link" : '.*-> \(.*\)'`
104e867904c8295537803c1c8a076e130df5674b58mikesamuel	if [ "`expr "$link" : '/.*'`" = 0 ]; then
114e867904c8295537803c1c8a076e130df5674b58mikesamuel		# Relative
124e867904c8295537803c1c8a076e130df5674b58mikesamuel		dir=`dirname "$program"`
134e867904c8295537803c1c8a076e130df5674b58mikesamuel		program="$dir/$link"
144e867904c8295537803c1c8a076e130df5674b58mikesamuel	else
154e867904c8295537803c1c8a076e130df5674b58mikesamuel		# Absolute
164e867904c8295537803c1c8a076e130df5674b58mikesamuel		program="$link"
174e867904c8295537803c1c8a076e130df5674b58mikesamuel	fi
184e867904c8295537803c1c8a076e130df5674b58mikesamueldone
194e867904c8295537803c1c8a076e130df5674b58mikesamuel
204e867904c8295537803c1c8a076e130df5674b58mikesamuel# Assume findbugs home directory is the parent
214e867904c8295537803c1c8a076e130df5674b58mikesamuel# of the directory containing the script (which should
224e867904c8295537803c1c8a076e130df5674b58mikesamuel# normally be "$findbugs_home/bin").
234e867904c8295537803c1c8a076e130df5674b58mikesamueldir=`dirname "$program"`
244e867904c8295537803c1c8a076e130df5674b58mikesamuelfindbugs_home="$dir/.."
254e867904c8295537803c1c8a076e130df5674b58mikesamuel
264e867904c8295537803c1c8a076e130df5674b58mikesamuel# Handle FHS-compliant installations (e.g., Fink)
274e867904c8295537803c1c8a076e130df5674b58mikesamuelif [ -d "$findbugs_home/share/findbugs" ]; then
284e867904c8295537803c1c8a076e130df5674b58mikesamuel	findbugs_home="$findbugs_home/share/findbugs"
294e867904c8295537803c1c8a076e130df5674b58mikesamuelfi
304e867904c8295537803c1c8a076e130df5674b58mikesamuel
314e867904c8295537803c1c8a076e130df5674b58mikesamuel# Make absolute
324e867904c8295537803c1c8a076e130df5674b58mikesamuelfindbugs_home=`cd "$findbugs_home" && pwd`
334e867904c8295537803c1c8a076e130df5674b58mikesamuel
344e867904c8295537803c1c8a076e130df5674b58mikesamuelfb_pathsep=':'
354e867904c8295537803c1c8a076e130df5674b58mikesamuel
364e867904c8295537803c1c8a076e130df5674b58mikesamuel# Handle cygwin, courtesy of Peter D. Stout
374e867904c8295537803c1c8a076e130df5674b58mikesamuelfb_osname=`uname`
384e867904c8295537803c1c8a076e130df5674b58mikesamuelif [ `expr "$fb_osname" : CYGWIN` -ne 0 ]; then
394e867904c8295537803c1c8a076e130df5674b58mikesamuel	findbugs_home=`cygpath --mixed "$findbugs_home"`
404e867904c8295537803c1c8a076e130df5674b58mikesamuel	fb_pathsep=';'
414e867904c8295537803c1c8a076e130df5674b58mikesamuelfi
424e867904c8295537803c1c8a076e130df5674b58mikesamuel# Handle MKS, courtesy of Kelly O'Hair
434e867904c8295537803c1c8a076e130df5674b58mikesamuelif [ "${fb_osname}" = "Windows_NT" ]; then
444e867904c8295537803c1c8a076e130df5674b58mikesamuel	fb_pathsep=';'
454e867904c8295537803c1c8a076e130df5674b58mikesamuelfi
464e867904c8295537803c1c8a076e130df5674b58mikesamuel
474e867904c8295537803c1c8a076e130df5674b58mikesamuelif [ ! -d "$findbugs_home" ]; then
484e867904c8295537803c1c8a076e130df5674b58mikesamuel	echo "The path $findbugs_home,"
494e867904c8295537803c1c8a076e130df5674b58mikesamuel	echo "which is where I think FindBugs is located,"
504e867904c8295537803c1c8a076e130df5674b58mikesamuel	echo "does not seem to be a directory."
514e867904c8295537803c1c8a076e130df5674b58mikesamuel	exit 1
524e867904c8295537803c1c8a076e130df5674b58mikesamuelfi
534e867904c8295537803c1c8a076e130df5674b58mikesamuel
544e867904c8295537803c1c8a076e130df5674b58mikesamuel# Choose default java binary
554e867904c8295537803c1c8a076e130df5674b58mikesamuelfb_javacmd=java
564e867904c8295537803c1c8a076e130df5674b58mikesamuelif [ ! -z "$JAVA_HOME" ] && [ -x "$JAVA_HOME/bin/java" ]; then
574e867904c8295537803c1c8a076e130df5674b58mikesamuel	if [ `expr "$fb_osname" : CYGWIN` -ne 0 ]; then
584e867904c8295537803c1c8a076e130df5674b58mikesamuel		fb_javacmd=`cygpath --mixed "$JAVA_HOME"`/bin/java
594e867904c8295537803c1c8a076e130df5674b58mikesamuel	else
604e867904c8295537803c1c8a076e130df5674b58mikesamuel		fb_javacmd="$JAVA_HOME/bin/java"
614e867904c8295537803c1c8a076e130df5674b58mikesamuel	fi
624e867904c8295537803c1c8a076e130df5674b58mikesamuelfi
634e867904c8295537803c1c8a076e130df5674b58mikesamuel
64489a0ec7301a86af8497d24748336db09ca278damikesamuelfb_mainclass=edu.umd.cs.findbugs.workflow.CloudSyncAndReport
654e867904c8295537803c1c8a076e130df5674b58mikesamuel
664e867904c8295537803c1c8a076e130df5674b58mikesamuelfb_javacmd=${fb_javacmd:-"java"}
67489a0ec7301a86af8497d24748336db09ca278damikesamuelfb_maxheap=${fb_maxheap:-"-Xmx768m"}
684e867904c8295537803c1c8a076e130df5674b58mikesamuelfb_appjar=${fb_appjar:-"$findbugs_home/lib/findbugs.jar"}
694e867904c8295537803c1c8a076e130df5674b58mikesamuelset -f
704e867904c8295537803c1c8a076e130df5674b58mikesamuel#echo command: \
714e867904c8295537803c1c8a076e130df5674b58mikesamuelexec "$fb_javacmd" \
724e867904c8295537803c1c8a076e130df5674b58mikesamuel	-classpath "$fb_appjar$fb_pathsep$CLASSPATH" \
734e867904c8295537803c1c8a076e130df5674b58mikesamuel	-Dfindbugs.home="$findbugs_home"\
744e867904c8295537803c1c8a076e130df5674b58mikesamuel	$fb_maxheap $fb_jvmargs $fb_mainclass ${@:+"$@"} $fb_appargs
754e867904c8295537803c1c8a076e130df5674b58mikesamuel
764e867904c8295537803c1c8a076e130df5674b58mikesamuel# vim:ts=3
77