Here is my current checkstyle shell script. It works fine if I commit on TRUNK but not on Branches. I don't really understand why it doesn't work. Can someone please help me?
#!/bin/sh
###################################################
#
# Verify Checkstyle
#
###################################################
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook
JAVA=/opt/ibm/java2-i386-50/bin/java
CHECKSTYLE=/usr/local/checkstyle/checkstyle-all-5.1.jar
TMPDIR=/tmp/$TXN
REPORT=/tmp/$TXN/report
CHECKSTYLE_CONFIG=/usr/local/checkstyle/checkstyle.xml
CHANGED=`$SVNLOOK changed -t "$TXN" "$REPOS" | grep -v "^D" | awk '{print $2}'`
mkdir -p $TMPDIR
for LINE in $CHANGED ; do
FILE=`echo $LINE | egrep -v Test\\.java$ | egrep -v \\/src\\/test\\/ | egrep -v \\/js\\/ext`
if [ -n "$FILE" ] ; then
DIRNAME=`dirname $FILE`
mkdir -p $TMPDIR/$DIRNAME
$SVNLOOK cat $REPOS --transaction $TXN $FILE > $TMPDIR/$FILE
fi
done
$JAVA -jar $CHECKSTYLE -c $CHECKSTYLE_CONFIG -r $TMPDIR > $TMPDIR/tmpfile.checkstyle
X=$?
if [ $X -ne 0 ] ; then
cat $TMPDIR/tmpfile.checkstyle > /dev/stderr
rm -Rf $TMPDIR
exit 1
fi
rm -Rf $TMPDIR
exit 0
Thanks!
Word of advice: Don't make this a pre-commit script.
checkstyle
catches something where it is not an issue, or the way the developer wrote it is actually clearer and easier to understand than what checkstyle
insists it should be? When you use something like checkstyle
or findbugs
, you have to understand you'll get a few false positives. A better method is to use a continuous build engine like Jenkins . Jenkins can be setup to automatically kick off a build with each and every commit. Jenkins can:
You don't have to use Jenkins. Hudson is still there. So is CruiseControl, and you can use TeamCity, Bamboo, and dozens of other continuous build systems out there. I like Jenkins because development is very active, and it's dead simple to setup. It took me about 30 minutes to download it and run my first job the very first time I heard of it.
I know you asked about your pre-commit hook, and I don't want to sound like a salesman (Jenkins is free and open source, and I have no connection to the project), but making something as complex as a checkstyle
check a pre-commit hook is asking for trouble. Using a continuous build server is simply a better way of handling this issue.
A hint.
Try to compare the directory structure, whitch you create temporary (remove "rm -Rf $TMPDIR").
Perhaps you have diferences between trunk and branches like:
Trunk: /tmp/12/code/file.java
Branches: /tmp/br1/12/code/file.java
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.