test-patch.sh 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  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. ### BUILD_URL is 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. GIT=${GIT:-git}
  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 "--git-cmd=<cmd> The 'git' command to use (default 'git')"
  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 git 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. --git-cmd=*)
  100. GIT=${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=`$GIT status --porcelain`
  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. $GIT reset --hard
  189. $GIT clean -xdf
  190. $GIT checkout trunk
  191. $GIT pull --rebase
  192. fi
  193. GIT_REVISION=`git rev-parse --verify --short HEAD`
  194. return $?
  195. }
  196. ###############################################################################
  197. setup () {
  198. ### Download latest patch file (ignoring .htm and .html) when run from patch process
  199. if [[ $JENKINS == "true" ]] ; then
  200. $WGET -q -O $PATCH_DIR/jira http://issues.apache.org/jira/browse/$defect
  201. if [[ `$GREP -c 'Patch Available' $PATCH_DIR/jira` == 0 ]] ; then
  202. echo "$defect is not \"Patch Available\". Exiting."
  203. cleanupAndExit 0
  204. fi
  205. 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]*/[^"]*'`
  206. patchURL="http://issues.apache.org${relativePatchURL}"
  207. patchNum=`echo $patchURL | $GREP -o '[0-9]*/' | $GREP -o '[0-9]*'`
  208. echo "$defect patch is being downloaded at `date` from"
  209. echo "$patchURL"
  210. $WGET -q -O $PATCH_DIR/patch $patchURL
  211. VERSION=${GIT_REVISION}_${defect}_PATCH-${patchNum}
  212. JIRA_COMMENT="Here are the results of testing the latest attachment
  213. $patchURL
  214. against trunk revision ${GIT_REVISION}."
  215. ### Copy in any supporting files needed by this process
  216. cp -r $SUPPORT_DIR/lib/* ./lib
  217. #PENDING: cp -f $SUPPORT_DIR/etc/checkstyle* ./src/test
  218. ### Copy the patch file to $PATCH_DIR
  219. else
  220. VERSION=PATCH-${defect}
  221. cp $PATCH_FILE $PATCH_DIR/patch
  222. if [[ $? == 0 ]] ; then
  223. echo "Patch file $PATCH_FILE copied to $PATCH_DIR"
  224. else
  225. echo "Could not copy $PATCH_FILE to $PATCH_DIR"
  226. cleanupAndExit 0
  227. fi
  228. fi
  229. . $BASEDIR/dev-support/test-patch.properties
  230. ### exit if warnings are NOT defined in the properties file
  231. if [ -z "$OK_FINDBUGS_WARNINGS" ] || [[ -z "$OK_JAVADOC_WARNINGS" ]] || [[ -z $OK_RELEASEAUDIT_WARNINGS ]]; then
  232. echo "Please define the following properties in test-patch.properties file"
  233. echo "OK_FINDBUGS_WARNINGS"
  234. echo "OK_RELEASEAUDIT_WARNINGS"
  235. echo "OK_JAVADOC_WARNINGS"
  236. cleanupAndExit 1
  237. fi
  238. echo ""
  239. echo ""
  240. echo "======================================================================"
  241. echo "======================================================================"
  242. echo " Pre-build trunk to verify trunk stability and javac warnings"
  243. echo "======================================================================"
  244. echo "======================================================================"
  245. echo ""
  246. echo ""
  247. if [[ ! -d hadoop-common-project ]]; then
  248. cd $bindir/..
  249. echo "Compiling $(pwd)"
  250. echo "$MVN clean test -DskipTests > $PATCH_DIR/trunkCompile.txt 2>&1"
  251. $MVN clean test -DskipTests > $PATCH_DIR/trunkCompile.txt 2>&1
  252. if [[ $? != 0 ]] ; then
  253. echo "Top-level trunk compilation is broken?"
  254. cleanupAndExit 1
  255. fi
  256. cd -
  257. fi
  258. echo "Compiling $(pwd)"
  259. echo "$MVN clean test -DskipTests -D${PROJECT_NAME}PatchProcess -Ptest-patch > $PATCH_DIR/trunkJavacWarnings.txt 2>&1"
  260. $MVN clean test -DskipTests -D${PROJECT_NAME}PatchProcess -Ptest-patch > $PATCH_DIR/trunkJavacWarnings.txt 2>&1
  261. if [[ $? != 0 ]] ; then
  262. echo "Trunk compilation is broken?"
  263. cleanupAndExit 1
  264. fi
  265. }
  266. ###############################################################################
  267. ### Check for @author tags in the patch
  268. checkAuthor () {
  269. echo ""
  270. echo ""
  271. echo "======================================================================"
  272. echo "======================================================================"
  273. echo " Checking there are no @author tags in the patch."
  274. echo "======================================================================"
  275. echo "======================================================================"
  276. echo ""
  277. echo ""
  278. authorTags=`$GREP -c -i '@author' $PATCH_DIR/patch`
  279. echo "There appear to be $authorTags @author tags in the patch."
  280. if [[ $authorTags != 0 ]] ; then
  281. JIRA_COMMENT="$JIRA_COMMENT
  282. -1 @author. The patch appears to contain $authorTags @author tags which the Hadoop community has agreed to not allow in code contributions."
  283. return 1
  284. fi
  285. JIRA_COMMENT="$JIRA_COMMENT
  286. +1 @author. The patch does not contain any @author tags."
  287. return 0
  288. }
  289. ###############################################################################
  290. ### Check for tests in the patch
  291. checkTests () {
  292. echo ""
  293. echo ""
  294. echo "======================================================================"
  295. echo "======================================================================"
  296. echo " Checking there are new or changed tests in the patch."
  297. echo "======================================================================"
  298. echo "======================================================================"
  299. echo ""
  300. echo ""
  301. testReferences=`$GREP -c -i '/test' $PATCH_DIR/patch`
  302. echo "There appear to be $testReferences test files referenced in the patch."
  303. if [[ $testReferences == 0 ]] ; then
  304. if [[ $JENKINS == "true" ]] ; then
  305. patchIsDoc=`$GREP -c -i 'title="documentation' $PATCH_DIR/jira`
  306. if [[ $patchIsDoc != 0 ]] ; then
  307. echo "The patch appears to be a documentation patch that doesn't require tests."
  308. JIRA_COMMENT="$JIRA_COMMENT
  309. +0 tests included. The patch appears to be a documentation patch that doesn't require tests."
  310. return 0
  311. fi
  312. fi
  313. JIRA_COMMENT="$JIRA_COMMENT
  314. -1 tests included. The patch doesn't appear to include any new or modified tests.
  315. Please justify why no new tests are needed for this patch.
  316. Also please list what manual steps were performed to verify this patch."
  317. return 1
  318. fi
  319. JIRA_COMMENT="$JIRA_COMMENT
  320. +1 tests included. The patch appears to include $testReferences new or modified tests."
  321. return 0
  322. }
  323. cleanUpXml () {
  324. cd $BASEDIR/conf
  325. for file in `ls *.xml.template`
  326. do
  327. rm -f `basename $file .template`
  328. done
  329. cd $BASEDIR
  330. }
  331. ###############################################################################
  332. ### Attempt to apply the patch
  333. applyPatch () {
  334. echo ""
  335. echo ""
  336. echo "======================================================================"
  337. echo "======================================================================"
  338. echo " Applying patch."
  339. echo "======================================================================"
  340. echo "======================================================================"
  341. echo ""
  342. echo ""
  343. export PATCH
  344. $bindir/smart-apply-patch.sh $PATCH_DIR/patch
  345. if [[ $? != 0 ]] ; then
  346. echo "PATCH APPLICATION FAILED"
  347. JIRA_COMMENT="$JIRA_COMMENT
  348. -1 patch. The patch command could not apply the patch."
  349. return 1
  350. fi
  351. return 0
  352. }
  353. ###############################################################################
  354. ### Check there are no javadoc warnings
  355. checkJavadocWarnings () {
  356. echo ""
  357. echo ""
  358. echo "======================================================================"
  359. echo "======================================================================"
  360. echo " Determining number of patched javadoc warnings."
  361. echo "======================================================================"
  362. echo "======================================================================"
  363. echo ""
  364. echo ""
  365. echo "$MVN clean test javadoc:javadoc -DskipTests -Pdocs -D${PROJECT_NAME}PatchProcess > $PATCH_DIR/patchJavadocWarnings.txt 2>&1"
  366. if [ -d hadoop-project ]; then
  367. (cd hadoop-project; $MVN install)
  368. fi
  369. if [ -d hadoop-common-project/hadoop-annotations ]; then
  370. (cd hadoop-common-project/hadoop-annotations; $MVN install)
  371. fi
  372. $MVN clean test javadoc:javadoc -DskipTests -Pdocs -D${PROJECT_NAME}PatchProcess > $PATCH_DIR/patchJavadocWarnings.txt 2>&1
  373. javadocWarnings=`$GREP '\[WARNING\]' $PATCH_DIR/patchJavadocWarnings.txt | $AWK '/Javadoc Warnings/,EOF' | $GREP warning | $AWK 'BEGIN {total = 0} {total += 1} END {print total}'`
  374. echo ""
  375. echo ""
  376. echo "There appear to be $javadocWarnings javadoc warnings generated by the patched build."
  377. #There are 12 warnings that are caused by things that are caused by using sun internal APIs.
  378. #There are 2 warnings that are caused by the Apache DS Dn class used in MiniKdc.
  379. OK_JAVADOC_WARNINGS=14;
  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 -Pnative -Ptest-patch > $PATCH_DIR/patchJavacWarnings.txt 2>&1"
  403. $MVN clean test -DskipTests -D${PROJECT_NAME}PatchProcess -Pnative -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. trunkJavacWarnings=`$GREP '\[WARNING\]' $PATCH_DIR/trunkJavacWarnings.txt | $AWK 'BEGIN {total = 0} {total += 1} END {print total}'`
  412. patchJavacWarnings=`$GREP '\[WARNING\]' $PATCH_DIR/patchJavacWarnings.txt | $AWK 'BEGIN {total = 0} {total += 1} END {print total}'`
  413. echo "There appear to be $trunkJavacWarnings javac compiler warnings before the patch and $patchJavacWarnings javac compiler warnings after applying the patch."
  414. if [[ $patchJavacWarnings != "" && $trunkJavacWarnings != "" ]] ; then
  415. if [[ $patchJavacWarnings -gt $trunkJavacWarnings ]] ; then
  416. JIRA_COMMENT="$JIRA_COMMENT
  417. -1 javac. The applied patch generated $patchJavacWarnings javac compiler warnings (more than the trunk's current $trunkJavacWarnings warnings)."
  418. return 1
  419. fi
  420. fi
  421. fi
  422. JIRA_COMMENT="$JIRA_COMMENT
  423. +1 javac. The applied patch does not increase the total number of javac compiler warnings."
  424. return 0
  425. }
  426. ###############################################################################
  427. ### Check there are no changes in the number of release audit (RAT) warnings
  428. checkReleaseAuditWarnings () {
  429. echo ""
  430. echo ""
  431. echo "======================================================================"
  432. echo "======================================================================"
  433. echo " Determining number of patched release audit warnings."
  434. echo "======================================================================"
  435. echo "======================================================================"
  436. echo ""
  437. echo ""
  438. echo "$MVN apache-rat:check -D${PROJECT_NAME}PatchProcess 2>&1"
  439. $MVN apache-rat:check -D${PROJECT_NAME}PatchProcess 2>&1
  440. find $BASEDIR -name rat.txt | xargs cat > $PATCH_DIR/patchReleaseAuditWarnings.txt
  441. ### Compare trunk and patch release audit warning numbers
  442. if [[ -f $PATCH_DIR/patchReleaseAuditWarnings.txt ]] ; then
  443. patchReleaseAuditWarnings=`$GREP -c '\!?????' $PATCH_DIR/patchReleaseAuditWarnings.txt`
  444. echo ""
  445. echo ""
  446. echo "There appear to be $OK_RELEASEAUDIT_WARNINGS release audit warnings before the patch and $patchReleaseAuditWarnings release audit warnings after applying the patch."
  447. if [[ $patchReleaseAuditWarnings != "" && $OK_RELEASEAUDIT_WARNINGS != "" ]] ; then
  448. if [[ $patchReleaseAuditWarnings -gt $OK_RELEASEAUDIT_WARNINGS ]] ; then
  449. JIRA_COMMENT="$JIRA_COMMENT
  450. -1 release audit. The applied patch generated $patchReleaseAuditWarnings release audit warnings (more than the trunk's current $OK_RELEASEAUDIT_WARNINGS warnings)."
  451. $GREP '\!?????' $PATCH_DIR/patchReleaseAuditWarnings.txt > $PATCH_DIR/patchReleaseAuditProblems.txt
  452. echo "Lines that start with ????? in the release audit report indicate files that do not have an Apache license header." >> $PATCH_DIR/patchReleaseAuditProblems.txt
  453. JIRA_COMMENT_FOOTER="Release audit warnings: $BUILD_URL/artifact/trunk/patchprocess/patchReleaseAuditProblems.txt
  454. $JIRA_COMMENT_FOOTER"
  455. return 1
  456. fi
  457. fi
  458. fi
  459. JIRA_COMMENT="$JIRA_COMMENT
  460. +1 release audit. The applied patch does not increase the total number of release audit warnings."
  461. return 0
  462. }
  463. ###############################################################################
  464. ### Check there are no changes in the number of Checkstyle warnings
  465. checkStyle () {
  466. echo ""
  467. echo ""
  468. echo "======================================================================"
  469. echo "======================================================================"
  470. echo " Determining number of patched checkstyle warnings."
  471. echo "======================================================================"
  472. echo "======================================================================"
  473. echo ""
  474. echo ""
  475. echo "THIS IS NOT IMPLEMENTED YET"
  476. echo ""
  477. echo ""
  478. echo "$MVN test checkstyle:checkstyle -DskipTests -D${PROJECT_NAME}PatchProcess"
  479. $MVN test checkstyle:checkstyle -DskipTests -D${PROJECT_NAME}PatchProcess
  480. JIRA_COMMENT_FOOTER="Checkstyle results: $BUILD_URL/artifact/trunk/build/test/checkstyle-errors.html
  481. $JIRA_COMMENT_FOOTER"
  482. ### TODO: calculate actual patchStyleErrors
  483. # patchStyleErrors=0
  484. # if [[ $patchStyleErrors != 0 ]] ; then
  485. # JIRA_COMMENT="$JIRA_COMMENT
  486. #
  487. # -1 checkstyle. The patch generated $patchStyleErrors code style errors."
  488. # return 1
  489. # fi
  490. # JIRA_COMMENT="$JIRA_COMMENT
  491. #
  492. # +1 checkstyle. The patch generated 0 code style errors."
  493. return 0
  494. }
  495. ###############################################################################
  496. ### Check there are no changes in the number of Findbugs warnings
  497. checkFindbugsWarnings () {
  498. findbugs_version=`${FINDBUGS_HOME}/bin/findbugs -version`
  499. echo ""
  500. echo ""
  501. echo "======================================================================"
  502. echo "======================================================================"
  503. echo " Determining number of patched Findbugs warnings."
  504. echo "======================================================================"
  505. echo "======================================================================"
  506. echo ""
  507. echo ""
  508. echo "$MVN clean test findbugs:findbugs -DskipTests -D${PROJECT_NAME}PatchProcess"
  509. $MVN clean test findbugs:findbugs -DskipTests -D${PROJECT_NAME}PatchProcess < /dev/null
  510. if [ $? != 0 ] ; then
  511. JIRA_COMMENT="$JIRA_COMMENT
  512. -1 findbugs. The patch appears to cause Findbugs (version ${findbugs_version}) to fail."
  513. return 1
  514. fi
  515. findbugsWarnings=0
  516. for file in $(find $BASEDIR -name findbugsXml.xml)
  517. do
  518. relative_file=${file#$BASEDIR/} # strip leading $BASEDIR prefix
  519. if [ ! $relative_file == "target/findbugsXml.xml" ]; then
  520. module_suffix=${relative_file%/target/findbugsXml.xml} # strip trailing path
  521. module_suffix=`basename ${module_suffix}`
  522. fi
  523. cp $file $PATCH_DIR/patchFindbugsWarnings${module_suffix}.xml
  524. $FINDBUGS_HOME/bin/setBugDatabaseInfo -timestamp "01/01/2000" \
  525. $PATCH_DIR/patchFindbugsWarnings${module_suffix}.xml \
  526. $PATCH_DIR/patchFindbugsWarnings${module_suffix}.xml
  527. newFindbugsWarnings=`$FINDBUGS_HOME/bin/filterBugs -first "01/01/2000" $PATCH_DIR/patchFindbugsWarnings${module_suffix}.xml \
  528. $PATCH_DIR/newPatchFindbugsWarnings${module_suffix}.xml | $AWK '{print $1}'`
  529. echo "Found $newFindbugsWarnings Findbugs warnings ($file)"
  530. findbugsWarnings=$((findbugsWarnings+newFindbugsWarnings))
  531. $FINDBUGS_HOME/bin/convertXmlToText -html \
  532. $PATCH_DIR/newPatchFindbugsWarnings${module_suffix}.xml \
  533. $PATCH_DIR/newPatchFindbugsWarnings${module_suffix}.html
  534. JIRA_COMMENT_FOOTER="Findbugs warnings: $BUILD_URL/artifact/trunk/patchprocess/newPatchFindbugsWarnings${module_suffix}.html
  535. $JIRA_COMMENT_FOOTER"
  536. done
  537. ### if current warnings greater than OK_FINDBUGS_WARNINGS
  538. if [[ $findbugsWarnings -gt $OK_FINDBUGS_WARNINGS ]] ; then
  539. JIRA_COMMENT="$JIRA_COMMENT
  540. -1 findbugs. The patch appears to introduce `expr $(($findbugsWarnings-$OK_FINDBUGS_WARNINGS))` new Findbugs (version ${findbugs_version}) warnings."
  541. return 1
  542. fi
  543. JIRA_COMMENT="$JIRA_COMMENT
  544. +1 findbugs. The patch does not introduce any new Findbugs (version ${findbugs_version}) warnings."
  545. return 0
  546. }
  547. ###############################################################################
  548. ### Verify eclipse:eclipse works
  549. checkEclipseGeneration () {
  550. echo ""
  551. echo ""
  552. echo "======================================================================"
  553. echo "======================================================================"
  554. echo " Running mvn eclipse:eclipse."
  555. echo "======================================================================"
  556. echo "======================================================================"
  557. echo ""
  558. echo ""
  559. echo "$MVN eclipse:eclipse -D${PROJECT_NAME}PatchProcess"
  560. $MVN eclipse:eclipse -D${PROJECT_NAME}PatchProcess
  561. if [[ $? != 0 ]] ; then
  562. JIRA_COMMENT="$JIRA_COMMENT
  563. -1 eclipse:eclipse. The patch failed to build with eclipse:eclipse."
  564. return 1
  565. fi
  566. JIRA_COMMENT="$JIRA_COMMENT
  567. +1 eclipse:eclipse. The patch built with eclipse:eclipse."
  568. return 0
  569. }
  570. ###############################################################################
  571. ### Run the tests
  572. runTests () {
  573. echo ""
  574. echo ""
  575. echo "======================================================================"
  576. echo "======================================================================"
  577. echo " Running tests."
  578. echo "======================================================================"
  579. echo "======================================================================"
  580. echo ""
  581. echo ""
  582. echo "$MVN clean install -Pnative -D${PROJECT_NAME}PatchProcess"
  583. $MVN clean install -Pnative -Drequire.test.libhadoop -D${PROJECT_NAME}PatchProcess
  584. if [[ $? != 0 ]] ; then
  585. ### Find and format names of failed tests
  586. 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"`
  587. if [[ -n "$failed_tests" ]] ; then
  588. JIRA_COMMENT="$JIRA_COMMENT
  589. -1 core tests. The patch failed these unit tests:
  590. $failed_tests"
  591. else
  592. JIRA_COMMENT="$JIRA_COMMENT
  593. -1 core tests. The patch failed the unit tests build"
  594. fi
  595. return 1
  596. fi
  597. JIRA_COMMENT="$JIRA_COMMENT
  598. +1 core tests. The patch passed unit tests in $modules."
  599. return 0
  600. }
  601. ###############################################################################
  602. ### Run the test-contrib target
  603. runContribTests () {
  604. echo ""
  605. echo ""
  606. echo "======================================================================"
  607. echo "======================================================================"
  608. echo " Running contrib tests."
  609. echo "======================================================================"
  610. echo "======================================================================"
  611. echo ""
  612. echo ""
  613. if [[ `$GREP -c 'test-contrib' build.xml` == 0 ]] ; then
  614. echo "No contrib tests in this project."
  615. return 0
  616. fi
  617. ### Kill any rogue build processes from the last attempt
  618. $PS auxwww | $GREP ${PROJECT_NAME}PatchProcess | $AWK '{print $2}' | /usr/bin/xargs -t -I {} /bin/kill -9 {} > /dev/null
  619. #echo "$ANT_HOME/bin/ant -Dversion="${VERSION}" $ECLIPSE_PROPERTY -DHadoopPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=no test-contrib"
  620. #$ANT_HOME/bin/ant -Dversion="${VERSION}" $ECLIPSE_PROPERTY -DHadoopPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=no test-contrib
  621. echo "NOP"
  622. if [[ $? != 0 ]] ; then
  623. JIRA_COMMENT="$JIRA_COMMENT
  624. -1 contrib tests. The patch failed contrib unit tests."
  625. return 1
  626. fi
  627. JIRA_COMMENT="$JIRA_COMMENT
  628. +1 contrib tests. The patch passed contrib unit tests."
  629. return 0
  630. }
  631. ###############################################################################
  632. ### Run the inject-system-faults target
  633. checkInjectSystemFaults () {
  634. echo ""
  635. echo ""
  636. echo "======================================================================"
  637. echo "======================================================================"
  638. echo " Checking the integrity of system test framework code."
  639. echo "======================================================================"
  640. echo "======================================================================"
  641. echo ""
  642. echo ""
  643. ### Kill any rogue build processes from the last attempt
  644. $PS auxwww | $GREP ${PROJECT_NAME}PatchProcess | $AWK '{print $2}' | /usr/bin/xargs -t -I {} /bin/kill -9 {} > /dev/null
  645. #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"
  646. #$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
  647. echo "NOP"
  648. return 0
  649. if [[ $? != 0 ]] ; then
  650. JIRA_COMMENT="$JIRA_COMMENT
  651. -1 system test framework. The patch failed system test framework compile."
  652. return 1
  653. fi
  654. JIRA_COMMENT="$JIRA_COMMENT
  655. +1 system test framework. The patch passed system test framework compile."
  656. return 0
  657. }
  658. ###############################################################################
  659. ### Submit a comment to the defect's Jira
  660. submitJiraComment () {
  661. local result=$1
  662. ### Do not output the value of JIRA_COMMENT_FOOTER when run by a developer
  663. if [[ $JENKINS == "false" ]] ; then
  664. JIRA_COMMENT_FOOTER=""
  665. fi
  666. if [[ $result == 0 ]] ; then
  667. comment="+1 overall. $JIRA_COMMENT
  668. $JIRA_COMMENT_FOOTER"
  669. else
  670. comment="-1 overall. $JIRA_COMMENT
  671. $JIRA_COMMENT_FOOTER"
  672. fi
  673. ### Output the test result to the console
  674. echo "
  675. $comment"
  676. if [[ $JENKINS == "true" ]] ; then
  677. echo ""
  678. echo ""
  679. echo "======================================================================"
  680. echo "======================================================================"
  681. echo " Adding comment to Jira."
  682. echo "======================================================================"
  683. echo "======================================================================"
  684. echo ""
  685. echo ""
  686. ### Update Jira with a comment
  687. export USER=hudson
  688. $JIRACLI -s https://issues.apache.org/jira -a addcomment -u hadoopqa -p $JIRA_PASSWD --comment "$comment" --issue $defect
  689. $JIRACLI -s https://issues.apache.org/jira -a logout -u hadoopqa -p $JIRA_PASSWD
  690. fi
  691. }
  692. ###############################################################################
  693. ### Cleanup files
  694. cleanupAndExit () {
  695. local result=$1
  696. if [[ $JENKINS == "true" ]] ; then
  697. if [ -e "$PATCH_DIR" ] ; then
  698. mv $PATCH_DIR $BASEDIR
  699. fi
  700. fi
  701. echo ""
  702. echo ""
  703. echo "======================================================================"
  704. echo "======================================================================"
  705. echo " Finished build."
  706. echo "======================================================================"
  707. echo "======================================================================"
  708. echo ""
  709. echo ""
  710. exit $result
  711. }
  712. ###############################################################################
  713. ###############################################################################
  714. ###############################################################################
  715. JIRA_COMMENT=""
  716. JIRA_COMMENT_FOOTER="Console output: $BUILD_URL/console
  717. This message is automatically generated."
  718. ### Check if arguments to the script have been specified properly or not
  719. parseArgs $@
  720. cd $BASEDIR
  721. checkout
  722. RESULT=$?
  723. if [[ $JENKINS == "true" ]] ; then
  724. if [[ $RESULT != 0 ]] ; then
  725. exit 100
  726. fi
  727. fi
  728. setup
  729. checkAuthor
  730. RESULT=$?
  731. if [[ $JENKINS == "true" ]] ; then
  732. cleanUpXml
  733. fi
  734. checkTests
  735. (( RESULT = RESULT + $? ))
  736. applyPatch
  737. if [[ $? != 0 ]] ; then
  738. submitJiraComment 1
  739. cleanupAndExit 1
  740. fi
  741. checkJavadocWarnings
  742. (( RESULT = RESULT + $? ))
  743. checkJavacWarnings
  744. (( RESULT = RESULT + $? ))
  745. checkEclipseGeneration
  746. (( RESULT = RESULT + $? ))
  747. ### Checkstyle not implemented yet
  748. #checkStyle
  749. #(( RESULT = RESULT + $? ))
  750. checkFindbugsWarnings
  751. (( RESULT = RESULT + $? ))
  752. checkReleaseAuditWarnings
  753. (( RESULT = RESULT + $? ))
  754. ### Run tests for Jenkins or if explictly asked for by a developer
  755. if [[ $JENKINS == "true" || $RUN_TESTS == "true" ]] ; then
  756. runTests
  757. (( RESULT = RESULT + $? ))
  758. runContribTests
  759. (( RESULT = RESULT + $? ))
  760. fi
  761. checkInjectSystemFaults
  762. (( RESULT = RESULT + $? ))
  763. JIRA_COMMENT_FOOTER="Test results: $BUILD_URL/testReport/
  764. $JIRA_COMMENT_FOOTER"
  765. submitJiraComment $RESULT
  766. cleanupAndExit $RESULT