[英]Svn pre-commit hook for checkstyle
Here is my current checkstyle shell script. 这是我当前的checkstyle shell脚本。 It works fine if I commit on TRUNK but not on Branches.
如果我在TRUNK上提交但不在分支上提交,则可以正常工作。 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? checkstyle
捕获了一些不是问题的东西,或者开发人员写的方式实际上比checkstyle
坚持的应该更清楚,更容易理解,该怎么办? When you use something like checkstyle
or findbugs
, you have to understand you'll get a few false positives. checkstyle
或findbugs
类的东西时,您必须了解您会得到一些误报。 A better method is to use a continuous build engine like Jenkins . 更好的方法是使用像Jenkins这样的连续构建引擎。 Jenkins can be setup to automatically kick off a build with each and every commit.
可以将Jenkins设置为在每次提交时自动启动构建。 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.
CruiseControl也是如此,您可以在那里使用TeamCity,Bamboo和许多其他连续构建系统。 I like Jenkins because development is very active, and it's dead simple to setup.
我喜欢Jenkins,因为开发非常活跃,而且设置非常简单。 It took me about 30 minutes to download it and run my first job the very first time I heard of it.
我花了30分钟左右的时间下载并开始我的第一份工作。
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. 我知道您问过您的预提交钩子,但我不想听起来像个推销员(詹金斯是自由开放的源代码,并且我与项目没有任何联系),但是像检查
checkstyle
一样复杂。提交前的钩子正在请求麻烦。 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"). 尝试比较目录结构,然后创建临时目录(删除“ rm -Rf $ TMPDIR”)。
Perhaps you have diferences between trunk and branches like: 也许您在主干和分支之间有区别,例如:
Trunk: /tmp/12/code/file.java 中继线:/tmp/12/code/file.java
Branches: /tmp/br1/12/code/file.java 分支:/tmp/br1/12/code/file.java
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.