1. 环境:windows2003. jdk6,python2.6(3不兼容)
2. SVN服务器:VisualSVN。
3.Checkstyle jar包: http://checkstyle.sourceforge.net/
4. svn和checkstyle是通过svn的hooks来实现整合。这里是通过python来实现一个脚本hook去编译checkstyle。
5. python hooks脚本是svnchecker。
http://svnchecker.tigris.org/servlets/ProjectDocumentList?folderID=9752&expandFolder=9752&folderID=0
6.假定SVN server安装在F:\java\svn. 仓库在F:\java_Repositories\admwh.
Checkstyle.xml文件和checkstyle-5.3-all.jar在F:\java\checkstyle里。
Svnchecker也放在F:\java\checkstyle。
7.修改一下svnchecker里modules\transaction.py代码
def __executeSVN(self, command, arg = "", split=False):
command = "svnlook --%s %s %s %s %s" % (self.type, self.txnName, command, self.reposPath, arg)
command = command.replace('svnlook','%svnlook%'); //增加
8.新建一个svncheckerconfig.ini文件
svnchecker的初始文件。应放在
文件内容:
#This property tells Subversionchecker about all checks
#(UnitTests, AccessRights, XMLValidator etc) it should execute.
#Separated with comma (",")
Main.PreCommitChecks=Checkstyle
#Path of java executable to run Checkstyle command
Checkstyle.Java=java
#Classpath for executing Checkstyle rules
Checkstyle.Classpath=F:\java\checkstyle\checkstyle-5.3\checkstyle-5.3-all.jar
#Configuration file for Checkstyle to run its rules.
Checkstyle.ConfigFile=F:\java\checkstyle\checkstyle_springside.xml
#In case of failures, where should Subversionchecker redirect the errors
Checkstyle.FailureHandlers=Console
9.编写Pre-commit hook:
具体做法,svn server里,找到仓库admwh--》右键properties --》hooks --》选择pre-commit ,在添加下面的hook 脚本
set python="F:\java\python\python.exe"
set svnchecker="F:\java\checkstyle\svnchecker-0.3"
set svnlook="F:\java\svn\bin\svnlook.exe"
setlocal
set REPOS=%1
set TXN=%2
rem checkstyle hooks
%python% %svnchecker%\Main.py PreCommit %REPOS% %TXN% || exit 1
rem check that logmessage contains at least 5 characters
%svnlook% log "%REPOS%" -t "%TXN%" | findstr "....." > nul
if %errorlevel% gtr 0 goto err
exit 0
:err
echo Empty message not allowed. Please write some message at least 5 characters.Commit refuse! 1>&2
exit 2
10.重启svn server