test-patch.sh 31 KB

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