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