#!/bin/bash # # Execution: % findbugs -cos226 HelloWorld.class # Execution: % findbugs -cos126 *.class # # To see descriptions of bugs: http://findbugs.sourceforge.net/bugDescriptions.html # set -o xtrace usage() { echo "Usage: ${0##*/} [-cos126 | -cos226 | -algs4 | -introcs | -coursera] classname1 classname2 ..." exit 1 } INSTALL_ALGS4=/usr/local/algs4 INSTALL_INTROCS=/usr/local/introcs JAVA=java # find the latest version of Findbugs FINDBUGS_VERSION=findbugs-[0-9].[0-9].[0-9] FINDBUGS_JAR=$(ls -td ${INSTALL_ALGS4}/${FINDBUGS_VERSION}/lib/findbugs.jar | head -1) FINDBUGS=$(ls -td ${INSTALL_ALGS4}/${FINDBUGS_VERSION}/bin/findbugs | head -1) # no command-line arguments if [ ! -n "$1" ]; then echo 'Specify .class or .jar files as arguments.' usage fi # check for command-line options if [ "$1" == "-cos126" ]; then echo 'Detected cos126' AUX_CLASSPATH=${INSTALL_INTROCS}/stdlib.jar FINDBUGS_XML=${INSTALL_INTROCS}/findbugs.xml shift elif [ "$1" = "-cos226" ]; then echo 'Detected cos226' AUX_CLASSPATH=${INSTALL_ALGS4}/algs4.jar FINDBUGS_XML=${INSTALL_ALGS4}/findbugs.xml shift elif [ "$1" = "-algs4" ]; then echo 'Detected algs4' AUX_CLASSPATH=${INSTALL_ALGS4}/algs4.jar FINDBUGS_XML=${INSTALL_ALGS4}/findbugs.xml shift elif [ "$1" = "-coursera" ]; then echo 'Detected coursera' AUX_CLASSPATH=${INSTALL_ALGS4}/algs4.jar FINDBUGS_XML=${INSTALL_ALGS4}/findbugs.xml shift else echo "Running Findbugs on $*:" $FINDBUGS $* exit fi # if the first argument is either a .class or .java file that exists, runs findbugs if [ "${1##*.}" = "class" ] || [ "${1##*.}" = "jar" ]; then if [ -e "$1" ]; then echo "Running findbugs on $*:" $JAVA -Duser.language=novice -jar "${FINDBUGS_JAR}" -textui -low -auxclasspath $AUX_CLASSPATH -longBugCodes -exclude "${FINDBUGS_XML}" $* exit else echo "File not found! Make sure you are specifying the path correctly." echo "The filename is case sensitive." usage fi else echo "Findbugs needs .class or .jar files as arguments!" echo "The filename is case sensitive." usage fi