#######################################################################################################################
# Java 应用构建脚本
#######################################################################################################################
#!/bin/bash

app=$1
env=$2
if [[ -z ${app} ]] || [ -z ${env} ]; then
  echo 'error: sh build.sh app env'
  exit -1
fi

# 项目根目录
proj_home="/home/reghao/code/aha/autodop"
proj=`basename ${proj_home}`
app_name=${proj}-${app}
cd ${proj_home}
mvn clean package -am -Dmaven.test.skip=true -pl ${app} -P${env}

# 存放应用的根目录
jar_home="/home/reghao/dev/tmp/apps"
if [[ -d ${jar_home}/${app_name} ]]; then
  rm -rf ${jar_home}/${app_name}/*
else
  mkdir -p ${jar_home}/${app_name}
fi
cp ${app}/target/${app_name}.jar ${jar_home}/${app_name}
cp scripts/runner.sh ${jar_home}/${app_name}

cd ${jar_home}
sed -i "s/placeholder/${app_name}/" ${app_name}/runner.sh
zip -r ${app_name}.zip ${app_name}
rm -rf ${app_name}

cd ${proj_home}
mvn clean

#mvn clean package -am -Dmaven.test.skip=true -Ptest
#mvn clean package -am -Dmaven.test.skip=true -pl dmaster -Pdev
#mvn clean package -am -Dmaven.test.skip=true -pl dmaster -Ptest
#mvn clean package -am -Dmaven.test.skip=true -pl dagent -Ptest