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