test-patch.sh 36 KB

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