PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/bin/test-patch-10-compile

https://github.com/Chanjet/oozie
#! | 141 lines | 134 code | 7 blank | 0 comment | 0 complexity | a01430633d0bb0519896aa23f2bb9f02 MD5 | raw file
  1. #!/bin/bash
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. if [ "${TESTPATCHDEBUG}" == "true" ] ; then
  15. set -x
  16. fi
  17. BASEDIR=$(pwd)
  18. TASKNAME="COMPILE"
  19. OP=""
  20. TEMPDIR=""
  21. REPORTDIR=""
  22. SUMMARYFILE=""
  23. STDOUT="/dev/null"
  24. MVNPASSTHRU=""
  25. ###############################################################################
  26. cleanupAndExit() {
  27. exit $1
  28. }
  29. ###############################################################################
  30. printUsage() {
  31. echo "Usage: $0 --taskname | (--op=pre|post|report --tempdir=<TEMP DIR> --reportdir=<REPORT DIR> --summaryfile=<SUMMARY FILE>) [--verbose] [-D<VALUE>...] [-P<VALUE>...]"
  32. echo
  33. }
  34. ###############################################################################
  35. parseArgs() {
  36. for i in $*
  37. do
  38. case $i in
  39. --taskname)
  40. echo ${TASKNAME}
  41. exit 0
  42. ;;
  43. --op=*)
  44. OP=${i#*=}
  45. ;;
  46. --tempdir=*)
  47. TEMPDIR=${i#*=}
  48. ;;
  49. --reportdir=*)
  50. REPORTDIR=${i#*=}
  51. ;;
  52. --summaryfile=*)
  53. SUMMARYFILE=${i#*=}
  54. ;;
  55. --verbose)
  56. STDOUT="/dev/stdout"
  57. ;;
  58. -D*)
  59. MVNPASSTHRU="${MVNPASSTHRU} $i"
  60. ;;
  61. -P*)
  62. MVNPASSTHRU="${MVNPASSTHRU} $i"
  63. ;;
  64. esac
  65. done
  66. if [[ "${TASKNAME}" == "" || "${OP}" == "" || "${TEMPDIR}" == "" || "${REPORTDIR}" == "" || "${SUMMARYFILE}" == "" ]] ; then
  67. echo "Missing options"
  68. echo
  69. printUsage
  70. cleanupAndExit 1
  71. fi
  72. if [[ "${OP}" != "pre" && "${OP}" != "post" && "${OP}" != "report" ]] ; then
  73. echo "Invalid operation"
  74. echo
  75. printUsage
  76. cleanupAndExit 1
  77. fi
  78. }
  79. ###############################################################################
  80. checkForWarnings() {
  81. grep '\[WARNING\]' ${REPORTDIR}/${TASKNAME}-clean.txt > ${TEMPDIR}/${TASKNAME}-javacwarns-clean.txt
  82. grep '\[WARNING\]' ${REPORTDIR}/${TASKNAME}-patch.txt > ${TEMPDIR}/${TASKNAME}-javacwarns-patch.txt
  83. cleanWarns=`cat ${TEMPDIR}/${TASKNAME}-javacwarns-clean.txt | awk 'BEGIN {total = 0} {total += 1} END {print total}'`
  84. patchWarns=`cat ${TEMPDIR}/${TASKNAME}-javacwarns-patch.txt | awk 'BEGIN {total = 0} {total += 1} END {print total}'`
  85. newWarns=`expr $patchWarns - $cleanWarns`
  86. if [[ $newWarns -le 0 ]] ; then
  87. REPORT+=("{color:green}+1{color} the patch does not seem to introduce new javac warnings")
  88. newWarns=0
  89. else
  90. REPORT+=("{color:red}-1{color} the patch seems to introduce $newWarns new javac warning(s)")
  91. newWarns=1
  92. fi
  93. }
  94. ###############################################################################
  95. parseArgs "$@"
  96. case $OP in
  97. pre)
  98. mvn clean test -PtestPatchCompile -DskipTests ${MVNPASSTHRU} | tee ${REPORTDIR}/${TASKNAME}-clean.txt >> $STDOUT
  99. if [[ ${PIPESTATUS[0]} == 0 ]] ; then
  100. echo "{color:green}+1{color} HEAD compiles" >> ${TEMPDIR}/${TASKNAME}-compile.txt
  101. else
  102. echo "{color:red}-1{color} HEAD does not compile" >> ${TEMPDIR}/${TASKNAME}-compile.txt
  103. fi
  104. ;;
  105. post)
  106. mvn clean test -PtestPatchCompile -DskipTests ${MVNPASSTHRU} | tee ${REPORTDIR}/${TASKNAME}-patch.txt >> $STDOUT
  107. if [[ ${PIPESTATUS[0]} == 0 ]] ; then
  108. echo "{color:green}+1{color} patch compiles" >> ${TEMPDIR}/${TASKNAME}-compile.txt
  109. else
  110. echo "{color:red}-1{color} patch does not compile" >> ${TEMPDIR}/${TASKNAME}-compile.txt
  111. fi
  112. ;;
  113. report)
  114. REPORT=()
  115. compileErrors=0
  116. while read line; do
  117. REPORT+=("$line")
  118. if [[ "$line" =~ "-1" ]] ; then
  119. compileErrors=1
  120. fi
  121. done < ${TEMPDIR}/${TASKNAME}-compile.txt
  122. checkForWarnings
  123. total=`expr $compileErrors + $newWarns`
  124. if [[ $total == 0 ]] ; then
  125. echo "{color:green}+1 ${TASKNAME}{color}" >> $SUMMARYFILE
  126. else
  127. echo "{color:red}-1 ${TASKNAME}{color}" >> $SUMMARYFILE
  128. fi
  129. for line in "${REPORT[@]}" ; do
  130. echo ". ${line}" >> $SUMMARYFILE
  131. done
  132. ;;
  133. esac
  134. exit 0