#!/bin/bash # # Execution: % findbugs-algs4 HelloWorld.class # Execution: % findbugs-algs4 *.class # # To see descriptions of bugs: http://findbugs.sourceforge.net/bugDescriptions.html INSTALL=/usr/local/algs4 JAVA=java AUX_CLASSPATH=${INSTALL}/algs4.jar # find the latest version of Findbugs FINDBUGS=findbugs-[0-9].[0-9].[0-9] FINDBUGS_JAR=$(ls -td ${INSTALL}/${FINDBUGS}/lib/findbugs.jar | head -1) FINDBUGS_XML=${INSTALL}/findbugs.xml # If there are no arguments if [ ! -n "$1" ]; then echo 'Specify .class or .jar files as arguments.' echo "Usage: 'findbugs Test.class'" 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}" $* else echo "File not found! Make sure you are specifying the path correctly." echo "The filename is case sensitive." fi exit fi echo "Findbugs needs .class or .jar files as arguments!" echo "The filename is case sensitive." exit