使用statsvn來統計svn中的代碼量

StatSVN介紹

StatSVN是一個Java寫的開源代碼統計程序,從statCVS移植而來,能夠從Subversion版本庫中取得信息,然後生成描述項目開發的各種表格和圖表。比如:代碼行數的時間線;針對每個開發者的代碼行數;開發者的活躍程度;開發者最近所提交的;文件數量;平均文件大小;最大文件;哪個文件是修改最多次數的;目錄大小;帶有文件數量和代碼行數的Repository tree。StatSVN當前版本能夠生成一組包括表格與圖表的靜態HTML文檔。

StatSVN下載

StartSVN官網地址爲:http://www.statsvn.org/index.html 

StartSVN的下載頁面爲:http://www.statsvn.org/downloads.html也可以下載本文的附件

現在官網上最新的版本爲:statsvn-0.7.0

StatSVN使用

使用須知

 

StatSVN的運行需要Java的運行環境支持,所以大家需要安裝Java的運行環境(Java RuntimeEnvironment)。JRE可以從Sun的網站上下載。

Statsvn在使用中需要使用SVN的客戶端,因此需要確保機器上可以訪問到SVN的客戶端命令

 

Checkout工作拷貝

 

首先從SVN倉庫中checkout一個需要統計的路徑(如果在工作目錄下進行統計,首先請更新,保證工作區中的版本是最新的版本,確保統計結果的準確性),例如我把我的某個路徑下的工程checkout在我的電腦上的 D:\MyProjects 路徑下。

 

生成svn log文件

 

首先通過命令行進入工作目錄:D:\MyProjects ,再使用svn log -v --xml > logfile.log的命令,其中logfile.log爲log文件的名稱,可以根據需要自行定義。這樣就在工作拷貝的目錄下生成一個名稱爲logfile.log的文件。

 

此處需注意,如果SVN 用的是證書登錄,需要證書、用戶名、密碼等 一步一步生成.log 文件,然後調用java -jar statsvn.jar D:\MyProjects\logfile.log D:\MyProjects  來出report。

 

調用StatSVN進行統計

 

首先我們把從官網上下載的statsvn-0.7.0.zip包解壓縮到D:\statsvn-0.7.0目錄下

通過命令行進入D:\statsvn-0.7.0目錄

調用命令java -jar statsvn.jar D:\MyProjects\logfile.log D:\MyProjects,命令運行成功即完成了統計工作。

該命令的格式是java -jar statsvn.jar [options] <logfile> <checked-out-module>

參數<logfile>爲前一步中生成的svn log文件,<checked-out-module>爲checkout工作拷貝目錄,注意兩個參數都要列出正確的全路徑,否則會提示錯誤如logfile.log找不到等等。

 

Java代碼  收藏代碼
  1. <logfile>          path to the svn logfile of the module  
  2. <directory>        path to the directory of the checked out module  

 

[options]爲可選參數,該參數格式及用法如下:

 

Java代碼  收藏代碼
  1. Some options:  
  2. -version            print the version information and exit  
  3. -output-dir <dir>         directory where HTML suite will be saved  
  4. -include <pattern>        include only files matching pattern, e.g. **/*.c;**/*.h  
  5. -exclude <pattern>    exclude matching files, e.g. tests/**;docs/**  
  6. -tags <regexp>        show matching tags in lines of code chart, e.g. version-.*  
  7. -title <title>            Project title to be used in reports  
  8. -viewvc <url>         integrate with ViewVC installation at <url>  
  9. -trac <url>           integrate with Trac at <url>  
  10. -bugzilla <url>           integrate with Bugzilla installation at <url>  
  11. -username <svnusername> username to pass to svn  
  12. -password <svnpassword> password to pass to svn  
  13. -verbose            print extra progress information  
  14. -xdoc                   optional switch output to xdoc  
  15. -xml                    optional switch output to xml  
  16. -threads <int>            how many threads for svn diff (default25)  
  17. -concurrency-threshold <millisec> switch to concurrent svn diff if 1st call>threshol  
  18. -dump               dump the Repository content on console  
  19. -charset <charset>        specify the charset to use for html/xdoc  
  20. -tags-dir <directory>     optional, specifies the director for tags (default '/tags/')  
  21. Full options list: http://www.statsvn.org  

 

 

查看統計結果

 

上述命令運行成功後,可以看到在D:\MyProjects目錄下生成一組包括表格與圖表的靜態HTML文檔。可以用瀏覽器打開index.html查看統計結果。

示例圖片:

StatSVN優缺點分析

優點

StatSVN會把當前SVN庫的狀態用圖片和圖表的方式展現出來,可以按不同分類分別展開,功能強大。

缺點

StatSVN統計的是所有代碼行,包括註釋和空行,但一般度量要求是有效代碼行,在分析時需要注意這一點。

StatSVN不考慮修改的代碼行數,只考慮與上一版本相比新增(+)與刪除(-)的代碼行數。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章