-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit
More file actions
40 lines (40 loc) · 1.53 KB
/
Copy pathpre-commit
File metadata and controls
40 lines (40 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/sh
#execute shell before commit,check the code
#echo "正在检测项目..."
mvn clean package -Dmaven.test.skip=true >/dev/null 2>&1
#得到项目打包结果,打包成功 执行结果为0;打包不成功 执行结果为非0
package_result=$?
if [ $package_result -eq 0 ]
then
#echo "正在执行findbugs检测..."
mvn findbugs:check >/dev/null 2>&1
#得到findbugs检测结果,没有bug 执行结果为0;有bug 执行结果为非0
findbugs_result=$?
if [ $findbugs_result -eq 0 ]
then
#echo "正在执行checkstyle检测..."
mvn checkstyle:check >/dev/null 2>&1
#得到checkstyle检测结果,没有代码规范问题 执行结果为0;有代码规范问题 执行结果为非0
checkstyle_result=$?
if [ $checkstyle_result -eq 0 ]
then
#echo "项目执行checkstyle检测成功"
exit 0
else
mvn jxr:jxr >/dev/null 2>&1
echo "提交失败,源于项目存在代码规范问题(mvn checkstyle:check)"
cat target/checkstyle-result.xml
echo "请查看target目录下的checkstyle-result.xml文件得知详情"
exit 1
fi
else
echo "提交失败,源于项目存在bug(mvn findbugs:check)"
echo "请从弹出的findbugs:gui界面中查看错误详情"
mvn findbugs:gui
echo "请修正后重新提交!!!"
exit 1
fi
else
echo "提交失败,源于项目清空或打包失败(mvn clean package)"
exit 1
fi