test-patch.sh 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  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 20480
  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=Ambari
  26. JENKINS=false
  27. PATCH_DIR=/tmp
  28. SUPPORT_DIR=/tmp
  29. BASEDIR=$(pwd)
  30. PS=${PS:-ps}
  31. AWK=${AWK:-awk}
  32. WGET=${WGET:-wget}
  33. GIT=${GIT:-git}
  34. GREP=${GREP:-grep}
  35. PATCH=${PATCH:-patch}
  36. 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 "--git-cmd=<cmd> The 'git' command to use (default 'git')"
  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. --git-cmd=*)
  102. GIT=${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. ### Obtain the patch filename to append it to the version number
  157. defect=`basename $PATCH_FILE`
  158. fi
  159. }
  160. ###############################################################################
  161. checkout () {
  162. echo ""
  163. echo ""
  164. echo "======================================================================"
  165. echo "======================================================================"
  166. echo " Testing patch for ${defect}."
  167. echo "======================================================================"
  168. echo "======================================================================"
  169. echo ""
  170. echo ""
  171. ### When run by a developer, if the workspace contains modifications, do not continue
  172. ### unless the --dirty-workspace option was set
  173. # status=`$GIT status -s | sed -e '/^X[ ]*/D'`
  174. status=`$GIT status -s `
  175. if [[ $JENKINS == "false" ]] ; then
  176. if [[ "$status" != "" && -z $DIRTY_WORKSPACE ]] ; then
  177. echo "ERROR: can't run in a workspace that contains the following modifications"
  178. echo "$status"
  179. cleanupAndExit 1
  180. fi
  181. echo
  182. else
  183. cd $BASEDIR
  184. $GIT checkout -- .
  185. $GIT clean -x -f -d
  186. $GIT pull
  187. fi
  188. return $?
  189. }
  190. ###############################################################################
  191. downloadPatch () {
  192. ### Download latest patch file (ignoring .htm and .html) when run from patch process
  193. if [[ $JENKINS == "true" ]] ; then
  194. $WGET -q -O $PATCH_DIR/jira http://issues.apache.org/jira/browse/$defect
  195. if [[ `$GREP -c 'Patch Available' $PATCH_DIR/jira` == 0 ]] ; then
  196. echo "$defect is not \"Patch Available\". Exiting."
  197. cleanupAndExit 0
  198. fi
  199. 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]*/[^"]*'`
  200. patchURL="http://issues.apache.org${relativePatchURL}"
  201. patchNum=`echo $patchURL | $GREP -o '[0-9]*/' | $GREP -o '[0-9]*'`
  202. echo "$defect patch is being downloaded at `date` from"
  203. echo "$patchURL"
  204. $WGET -q -O $PATCH_DIR/patch $patchURL
  205. VERSION=${SVN_REVISION}_${defect}_PATCH-${patchNum}
  206. JIRA_COMMENT="Here are the results of testing the latest attachment
  207. $patchURL
  208. against trunk revision ${SVN_REVISION}."
  209. ### Copy in any supporting files needed by this process
  210. # cp -r $SUPPORT_DIR/lib/* ./lib
  211. #PENDING: cp -f $SUPPORT_DIR/etc/checkstyle* ./src/test
  212. ### Copy the patch file to $PATCH_DIR
  213. else
  214. VERSION=PATCH-${defect}
  215. cp $PATCH_FILE $PATCH_DIR/patch
  216. if [[ $? == 0 ]] ; then
  217. echo "Patch file $PATCH_FILE copied to $PATCH_DIR"
  218. else
  219. echo "Could not copy $PATCH_FILE to $PATCH_DIR"
  220. cleanupAndExit 0
  221. fi
  222. fi
  223. }
  224. ###############################################################################
  225. verifyPatch () {
  226. # Before building, check to make sure that the patch is valid
  227. # $bindir/smart-apply-patch.sh $PATCH_DIR/patch dryrun
  228. $GIT apply --check $PATCH_DIR/patch
  229. if [[ $? != 0 ]] ; then
  230. echo "PATCH APPLICATION FAILED"
  231. JIRA_COMMENT="$JIRA_COMMENT
  232. {color:red}-1 patch{color}. The patch command could not apply the patch."
  233. return 1
  234. else
  235. return 0
  236. fi
  237. }
  238. ###############################################################################
  239. prebuildWithoutPatch () {
  240. echo ""
  241. echo ""
  242. echo "======================================================================"
  243. echo "======================================================================"
  244. echo " Pre-build trunk to verify trunk stability and javac warnings"
  245. echo "======================================================================"
  246. echo "======================================================================"
  247. echo ""
  248. echo ""
  249. if [[ ! -d hadoop-common-project ]]; then
  250. cd $bindir/..
  251. echo "Compiling $(pwd)"
  252. echo "$MVN clean test -DskipTests > $PATCH_DIR/trunkCompile.txt 2>&1"
  253. $MVN clean test -DskipTests > $PATCH_DIR/trunkCompile.txt 2>&1
  254. if [[ $? != 0 ]] ; then
  255. echo "Top-level trunk compilation is broken?"
  256. JIRA_COMMENT="$JIRA_COMMENT
  257. {color:red}-1 patch{color}. Top-level trunk compilation may be broken."
  258. return 1
  259. fi
  260. cd -
  261. fi
  262. echo "Compiling $(pwd)"
  263. echo "$MVN clean test -DskipTests -D${PROJECT_NAME}PatchProcess > $PATCH_DIR/trunkJavacWarnings.txt 2>&1"
  264. $MVN clean test -DskipTests -D${PROJECT_NAME}PatchProcess > $PATCH_DIR/trunkJavacWarnings.txt 2>&1
  265. if [[ $? != 0 ]] ; then
  266. echo "Trunk compilation is broken?"
  267. JIRA_COMMENT="$JIRA_COMMENT
  268. {color:red}-1 patch{color}. Trunk compilation may be broken."
  269. return 1
  270. fi
  271. return 0
  272. }
  273. ###############################################################################
  274. ### Check for @author tags in the patch
  275. checkAuthor () {
  276. echo ""
  277. echo ""
  278. echo "======================================================================"
  279. echo "======================================================================"
  280. echo " Checking there are no @author tags in the patch."
  281. echo "======================================================================"
  282. echo "======================================================================"
  283. echo ""
  284. echo ""
  285. authorTags=`$GREP -c -i '@author' $PATCH_DIR/patch`
  286. echo "There appear to be $authorTags @author tags in the patch."
  287. if [[ $authorTags != 0 ]] ; then
  288. JIRA_COMMENT="$JIRA_COMMENT
  289. {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."
  290. return 1
  291. fi
  292. JIRA_COMMENT="$JIRA_COMMENT
  293. {color:green}+1 @author{color}. The patch does not contain any @author tags."
  294. return 0
  295. }
  296. ###############################################################################
  297. ### Check for tests in the patch
  298. checkTests () {
  299. echo ""
  300. echo ""
  301. echo "======================================================================"
  302. echo "======================================================================"
  303. echo " Checking there are new or changed tests in the patch."
  304. echo "======================================================================"
  305. echo "======================================================================"
  306. echo ""
  307. echo ""
  308. testReferences=`$GREP -c -i -e '^+++.*/test' $PATCH_DIR/patch`
  309. echo "There appear to be $testReferences test files referenced in the patch."
  310. if [[ $testReferences == 0 ]] ; then
  311. if [[ $JENKINS == "true" ]] ; then
  312. patchIsDoc=`$GREP -c -i 'title="documentation' $PATCH_DIR/jira`
  313. if [[ $patchIsDoc != 0 ]] ; then
  314. echo "The patch appears to be a documentation patch that doesn't require tests."
  315. JIRA_COMMENT="$JIRA_COMMENT
  316. {color:green}+0 tests included{color}. The patch appears to be a documentation patch that doesn't require tests."
  317. return 0
  318. fi
  319. fi
  320. JIRA_COMMENT="$JIRA_COMMENT
  321. {color:red}-1 tests included{color}. The patch doesn't appear to include any new or modified tests.
  322. Please justify why no new tests are needed for this patch.
  323. Also please list what manual steps were performed to verify this patch."
  324. return 1
  325. fi
  326. JIRA_COMMENT="$JIRA_COMMENT
  327. {color:green}+1 tests included{color}. The patch appears to include $testReferences new or modified test files."
  328. return 0
  329. }
  330. cleanUpXml () {
  331. cd $BASEDIR/conf
  332. for file in `ls *.xml.template`
  333. do
  334. rm -f `basename $file .template`
  335. done
  336. cd $BASEDIR
  337. }
  338. ###############################################################################
  339. ### Attempt to apply the patch
  340. applyPatch () {
  341. echo ""
  342. echo ""
  343. echo "======================================================================"
  344. echo "======================================================================"
  345. echo " Applying patch."
  346. echo "======================================================================"
  347. echo "======================================================================"
  348. echo ""
  349. echo ""
  350. export PATCH
  351. # $bindir/smart-apply-patch.sh $PATCH_DIR/patch
  352. $GIT apply $PATCH_DIR/patch
  353. if [[ $? != 0 ]] ; then
  354. echo "PATCH APPLICATION FAILED"
  355. JIRA_COMMENT="$JIRA_COMMENT
  356. {color:red}-1 patch{color}. The patch command could not apply the patch."
  357. return 1
  358. fi
  359. return 0
  360. }
  361. ###############################################################################
  362. ### Check there are no changes in the number of Javac warnings
  363. checkJavacWarnings () {
  364. echo ""
  365. echo ""
  366. echo "======================================================================"
  367. echo "======================================================================"
  368. echo " Determining number of patched javac warnings."
  369. echo "======================================================================"
  370. echo "======================================================================"
  371. echo ""
  372. echo ""
  373. echo "$MVN clean test -DskipTests -D${PROJECT_NAME}PatchProcess > $PATCH_DIR/patchJavacWarnings.txt 2>&1"
  374. $MVN clean test -DskipTests -D${PROJECT_NAME}PatchProcess > $PATCH_DIR/patchJavacWarnings.txt 2>&1
  375. if [[ $? != 0 ]] ; then
  376. JIRA_COMMENT="$JIRA_COMMENT
  377. {color:red}-1 javac{color:red}. The patch appears to cause the build to fail."
  378. return 2
  379. fi
  380. ### Compare trunk and patch javac warning numbers
  381. if [[ -f $PATCH_DIR/patchJavacWarnings.txt ]] ; then
  382. $GREP '\[WARNING\]' $PATCH_DIR/trunkJavacWarnings.txt > $PATCH_DIR/filteredTrunkJavacWarnings.txt
  383. $GREP '\[WARNING\]' $PATCH_DIR/patchJavacWarnings.txt > $PATCH_DIR/filteredPatchJavacWarnings.txt
  384. trunkJavacWarnings=`cat $PATCH_DIR/filteredTrunkJavacWarnings.txt | $AWK 'BEGIN {total = 0} {total += 1} END {print total}'`
  385. patchJavacWarnings=`cat $PATCH_DIR/filteredPatchJavacWarnings.txt | $AWK 'BEGIN {total = 0} {total += 1} END {print total}'`
  386. echo "There appear to be $trunkJavacWarnings javac compiler warnings before the patch and $patchJavacWarnings javac compiler warnings after applying the patch."
  387. if [[ $patchJavacWarnings != "" && $trunkJavacWarnings != "" ]] ; then
  388. if [[ $patchJavacWarnings -gt $trunkJavacWarnings ]] ; then
  389. JIRA_COMMENT="$JIRA_COMMENT
  390. {color:red}-1 javac{color}. The applied patch generated $patchJavacWarnings javac compiler warnings (more than the trunk's current $trunkJavacWarnings warnings)."
  391. $DIFF $PATCH_DIR/filteredTrunkJavacWarnings.txt $PATCH_DIR/filteredPatchJavacWarnings.txt > $PATCH_DIR/diffJavacWarnings.txt
  392. JIRA_COMMENT_FOOTER="Javac warnings: $BUILD_URL/artifact/trunk/patchprocess/diffJavacWarnings.txt
  393. $JIRA_COMMENT_FOOTER"
  394. return 1
  395. fi
  396. fi
  397. fi
  398. JIRA_COMMENT="$JIRA_COMMENT
  399. {color:green}+1 javac{color}. The applied patch does not increase the total number of javac compiler warnings."
  400. return 0
  401. }
  402. ###############################################################################
  403. ### Check there are no changes in the number of release audit (RAT) warnings
  404. checkReleaseAuditWarnings () {
  405. echo ""
  406. echo ""
  407. echo "======================================================================"
  408. echo "======================================================================"
  409. echo " Determining number of patched release audit warnings."
  410. echo "======================================================================"
  411. echo "======================================================================"
  412. echo ""
  413. echo ""
  414. echo "$MVN apache-rat:check -D${PROJECT_NAME}PatchProcess > $PATCH_DIR/patchReleaseAuditOutput.txt 2>&1"
  415. $MVN apache-rat:check -D${PROJECT_NAME}PatchProcess > $PATCH_DIR/patchReleaseAuditOutput.txt 2>&1
  416. find $BASEDIR -name rat.txt | xargs cat > $PATCH_DIR/patchReleaseAuditWarnings.txt
  417. ### Compare trunk and patch release audit warning numbers
  418. if [[ -f $PATCH_DIR/patchReleaseAuditWarnings.txt ]] ; then
  419. patchReleaseAuditWarnings=`$GREP -c '\!?????' $PATCH_DIR/patchReleaseAuditWarnings.txt`
  420. echo ""
  421. echo ""
  422. echo "There appear to be $patchReleaseAuditWarnings release audit warnings after applying the patch."
  423. if [[ $patchReleaseAuditWarnings != "" ]] ; then
  424. if [[ $patchReleaseAuditWarnings -gt 0 ]] ; then
  425. JIRA_COMMENT="$JIRA_COMMENT
  426. {color:red}-1 release audit{color}. The applied patch generated $patchReleaseAuditWarnings release audit warnings."
  427. $GREP '\!?????' $PATCH_DIR/patchReleaseAuditWarnings.txt > $PATCH_DIR/patchReleaseAuditProblems.txt
  428. echo "Lines that start with ????? in the release audit report indicate files that do not have an Apache license header." >> $PATCH_DIR/patchReleaseAuditProblems.txt
  429. JIRA_COMMENT_FOOTER="Release audit warnings: $BUILD_URL/artifact/trunk/patchprocess/patchReleaseAuditProblems.txt
  430. $JIRA_COMMENT_FOOTER"
  431. return 1
  432. fi
  433. fi
  434. fi
  435. JIRA_COMMENT="$JIRA_COMMENT
  436. {color:green}+1 release audit{color}. The applied patch does not increase the total number of release audit warnings."
  437. return 0
  438. }
  439. ###############################################################################
  440. ### Check there are no changes in the number of Checkstyle warnings
  441. checkStyle () {
  442. echo ""
  443. echo ""
  444. echo "======================================================================"
  445. echo "======================================================================"
  446. echo " Determining number of patched checkstyle warnings."
  447. echo "======================================================================"
  448. echo "======================================================================"
  449. echo ""
  450. echo ""
  451. echo "THIS IS NOT IMPLEMENTED YET"
  452. echo ""
  453. echo ""
  454. echo "$MVN test checkstyle:checkstyle -DskipTests -D${PROJECT_NAME}PatchProcess"
  455. $MVN test checkstyle:checkstyle -DskipTests -D${PROJECT_NAME}PatchProcess
  456. JIRA_COMMENT_FOOTER="Checkstyle results: $BUILD_URL/artifact/trunk/build/test/checkstyle-errors.html
  457. $JIRA_COMMENT_FOOTER"
  458. ### TODO: calculate actual patchStyleErrors
  459. # patchStyleErrors=0
  460. # if [[ $patchStyleErrors != 0 ]] ; then
  461. # JIRA_COMMENT="$JIRA_COMMENT
  462. #
  463. # {color:red}-1 checkstyle{color}. The patch generated $patchStyleErrors code style errors."
  464. # return 1
  465. # fi
  466. # JIRA_COMMENT="$JIRA_COMMENT
  467. #
  468. # {color:green}+1 checkstyle{color}. The patch generated 0 code style errors."
  469. return 0
  470. }
  471. ###############################################################################
  472. ### Install the new jars so tests and findbugs can find all of the updated jars
  473. buildAndInstall () {
  474. echo ""
  475. echo ""
  476. echo "======================================================================"
  477. echo "======================================================================"
  478. echo " Installing all of the jars"
  479. echo "======================================================================"
  480. echo "======================================================================"
  481. echo ""
  482. echo ""
  483. echo "$MVN install -Dmaven.javadoc.skip=true -DskipTests -D${PROJECT_NAME}PatchProcess"
  484. $MVN install -Dmaven.javadoc.skip=true -DskipTests -D${PROJECT_NAME}PatchProcess
  485. return $?
  486. }
  487. ###############################################################################
  488. ### Check there are no changes in the number of Findbugs warnings
  489. checkFindbugsWarnings () {
  490. findbugs_version=`${FINDBUGS_HOME}/bin/findbugs -version`
  491. echo ""
  492. echo ""
  493. echo "======================================================================"
  494. echo "======================================================================"
  495. echo " Determining number of patched Findbugs warnings."
  496. echo "======================================================================"
  497. echo "======================================================================"
  498. echo ""
  499. echo ""
  500. modules=$(findModules)
  501. rc=0
  502. for module in $modules;
  503. do
  504. cd $module
  505. echo " Running findbugs in $module"
  506. module_suffix=`basename ${module}`
  507. echo "$MVN clean test findbugs:findbugs -DskipTests -D${PROJECT_NAME}PatchProcess < /dev/null > $PATCH_DIR/patchFindBugsOutput${module_suffix}.txt 2>&1"
  508. $MVN clean test findbugs:findbugs -DskipTests -D${PROJECT_NAME}PatchProcess < /dev/null > $PATCH_DIR/patchFindBugsOutput${module_suffix}.txt 2>&1
  509. (( rc = rc + $? ))
  510. cd -
  511. done
  512. if [ $rc != 0 ] ; then
  513. JIRA_COMMENT="$JIRA_COMMENT
  514. {color:red}-1 findbugs{color}. The patch appears to cause Findbugs (version ${findbugs_version}) to fail."
  515. return 1
  516. fi
  517. findbugsWarnings=0
  518. for file in $(find $BASEDIR -name findbugsXml.xml)
  519. do
  520. relative_file=${file#$BASEDIR/} # strip leading $BASEDIR prefix
  521. if [ ! $relative_file == "target/findbugsXml.xml" ]; then
  522. module_suffix=${relative_file%/target/findbugsXml.xml} # strip trailing path
  523. module_suffix=`basename ${module_suffix}`
  524. fi
  525. cp $file $PATCH_DIR/patchFindbugsWarnings${module_suffix}.xml
  526. $FINDBUGS_HOME/bin/setBugDatabaseInfo -timestamp "01/01/2000" \
  527. $PATCH_DIR/patchFindbugsWarnings${module_suffix}.xml \
  528. $PATCH_DIR/patchFindbugsWarnings${module_suffix}.xml
  529. newFindbugsWarnings=`$FINDBUGS_HOME/bin/filterBugs -first "01/01/2000" $PATCH_DIR/patchFindbugsWarnings${module_suffix}.xml \
  530. $PATCH_DIR/newPatchFindbugsWarnings${module_suffix}.xml | $AWK '{print $1}'`
  531. echo "Found $newFindbugsWarnings Findbugs warnings ($file)"
  532. findbugsWarnings=$((findbugsWarnings+newFindbugsWarnings))
  533. $FINDBUGS_HOME/bin/convertXmlToText -html \
  534. $PATCH_DIR/newPatchFindbugsWarnings${module_suffix}.xml \
  535. $PATCH_DIR/newPatchFindbugsWarnings${module_suffix}.html
  536. if [[ $newFindbugsWarnings > 0 ]] ; then
  537. JIRA_COMMENT_FOOTER="Findbugs warnings: $BUILD_URL/artifact/trunk/patchprocess/newPatchFindbugsWarnings${module_suffix}.html
  538. $JIRA_COMMENT_FOOTER"
  539. fi
  540. done
  541. if [[ $findbugsWarnings -gt 0 ]] ; then
  542. JIRA_COMMENT="$JIRA_COMMENT
  543. {color:red}-1 findbugs{color}. The patch appears to introduce $findbugsWarnings new Findbugs (version ${findbugs_version}) warnings."
  544. return 1
  545. fi
  546. JIRA_COMMENT="$JIRA_COMMENT
  547. {color:green}+1 findbugs{color}. The patch does not introduce any new Findbugs (version ${findbugs_version}) warnings."
  548. return 0
  549. }
  550. ###############################################################################
  551. ### Verify eclipse:eclipse works
  552. checkEclipseGeneration () {
  553. echo ""
  554. echo ""
  555. echo "======================================================================"
  556. echo "======================================================================"
  557. echo " Running mvn eclipse:eclipse."
  558. echo "======================================================================"
  559. echo "======================================================================"
  560. echo ""
  561. echo ""
  562. echo "$MVN eclipse:eclipse -D${PROJECT_NAME}PatchProcess > $PATCH_DIR/patchEclipseOutput.txt 2>&1"
  563. $MVN eclipse:eclipse -D${PROJECT_NAME}PatchProcess > $PATCH_DIR/patchEclipseOutput.txt 2>&1
  564. if [[ $? != 0 ]] ; then
  565. JIRA_COMMENT="$JIRA_COMMENT
  566. {color:red}-1 eclipse:eclipse{color}. The patch failed to build with eclipse:eclipse."
  567. return 1
  568. fi
  569. JIRA_COMMENT="$JIRA_COMMENT
  570. {color:green}+1 eclipse:eclipse{color}. The patch built with eclipse:eclipse."
  571. return 0
  572. }
  573. ###############################################################################
  574. ### Run the tests
  575. runTests () {
  576. echo ""
  577. echo ""
  578. echo "======================================================================"
  579. echo "======================================================================"
  580. echo " Running tests."
  581. echo "======================================================================"
  582. echo "======================================================================"
  583. echo ""
  584. echo ""
  585. failed_tests=""
  586. modules=$(findModules)
  587. #
  588. # If we are building hadoop-hdfs-project, we must build the native component
  589. # of hadoop-common-project first. In order to accomplish this, we move the
  590. # hadoop-hdfs subprojects to the end of the list so that common will come
  591. # first.
  592. #
  593. # Of course, we may not be building hadoop-common at all-- in this case, we
  594. # explicitly insert a mvn compile -Pnative of common, to ensure that the
  595. # native libraries show up where we need them.
  596. #
  597. building_common=0
  598. for module in $modules; do
  599. if [[ $module == hadoop-hdfs-project* ]]; then
  600. hdfs_modules="$hdfs_modules $module"
  601. elif [[ $module == hadoop-common-project* ]]; then
  602. ordered_modules="$ordered_modules $module"
  603. building_common=1
  604. else
  605. ordered_modules="$ordered_modules $module"
  606. fi
  607. done
  608. if [ -n "$hdfs_modules" ]; then
  609. ordered_modules="$ordered_modules $hdfs_modules"
  610. if [[ $building_common -eq 0 ]]; then
  611. echo " Building hadoop-common with -Pnative in order to provide \
  612. libhadoop.so to the hadoop-hdfs unit tests."
  613. echo " $MVN compile -D${PROJECT_NAME}PatchProcess"
  614. if ! $MVN compile -D${PROJECT_NAME}PatchProcess; then
  615. JIRA_COMMENT="$JIRA_COMMENT
  616. {color:red}-1 core tests{color}. Failed to build the native portion \
  617. of hadoop-common prior to running the unit tests in $ordered_modules"
  618. return 1
  619. fi
  620. fi
  621. fi
  622. failed_test_builds=""
  623. test_timeouts=""
  624. # Get the list of modified files
  625. TMP=/tmp/tmp.paths.$$
  626. $GREP '^+++ \|^--- ' $PATCH_DIR/patch | cut -c '5-' | $GREP -v /dev/null | sort > $TMP
  627. # if all of the lines start with a/ or b/, then this is a git patch that
  628. # was generated without --no-prefix
  629. if ! $GREP -qv '^a/\|^b/' $TMP ; then
  630. sed -i -e 's,^[ab]/,,' $TMP
  631. fi
  632. for module in $ordered_modules; do
  633. cd $module
  634. skip_surefiretests=1
  635. module_suffix=`basename ${module}`
  636. echo "Get the list of files modified in module $module"
  637. # Come up with a list of changed files for $module into $MODULE_FILES
  638. MODULE_FILES=/tmp/${module_suffix}_files.txt
  639. $GREP $module $TMP > $MODULE_FILES
  640. module_files=$(cat $MODULE_FILES)
  641. for module_filename in $module_files; do
  642. file_ext=$(echo $module_filename | awk -F . '{if (NF>1) {print $NF}}')
  643. # Look for java extension
  644. if [[ "$file_ext" == "java" ]]; then
  645. skip_surefiretests=0
  646. break
  647. fi
  648. done
  649. test_logfile=$PATCH_DIR/testrun_${module_suffix}.txt
  650. echo " Running tests in $module"
  651. # Skip java tests if this module did not have changes to java files
  652. if [[ $skip_surefiretests -eq 0 ]];
  653. then
  654. echo " $MVN clean install -fae -D${PROJECT_NAME}PatchProcess"
  655. $MVN clean install -fae -D${PROJECT_NAME}PatchProcess > $test_logfile 2>&1
  656. else
  657. echo " $MVN clean install -fae -D${PROJECT_NAME}PatchProcess -DskipSurefireTests"
  658. $MVN clean install -fae -D${PROJECT_NAME}PatchProcess -DskipSurefireTests > $test_logfile 2>&1
  659. fi
  660. test_build_result=$?
  661. cat $test_logfile
  662. # module_test_timeouts=`$AWK '/^Running / { if (last) { print last } last=$2 } /^Tests run: / { last="" }' $test_logfile`
  663. module_test_timeouts=""
  664. if [[ -n "$module_test_timeouts" ]] ; then
  665. test_timeouts="$test_timeouts
  666. $module_test_timeouts"
  667. fi
  668. 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"`
  669. if [[ -n "$module_failed_tests" ]] ; then
  670. failed_tests="${failed_tests}
  671. ${module_failed_tests}"
  672. fi
  673. if [[ $test_build_result != 0 && -z "$module_failed_tests" && -z "$module_test_timeouts" ]] ; then
  674. failed_test_builds="$module $failed_test_builds"
  675. fi
  676. cd -
  677. done
  678. result=0
  679. comment_prefix=" {color:red}-1 core tests{color}."
  680. if [[ -n "$failed_tests" ]] ; then
  681. JIRA_COMMENT="$JIRA_COMMENT
  682. $comment_prefix The patch failed these unit tests in $modules:
  683. $failed_tests"
  684. comment_prefix=" "
  685. result=1
  686. fi
  687. if [[ -n "$test_timeouts" ]] ; then
  688. JIRA_COMMENT="$JIRA_COMMENT
  689. $comment_prefix The following test timeouts occurred in $modules:
  690. $test_timeouts"
  691. comment_prefix=" "
  692. result=1
  693. fi
  694. if [[ -n "$failed_test_builds" ]] ; then
  695. JIRA_COMMENT="$JIRA_COMMENT
  696. $comment_prefix The test build failed in $failed_test_builds"
  697. result=1
  698. fi
  699. if [[ $result == 0 ]] ; then
  700. JIRA_COMMENT="$JIRA_COMMENT
  701. {color:green}+1 core tests{color}. The patch passed unit tests in $modules."
  702. fi
  703. return $result
  704. }
  705. ###############################################################################
  706. # Find the maven module containing the given file.
  707. findModule (){
  708. dir=`dirname $1`
  709. while [ 1 ]
  710. do
  711. if [ -f "$dir/pom.xml" ]
  712. then
  713. echo $dir
  714. return
  715. else
  716. dir=`dirname $dir`
  717. fi
  718. done
  719. }
  720. findModules () {
  721. # Come up with a list of changed files into $TMP
  722. TMP=/tmp/tmp.paths.$$
  723. $GREP '^+++ \|^--- ' $PATCH_DIR/patch | cut -c '5-' | $GREP -v /dev/null | sort | uniq > $TMP
  724. # if all of the lines start with a/ or b/, then this is a git patch that
  725. # was generated without --no-prefix
  726. if ! $GREP -qv '^a/\|^b/' $TMP ; then
  727. sed -i -e 's,^[ab]/,,' $TMP
  728. fi
  729. # Now find all the modules that were changed
  730. TMP_MODULES=/tmp/tmp.modules.$$
  731. for file in $(cut -f 1 $TMP | sort | uniq); do
  732. echo $(findModule $file) >> $TMP_MODULES
  733. done
  734. rm $TMP
  735. # Filter out modules without code
  736. CHANGED_MODULES=""
  737. for module in $(cat $TMP_MODULES | sort | uniq); do
  738. $GREP "<packaging>pom</packaging>" $module/pom.xml > /dev/null
  739. if [ "$?" != 0 ] || [ "$module" == "ambari-web" ]; then # ambari-web is packing = pom but has unit tests
  740. CHANGED_MODULES="$CHANGED_MODULES $module"
  741. fi
  742. done
  743. rm $TMP_MODULES
  744. echo $CHANGED_MODULES
  745. }
  746. ###############################################################################
  747. ### Run the test-contrib target
  748. runContribTests () {
  749. echo ""
  750. echo ""
  751. echo "======================================================================"
  752. echo "======================================================================"
  753. echo " Running contrib tests."
  754. echo "======================================================================"
  755. echo "======================================================================"
  756. echo ""
  757. echo ""
  758. if [[ `$GREP -c 'test-contrib' build.xml` == 0 ]] ; then
  759. echo "No contrib tests in this project."
  760. return 0
  761. fi
  762. ### Kill any rogue build processes from the last attempt
  763. $PS auxwww | $GREP ${PROJECT_NAME}PatchProcess | $AWK '{print $2}' | /usr/bin/xargs -t -I {} /bin/kill -9 {} > /dev/null
  764. #echo "$ANT_HOME/bin/ant -Dversion="${VERSION}" $ECLIPSE_PROPERTY -DHadoopPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=no test-contrib"
  765. #$ANT_HOME/bin/ant -Dversion="${VERSION}" $ECLIPSE_PROPERTY -DHadoopPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=no test-contrib
  766. echo "NOP"
  767. if [[ $? != 0 ]] ; then
  768. JIRA_COMMENT="$JIRA_COMMENT
  769. {color:red}-1 contrib tests{color}. The patch failed contrib unit tests."
  770. return 1
  771. fi
  772. JIRA_COMMENT="$JIRA_COMMENT
  773. {color:green}+1 contrib tests{color}. The patch passed contrib unit tests."
  774. return 0
  775. }
  776. ###############################################################################
  777. ### Run the inject-system-faults target
  778. checkInjectSystemFaults () {
  779. echo ""
  780. echo ""
  781. echo "======================================================================"
  782. echo "======================================================================"
  783. echo " Checking the integrity of system test framework code."
  784. echo "======================================================================"
  785. echo "======================================================================"
  786. echo ""
  787. echo ""
  788. ### Kill any rogue build processes from the last attempt
  789. $PS auxwww | $GREP ${PROJECT_NAME}PatchProcess | $AWK '{print $2}' | /usr/bin/xargs -t -I {} /bin/kill -9 {} > /dev/null
  790. #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"
  791. #$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
  792. echo "NOP"
  793. return 0
  794. if [[ $? != 0 ]] ; then
  795. JIRA_COMMENT="$JIRA_COMMENT
  796. {color:red}-1 system test framework{color}. The patch failed system test framework compile."
  797. return 1
  798. fi
  799. JIRA_COMMENT="$JIRA_COMMENT
  800. {color:green}+1 system test framework{color}. The patch passed system test framework compile."
  801. return 0
  802. }
  803. ###############################################################################
  804. ### Submit a comment to the defect's Jira
  805. submitJiraComment () {
  806. local result=$1
  807. ### Do not output the value of JIRA_COMMENT_FOOTER when run by a developer
  808. if [[ $JENKINS == "false" ]] ; then
  809. JIRA_COMMENT_FOOTER=""
  810. fi
  811. if [[ $result == 0 ]] ; then
  812. comment="{color:green}+1 overall{color}. $JIRA_COMMENT
  813. $JIRA_COMMENT_FOOTER"
  814. else
  815. comment="{color:red}-1 overall{color}. $JIRA_COMMENT
  816. $JIRA_COMMENT_FOOTER"
  817. fi
  818. ### Output the test result to the console
  819. echo "
  820. $comment"
  821. if [[ $JENKINS == "true" ]] ; then
  822. echo ""
  823. echo ""
  824. echo "======================================================================"
  825. echo "======================================================================"
  826. echo " Adding comment to Jira."
  827. echo "======================================================================"
  828. echo "======================================================================"
  829. echo ""
  830. echo ""
  831. ### Update Jira with a comment
  832. export USER=hudson
  833. $JIRACLI -s https://issues.apache.org/jira -a addcomment -u hadoopqa -p $JIRA_PASSWD --comment "$comment" --issue $defect
  834. $JIRACLI -s https://issues.apache.org/jira -a logout -u hadoopqa -p $JIRA_PASSWD
  835. fi
  836. }
  837. ###############################################################################
  838. ### Cleanup files
  839. cleanupAndExit () {
  840. local result=$1
  841. echo ""
  842. echo ""
  843. echo "======================================================================"
  844. echo "======================================================================"
  845. echo " Finished build."
  846. echo "======================================================================"
  847. echo "======================================================================"
  848. echo ""
  849. echo ""
  850. exit $result
  851. }
  852. ###############################################################################
  853. ###############################################################################
  854. ###############################################################################
  855. JIRA_COMMENT=""
  856. JIRA_COMMENT_FOOTER="Console output: $BUILD_URL/console
  857. This message is automatically generated."
  858. ### Check if arguments to the script have been specified properly or not
  859. parseArgs $@
  860. cd $BASEDIR
  861. checkout
  862. RESULT=$?
  863. if [[ $JENKINS == "true" ]] ; then
  864. if [[ $RESULT != 0 ]] ; then
  865. exit 100
  866. fi
  867. fi
  868. ### Check if $PATCH_DIR exists. If it does not exist, create a new directory
  869. if [[ ! -e "$PATCH_DIR" ]] ; then
  870. mkdir "$PATCH_DIR"
  871. if [[ $? == 0 ]] ; then
  872. echo "$PATCH_DIR has been created"
  873. else
  874. echo "Unable to create $PATCH_DIR"
  875. cleanupAndExit 0
  876. fi
  877. fi
  878. downloadPatch
  879. verifyPatch
  880. (( RESULT = RESULT + $? ))
  881. if [[ $RESULT != 0 ]] ; then
  882. submitJiraComment 1
  883. cleanupAndExit 1
  884. fi
  885. prebuildWithoutPatch
  886. (( RESULT = RESULT + $? ))
  887. if [[ $RESULT != 0 ]] ; then
  888. submitJiraComment 1
  889. cleanupAndExit 1
  890. fi
  891. checkAuthor
  892. (( RESULT = RESULT + $? ))
  893. # if [[ $JENKINS == "true" ]] ; then
  894. # cleanUpXml
  895. # fi
  896. echo "before checkTests $RESULT"
  897. checkTests
  898. (( RESULT = RESULT + $? ))
  899. applyPatch
  900. APPLY_PATCH_RET=$?
  901. (( RESULT = RESULT + $APPLY_PATCH_RET ))
  902. echo "after applyPatch $RESULT"
  903. if [[ $APPLY_PATCH_RET != 0 ]] ; then
  904. submitJiraComment 1
  905. cleanupAndExit 1
  906. fi
  907. checkJavacWarnings
  908. JAVAC_RET=$?
  909. #2 is returned if the code could not compile
  910. if [[ $JAVAC_RET == 2 ]] ; then
  911. submitJiraComment 1
  912. cleanupAndExit 1
  913. fi
  914. (( RESULT = RESULT + $JAVAC_RET ))
  915. ### Checkstyle not implemented yet
  916. #checkStyle
  917. #(( RESULT = RESULT + $? ))
  918. echo "before buildAndInstall $RESULT"
  919. buildAndInstall
  920. # checkEclipseGeneration
  921. # (( RESULT = RESULT + $? ))
  922. # checkFindbugsWarnings
  923. # (( RESULT = RESULT + $? ))
  924. echo "before checkReleaseAuditWarnings $RESULT"
  925. checkReleaseAuditWarnings
  926. (( RESULT = RESULT + $? ))
  927. echo "before runTests $RESULT"
  928. ### Run tests for Jenkins or if explictly asked for by a developer
  929. if [[ $JENKINS == "true" || $RUN_TESTS == "true" ]] ; then
  930. runTests
  931. (( RESULT = RESULT + $? ))
  932. # runContribTests
  933. # (( RESULT = RESULT + $? ))
  934. fi
  935. checkInjectSystemFaults
  936. (( RESULT = RESULT + $? ))
  937. JIRA_COMMENT_FOOTER="Test results: $BUILD_URL/testReport/
  938. $JIRA_COMMENT_FOOTER"
  939. submitJiraComment $RESULT
  940. cleanupAndExit $RESULT