build.sh 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. # /////////////////////////////////////////////////////////////////////////////
  2. # REFCODES.ORG
  3. # =============================================================================
  4. # This code is copyright (c) by Siegfried Steiner, Munich, Germany and licensed
  5. # under the following (see "http://en.wikipedia.org/wiki/Multi-licensing")
  6. # licenses:
  7. # =============================================================================
  8. # GNU General Public License, v3.0 ("http://www.gnu.org/licenses/gpl-3.0.html")
  9. # =============================================================================
  10. # Apache License, v2.0 ("http://www.apache.org/licenses/LICENSE-2.0")
  11. # =============================================================================
  12. # Please contact the copyright holding author(s) of the software artifacts in
  13. # question for licensing issues not being covered by the above listed licenses,
  14. # also regarding commercial licensing models or regarding the compatibility
  15. # with other open source licenses.
  16. # /////////////////////////////////////////////////////////////////////////////
  17. #!/bin/bash
  18. # ------------------------------------------------------------------------------
  19. # INIT:
  20. # ------------------------------------------------------------------------------
  21. CURRENT_PATH="$(pwd)"
  22. SCRIPT_PATH="$(dirname $0)"
  23. cd "${SCRIPT_PATH}"
  24. SCRIPT_PATH="$(pwd)"
  25. cd "${CURRENT_PATH}"
  26. SCRIPT_DIR="${SCRIPT_PATH##*/}"
  27. SCRIPT_NAME="$(basename $0 .sh)"
  28. PARENT_PATH="$(realpath $(dirname $0)/..)"
  29. PARENT_DIR="${PARENT_PATH##*/}"
  30. MODULE_NAME="$(echo -e "${SCRIPT_DIR}" | cut -d- -f3- )"
  31. if [ -z "${MODULE_NAME}" ]; then
  32. MODULE_NAME="$(echo -e "${SCRIPT_DIR}" | cut -d- -f2- )"
  33. if [ -z "${MODULE_NAME}" ]; then
  34. MODULE_NAME="${SCRIPT_DIR}"
  35. fi
  36. fi
  37. # ------------------------------------------------------------------------------
  38. # ANSI ESCAPE CODES:
  39. # ------------------------------------------------------------------------------
  40. ESC_BOLD="\E[1m"
  41. ESC_FAINT="\E[2m"
  42. ESC_FG_RED="\E[31m"
  43. ESC_FG_GREEN="\E[32m"
  44. ESC_FG_YELLOW="\E[33m"
  45. ESC_FG_BLUE="\E[34m"
  46. ESC_FG_MAGENTA="\E[35m"
  47. ESC_FG_CYAN="\E[36m"
  48. ESC_FG_WHITE="\E[37m"
  49. ESC_RESET="\E[0m"
  50. # ------------------------------------------------------------------------------
  51. # PRINTLN:
  52. # ------------------------------------------------------------------------------
  53. function printLn {
  54. char="-"
  55. if [[ $# == 1 ]] ; then
  56. char="$1"
  57. fi
  58. echo -en "${ESC_FAINT}"
  59. printf '%*s' "${COLUMNS:-$(tput cols)}" '' | tr ' ' ${char}
  60. echo -en "${ESC_RESET}"
  61. }
  62. # ------------------------------------------------------------------------------
  63. # QUIT:
  64. # ------------------------------------------------------------------------------
  65. function quit {
  66. input=""
  67. while ([ "$input" != "q" ] && [ "$input" != "y" ]); do
  68. echo -ne "> Continue? Enter [${ESC_BOLD}q${ESC_RESET}] to quit, [${ESC_BOLD}y${ESC_RESET}] to continue: ";
  69. read input;
  70. done
  71. # printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -
  72. if [ "$input" == "q" ] ; then
  73. printLn
  74. echo -e "> ${ESC_BOLD}Aborting due to user input.${ESC_RESET}"
  75. exit
  76. fi
  77. }
  78. # ------------------------------------------------------------------------------
  79. # BANNER:
  80. # ------------------------------------------------------------------------------
  81. function printBanner {
  82. figlet -w 180 "/${MODULE_NAME}:>>>${SCRIPT_NAME}..." 2> /dev/null
  83. if [ $? -ne 0 ]; then
  84. banner "${SCRIPT_NAME}..." 2> /dev/null
  85. if [ $? -ne 0 ]; then
  86. echo -e "> ${SCRIPT_NAME}:" | tr a-z A-Z
  87. fi
  88. fi
  89. }
  90. printBanner
  91. # ------------------------------------------------------------------------------
  92. # HELP:
  93. # ------------------------------------------------------------------------------
  94. function printHelp {
  95. printLn
  96. echo -e "Usage: ${ESC_BOLD}${SCRIPT_NAME}${ESC_RESET}.sh [-h]"
  97. printLn
  98. echo -e "Builds the project and scriptifies the Fat-JAR to a Bash script containing and launching the executable JAR."
  99. printLn
  100. echo -e "${ESC_BOLD}-h${ESC_RESET}: Print this help"
  101. printLn
  102. }
  103. if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
  104. printHelp
  105. exit 0
  106. fi
  107. # ------------------------------------------------------------------------------
  108. # MAIN:
  109. # ------------------------------------------------------------------------------
  110. moduleName=$(xml2 < "${SCRIPT_PATH}/pom.xml" 2>/dev/null | grep "/project/artifactId=")
  111. moduleName="${moduleName#/project/artifactId=}"
  112. if [ -z "${moduleName}" ]; then
  113. moduleName=$(mvn org.apache.maven.plugins:maven-help-plugin:evaluate -Dexpression=project.artifactId -q -DforceStdout)
  114. fi
  115. echo -e "> Building <${ESC_BOLD}${moduleName}${ESC_RESET}>..."
  116. cd "${SCRIPT_PATH}"
  117. mvn clean install "$@"
  118. if (($? != 0)); then
  119. echo -e "> Failed to build <${moduleName}>, aborting!" 1>&2;
  120. exit 1
  121. fi
  122. "${SCRIPT_PATH}/scriptify.sh"
  123. if (($? != 0)); then
  124. echo -e "> ${ESC_BOLD}Failed to scriptify <${moduleName}>, aborting!${ESC_RESET}" 1>&2;
  125. exit 1
  126. fi
  127. "${SCRIPT_PATH}/jexefy.sh"
  128. if (($? != 0)); then
  129. echo -e "> ${ESC_BOLD}Failed to jexefy <${moduleName}>, aborting!${ESC_RESET}" 1>&2;
  130. exit 1
  131. fi
  132. cd "${CURRENT_PATH}"