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