菜鸟涛

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: :: 管理 ::

1. 环境:windows2003. jdk6python2.63不兼容)

2. SVN服务器:VisualSVN

http://www.visualsvn.com/

3.Checkstyle jar包: http://checkstyle.sourceforge.net/ 

4. svncheckstyle是通过svnhooks来实现整合。这里是通过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.jarF:\java\checkstyle里。

Svnchecker也放在F:\java\checkstyle

7.修改一下svncheckermodules\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的初始文件。应放在


文件内容:

 

[Default]

#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 脚本

@echo off
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

posted on 2011-04-20 13:35  菜鸟涛  阅读(1675)  评论(2编辑  收藏  举报