test-patch.sh 30 KB

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