利用Source Monitor分析代码复杂度

本文介绍如何结合SourceMonitor、ASP和BAT脚本来分析代码,并生成静态分析文件。通过shell脚本从CVS检出代码,然后利用SourceMonitor创建项目并设置语言、源代码目录、文件扩展名等,进行复杂度分析。分析完成后,通过Combine.asp生成统计页面,展示代码的模块、文件、路径、复杂度和深度等信息。

最近利用SourceMonitor+ ASP+BAT来分析代码并生成静态分析文件:
1. 利用shell从CVS check out code:

运行此程序; ./ auto_checkout.sh page. page” 对应page_cfg.sh

a) Auto_checkout.sh

#!/bin/bash

#function log_time() {
# echo `$DT_FORMAT` ": $1 " 
# echo `$DT_FORMAT` ": $1 " >> $TIMELOG 
#}

GOAL=$1

CFG_FILE="${GOAL}_cfg.sh"
#Get configuration from cfg.sh
source ${CFG_FILE}

#DT_STAMP=`date +%Y%m%d_%H%M%S`
#DT_FORMAT="date -R"

WORKDIR=/sourcemonitor
#WORKDIR=/cvstest/builds/all
WORKDIR_REPO=${WORKDIR}/${REPONAME}

mkdir -p $WORKDIR_REPO
##################################################################
# Check out cvs log from every modules
##################################################################
cd $WORKDIR_REPO

echo "=========ALL_MODS:$ALL_MODS=========="
for MOD in $ALL_MODS; do
echo "=========WORKDIR:$WORKDIR=========="
echo "=========MOD:$MOD=========="

if [ "$BRANCH" = "HEAD" ]; then
  cvs -z9 co $MOD
else
  cvs -z9 co -r $BRANCH $MOD
fi  
done

b) Page_cfg.sh

export CVSROOT=:pserver:lliu@engcvsserv.corp.webex.com:/cvs/webapps
export REPONAME=webapps
export ALL_MODS="meetingcenter trainingcenter siteadmin branding urlapi reminder waf svccomponents mywebex nbr dispatcher npp logadmin apidispatcher webcomponents webacd"
export BRANCH=HEAD

c). SourceMonitor optional file: Baseline.xml

 <?xml version="1.0" encoding="UTF-8" ?>

<!-- =======================================================================
 Examples of typical SourceMonitor command line script commands.
======================================================================== -->

<sourcemonitor_commands>

    <!-- ===================================================================
     The write_log element value is used for execution of commands in this
     file, not the log errors flag set in SourceMonitor's options dialog.
     If this element is missing, command progress and errors will be written
     to the SourceMonitor log file.
     =================================================================== -->

    <write_log>true</write_log>

    <!-- ===============================================================
      This command is typical for a project that does not yet exist.
      The file name becomes the project name of the new project.
    ================================================================ -->

    <command>

        <project_file>D:/CVS/SM/AllC++.smp</project_file>

        <!-- ===============================================================
         For a new project, you must specify the language and the location
         of the source code.
        ================================================================ -->

        <project_language>C++</project_language>
        <source_directory>H:/</source_directory>
        <checkpoint_name>BaselineC++</checkpoint_name>
        <checkpoint_date>2007-05-17T16:00:00</checkpoint_date>

        <!-- ===============================================================
         For either a new or existing project, you can override the default
         or current file extensions (set in the Options dialog) for source
         files to be included in a new checkpoint. All files with the
         extensions you specify here will be included in the new checkpoint.
        ================================================================ -->

        <file_extensions>*.cpp;*.h;*.hpp</file_extensions>
        <include_subdirectories>true</include_subdirectories>
        <ignore_headers_footers>true</ignore_headers_footers>

        <!-- ===============================================================
         Export of metrics data is supported for a single checkpoint per
         command (the one identified in the <checkpoint_name> tag or one that
         is automatically created as explained below). Exported metrics data
         is specified by the export type: "1" for the project summary as XML,
         "2" for checkpoint details as XML, or "3" project details as CSV.
         You specify the type with a number 1, 2 or 3 in the element's
         contents. All other text is ignored. The following examples are
         all valid specification of export type 2:
           <export_type>2 (project details as XML)</export_type>
           <export_type>Project details as XML: 2</export_type>
           <export_type>2</export_type>
        ================================================================ -->

        <export>
            <export_file>D:/CVS/SM/dumpCAA.csv</export_file>
       &nbs

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值