#!/bin/bash # ************************************************* # checkstyle-cos226 # Hayk Martirosyan # ------------------- # Easy-to-understand wrapper for using checkstyle. # ************************************************* usage() { echo "Usage: ${0##*/} [-cos126 | -cos226 | -algs4 | -introcs | -coursera] filename1 filename2 ..." exit 1 } # This must match the install directory INSTALL=/usr/local/algs4 INSTALL_ALGS4=/usr/local/algs4 INSTALL_INTROCS=/usr/local/introcs JAVA=java # Find most recent version of Checkstyle CHECKSTYLE=checkstyle-[0-9].[0-9]* CHECKSTYLE_JAR=$(ls -td ${INSTALL}/${CHECKSTYLE}/${CHECKSTYLE}-all.jar | head -1) # xml files that specify which Checkstyle checks to run or suppress CHECKSTYLE_XML=${INSTALL}/checkstyle-cos226.xml SUPPRESSIONS_XML=${INSTALL}/checkstyle-suppressions.xml # set base directory to current working directory BASEDIR=`pwd -P` # If there are no arguments if [ ! -n "$1" ]; then echo 'Specify .java files as arguments.' usage fi if [ "$1" == "-cos126" ]; then echo 'Detected cos126' CHECKSTYLE_XML=${INSTALL_INTROCS}/checkstyle-cos126.xml shift elif [ "$1" = "-cos226" ]; then echo 'Detected cos226' CHECKSTYLE_XML=${INSTALL_ALGS4}/checkstyle-cos226.xml shift elif [ "$1" = "-algs4" ]; then echo 'Detected algs4' CHECKSTYLE_XML=${INSTALL_ALGS4}/checkstyle-algs4.xml shift elif [ "$1" = "-coursera" ]; then echo 'Detected coursera' CHECKSTYLE_XML=${INSTALL_ALGS4}/checkstyle-coursera.xml shift else echo "Running checkstyle on $*:" $JAVA -jar "${CHECKSTYLE_JAR}" -c /google_checks.xml $* exit fi # If the first remaining argument is .java file that exists, runs Checkstyle if [ "${1##*.}" = "java" ]; then if [ -e "$1" ]; then echo "Running checkstyle on $*:" # $JAVA -cp "${CHECKSTYLE_JAR}" -Dsuppressions="${SUPPRESSIONS_XML}" -Dbasedir="${BASEDIR}" com.puppycrawl.tools.checkstyle.Main -c "${CHECKSTYLE_XML}" $* | sed 's/\[ERROR\] //' $JAVA -cp "${CHECKSTYLE_JAR}" -Dsuppressions="${SUPPRESSIONS_XML}" -Dbasedir="${BASEDIR}" com.puppycrawl.tools.checkstyle.Main -c "${CHECKSTYLE_XML}" $* else echo "File not found! Make sure you are specifying the path correctly." echo "The filename is case sensitive." usage fi else echo "Checkstyle needs a .java file as an argument!" echo "The filename is case sensitive." usage fi