test-patch.sh 31 KB

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