test-patch.sh 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015
  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. for module in $ordered_modules; do
  625. cd $module
  626. module_suffix=`basename ${module}`
  627. test_logfile=$PATCH_DIR/testrun_${module_suffix}.txt
  628. echo " Running tests in $module"
  629. echo " $MVN clean install -fn -D${PROJECT_NAME}PatchProcess"
  630. $MVN clean install -fae -D${PROJECT_NAME}PatchProcess > $test_logfile 2>&1
  631. test_build_result=$?
  632. cat $test_logfile
  633. # module_test_timeouts=`$AWK '/^Running / { if (last) { print last } last=$2 } /^Tests run: / { last="" }' $test_logfile`
  634. module_test_timeouts=""
  635. if [[ -n "$module_test_timeouts" ]] ; then
  636. test_timeouts="$test_timeouts
  637. $module_test_timeouts"
  638. fi
  639. 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"`
  640. if [[ -n "$module_failed_tests" ]] ; then
  641. failed_tests="${failed_tests}
  642. ${module_failed_tests}"
  643. fi
  644. if [[ $test_build_result != 0 && -z "$module_failed_tests" && -z "$module_test_timeouts" ]] ; then
  645. failed_test_builds="$module $failed_test_builds"
  646. fi
  647. cd -
  648. done
  649. result=0
  650. comment_prefix=" {color:red}-1 core tests{color}."
  651. if [[ -n "$failed_tests" ]] ; then
  652. JIRA_COMMENT="$JIRA_COMMENT
  653. $comment_prefix The patch failed these unit tests in $modules:
  654. $failed_tests"
  655. comment_prefix=" "
  656. result=1
  657. fi
  658. if [[ -n "$test_timeouts" ]] ; then
  659. JIRA_COMMENT="$JIRA_COMMENT
  660. $comment_prefix The following test timeouts occurred in $modules:
  661. $test_timeouts"
  662. comment_prefix=" "
  663. result=1
  664. fi
  665. if [[ -n "$failed_test_builds" ]] ; then
  666. JIRA_COMMENT="$JIRA_COMMENT
  667. $comment_prefix The test build failed in $failed_test_builds"
  668. result=1
  669. fi
  670. if [[ $result == 0 ]] ; then
  671. JIRA_COMMENT="$JIRA_COMMENT
  672. {color:green}+1 core tests{color}. The patch passed unit tests in $modules."
  673. fi
  674. return $result
  675. }
  676. ###############################################################################
  677. # Find the maven module containing the given file.
  678. findModule (){
  679. dir=`dirname $1`
  680. while [ 1 ]
  681. do
  682. if [ -f "$dir/pom.xml" ]
  683. then
  684. echo $dir
  685. return
  686. else
  687. dir=`dirname $dir`
  688. fi
  689. done
  690. }
  691. findModules () {
  692. # Come up with a list of changed files into $TMP
  693. TMP=/tmp/tmp.paths.$$
  694. $GREP '^+++ \|^--- ' $PATCH_DIR/patch | cut -c '5-' | $GREP -v /dev/null | sort | uniq > $TMP
  695. # if all of the lines start with a/ or b/, then this is a git patch that
  696. # was generated without --no-prefix
  697. if ! $GREP -qv '^a/\|^b/' $TMP ; then
  698. sed -i -e 's,^[ab]/,,' $TMP
  699. fi
  700. # Now find all the modules that were changed
  701. TMP_MODULES=/tmp/tmp.modules.$$
  702. for file in $(cut -f 1 $TMP | sort | uniq); do
  703. echo $(findModule $file) >> $TMP_MODULES
  704. done
  705. rm $TMP
  706. # Filter out modules without code
  707. CHANGED_MODULES=""
  708. for module in $(cat $TMP_MODULES | sort | uniq); do
  709. $GREP "<packaging>pom</packaging>" $module/pom.xml > /dev/null
  710. if [ "$?" != 0 ]; then
  711. CHANGED_MODULES="$CHANGED_MODULES $module"
  712. fi
  713. done
  714. rm $TMP_MODULES
  715. echo $CHANGED_MODULES
  716. }
  717. ###############################################################################
  718. ### Run the test-contrib target
  719. runContribTests () {
  720. echo ""
  721. echo ""
  722. echo "======================================================================"
  723. echo "======================================================================"
  724. echo " Running contrib tests."
  725. echo "======================================================================"
  726. echo "======================================================================"
  727. echo ""
  728. echo ""
  729. if [[ `$GREP -c 'test-contrib' build.xml` == 0 ]] ; then
  730. echo "No contrib tests in this project."
  731. return 0
  732. fi
  733. ### Kill any rogue build processes from the last attempt
  734. $PS auxwww | $GREP ${PROJECT_NAME}PatchProcess | $AWK '{print $2}' | /usr/bin/xargs -t -I {} /bin/kill -9 {} > /dev/null
  735. #echo "$ANT_HOME/bin/ant -Dversion="${VERSION}" $ECLIPSE_PROPERTY -DHadoopPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=no test-contrib"
  736. #$ANT_HOME/bin/ant -Dversion="${VERSION}" $ECLIPSE_PROPERTY -DHadoopPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=no test-contrib
  737. echo "NOP"
  738. if [[ $? != 0 ]] ; then
  739. JIRA_COMMENT="$JIRA_COMMENT
  740. {color:red}-1 contrib tests{color}. The patch failed contrib unit tests."
  741. return 1
  742. fi
  743. JIRA_COMMENT="$JIRA_COMMENT
  744. {color:green}+1 contrib tests{color}. The patch passed contrib unit tests."
  745. return 0
  746. }
  747. ###############################################################################
  748. ### Run the inject-system-faults target
  749. checkInjectSystemFaults () {
  750. echo ""
  751. echo ""
  752. echo "======================================================================"
  753. echo "======================================================================"
  754. echo " Checking the integrity of system test framework code."
  755. echo "======================================================================"
  756. echo "======================================================================"
  757. echo ""
  758. echo ""
  759. ### Kill any rogue build processes from the last attempt
  760. $PS auxwww | $GREP ${PROJECT_NAME}PatchProcess | $AWK '{print $2}' | /usr/bin/xargs -t -I {} /bin/kill -9 {} > /dev/null
  761. #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"
  762. #$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
  763. echo "NOP"
  764. return 0
  765. if [[ $? != 0 ]] ; then
  766. JIRA_COMMENT="$JIRA_COMMENT
  767. {color:red}-1 system test framework{color}. The patch failed system test framework compile."
  768. return 1
  769. fi
  770. JIRA_COMMENT="$JIRA_COMMENT
  771. {color:green}+1 system test framework{color}. The patch passed system test framework compile."
  772. return 0
  773. }
  774. ###############################################################################
  775. ### Submit a comment to the defect's Jira
  776. submitJiraComment () {
  777. local result=$1
  778. ### Do not output the value of JIRA_COMMENT_FOOTER when run by a developer
  779. if [[ $JENKINS == "false" ]] ; then
  780. JIRA_COMMENT_FOOTER=""
  781. fi
  782. if [[ $result == 0 ]] ; then
  783. comment="{color:green}+1 overall{color}. $JIRA_COMMENT
  784. $JIRA_COMMENT_FOOTER"
  785. else
  786. comment="{color:red}-1 overall{color}. $JIRA_COMMENT
  787. $JIRA_COMMENT_FOOTER"
  788. fi
  789. ### Output the test result to the console
  790. echo "
  791. $comment"
  792. if [[ $JENKINS == "true" ]] ; then
  793. echo ""
  794. echo ""
  795. echo "======================================================================"
  796. echo "======================================================================"
  797. echo " Adding comment to Jira."
  798. echo "======================================================================"
  799. echo "======================================================================"
  800. echo ""
  801. echo ""
  802. ### Update Jira with a comment
  803. export USER=hudson
  804. $JIRACLI -s https://issues.apache.org/jira -a addcomment -u hadoopqa -p $JIRA_PASSWD --comment "$comment" --issue $defect
  805. $JIRACLI -s https://issues.apache.org/jira -a logout -u hadoopqa -p $JIRA_PASSWD
  806. fi
  807. }
  808. ###############################################################################
  809. ### Cleanup files
  810. cleanupAndExit () {
  811. local result=$1
  812. echo ""
  813. echo ""
  814. echo "======================================================================"
  815. echo "======================================================================"
  816. echo " Finished build."
  817. echo "======================================================================"
  818. echo "======================================================================"
  819. echo ""
  820. echo ""
  821. exit $result
  822. }
  823. ###############################################################################
  824. ###############################################################################
  825. ###############################################################################
  826. JIRA_COMMENT=""
  827. JIRA_COMMENT_FOOTER="Console output: $BUILD_URL/console
  828. This message is automatically generated."
  829. ### Check if arguments to the script have been specified properly or not
  830. parseArgs $@
  831. cd $BASEDIR
  832. checkout
  833. RESULT=$?
  834. if [[ $JENKINS == "true" ]] ; then
  835. if [[ $RESULT != 0 ]] ; then
  836. exit 100
  837. fi
  838. fi
  839. ### Check if $PATCH_DIR exists. If it does not exist, create a new directory
  840. if [[ ! -e "$PATCH_DIR" ]] ; then
  841. mkdir "$PATCH_DIR"
  842. if [[ $? == 0 ]] ; then
  843. echo "$PATCH_DIR has been created"
  844. else
  845. echo "Unable to create $PATCH_DIR"
  846. cleanupAndExit 0
  847. fi
  848. fi
  849. downloadPatch
  850. verifyPatch
  851. (( RESULT = RESULT + $? ))
  852. if [[ $RESULT != 0 ]] ; then
  853. submitJiraComment 1
  854. cleanupAndExit 1
  855. fi
  856. prebuildWithoutPatch
  857. (( RESULT = RESULT + $? ))
  858. if [[ $RESULT != 0 ]] ; then
  859. submitJiraComment 1
  860. cleanupAndExit 1
  861. fi
  862. checkAuthor
  863. (( RESULT = RESULT + $? ))
  864. # if [[ $JENKINS == "true" ]] ; then
  865. # cleanUpXml
  866. # fi
  867. echo "before checkTests $RESULT"
  868. checkTests
  869. (( RESULT = RESULT + $? ))
  870. applyPatch
  871. APPLY_PATCH_RET=$?
  872. (( RESULT = RESULT + $APPLY_PATCH_RET ))
  873. echo "after applyPatch $RESULT"
  874. if [[ $APPLY_PATCH_RET != 0 ]] ; then
  875. submitJiraComment 1
  876. cleanupAndExit 1
  877. fi
  878. checkJavacWarnings
  879. JAVAC_RET=$?
  880. #2 is returned if the code could not compile
  881. if [[ $JAVAC_RET == 2 ]] ; then
  882. submitJiraComment 1
  883. cleanupAndExit 1
  884. fi
  885. (( RESULT = RESULT + $JAVAC_RET ))
  886. ### Checkstyle not implemented yet
  887. #checkStyle
  888. #(( RESULT = RESULT + $? ))
  889. echo "before buildAndInstall $RESULT"
  890. buildAndInstall
  891. # checkEclipseGeneration
  892. # (( RESULT = RESULT + $? ))
  893. # checkFindbugsWarnings
  894. # (( RESULT = RESULT + $? ))
  895. echo "before checkReleaseAuditWarnings $RESULT"
  896. checkReleaseAuditWarnings
  897. (( RESULT = RESULT + $? ))
  898. echo "before runTests $RESULT"
  899. ### Run tests for Jenkins or if explictly asked for by a developer
  900. if [[ $JENKINS == "true" || $RUN_TESTS == "true" ]] ; then
  901. runTests
  902. (( RESULT = RESULT + $? ))
  903. # runContribTests
  904. # (( RESULT = RESULT + $? ))
  905. fi
  906. checkInjectSystemFaults
  907. (( RESULT = RESULT + $? ))
  908. JIRA_COMMENT_FOOTER="Test results: $BUILD_URL/testReport/
  909. $JIRA_COMMENT_FOOTER"
  910. submitJiraComment $RESULT
  911. cleanupAndExit $RESULT