StatSVN统计SVN中的代码量

来源:互联网 发布:衣服在淘宝找不到 编辑:程序博客网 时间:2024/05/21 11:32

注意事项

  • 可以到虚拟机上进行安装调试
  • 必须首先将SVN环境搭建完成
  • 感觉只是生成了一个初略的统计,但是期望大家能够挖掘下它内在的功能,共同提高


StatSVN介绍

StatSVN是一个Java写的开源代码统计程序,从statCVS移植而来,能够从Subversion版本库中取得信息,然后生成描述项目开发的各种表格和图表。比如:代码行数的时间线;针对每个开发者的代码行数;开发者的活跃程度;开发者最近所提交的;文件数量;平均文件大小;最大文件;哪个文件是修改最多次数的;目录大小;带有文件数量和代码行数的Repository tree。StatSVN当前版本能够生成一组包括表格与图表的静态HTML文档。


StatSVN、Subversion下载
StartSVN本文下载地址:http://download.csdn.net/detail/heydaytoheyong/5544829 (欢迎下载评论,只需要1个积分哦大笑,感谢感谢.....)

StartSVN官网地址为:http://www.statsvn.org/index.html 

StartSVN的下载页面为:http://www.statsvn.org/downloads.html(下载完成后解压到一个目录,比如E:\statsvn,里面有一个statsvn.jar的文件,无需安装)

现在官网上最新的版本为:statsvn-0.7.0

Subversion官网下载地址:http://sourceforge.net/projects/win32svn/(这个是Windows版,安装之后就有了svn.exe这个基于命令行的客户端工具,安装程序把svn.exe的路径加入了path环境变量,我们已经可以在命令行中直接输入svn就可以使用了)


StatSVN使用

使用须知

StatSVN的运行需要Java的运行环境支持,所以大家需要安装Java的运行环境(Java Runtime Environment)。JRE可以从Sun的网站上下载。
Statsvn在使用中需要使用SVN的客户端,因此需要确保机器上可以访问到SVN的客户端命令
 
Checkout工作拷贝

首先从SVN仓库中checkout一个需要统计的路径(如果在工作目录下进行统计,首先请更新,保证工作区中的版本是最新的版本,确保统计结果的准确性),例如我把我的某个路径下的工程checkout在我的电脑上的E:\hei-ws\myproject 路径下。
 
生成svn log文件

首先通过命令行进入工作目录:E:\hei-ws\myproject ,再使用命令,其中 logfileName.log 为log文件的名称,可以根据需要自行定义。

  • svn log -v --xml > logfileName.log (导出所有的svn log)
  • svn log -r HEAD:版本号 -v --xml > logfileName.log(导出指定版本的svn log)
  • svn log -r {2013-3-1}:{2013-6-1} -v --xml --username yong.he --password 123456 E:\hei-ws\myproject > E:\hei-ws\myproject\logfileName.log (生成E:\hei-ws\myproject工作目录的2013-3-1到2013-6-1的代码日志文件到E:\hei-ws\myproject\logfileName.log下)

    SVN还可以使用版本日期来指定某个版本,日期格式使用ISO-8601标准,一般是yyyy-mm-dd hh:mm:ss。当你指定一个日期,SVN会在版本库中找到最接近这个日期的版本。

       SVN对日期的解释是“之前最近”,因此,如果给出的时间只包含日期的话,例如2012-08-25,SVN会在2012-08-25 00:00:00这个时间点之前寻找,所以有可能会发生结果与预期不一致的情况,这个时候就需要想到这一点;另外某个版本对应的时间戳可以伪造,因此使用日期有时候不太保险。

       示例:

       $ svn log -r {2006-11-20}:{2006-11-29}


调用StatSVN进行统计

首先我们把从官网上下载的statsvn-0.7.0.zip包解压缩到D:\statsvn-0.7.0目录下
通过命令行进入D:\statsvn-0.7.0目录
调用命令java -jar statsvn.jar E:\hei-ws\myproject\logfileName.logE:\hei-ws\myproject,命令运行成功即完成了统计工作。
该命令的格式是java -jar statsvn.jar [options] <logfile> <checked-out-module>


参数(注意两个参数都要列出正确的全路径,否则会提示错误如logfile.log找不到):

  • <logfile>:为前一步中生成的svn log文件
  • <checked-out-module>:为checkout工作拷贝目录
  • [options]为可选参数,该参数格式及用法如下:
    Some options:-version           print the version information and exit-output-dir <dir>  directory where HTML suite will be saved-include <pattern> include only files matching pattern, e.g. **/*.c;**/*.h-exclude <pattern> exclude matching files, e.g. tests/**;docs/**-tags <regexp>     show matching tags in lines of code chart, e.g. version-.*-title <title>     Project title to be used in reports-viewvc <url>      integrate with ViewVC installation at <url>-trac <url>        integrate with Trac at <url>-bugzilla <url>    integrate with Bugzilla installation at <url>-username <svnusername> username to pass to svn-password <svnpassword> password to pass to svn-verbose           print extra progress information-xdoc               optional switch output to xdoc-xml                optional switch output to xml-threads <int>        how many threads for svn diff (default: 25)-concurrency-threshold <millisec> switch to concurrent svn diff if 1st call>threshol-dump              dump the Repository content on console-charset <charset> specify the charset to use for html/xdoc-tags-dir <directory> optional, specifies the director for tags (default '/tags/')Full options list: http://www.statsvn.org

查看统计结果


StatSVN优缺点分析

优点
StatSVN会把当前SVN库的状态用图片和图表的方式展现出来,可以按不同分类分别展开,功能强大。
缺点
StatSVN统计的是所有代码行,包括注释和空行,但一般度量要求是有效代码行,在分析时需要注意这一点。
StatSVN不考虑修改的代码行数,只考虑与上一版本相比新增(+)与删除(-)的代码行数。