Chinaunix首页 | 论坛 | 博客
  • 博客访问: 64765
  • 博文数量: 7
  • 博客积分: 249
  • 博客等级: 二等列兵
  • 技术积分: 95
  • 用 户 组: 普通用户
  • 注册时间: 2012-08-22 18:10
文章分类

全部博文(7)

文章存档

2012年(7)

我的朋友

分类: LINUX

2012-08-23 11:02:35

为了使项目代码的质量更高,于是用jenkins集成了几个java代码分析工具,并没有使用jenkins中的ant或者maven来调用工具(网上搜到的全是这些),而是使用bash shell来调用。
环境 ubuntu 10.0.4 + jenkins
需要单独下载的工具:
1.findbugs
2.checkstyle
3.PMD
4. SKD

jenkins 插件
1.
2.
3.
4. (使用谷歌SDK中自带的lint工具来分析整个android项目)

所有以上安装好后,并且配置好jenkins中相应的job,build即可。附调用工具的shell代码。
由于对这几个工具的命令还不是很熟悉,故代码还没有相应的优化。


点击(此处)折叠或打开

  1. #!/bin/bash
  2. set -x

  3. project_dir=$1

  4. function set_env()
  5. {
  6.     #src_dir=''
  7.     checkstyle_tool_dir='/mnt/nfs/checkstyle-5.5'
  8.     pmd_tool_dir='/mnt/nfs/pmd-bin-5.0.0'
  9.     findbugs_tool_dir='/mnt/nfs/findbugs-2.0.1'
  10.     android_sdk_lint_tool_dir='/mnt/nfs/android-sdk-linux/tools'
  11.     lint_result_tmp='/tmp/lint-results.xml'
  12.     lint_result_file="${project_dir}/lint-results.xml"
  13.     checkstyle_result_tmp='/tmp/checkstyle-result.xml'
  14.     style_result_file="${project_dir}/checkstyle-result.xml"
  15.     pmd_result_tmp='/tmp/pmd-tmp.xml'
  16.     pmd_result_file="${project_dir}/pmd-result.xml"
  17.     findbugs_result_tmp="/tmp/findbugs-report.xml"
  18.     findbugs_result_file="${project_dir}/findbugs-report.xml"

  19. }
  20. function remove_old_result()
  21. {
  22.     rm $style_result_file
  23.     rm $pmd_result_file
  24.     rm $findbugs_result_file
  25.     rm $lint_result_file
  26. }

  27. function run_checkstyle()
  28. {
  29.     if [[ -d $checkstyle_tool_dir ]];then
  30.         echo "checkstyle tool dir is exist"
  31.     else
  32.         exit 0
  33.     fi
  34.     cd $checkstyle_tool_dir
  35.     java -jar checkstyle-5.5-all.jar -c sun_checks.xml -f xml -o $checkstyle_result_tmp -r $check_dir
  36.     cat $checkstyle_result_tmp >> $style_result_file
  37.     sed -i '/[]/{N;N};s/[<][/]checkstyle[>]\n[<][?]xml version="1.0" encoding="UTF-8"[?][>]\n[<]checkstyle version="5.5"[>]//g' $style_result_file
  38.     rm $checkstyle_result_tmp

  39. }

  40. function run_pmd()
  41. {
  42.     if [[ -d $pmd_tool_dir ]];then
  43.         echo "PMD dir is exist"
  44.     else
  45.         exit 0
  46.     fi
  47.     cd ${pmd_tool_dir}/bin
  48.    ./run.sh pmd $check_dir xml java-basic,java-imports,java-unusedcode > $pmd_result_tmp
  49.     cat $pmd_result_tmp >> $pmd_result_file
  50.     sed -i '/[]/{N;N};s/[<][/]pmd[>]\n[<][?]xml version="1.0" encoding="UTF-8"[?][>]\n[<]pmd version="5.0.0" timestamp="(.*)"[>]\n//g' $pmd_result_file
  51.     rm $pmd_result_tmp

  52. }

  53. function run_findbugs()
  54. {
  55.     if [[ -d $findbugs_tool_dir ]];then
  56.         echo "findbugs tool is exist"
  57.     else
  58.         exit 0
  59.     fi
  60.     cd $findbugs_tool_dir/bin
  61.     ./findbugs -textui -xml -outputFile $findbugs_result_tmp "$src_dir/$class_dir"
  62. }

  63. function run_androidlint()
  64. {
  65.     if [[ -d $android_sdk_lint_tool_dir ]];then
  66.         echo "lint dir is exist"
  67.     else
  68.         exit 0
  69.     fi
  70.     cd $android_sdk_lint_tool_dir
  71.     ./lint --fullpath --xml ${lint_result_tmp} ${src_dir}
  72.     cat ${lint_result_tmp} >> $lint_result_file
  73.     rm ${lint_result_tmp}

  74. }

  75. function java_check()
  76. {
  77.     echo 'check dir' $java_dir
  78.     dir_name=(`echo $java_dir | sed 's/,/ /g'`)
  79.     echo $dir_name
  80.     for i in ${dir_name[@]}
  81.     do
  82.         check_dir="$src_dir/$i"
  83.         find $check_dir -name .git | xargs rm -rf
  84.         run_checkstyle
  85.         run_pmd
  86.     done
  87.     run_findbugs
  88. }

  89.     
  90. function main()
  91. {
  92.     set_env
  93.     remove_old_result
  94.     java_check
  95.     if [ "$android_lint" == "true" ];then
  96.         run_androidlint
  97.     fi
  98. }
  99. main

阅读(1387) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~