IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    maven wrapper script

    hongjiang发表于 2015-08-15 11:04:29
    love 0

    这个脚本用于简化mvn的操作,在mac/bash, linux/bash, cygwin/bash下测试过

    #!/bin/bash - 
    
    TOP_PID=$$
    PROG_NAME=$0
    ACTION=$1
    
    function get_children() {
      ps -ef | grep $$ | grep -v grep | awk '$3=='"$$"'{print $2}' | xargs
    }
    
    trap "kill $(get_children) >/dev/null 2>&1; exit 1" SIGINT SIGTERM
    
    function usage() {
      echo "Usage: $PROG_NAME {verify|compile|run|debug|package|eclipse|get-src|dep-tree}"
      exit 1;
    }
    
    function get_mvn_cmd() {
      if [[ "$OSTYPE" == *cygwin* ]];then
        ppid=$( ps -ef -p $$ | awk 'NR==2{print $3}' )
        user_shell=$( ps -p $ppid | awk 'NR==2{print $8}' )
        #has some trouble with cygwin, while Ctrl-c cannot terminal
        set -m
      else
        ppid=$( ps -oppid= $$ )
        user_shell=$( ps -ocomm= -p $ppid )
      fi
    
      mvn=$( $user_shell -ic "alias mvn" 2>/dev/null | cut -d'=' -f2 | sed "s/'//g" )
    
      if [ -z "$mvn" ];then
        $user_shell -ic "which mvn" >/dev/null
        if [ $? -eq 0 ];then
          mvn=$( $user_shell -ic "which mvn" | head -1 )
        fi
      fi
    
      if [ -z "$mvn" ]; then 
        echo "mvn command not found" >&2
        kill -s TERM $TOP_PID
      else
        echo $mvn
      fi
    }
    
    MVN=$( get_mvn_cmd )
    
    function mvn_verify() {
      $MVN verify $@
    }
    
    function mvn_compile() {
      $MVN clean compile $@
    }
    
    function mvn_run() {
      $MVN scala:run $@
    }
    
    function mvn_debug() {
      $MVN scala:run -Dlauncher=debug $@
    }
    
    function mvn_package() {
      $MVN clean package -Dmaven.javadoc.skip -Dmaven.test.skip $@
    }
    
    function mvn_src() {
      $MVN dependency:sources
    }
    
    function mvn_dep_tree() {
      $MVN dependency:tree -Dverbose
    }
    
    function mvn_eclipse() {
      $MVN eclipse:eclipse
    }
    
    case "$ACTION" in
      verify)
        shift && mvn_verify $@
      ;;
      compile)
        shift && mvn_compile $@
      ;;
      run)
        shift && mvn_run $@
      ;;
      debug)
        shift && mvn_debug $@
      ;;
      package)
        shift && mvn_package $@
      ;;
      get-src)
        mvn_src
      ;;
      dep-tree)
        mvn_dep_tree
      ;;
      eclipse)
        mvn_eclipse
      ;;
      *)
        usage
      ;;
    esac
    


沪ICP备19023445号-2号
友情链接