SvnCheckstyle整合

 

1、  安装jdk

默认路径: /usr/bin/java

 

2、  配置checkstyle规则文件

默认路径:http://192.168.30.21/checkstyle/checkstyle.xml

 

3、  下载Checkstyle

checkstyle-5.5-bin.tar.gz

 

 

4、  下载SvnChecker

svnchecker-0.3.tar.gz

 

 

5、  拷贝压缩包到svn服务器

cp checkstyle-5.5-bin.tar.gz  /home/svn

cp svnchecker-0.3.tar.gz /home/svn

 

6、  解压缩刚上传的压缩包到指定目录

cd /home/svn

tar –xzvf checkstyle-5.5-bin.tar.gz  

tar –xzvf svnchecker-0.3.tar.gz  

 

7、  svnchecker执行权限 

cd /home/svn

chown –R root:subversion svnchecker-0.3

chmod –R 774 svnchecker-0.3

 

说明:(apache2服务的执行者www-data需要加入subversion组)

 

8、  编辑svncheckerconfig.ini  

cd  /home/svn/svnchecker-0.3

vim svncheckerconfig.ini

 

[Default]

#This property tells Subversionchecker about all checks

#(UnitTests, Acce***ights, XMLValidator etc) it should execute.

#Separated with comma (",")

Main.PreCommitChecks=Checkstyle

 

#Path of java executable to run Checkstyle command

#指定java运行环境

Checkstyle.Java=/usr/bin/java

 

#Classpath for executing Checkstyle rules

#指定checkstylejava

Checkstyle.Classpath=/home/svn/checkstyle-5.5/checkstyle-5.5-all.jar

 

#Configuration file for Checkstyle to run its rules.

#指定checkstyle配置规则文件

Checkstyle.ConfigFile=http://192.168.30.21/checkstyle/checkstyle.xml

 

#In case of failures, where should Subversionchecker redirect the errors

Checkstyle.FailureHandlers=Console

 

 

9、   编辑pre-commit文件

cd  /home/svn/svnchecker-0.3

touch pre-commit

chgrp subversion pre-commit

chmod 774 pre-commit

vim pre-commit

 

 

REPOS="$1"

TXN="$2"

 

# Make sure that the log message contains some text.

SVNLOOK=/usr/bin/svnlook

$SVNLOOK log -t "$TXN" "$REPOS" | \

   grep "[a-zA-Z0-9]" > /dev/null || exit 1

 

# Exit on all errors.

set -e

 

# Check that the author of this commit has the rights to perform

# the commit on the files and directories being modified.

#这段验证需要注释,如果没有安装subversion-tools(ubuntu)

#"$REPOS"/hooks/commit-access-control.pl "$REPOS" $TXN \

#  "$REPOS"/hooks/commit-access-control.cfg

 

# All checks passed, so allow the commit.

#开启svnchecker检查

/home/svn/svnchecker-0.3/Main.py PreCommit $REPOS $TXN || exit 1

 

exit 0

 

 

10、              pre-commit文件放置到svn资源库的hook目录

 

cd  /home/svn/Vlives.Merchant/hooks

ln –s /home/svn/svchecker-0.3/pre-commit