test-patch.sh 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. #!/usr/bin/env bash
  2. # Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software
  9. # distributed under the License is distributed on an "AS IS" BASIS,
  10. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. # See the License for the specific language governing permissions and
  12. # limitations under the License.
  13. #set -x
  14. ulimit -n 1024
  15. ### Setup some variables.
  16. ### SVN_REVISION and BUILD_URL are set by Hudson if it is run by patch process
  17. ### Read variables from properties file
  18. bindir=$(dirname $0)
  19. # Defaults
  20. if [ -z "$MAVEN_HOME" ]; then
  21. MVN=mvn
  22. else
  23. MVN=$MAVEN_HOME/bin/mvn
  24. fi
  25. PROJECT_NAME=Hadoop
  26. JENKINS=false
  27. PATCH_DIR=/tmp
  28. SUPPORT_DIR=/tmp
  29. BASEDIR=$(pwd)
  30. PS=${PS:-ps}
  31. AWK=${AWK:-awk}
  32. WGET=${WGET:-wget}
  33. SVN=${SVN:-svn}
  34. GREP=${GREP:-grep}
  35. PATCH=${PATCH:-patch}
  36. JIRACLI=${JIRA:-jira}
  37. FINDBUGS_HOME=${FINDBUGS_HOME}
  38. FORREST_HOME=${FORREST_HOME}
  39. ECLIPSE_HOME=${ECLIPSE_HOME}
  40. ###############################################################################
  41. printUsage() {
  42. echo "Usage: $0 [options] patch-file | defect-number"
  43. echo
  44. echo "Where:"
  45. echo " patch-file is a local patch file containing the changes to test"
  46. echo " defect-number is a JIRA defect number (e.g. 'HADOOP-1234') to test (Jenkins only)"
  47. echo
  48. echo "Options:"
  49. echo "--patch-dir=<dir> The directory for working and output files (default '/tmp')"
  50. echo "--basedir=<dir> The directory to apply the patch to (default current directory)"
  51. echo "--mvn-cmd=<cmd> The 'mvn' command to use (default \$MAVEN_HOME/bin/mvn, or 'mvn')"
  52. echo "--ps-cmd=<cmd> The 'ps' command to use (default 'ps')"
  53. echo "--awk-cmd=<cmd> The 'awk' command to use (default 'awk')"
  54. echo "--svn-cmd=<cmd> The 'svn' command to use (default 'svn')"
  55. echo "--grep-cmd=<cmd> The 'grep' command to use (default 'grep')"
  56. echo "--patch-cmd=<cmd> The 'patch' command to use (default 'patch')"
  57. echo "--findbugs-home=<path> Findbugs home directory (default FINDBUGS_HOME environment variable)"
  58. echo "--forrest-home=<path> Forrest home directory (default FORREST_HOME environment variable)"
  59. echo "--dirty-workspace Allow the local SVN workspace to have uncommitted changes"
  60. echo "--run-tests Run all tests below the base directory"
  61. echo
  62. echo "Jenkins-only options:"
  63. echo "--jenkins Run by Jenkins (runs tests and posts results to JIRA)"
  64. echo "--support-dir=<dir> The directory to find support files in"
  65. echo "--wget-cmd=<cmd> The 'wget' command to use (default 'wget')"
  66. echo "--jira-cmd=<cmd> The 'jira' command to use (default 'jira')"
  67. echo "--jira-password=<pw> The password for the 'jira' command"
  68. echo "--eclipse-home=<path> Eclipse home directory (default ECLIPSE_HOME environment variable)"
  69. }
  70. ###############################################################################
  71. parseArgs() {
  72. for i in $*
  73. do
  74. case $i in
  75. --jenkins)
  76. JENKINS=true
  77. ;;
  78. --patch-dir=*)
  79. PATCH_DIR=${i#*=}
  80. ;;
  81. --support-dir=*)
  82. SUPPORT_DIR=${i#*=}
  83. ;;
  84. --basedir=*)
  85. BASEDIR=${i#*=}
  86. ;;
  87. --mvn-cmd=*)
  88. MVN=${i#*=}
  89. ;;
  90. --ps-cmd=*)
  91. PS=${i#*=}
  92. ;;
  93. --awk-cmd=*)
  94. AWK=${i#*=}
  95. ;;
  96. --wget-cmd=*)
  97. WGET=${i#*=}
  98. ;;
  99. --svn-cmd=*)
  100. SVN=${i#*=}
  101. ;;
  102. --grep-cmd=*)
  103. GREP=${i#*=}
  104. ;;
  105. --patch-cmd=*)
  106. PATCH=${i#*=}
  107. ;;
  108. --jira-cmd=*)
  109. JIRACLI=${i#*=}
  110. ;;
  111. --jira-password=*)
  112. JIRA_PASSWD=${i#*=}
  113. ;;
  114. --findbugs-home=*)
  115. FINDBUGS_HOME=${i#*=}
  116. ;;
  117. --forrest-home=*)
  118. FORREST_HOME=${i#*=}
  119. ;;
  120. --eclipse-home=*)
  121. ECLIPSE_HOME=${i#*=}
  122. ;;
  123. --dirty-workspace)
  124. DIRTY_WORKSPACE=true
  125. ;;
  126. --run-tests)
  127. RUN_TESTS=true
  128. ;;
  129. *)
  130. PATCH_OR_DEFECT=$i
  131. ;;
  132. esac
  133. done
  134. if [ -z "$PATCH_OR_DEFECT" ]; then
  135. printUsage
  136. exit 1
  137. fi
  138. if [[ $JENKINS == "true" ]] ; then
  139. echo "Running in Jenkins mode"
  140. defect=$PATCH_OR_DEFECT
  141. ECLIPSE_PROPERTY="-Declipse.home=$ECLIPSE_HOME"
  142. else
  143. echo "Running in developer mode"
  144. JENKINS=false
  145. ### PATCH_FILE contains the location of the patchfile
  146. PATCH_FILE=$PATCH_OR_DEFECT
  147. if [[ ! -e "$PATCH_FILE" ]] ; then
  148. echo "Unable to locate the patch file $PATCH_FILE"
  149. cleanupAndExit 0
  150. fi
  151. ### Check if $PATCH_DIR exists. If it does not exist, create a new directory
  152. if [[ ! -e "$PATCH_DIR" ]] ; then
  153. mkdir "$PATCH_DIR"
  154. if [[ $? == 0 ]] ; then
  155. echo "$PATCH_DIR has been created"
  156. else
  157. echo "Unable to create $PATCH_DIR"
  158. cleanupAndExit 0
  159. fi
  160. fi
  161. ### Obtain the patch filename to append it to the version number
  162. defect=`basename $PATCH_FILE`
  163. fi
  164. }
  165. ###############################################################################
  166. checkout () {
  167. echo ""
  168. echo ""
  169. echo "======================================================================"
  170. echo "======================================================================"
  171. echo " Testing patch for ${defect}."
  172. echo "======================================================================"
  173. echo "======================================================================"
  174. echo ""
  175. echo ""
  176. ### When run by a developer, if the workspace contains modifications, do not continue
  177. ### unless the --dirty-workspace option was set
  178. status=`$SVN stat --ignore-externals | sed -e '/^X[ ]*/D'`
  179. if [[ $JENKINS == "false" ]] ; then
  180. if [[ "$status" != "" && -z $DIRTY_WORKSPACE ]] ; then
  181. echo "ERROR: can't run in a workspace that contains the following modifications"
  182. echo "$status"
  183. cleanupAndExit 1
  184. fi
  185. echo
  186. else
  187. cd $BASEDIR
  188. $SVN revert -R .
  189. rm -rf `$SVN status --no-ignore`
  190. $SVN update
  191. fi
  192. return $?
  193. }
  194. ###############################################################################
  195. setup () {
  196. ### Download latest patch file (ignoring .htm and .html) when run from patch process
  197. if [[ $JENKINS == "true" ]] ; then
  198. $WGET -q -O $PATCH_DIR/jira http://issues.apache.org/jira/browse/$defect
  199. if [[ `$GREP -c 'Patch Available' $PATCH_DIR/jira` == 0 ]] ; then
  200. echo "$defect is not \"Patch Available\". Exiting."
  201. cleanupAndExit 0
  202. fi
  203. relativePatchURL=`$GREP -o '"/jira/secure/attachment/[0-9]*/[^"]*' $PATCH_DIR/jira | $GREP -v -e 'htm[l]*$' | sort | tail -1 | $GREP -o '/jira/secure/attachment/[0-9]*/[^"]*'`
  204. patchURL="http://issues.apache.org${relativePatchURL}"
  205. patchNum=`echo $patchURL | $GREP -o '[0-9]*/' | $GREP -o '[0-9]*'`
  206. echo "$defect patch is being downloaded at `date` from"
  207. echo "$patchURL"
  208. $WGET -q -O $PATCH_DIR/patch $patchURL
  209. VERSION=${SVN_REVISION}_${defect}_PATCH-${patchNum}
  210. JIRA_COMMENT="Here are the results of testing the latest attachment
  211. $patchURL
  212. against trunk revision ${SVN_REVISION}."
  213. ### Copy in any supporting files needed by this process
  214. cp -r $SUPPORT_DIR/lib/* ./lib
  215. #PENDING: cp -f $SUPPORT_DIR/etc/checkstyle* ./src/test
  216. ### Copy the patch file to $PATCH_DIR
  217. else
  218. VERSION=PATCH-${defect}
  219. cp $PATCH_FILE $PATCH_DIR/patch
  220. if [[ $? == 0 ]] ; then
  221. echo "Patch file $PATCH_FILE copied to $PATCH_DIR"
  222. else
  223. echo "Could not copy $PATCH_FILE to $PATCH_DIR"
  224. cleanupAndExit 0
  225. fi
  226. fi
  227. . $BASEDIR/dev-support/test-patch.properties
  228. ### exit if warnings are NOT defined in the properties file
  229. if [ -z "$OK_FINDBUGS_WARNINGS" ] || [[ -z "$OK_JAVADOC_WARNINGS" ]] || [[ -z $OK_RELEASEAUDIT_WARNINGS ]]; then
  230. echo "Please define the following properties in test-patch.properties file"
  231. echo "OK_FINDBUGS_WARNINGS"
  232. echo "OK_RELEASEAUDIT_WARNINGS"
  233. echo "OK_JAVADOC_WARNINGS"
  234. cleanupAndExit 1
  235. fi
  236. echo ""
  237. echo ""
  238. echo "======================================================================"
  239. echo "======================================================================"
  240. echo " Pre-build trunk to verify trunk stability and javac warnings"
  241. echo "======================================================================"
  242. echo "======================================================================"
  243. echo ""
  244. echo ""
  245. if [[ ! -d hadoop-common-project ]]; then
  246. cd $bindir/..
  247. echo "Compiling $(pwd)"
  248. echo "$MVN clean test -DskipTests > $PATCH_DIR/trunkCompile.txt 2>&1"
  249. $MVN clean test -DskipTests > $PATCH_DIR/trunkCompile.txt 2>&1
  250. if [[ $? != 0 ]] ; then
  251. echo "Top-level trunk compilation is broken?"
  252. cleanupAndExit 1
  253. fi
  254. cd -
  255. fi
  256. echo "Compiling $(pwd)"
  257. echo "$MVN clean test -DskipTests -D${PROJECT_NAME}PatchProcess -Ptest-patch > $PATCH_DIR/trunkJavacWarnings.txt 2>&1"
  258. $MVN clean test -DskipTests -D${PROJECT_NAME}PatchProcess -Ptest-patch > $PATCH_DIR/trunkJavacWarnings.txt 2>&1
  259. if [[ $? != 0 ]] ; then
  260. echo "Trunk compilation is broken?"
  261. cleanupAndExit 1
  262. fi
  263. }
  264. ###############################################################################
  265. ### Check for @author tags in the patch
  266. checkAuthor () {
  267. echo ""
  268. echo ""
  269. echo "======================================================================"
  270. echo "======================================================================"
  271. echo " Checking there are no @author tags in the patch."
  272. echo "======================================================================"
  273. echo "======================================================================"
  274. echo ""
  275. echo ""
  276. authorTags=`$GREP -c -i '@author' $PATCH_DIR/patch`
  277. echo "There appear to be $authorTags @author tags in the patch."
  278. if [[ $authorTags != 0 ]] ; then
  279. JIRA_COMMENT="$JIRA_COMMENT
  280. -1 @author. The patch appears to contain $authorTags @author tags which the Hadoop community has agreed to not allow in code contributions."
  281. return 1
  282. fi
  283. JIRA_COMMENT="$JIRA_COMMENT
  284. +1 @author. The patch does not contain any @author tags."
  285. return 0
  286. }
  287. ###############################################################################
  288. ### Check for tests in the patch
  289. checkTests () {
  290. echo ""
  291. echo ""
  292. echo "======================================================================"
  293. echo "======================================================================"
  294. echo " Checking there are new or changed tests in the patch."
  295. echo "======================================================================"
  296. echo "======================================================================"
  297. echo ""
  298. echo ""
  299. testReferences=`$GREP -c -i '/test' $PATCH_DIR/patch`
  300. echo "There appear to be $testReferences test files referenced in the patch."
  301. if [[ $testReferences == 0 ]] ; then
  302. if [[ $JENKINS == "true" ]] ; then
  303. patchIsDoc=`$GREP -c -i 'title="documentation' $PATCH_DIR/jira`
  304. if [[ $patchIsDoc != 0 ]] ; then
  305. echo "The patch appears to be a documentation patch that doesn't require tests."
  306. JIRA_COMMENT="$JIRA_COMMENT
  307. +0 tests included. The patch appears to be a documentation patch that doesn't require tests."
  308. return 0
  309. fi
  310. fi
  311. JIRA_COMMENT="$JIRA_COMMENT
  312. -1 tests included. The patch doesn't appear to include any new or modified tests.
  313. Please justify why no new tests are needed for this patch.
  314. Also please list what manual steps were performed to verify this patch."
  315. return 1
  316. fi
  317. JIRA_COMMENT="$JIRA_COMMENT
  318. +1 tests included. The patch appears to include $testReferences new or modified tests."
  319. return 0
  320. }
  321. cleanUpXml () {
  322. cd $BASEDIR/conf
  323. for file in `ls *.xml.template`
  324. do
  325. rm -f `basename $file .template`
  326. done
  327. cd $BASEDIR
  328. }
  329. ###############################################################################
  330. ### Attempt to apply the patch
  331. applyPatch () {
  332. echo ""
  333. echo ""
  334. echo "======================================================================"
  335. echo "======================================================================"
  336. echo " Applying patch."
  337. echo "======================================================================"
  338. echo "======================================================================"
  339. echo ""
  340. echo ""
  341. export PATCH
  342. $bindir/smart-apply-patch.sh $PATCH_DIR/patch
  343. if [[ $? != 0 ]] ; then
  344. echo "PATCH APPLICATION FAILED"
  345. JIRA_COMMENT="$JIRA_COMMENT
  346. -1 patch. The patch command could not apply the patch."
  347. return 1
  348. fi
  349. return 0
  350. }
  351. ###############################################################################
  352. ### Check there are no javadoc warnings
  353. checkJavadocWarnings () {
  354. echo ""
  355. echo ""
  356. echo "======================================================================"
  357. echo "======================================================================"
  358. echo " Determining number of patched javadoc warnings."
  359. echo "======================================================================"
  360. echo "======================================================================"
  361. echo ""
  362. echo ""
  363. echo "$MVN clean test javadoc:javadoc -DskipTests -Pdocs -D${PROJECT_NAME}PatchProcess > $PATCH_DIR/patchJavadocWarnings.txt 2>&1"
  364. if [ -d hadoop-project ]; then
  365. (cd hadoop-project; $MVN install)
  366. fi
  367. if [ -d hadoop-common-project/hadoop-annotations ]; then
  368. (cd hadoop-common-project/hadoop-annotations; $MVN install)
  369. fi
  370. $MVN clean test javadoc:javadoc -DskipTests -Pdocs -D${PROJECT_NAME}PatchProcess > $PATCH_DIR/patchJavadocWarnings.txt 2>&1
  371. javadocWarnings=`$GREP '\[WARNING\]' $PATCH_DIR/patchJavadocWarnings.txt | $AWK '/Javadoc Warnings/,EOF' | $GREP warning | $AWK 'BEGIN {total = 0} {total += 1} END {print total}'`
  372. echo ""
  373. echo ""
  374. echo "There appear to be $javadocWarnings javadoc warnings generated by the patched build."
  375. ### if current warnings greater than OK_JAVADOC_WARNINGS
  376. if [[ $javadocWarnings > $OK_JAVADOC_WARNINGS ]] ; then
  377. JIRA_COMMENT="$JIRA_COMMENT
  378. -1 javadoc. The javadoc tool appears to have generated `expr $(($javadocWarnings-$OK_JAVADOC_WARNINGS))` warning messages."
  379. return 1
  380. fi
  381. JIRA_COMMENT="$JIRA_COMMENT
  382. +1 javadoc. The javadoc tool did not generate any warning messages."
  383. return 0
  384. }
  385. ###############################################################################
  386. ### Check there are no changes in the number of Javac warnings
  387. checkJavacWarnings () {
  388. echo ""
  389. echo ""
  390. echo "======================================================================"
  391. echo "======================================================================"
  392. echo " Determining number of patched javac warnings."
  393. echo "======================================================================"
  394. echo "======================================================================"
  395. echo ""
  396. echo ""
  397. echo "$MVN clean test -DskipTests -D${PROJECT_NAME}PatchProcess -Ptest-patch > $PATCH_DIR/patchJavacWarnings.txt 2>&1"
  398. $MVN clean test -DskipTests -D${PROJECT_NAME}PatchProcess -Ptest-patch > $PATCH_DIR/patchJavacWarnings.txt 2>&1
  399. if [[ $? != 0 ]] ; then
  400. JIRA_COMMENT="$JIRA_COMMENT
  401. -1 javac. The patch appears to cause tar ant target to fail."
  402. return 1
  403. fi
  404. ### Compare trunk and patch javac warning numbers
  405. if [[ -f $PATCH_DIR/patchJavacWarnings.txt ]] ; then
  406. trunkJavacWarnings=`$GREP '\[WARNING\]' $PATCH_DIR/trunkJavacWarnings.txt | $AWK 'BEGIN {total = 0} {total += 1} END {print total}'`
  407. patchJavacWarnings=`$GREP '\[WARNING\]' $PATCH_DIR/patchJavacWarnings.txt | $AWK 'BEGIN {total = 0} {total += 1} END {print total}'`
  408. echo "There appear to be $trunkJavacWarnings javac compiler warnings before the patch and $patchJavacWarnings javac compiler warnings after applying the patch."
  409. if [[ $patchJavacWarnings != "" && $trunkJavacWarnings != "" ]] ; then
  410. if [[ $patchJavacWarnings -gt $trunkJavacWarnings ]] ; then
  411. JIRA_COMMENT="$JIRA_COMMENT
  412. -1 javac. The applied patch generated $patchJavacWarnings javac compiler warnings (more than the trunk's current $trunkJavacWarnings warnings)."
  413. return 1
  414. fi
  415. fi
  416. fi
  417. JIRA_COMMENT="$JIRA_COMMENT
  418. +1 javac. The applied patch does not increase the total number of javac compiler warnings."
  419. return 0
  420. }
  421. ###############################################################################
  422. ### Check there are no changes in the number of release audit (RAT) warnings
  423. checkReleaseAuditWarnings () {
  424. echo ""
  425. echo ""
  426. echo "======================================================================"
  427. echo "======================================================================"
  428. echo " Determining number of patched release audit warnings."
  429. echo "======================================================================"
  430. echo "======================================================================"
  431. echo ""
  432. echo ""
  433. echo "$MVN apache-rat:check -D${PROJECT_NAME}PatchProcess 2>&1"
  434. $MVN apache-rat:check -D${PROJECT_NAME}PatchProcess 2>&1
  435. find $BASEDIR -name rat.txt | xargs cat > $PATCH_DIR/patchReleaseAuditWarnings.txt
  436. ### Compare trunk and patch release audit warning numbers
  437. if [[ -f $PATCH_DIR/patchReleaseAuditWarnings.txt ]] ; then
  438. patchReleaseAuditWarnings=`$GREP -c '\!?????' $PATCH_DIR/patchReleaseAuditWarnings.txt`
  439. echo ""
  440. echo ""
  441. echo "There appear to be $OK_RELEASEAUDIT_WARNINGS release audit warnings before the patch and $patchReleaseAuditWarnings release audit warnings after applying the patch."
  442. if [[ $patchReleaseAuditWarnings != "" && $OK_RELEASEAUDIT_WARNINGS != "" ]] ; then
  443. if [[ $patchReleaseAuditWarnings -gt $OK_RELEASEAUDIT_WARNINGS ]] ; then
  444. JIRA_COMMENT="$JIRA_COMMENT
  445. -1 release audit. The applied patch generated $patchReleaseAuditWarnings release audit warnings (more than the trunk's current $OK_RELEASEAUDIT_WARNINGS warnings)."
  446. $GREP '\!?????' $PATCH_DIR/patchReleaseAuditWarnings.txt > $PATCH_DIR/patchReleaseAuditProblems.txt
  447. echo "Lines that start with ????? in the release audit report indicate files that do not have an Apache license header." >> $PATCH_DIR/patchReleaseAuditProblems.txt
  448. JIRA_COMMENT_FOOTER="Release audit warnings: $BUILD_URL/artifact/trunk/patchprocess/patchReleaseAuditProblems.txt
  449. $JIRA_COMMENT_FOOTER"
  450. return 1
  451. fi
  452. fi
  453. fi
  454. JIRA_COMMENT="$JIRA_COMMENT
  455. +1 release audit. The applied patch does not increase the total number of release audit warnings."
  456. return 0
  457. }
  458. ###############################################################################
  459. ### Check there are no changes in the number of Checkstyle warnings
  460. checkStyle () {
  461. echo ""
  462. echo ""
  463. echo "======================================================================"
  464. echo "======================================================================"
  465. echo " Determining number of patched checkstyle warnings."
  466. echo "======================================================================"
  467. echo "======================================================================"
  468. echo ""
  469. echo ""
  470. echo "THIS IS NOT IMPLEMENTED YET"
  471. echo ""
  472. echo ""
  473. echo "$MVN test checkstyle:checkstyle -DskipTests -D${PROJECT_NAME}PatchProcess"
  474. $MVN test checkstyle:checkstyle -DskipTests -D${PROJECT_NAME}PatchProcess
  475. JIRA_COMMENT_FOOTER="Checkstyle results: $BUILD_URL/artifact/trunk/build/test/checkstyle-errors.html
  476. $JIRA_COMMENT_FOOTER"
  477. ### TODO: calculate actual patchStyleErrors
  478. # patchStyleErrors=0
  479. # if [[ $patchStyleErrors != 0 ]] ; then
  480. # JIRA_COMMENT="$JIRA_COMMENT
  481. #
  482. # -1 checkstyle. The patch generated $patchStyleErrors code style errors."
  483. # return 1
  484. # fi
  485. # JIRA_COMMENT="$JIRA_COMMENT
  486. #
  487. # +1 checkstyle. The patch generated 0 code style errors."
  488. return 0
  489. }
  490. ###############################################################################
  491. ### Check there are no changes in the number of Findbugs warnings
  492. checkFindbugsWarnings () {
  493. findbugs_version=`${FINDBUGS_HOME}/bin/findbugs -version`
  494. echo ""
  495. echo ""
  496. echo "======================================================================"
  497. echo "======================================================================"
  498. echo " Determining number of patched Findbugs warnings."
  499. echo "======================================================================"
  500. echo "======================================================================"
  501. echo ""
  502. echo ""
  503. echo "$MVN clean test findbugs:findbugs -DskipTests -D${PROJECT_NAME}PatchProcess"
  504. $MVN clean test findbugs:findbugs -DskipTests -D${PROJECT_NAME}PatchProcess < /dev/null
  505. if [ $? != 0 ] ; then
  506. JIRA_COMMENT="$JIRA_COMMENT
  507. -1 findbugs. The patch appears to cause Findbugs (version ${findbugs_version}) to fail."
  508. return 1
  509. fi
  510. findbugsWarnings=0
  511. for file in $(find $BASEDIR -name findbugsXml.xml)
  512. do
  513. relative_file=${file#$BASEDIR/} # strip leading $BASEDIR prefix
  514. if [ ! $relative_file == "target/findbugsXml.xml" ]; then
  515. module_suffix=${relative_file%/target/findbugsXml.xml} # strip trailing path
  516. module_suffix=`basename ${module_suffix}`
  517. fi
  518. cp $file $PATCH_DIR/patchFindbugsWarnings${module_suffix}.xml
  519. $FINDBUGS_HOME/bin/setBugDatabaseInfo -timestamp "01/01/2000" \
  520. $PATCH_DIR/patchFindbugsWarnings${module_suffix}.xml \
  521. $PATCH_DIR/patchFindbugsWarnings${module_suffix}.xml
  522. newFindbugsWarnings=`$FINDBUGS_HOME/bin/filterBugs -first "01/01/2000" $PATCH_DIR/patchFindbugsWarnings${module_suffix}.xml \
  523. $PATCH_DIR/newPatchFindbugsWarnings${module_suffix}.xml | $AWK '{print $1}'`
  524. echo "Found $newFindbugsWarnings Findbugs warnings ($file)"
  525. findbugsWarnings=$((findbugsWarnings+newFindbugsWarnings))
  526. $FINDBUGS_HOME/bin/convertXmlToText -html \
  527. $PATCH_DIR/newPatchFindbugsWarnings${module_suffix}.xml \
  528. $PATCH_DIR/newPatchFindbugsWarnings${module_suffix}.html
  529. if [[ $newFindbugsWarnings > 0 ]] ; then
  530. JIRA_COMMENT_FOOTER="Findbugs warnings: $BUILD_URL/artifact/trunk/$(basename $BASEDIR)/patchprocess/newPatchFindbugsWarnings${module_suffix}.html
  531. $JIRA_COMMENT_FOOTER"
  532. fi
  533. done
  534. ### if current warnings greater than OK_FINDBUGS_WARNINGS
  535. if [[ $findbugsWarnings > $OK_FINDBUGS_WARNINGS ]] ; then
  536. JIRA_COMMENT="$JIRA_COMMENT
  537. -1 findbugs. The patch appears to introduce `expr $(($findbugsWarnings-$OK_FINDBUGS_WARNINGS))` new Findbugs (version ${findbugs_version}) warnings."
  538. return 1
  539. fi
  540. JIRA_COMMENT="$JIRA_COMMENT
  541. +1 findbugs. The patch does not introduce any new Findbugs (version ${findbugs_version}) warnings."
  542. return 0
  543. }
  544. ###############################################################################
  545. ### Run the tests
  546. runTests () {
  547. echo ""
  548. echo ""
  549. echo "======================================================================"
  550. echo "======================================================================"
  551. echo " Running tests."
  552. echo "======================================================================"
  553. echo "======================================================================"
  554. echo ""
  555. echo ""
  556. echo "$MVN clean install test -Pnative -D${PROJECT_NAME}PatchProcess"
  557. $MVN clean install test -Pnative -D${PROJECT_NAME}PatchProcess
  558. if [[ $? != 0 ]] ; then
  559. ### Find and format names of failed tests
  560. failed_tests=`find . -name 'TEST*.xml' | xargs $GREP -l -E "<failure|<error" | sed -e "s|.*target/surefire-reports/TEST-| |g" | sed -e "s|\.xml||g"`
  561. fi
  562. if [[ -n "$failed_tests" ]] ; then
  563. JIRA_COMMENT="$JIRA_COMMENT
  564. -1 core tests. The patch failed these unit tests:
  565. $failed_tests"
  566. return 1
  567. fi
  568. JIRA_COMMENT="$JIRA_COMMENT
  569. +1 core tests. The patch passed unit tests in $modules."
  570. return 0
  571. }
  572. ###############################################################################
  573. ### Run the test-contrib target
  574. runContribTests () {
  575. echo ""
  576. echo ""
  577. echo "======================================================================"
  578. echo "======================================================================"
  579. echo " Running contrib tests."
  580. echo "======================================================================"
  581. echo "======================================================================"
  582. echo ""
  583. echo ""
  584. if [[ `$GREP -c 'test-contrib' build.xml` == 0 ]] ; then
  585. echo "No contrib tests in this project."
  586. return 0
  587. fi
  588. ### Kill any rogue build processes from the last attempt
  589. $PS auxwww | $GREP ${PROJECT_NAME}PatchProcess | $AWK '{print $2}' | /usr/bin/xargs -t -I {} /bin/kill -9 {} > /dev/null
  590. #echo "$ANT_HOME/bin/ant -Dversion="${VERSION}" $ECLIPSE_PROPERTY -DHadoopPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=no test-contrib"
  591. #$ANT_HOME/bin/ant -Dversion="${VERSION}" $ECLIPSE_PROPERTY -DHadoopPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=no test-contrib
  592. echo "NOP"
  593. if [[ $? != 0 ]] ; then
  594. JIRA_COMMENT="$JIRA_COMMENT
  595. -1 contrib tests. The patch failed contrib unit tests."
  596. return 1
  597. fi
  598. JIRA_COMMENT="$JIRA_COMMENT
  599. +1 contrib tests. The patch passed contrib unit tests."
  600. return 0
  601. }
  602. ###############################################################################
  603. ### Run the inject-system-faults target
  604. checkInjectSystemFaults () {
  605. echo ""
  606. echo ""
  607. echo "======================================================================"
  608. echo "======================================================================"
  609. echo " Checking the integrity of system test framework code."
  610. echo "======================================================================"
  611. echo "======================================================================"
  612. echo ""
  613. echo ""
  614. ### Kill any rogue build processes from the last attempt
  615. $PS auxwww | $GREP ${PROJECT_NAME}PatchProcess | $AWK '{print $2}' | /usr/bin/xargs -t -I {} /bin/kill -9 {} > /dev/null
  616. #echo "$ANT_HOME/bin/ant -Dversion="${VERSION}" -DHadoopPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=no -Dcompile.c++=yes -Dforrest.home=$FORREST_HOME inject-system-faults"
  617. #$ANT_HOME/bin/ant -Dversion="${VERSION}" -DHadoopPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=no -Dcompile.c++=yes -Dforrest.home=$FORREST_HOME inject-system-faults
  618. echo "NOP"
  619. return 0
  620. if [[ $? != 0 ]] ; then
  621. JIRA_COMMENT="$JIRA_COMMENT
  622. -1 system test framework. The patch failed system test framework compile."
  623. return 1
  624. fi
  625. JIRA_COMMENT="$JIRA_COMMENT
  626. +1 system test framework. The patch passed system test framework compile."
  627. return 0
  628. }
  629. ###############################################################################
  630. ### Submit a comment to the defect's Jira
  631. submitJiraComment () {
  632. local result=$1
  633. ### Do not output the value of JIRA_COMMENT_FOOTER when run by a developer
  634. if [[ $JENKINS == "false" ]] ; then
  635. JIRA_COMMENT_FOOTER=""
  636. fi
  637. if [[ $result == 0 ]] ; then
  638. comment="+1 overall. $JIRA_COMMENT
  639. $JIRA_COMMENT_FOOTER"
  640. else
  641. comment="-1 overall. $JIRA_COMMENT
  642. $JIRA_COMMENT_FOOTER"
  643. fi
  644. ### Output the test result to the console
  645. echo "
  646. $comment"
  647. if [[ $JENKINS == "true" ]] ; then
  648. echo ""
  649. echo ""
  650. echo "======================================================================"
  651. echo "======================================================================"
  652. echo " Adding comment to Jira."
  653. echo "======================================================================"
  654. echo "======================================================================"
  655. echo ""
  656. echo ""
  657. ### Update Jira with a comment
  658. export USER=hudson
  659. $JIRACLI -s https://issues.apache.org/jira -a addcomment -u hadoopqa -p $JIRA_PASSWD --comment "$comment" --issue $defect
  660. $JIRACLI -s https://issues.apache.org/jira -a logout -u hadoopqa -p $JIRA_PASSWD
  661. fi
  662. }
  663. ###############################################################################
  664. ### Cleanup files
  665. cleanupAndExit () {
  666. local result=$1
  667. if [[ $JENKINS == "true" ]] ; then
  668. if [ -e "$PATCH_DIR" ] ; then
  669. mv $PATCH_DIR $BASEDIR
  670. fi
  671. fi
  672. echo ""
  673. echo ""
  674. echo "======================================================================"
  675. echo "======================================================================"
  676. echo " Finished build."
  677. echo "======================================================================"
  678. echo "======================================================================"
  679. echo ""
  680. echo ""
  681. exit $result
  682. }
  683. ###############################################################################
  684. ###############################################################################
  685. ###############################################################################
  686. JIRA_COMMENT=""
  687. JIRA_COMMENT_FOOTER="Console output: $BUILD_URL/console
  688. This message is automatically generated."
  689. ### Check if arguments to the script have been specified properly or not
  690. parseArgs $@
  691. cd $BASEDIR
  692. checkout
  693. RESULT=$?
  694. if [[ $JENKINS == "true" ]] ; then
  695. if [[ $RESULT != 0 ]] ; then
  696. exit 100
  697. fi
  698. fi
  699. setup
  700. checkAuthor
  701. RESULT=$?
  702. if [[ $JENKINS == "true" ]] ; then
  703. cleanUpXml
  704. fi
  705. checkTests
  706. (( RESULT = RESULT + $? ))
  707. applyPatch
  708. if [[ $? != 0 ]] ; then
  709. submitJiraComment 1
  710. cleanupAndExit 1
  711. fi
  712. checkJavadocWarnings
  713. (( RESULT = RESULT + $? ))
  714. checkJavacWarnings
  715. (( RESULT = RESULT + $? ))
  716. ### Checkstyle not implemented yet
  717. #checkStyle
  718. #(( RESULT = RESULT + $? ))
  719. checkFindbugsWarnings
  720. (( RESULT = RESULT + $? ))
  721. checkReleaseAuditWarnings
  722. (( RESULT = RESULT + $? ))
  723. ### Run tests for Jenkins or if explictly asked for by a developer
  724. if [[ $JENKINS == "true" || $RUN_TESTS == "true" ]] ; then
  725. runTests
  726. (( RESULT = RESULT + $? ))
  727. runContribTests
  728. (( RESULT = RESULT + $? ))
  729. fi
  730. checkInjectSystemFaults
  731. (( RESULT = RESULT + $? ))
  732. JIRA_COMMENT_FOOTER="Test results: $BUILD_URL/testReport/
  733. $JIRA_COMMENT_FOOTER"
  734. submitJiraComment $RESULT
  735. cleanupAndExit $RESULT