test-patch.sh 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  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 -e '^+++.*/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 test files."
  319. return 0
  320. }
  321. cleanUpXml () {
  322. cd $BASEDIR/conf
  323. for file in `ls *.xml.template`
  324. do
  325. rm -f `basename $file .template`
  326. done
  327. cd $BASEDIR
  328. }
  329. ###############################################################################
  330. ### Attempt to apply the patch
  331. applyPatch () {
  332. echo ""
  333. echo ""
  334. echo "======================================================================"
  335. echo "======================================================================"
  336. echo " Applying patch."
  337. echo "======================================================================"
  338. echo "======================================================================"
  339. echo ""
  340. echo ""
  341. export PATCH
  342. $bindir/smart-apply-patch.sh $PATCH_DIR/patch
  343. if [[ $? != 0 ]] ; then
  344. echo "PATCH APPLICATION FAILED"
  345. JIRA_COMMENT="$JIRA_COMMENT
  346. -1 patch. The patch command could not apply the patch."
  347. return 1
  348. fi
  349. return 0
  350. }
  351. ###############################################################################
  352. ### Check there are no javadoc warnings
  353. checkJavadocWarnings () {
  354. echo ""
  355. echo ""
  356. echo "======================================================================"
  357. echo "======================================================================"
  358. echo " Determining number of patched javadoc warnings."
  359. echo "======================================================================"
  360. echo "======================================================================"
  361. echo ""
  362. echo ""
  363. echo "$MVN clean test javadoc:javadoc -DskipTests -Pdocs -D${PROJECT_NAME}PatchProcess > $PATCH_DIR/patchJavadocWarnings.txt 2>&1"
  364. if [ -d hadoop-project ]; then
  365. (cd hadoop-project; $MVN install)
  366. fi
  367. if [ -d hadoop-common-project/hadoop-annotations ]; then
  368. (cd hadoop-common-project/hadoop-annotations; $MVN install)
  369. fi
  370. $MVN clean test javadoc:javadoc -DskipTests -Pdocs -D${PROJECT_NAME}PatchProcess > $PATCH_DIR/patchJavadocWarnings.txt 2>&1
  371. javadocWarnings=`$GREP '\[WARNING\]' $PATCH_DIR/patchJavadocWarnings.txt | $AWK '/Javadoc Warnings/,EOF' | $GREP warning | $AWK 'BEGIN {total = 0} {total += 1} END {print total}'`
  372. echo ""
  373. echo ""
  374. echo "There appear to be $javadocWarnings javadoc warnings generated by the patched build."
  375. ### if current warnings greater than OK_JAVADOC_WARNINGS
  376. if [[ $javadocWarnings -gt $OK_JAVADOC_WARNINGS ]] ; then
  377. JIRA_COMMENT="$JIRA_COMMENT
  378. -1 javadoc. The javadoc tool appears to have generated `expr $(($javadocWarnings-$OK_JAVADOC_WARNINGS))` warning messages."
  379. return 1
  380. fi
  381. JIRA_COMMENT="$JIRA_COMMENT
  382. +1 javadoc. The javadoc tool did not generate any warning messages."
  383. return 0
  384. }
  385. ###############################################################################
  386. ### Check there are no changes in the number of Javac warnings
  387. checkJavacWarnings () {
  388. echo ""
  389. echo ""
  390. echo "======================================================================"
  391. echo "======================================================================"
  392. echo " Determining number of patched javac warnings."
  393. echo "======================================================================"
  394. echo "======================================================================"
  395. echo ""
  396. echo ""
  397. echo "$MVN clean test -DskipTests -D${PROJECT_NAME}PatchProcess -Ptest-patch > $PATCH_DIR/patchJavacWarnings.txt 2>&1"
  398. $MVN clean test -DskipTests -D${PROJECT_NAME}PatchProcess -Ptest-patch > $PATCH_DIR/patchJavacWarnings.txt 2>&1
  399. if [[ $? != 0 ]] ; then
  400. JIRA_COMMENT="$JIRA_COMMENT
  401. -1 javac. The patch appears to cause tar ant target to fail."
  402. return 1
  403. fi
  404. ### Compare trunk and patch javac warning numbers
  405. if [[ -f $PATCH_DIR/patchJavacWarnings.txt ]] ; then
  406. trunkJavacWarnings=`$GREP '\[WARNING\]' $PATCH_DIR/trunkJavacWarnings.txt | $AWK 'BEGIN {total = 0} {total += 1} END {print total}'`
  407. patchJavacWarnings=`$GREP '\[WARNING\]' $PATCH_DIR/patchJavacWarnings.txt | $AWK 'BEGIN {total = 0} {total += 1} END {print total}'`
  408. echo "There appear to be $trunkJavacWarnings javac compiler warnings before the patch and $patchJavacWarnings javac compiler warnings after applying the patch."
  409. if [[ $patchJavacWarnings != "" && $trunkJavacWarnings != "" ]] ; then
  410. if [[ $patchJavacWarnings -gt $trunkJavacWarnings ]] ; then
  411. JIRA_COMMENT="$JIRA_COMMENT
  412. -1 javac. The applied patch generated $patchJavacWarnings javac compiler warnings (more than the trunk's current $trunkJavacWarnings warnings)."
  413. return 1
  414. fi
  415. fi
  416. fi
  417. JIRA_COMMENT="$JIRA_COMMENT
  418. +1 javac. The applied patch does not increase the total number of javac compiler warnings."
  419. return 0
  420. }
  421. ###############################################################################
  422. ### Check there are no changes in the number of release audit (RAT) warnings
  423. checkReleaseAuditWarnings () {
  424. echo ""
  425. echo ""
  426. echo "======================================================================"
  427. echo "======================================================================"
  428. echo " Determining number of patched release audit warnings."
  429. echo "======================================================================"
  430. echo "======================================================================"
  431. echo ""
  432. echo ""
  433. echo "$MVN apache-rat:check -D${PROJECT_NAME}PatchProcess 2>&1"
  434. $MVN apache-rat:check -D${PROJECT_NAME}PatchProcess 2>&1
  435. find $BASEDIR -name rat.txt | xargs cat > $PATCH_DIR/patchReleaseAuditWarnings.txt
  436. ### Compare trunk and patch release audit warning numbers
  437. if [[ -f $PATCH_DIR/patchReleaseAuditWarnings.txt ]] ; then
  438. patchReleaseAuditWarnings=`$GREP -c '\!?????' $PATCH_DIR/patchReleaseAuditWarnings.txt`
  439. echo ""
  440. echo ""
  441. echo "There appear to be $OK_RELEASEAUDIT_WARNINGS release audit warnings before the patch and $patchReleaseAuditWarnings release audit warnings after applying the patch."
  442. if [[ $patchReleaseAuditWarnings != "" && $OK_RELEASEAUDIT_WARNINGS != "" ]] ; then
  443. if [[ $patchReleaseAuditWarnings -gt $OK_RELEASEAUDIT_WARNINGS ]] ; then
  444. JIRA_COMMENT="$JIRA_COMMENT
  445. -1 release audit. The applied patch generated $patchReleaseAuditWarnings release audit warnings (more than the trunk's current $OK_RELEASEAUDIT_WARNINGS warnings)."
  446. $GREP '\!?????' $PATCH_DIR/patchReleaseAuditWarnings.txt > $PATCH_DIR/patchReleaseAuditProblems.txt
  447. echo "Lines that start with ????? in the release audit report indicate files that do not have an Apache license header." >> $PATCH_DIR/patchReleaseAuditProblems.txt
  448. JIRA_COMMENT_FOOTER="Release audit warnings: $BUILD_URL/artifact/trunk/patchprocess/patchReleaseAuditProblems.txt
  449. $JIRA_COMMENT_FOOTER"
  450. return 1
  451. fi
  452. fi
  453. fi
  454. JIRA_COMMENT="$JIRA_COMMENT
  455. +1 release audit. The applied patch does not increase the total number of release audit warnings."
  456. return 0
  457. }
  458. ###############################################################################
  459. ### Check there are no changes in the number of Checkstyle warnings
  460. checkStyle () {
  461. echo ""
  462. echo ""
  463. echo "======================================================================"
  464. echo "======================================================================"
  465. echo " Determining number of patched checkstyle warnings."
  466. echo "======================================================================"
  467. echo "======================================================================"
  468. echo ""
  469. echo ""
  470. echo "THIS IS NOT IMPLEMENTED YET"
  471. echo ""
  472. echo ""
  473. echo "$MVN test checkstyle:checkstyle -DskipTests -D${PROJECT_NAME}PatchProcess"
  474. $MVN test checkstyle:checkstyle -DskipTests -D${PROJECT_NAME}PatchProcess
  475. JIRA_COMMENT_FOOTER="Checkstyle results: $BUILD_URL/artifact/trunk/build/test/checkstyle-errors.html
  476. $JIRA_COMMENT_FOOTER"
  477. ### TODO: calculate actual patchStyleErrors
  478. # patchStyleErrors=0
  479. # if [[ $patchStyleErrors != 0 ]] ; then
  480. # JIRA_COMMENT="$JIRA_COMMENT
  481. #
  482. # -1 checkstyle. The patch generated $patchStyleErrors code style errors."
  483. # return 1
  484. # fi
  485. # JIRA_COMMENT="$JIRA_COMMENT
  486. #
  487. # +1 checkstyle. The patch generated 0 code style errors."
  488. return 0
  489. }
  490. ###############################################################################
  491. ### Check there are no changes in the number of Findbugs warnings
  492. checkFindbugsWarnings () {
  493. findbugs_version=`${FINDBUGS_HOME}/bin/findbugs -version`
  494. echo ""
  495. echo ""
  496. echo "======================================================================"
  497. echo "======================================================================"
  498. echo " Determining number of patched Findbugs warnings."
  499. echo "======================================================================"
  500. echo "======================================================================"
  501. echo ""
  502. echo ""
  503. echo "$MVN clean test findbugs:findbugs -DskipTests -D${PROJECT_NAME}PatchProcess"
  504. $MVN clean test findbugs:findbugs -DskipTests -D${PROJECT_NAME}PatchProcess < /dev/null
  505. if [ $? != 0 ] ; then
  506. JIRA_COMMENT="$JIRA_COMMENT
  507. -1 findbugs. The patch appears to cause Findbugs (version ${findbugs_version}) to fail."
  508. return 1
  509. fi
  510. findbugsWarnings=0
  511. for file in $(find $BASEDIR -name findbugsXml.xml)
  512. do
  513. relative_file=${file#$BASEDIR/} # strip leading $BASEDIR prefix
  514. if [ ! $relative_file == "target/findbugsXml.xml" ]; then
  515. module_suffix=${relative_file%/target/findbugsXml.xml} # strip trailing path
  516. module_suffix=`basename ${module_suffix}`
  517. fi
  518. cp $file $PATCH_DIR/patchFindbugsWarnings${module_suffix}.xml
  519. $FINDBUGS_HOME/bin/setBugDatabaseInfo -timestamp "01/01/2000" \
  520. $PATCH_DIR/patchFindbugsWarnings${module_suffix}.xml \
  521. $PATCH_DIR/patchFindbugsWarnings${module_suffix}.xml
  522. newFindbugsWarnings=`$FINDBUGS_HOME/bin/filterBugs -first "01/01/2000" $PATCH_DIR/patchFindbugsWarnings${module_suffix}.xml \
  523. $PATCH_DIR/newPatchFindbugsWarnings${module_suffix}.xml | $AWK '{print $1}'`
  524. echo "Found $newFindbugsWarnings Findbugs warnings ($file)"
  525. findbugsWarnings=$((findbugsWarnings+newFindbugsWarnings))
  526. $FINDBUGS_HOME/bin/convertXmlToText -html \
  527. $PATCH_DIR/newPatchFindbugsWarnings${module_suffix}.xml \
  528. $PATCH_DIR/newPatchFindbugsWarnings${module_suffix}.html
  529. if [[ $newFindbugsWarnings > 0 ]] ; then
  530. JIRA_COMMENT_FOOTER="Findbugs warnings: $BUILD_URL/artifact/trunk/$(basename $BASEDIR)/patchprocess/newPatchFindbugsWarnings${module_suffix}.html
  531. $JIRA_COMMENT_FOOTER"
  532. fi
  533. done
  534. ### if current warnings greater than OK_FINDBUGS_WARNINGS
  535. if [[ $findbugsWarnings -gt $OK_FINDBUGS_WARNINGS ]] ; then
  536. JIRA_COMMENT="$JIRA_COMMENT
  537. -1 findbugs. The patch appears to introduce `expr $(($findbugsWarnings-$OK_FINDBUGS_WARNINGS))` new Findbugs (version ${findbugs_version}) warnings."
  538. return 1
  539. fi
  540. JIRA_COMMENT="$JIRA_COMMENT
  541. +1 findbugs. The patch does not introduce any new Findbugs (version ${findbugs_version}) warnings."
  542. return 0
  543. }
  544. ###############################################################################
  545. ### Verify eclipse:eclipse works
  546. checkEclipseGeneration () {
  547. echo ""
  548. echo ""
  549. echo "======================================================================"
  550. echo "======================================================================"
  551. echo " Running mvn eclipse:eclipse."
  552. echo "======================================================================"
  553. echo "======================================================================"
  554. echo ""
  555. echo ""
  556. echo "$MVN eclipse:eclipse -D${PROJECT_NAME}PatchProcess"
  557. $MVN eclipse:eclipse -D${PROJECT_NAME}PatchProcess
  558. if [[ $? != 0 ]] ; then
  559. JIRA_COMMENT="$JIRA_COMMENT
  560. -1 eclipse:eclipse. The patch failed to build with eclipse:eclipse."
  561. return 1
  562. fi
  563. JIRA_COMMENT="$JIRA_COMMENT
  564. +1 eclipse:eclipse. The patch built with eclipse:eclipse."
  565. return 0
  566. }
  567. ###############################################################################
  568. ### Run the tests
  569. runTests () {
  570. echo ""
  571. echo ""
  572. echo "======================================================================"
  573. echo "======================================================================"
  574. echo " Running tests."
  575. echo "======================================================================"
  576. echo "======================================================================"
  577. echo ""
  578. echo ""
  579. echo "$MVN clean install -Pnative -D${PROJECT_NAME}PatchProcess"
  580. $MVN clean install -Pnative -D${PROJECT_NAME}PatchProcess
  581. if [[ $? != 0 ]] ; then
  582. ### Find and format names of failed tests
  583. 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"`
  584. if [[ -n "$failed_tests" ]] ; then
  585. JIRA_COMMENT="$JIRA_COMMENT
  586. -1 core tests. The patch failed these unit tests:
  587. $failed_tests"
  588. else
  589. JIRA_COMMENT="$JIRA_COMMENT
  590. -1 core tests. The patch failed the unit tests build"
  591. fi
  592. return 1
  593. fi
  594. JIRA_COMMENT="$JIRA_COMMENT
  595. +1 core tests. The patch passed unit tests in $modules."
  596. return 0
  597. }
  598. ###############################################################################
  599. ### Run the test-contrib target
  600. runContribTests () {
  601. echo ""
  602. echo ""
  603. echo "======================================================================"
  604. echo "======================================================================"
  605. echo " Running contrib tests."
  606. echo "======================================================================"
  607. echo "======================================================================"
  608. echo ""
  609. echo ""
  610. if [[ `$GREP -c 'test-contrib' build.xml` == 0 ]] ; then
  611. echo "No contrib tests in this project."
  612. return 0
  613. fi
  614. ### Kill any rogue build processes from the last attempt
  615. $PS auxwww | $GREP ${PROJECT_NAME}PatchProcess | $AWK '{print $2}' | /usr/bin/xargs -t -I {} /bin/kill -9 {} > /dev/null
  616. #echo "$ANT_HOME/bin/ant -Dversion="${VERSION}" $ECLIPSE_PROPERTY -DHadoopPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=no test-contrib"
  617. #$ANT_HOME/bin/ant -Dversion="${VERSION}" $ECLIPSE_PROPERTY -DHadoopPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=no test-contrib
  618. echo "NOP"
  619. if [[ $? != 0 ]] ; then
  620. JIRA_COMMENT="$JIRA_COMMENT
  621. -1 contrib tests. The patch failed contrib unit tests."
  622. return 1
  623. fi
  624. JIRA_COMMENT="$JIRA_COMMENT
  625. +1 contrib tests. The patch passed contrib unit tests."
  626. return 0
  627. }
  628. ###############################################################################
  629. ### Run the inject-system-faults target
  630. checkInjectSystemFaults () {
  631. echo ""
  632. echo ""
  633. echo "======================================================================"
  634. echo "======================================================================"
  635. echo " Checking the integrity of system test framework code."
  636. echo "======================================================================"
  637. echo "======================================================================"
  638. echo ""
  639. echo ""
  640. ### Kill any rogue build processes from the last attempt
  641. $PS auxwww | $GREP ${PROJECT_NAME}PatchProcess | $AWK '{print $2}' | /usr/bin/xargs -t -I {} /bin/kill -9 {} > /dev/null
  642. #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"
  643. #$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. echo "NOP"
  645. return 0
  646. if [[ $? != 0 ]] ; then
  647. JIRA_COMMENT="$JIRA_COMMENT
  648. -1 system test framework. The patch failed system test framework compile."
  649. return 1
  650. fi
  651. JIRA_COMMENT="$JIRA_COMMENT
  652. +1 system test framework. The patch passed system test framework compile."
  653. return 0
  654. }
  655. ###############################################################################
  656. ### Submit a comment to the defect's Jira
  657. submitJiraComment () {
  658. local result=$1
  659. ### Do not output the value of JIRA_COMMENT_FOOTER when run by a developer
  660. if [[ $JENKINS == "false" ]] ; then
  661. JIRA_COMMENT_FOOTER=""
  662. fi
  663. if [[ $result == 0 ]] ; then
  664. comment="+1 overall. $JIRA_COMMENT
  665. $JIRA_COMMENT_FOOTER"
  666. else
  667. comment="-1 overall. $JIRA_COMMENT
  668. $JIRA_COMMENT_FOOTER"
  669. fi
  670. ### Output the test result to the console
  671. echo "
  672. $comment"
  673. if [[ $JENKINS == "true" ]] ; then
  674. echo ""
  675. echo ""
  676. echo "======================================================================"
  677. echo "======================================================================"
  678. echo " Adding comment to Jira."
  679. echo "======================================================================"
  680. echo "======================================================================"
  681. echo ""
  682. echo ""
  683. ### Update Jira with a comment
  684. export USER=hudson
  685. $JIRACLI -s https://issues.apache.org/jira -a addcomment -u hadoopqa -p $JIRA_PASSWD --comment "$comment" --issue $defect
  686. $JIRACLI -s https://issues.apache.org/jira -a logout -u hadoopqa -p $JIRA_PASSWD
  687. fi
  688. }
  689. ###############################################################################
  690. ### Cleanup files
  691. cleanupAndExit () {
  692. local result=$1
  693. if [[ $JENKINS == "true" ]] ; then
  694. if [ -e "$PATCH_DIR" ] ; then
  695. mv $PATCH_DIR $BASEDIR
  696. fi
  697. fi
  698. echo ""
  699. echo ""
  700. echo "======================================================================"
  701. echo "======================================================================"
  702. echo " Finished build."
  703. echo "======================================================================"
  704. echo "======================================================================"
  705. echo ""
  706. echo ""
  707. exit $result
  708. }
  709. ###############################################################################
  710. ###############################################################################
  711. ###############################################################################
  712. JIRA_COMMENT=""
  713. JIRA_COMMENT_FOOTER="Console output: $BUILD_URL/console
  714. This message is automatically generated."
  715. ### Check if arguments to the script have been specified properly or not
  716. parseArgs $@
  717. cd $BASEDIR
  718. checkout
  719. RESULT=$?
  720. if [[ $JENKINS == "true" ]] ; then
  721. if [[ $RESULT != 0 ]] ; then
  722. exit 100
  723. fi
  724. fi
  725. setup
  726. checkAuthor
  727. RESULT=$?
  728. if [[ $JENKINS == "true" ]] ; then
  729. cleanUpXml
  730. fi
  731. checkTests
  732. (( RESULT = RESULT + $? ))
  733. applyPatch
  734. if [[ $? != 0 ]] ; then
  735. submitJiraComment 1
  736. cleanupAndExit 1
  737. fi
  738. checkJavadocWarnings
  739. (( RESULT = RESULT + $? ))
  740. checkJavacWarnings
  741. (( RESULT = RESULT + $? ))
  742. checkEclipseGeneration
  743. (( RESULT = RESULT + $? ))
  744. ### Checkstyle not implemented yet
  745. #checkStyle
  746. #(( RESULT = RESULT + $? ))
  747. checkFindbugsWarnings
  748. (( RESULT = RESULT + $? ))
  749. checkReleaseAuditWarnings
  750. (( RESULT = RESULT + $? ))
  751. ### Run tests for Jenkins or if explictly asked for by a developer
  752. if [[ $JENKINS == "true" || $RUN_TESTS == "true" ]] ; then
  753. runTests
  754. (( RESULT = RESULT + $? ))
  755. runContribTests
  756. (( RESULT = RESULT + $? ))
  757. fi
  758. checkInjectSystemFaults
  759. (( RESULT = RESULT + $? ))
  760. JIRA_COMMENT_FOOTER="Test results: $BUILD_URL/testReport/
  761. $JIRA_COMMENT_FOOTER"
  762. submitJiraComment $RESULT
  763. cleanupAndExit $RESULT