`

maven pom文件查看依赖关系的小脚本

 
阅读更多

 因为mvn dependency:tree 包含了很多其他杂乱的信息,就写个简单的小脚本查看关系依赖树的关键部分!

#!/bin/bash 

# show part of  mvn dependency:tree result 
# author          :zhaoming.xue
# data            :2012-4-18
# last modify     :2012-4-18
# version         :1.0.0

# 1.check has the pom.xml file 
pom_file_num=`find . -maxdepth 1 -type f | grep pom.xml | wc -l`

if [ $pom_file_num -eq 0 ];then 
     echo "can't find pom.xml ,pls check ! "
     exit 1
fi

base_path=`pwd`
# 2.cut part of info 
# 2.1  execute and check has error ! 
mvn dependency:tree > temp.info 
if [ -f temp.info ];then
   has_error=`grep -i "error" temp.info  | wc -l`
   if [ $has_error -gt 0 ];then 
       echo "error ,pls check temp.info"
       exit 1 
   fi
fi 

# 2.2 cut info 
start_num=`grep -n + temp.info | awk -F ":" '{print $1}' | sed '2,$d'`
new_start_num=`expr $start_num - 1`
end_num=`grep -in "build success" temp.info | awk -F ":" '{print $1}'`

if [ $? -gt 0 ];then 
    echo "error ,pls check "
    exit 1 
fi

sed -n "$new_start_num,$end_num p" temp.info 

# 3.delete temp file 
if [ -f temp.info ];then 
    rm -rf temp.info
fi
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics