test-patch.sh 31 KB

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