test-patch.sh 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  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. . $bindir/test-patch.properties
  20. ###############################################################################
  21. parseArgs() {
  22. case "$1" in
  23. HUDSON)
  24. ### Set HUDSON to true to indicate that this script is being run by Hudson
  25. HUDSON=true
  26. if [[ $# != 16 ]] ; then
  27. echo "ERROR: usage $0 HUDSON <PATCH_DIR> <SUPPORT_DIR> <PS_CMD> <WGET_CMD> <JIRACLI> <SVN_CMD> <GREP_CMD> <PATCH_CMD> <FINDBUGS_HOME> <FORREST_HOME> <ECLIPSE_HOME> <WORKSPACE_BASEDIR> <JIRA_PASSWD> <CURL_CMD> <DEFECT> "
  28. cleanupAndExit 0
  29. fi
  30. PATCH_DIR=$2
  31. SUPPORT_DIR=$3
  32. PS=$4
  33. WGET=$5
  34. JIRACLI=$6
  35. SVN=$7
  36. GREP=$8
  37. PATCH=$9
  38. FINDBUGS_HOME=${10}
  39. FORREST_HOME=${11}
  40. ECLIPSE_HOME=${12}
  41. BASEDIR=${13}
  42. JIRA_PASSWD=${14}
  43. CURL=${15}
  44. defect=${16}
  45. ### Retrieve the defect number
  46. if [ -z "$defect" ] ; then
  47. echo "Could not determine the patch to test. Exiting."
  48. cleanupAndExit 0
  49. fi
  50. if [ ! -e "$PATCH_DIR" ] ; then
  51. mkdir -p $PATCH_DIR
  52. fi
  53. ECLIPSE_PROPERTY="-Declipse.home=$ECLIPSE_HOME"
  54. ;;
  55. DEVELOPER)
  56. ### Set HUDSON to false to indicate that this script is being run by a developer
  57. HUDSON=false
  58. if [[ $# != 9 ]] ; then
  59. echo "ERROR: usage $0 DEVELOPER <PATCH_FILE> <SCRATCH_DIR> <SVN_CMD> <GREP_CMD> <PATCH_CMD> <FINDBUGS_HOME> <FORREST_HOME> <WORKSPACE_BASEDIR>"
  60. cleanupAndExit 0
  61. fi
  62. ### PATCH_FILE contains the location of the patchfile
  63. PATCH_FILE=$2
  64. if [[ ! -e "$PATCH_FILE" ]] ; then
  65. echo "Unable to locate the patch file $PATCH_FILE"
  66. cleanupAndExit 0
  67. fi
  68. PATCH_DIR=$3
  69. ### Check if $PATCH_DIR exists. If it does not exist, create a new directory
  70. if [[ ! -e "$PATCH_DIR" ]] ; then
  71. mkdir "$PATCH_DIR"
  72. if [[ $? == 0 ]] ; then
  73. echo "$PATCH_DIR has been created"
  74. else
  75. echo "Unable to create $PATCH_DIR"
  76. cleanupAndExit 0
  77. fi
  78. fi
  79. SVN=$4
  80. GREP=$5
  81. PATCH=$6
  82. FINDBUGS_HOME=$7
  83. FORREST_HOME=$8
  84. BASEDIR=$9
  85. ### Obtain the patch filename to append it to the version number
  86. defect=`basename $PATCH_FILE`
  87. ;;
  88. *)
  89. echo "ERROR: usage $0 HUDSON [args] | DEVELOPER [args]"
  90. cleanupAndExit 0
  91. ;;
  92. esac
  93. }
  94. ###############################################################################
  95. checkout () {
  96. echo ""
  97. echo ""
  98. echo "======================================================================"
  99. echo "======================================================================"
  100. echo " Testing patch for ${defect}."
  101. echo "======================================================================"
  102. echo "======================================================================"
  103. echo ""
  104. echo ""
  105. ### When run by a developer, if the workspace contains modifications, do not continue
  106. status=`$SVN stat --ignore-externals | sed -e '/^X[ ]*/D'`
  107. if [[ $HUDSON == "false" ]] ; then
  108. if [[ "$status" != "" ]] ; then
  109. echo "ERROR: can't run in a workspace that contains the following modifications"
  110. echo "$status"
  111. cleanupAndExit 1
  112. fi
  113. echo
  114. else
  115. cd $BASEDIR
  116. $SVN revert -R .
  117. rm -rf `$SVN status --no-ignore`
  118. $SVN update
  119. fi
  120. return $?
  121. }
  122. ###############################################################################
  123. setup () {
  124. ### Download latest patch file (ignoring .htm and .html) when run from patch process
  125. if [[ $HUDSON == "true" ]] ; then
  126. $WGET -q -O $PATCH_DIR/jira http://issues.apache.org/jira/browse/$defect
  127. if [[ `$GREP -c 'Patch Available' $PATCH_DIR/jira` == 0 ]] ; then
  128. echo "$defect is not \"Patch Available\". Exiting."
  129. cleanupAndExit 0
  130. fi
  131. 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]*/[^"]*'`
  132. patchURL="http://issues.apache.org${relativePatchURL}"
  133. patchNum=`echo $patchURL | $GREP -o '[0-9]*/' | $GREP -o '[0-9]*'`
  134. echo "$defect patch is being downloaded at `date` from"
  135. echo "$patchURL"
  136. $WGET -q -O $PATCH_DIR/patch $patchURL
  137. VERSION=${SVN_REVISION}_${defect}_PATCH-${patchNum}
  138. JIRA_COMMENT="Here are the results of testing the latest attachment
  139. $patchURL
  140. against trunk revision ${SVN_REVISION}."
  141. ### Copy in any supporting files needed by this process
  142. cp -r $SUPPORT_DIR/lib/* ./lib
  143. #PENDING: cp -f $SUPPORT_DIR/etc/checkstyle* ./src/test
  144. ### Copy the patch file to $PATCH_DIR
  145. else
  146. VERSION=PATCH-${defect}
  147. cp $PATCH_FILE $PATCH_DIR/patch
  148. if [[ $? == 0 ]] ; then
  149. echo "Patch file $PATCH_FILE copied to $PATCH_DIR"
  150. else
  151. echo "Could not copy $PATCH_FILE to $PATCH_DIR"
  152. cleanupAndExit 0
  153. fi
  154. fi
  155. ### exit if warnings are NOT defined in the properties file
  156. if [ -z "$OK_FINDBUGS_WARNINGS" ] || [[ -z "$OK_JAVADOC_WARNINGS" ]] || [[ -z $OK_RELEASEAUDIT_WARNINGS ]]; then
  157. echo "Please define the following properties in test-patch.properties file"
  158. echo "OK_FINDBUGS_WARNINGS"
  159. echo "OK_RELEASEAUDIT_WARNINGS"
  160. echo "OK_JAVADOC_WARNINGS"
  161. cleanupAndExit 1
  162. fi
  163. echo ""
  164. echo ""
  165. echo "======================================================================"
  166. echo "======================================================================"
  167. echo " Pre-build trunk to verify trunk stability and javac warnings"
  168. echo "======================================================================"
  169. echo "======================================================================"
  170. echo ""
  171. echo ""
  172. # echo "$ANT_HOME/bin/ant -Djavac.args="-Xlint -Xmaxwarns 1000" $ECLIPSE_PROPERTY -Dforrest.home=${FORREST_HOME} -D${PROJECT_NAME}PatchProcess= clean tar > $PATCH_DIR/trunkJavacWarnings.txt 2>&1"
  173. # $ANT_HOME/bin/ant -Djavac.args="-Xlint -Xmaxwarns 1000" $ECLIPSE_PROPERTY -Dforrest.home=${FORREST_HOME} -D${PROJECT_NAME}PatchProcess= clean tar > $PATCH_DIR/trunkJavacWarnings.txt 2>&1
  174. $MAVEN_HOME/bin/mvn clean compile -DskipTests -D${PROJECT_NAME}PatchProcess -Ptest-patch > $PATCH_DIR/trunkJavacWarnings.txt 2>&1
  175. if [[ $? != 0 ]] ; then
  176. echo "Trunk compilation is broken?"
  177. cleanupAndExit 1
  178. fi
  179. }
  180. ###############################################################################
  181. ### Check for @author tags in the patch
  182. checkAuthor () {
  183. echo ""
  184. echo ""
  185. echo "======================================================================"
  186. echo "======================================================================"
  187. echo " Checking there are no @author tags in the patch."
  188. echo "======================================================================"
  189. echo "======================================================================"
  190. echo ""
  191. echo ""
  192. authorTags=`$GREP -c -i '@author' $PATCH_DIR/patch`
  193. echo "There appear to be $authorTags @author tags in the patch."
  194. if [[ $authorTags != 0 ]] ; then
  195. JIRA_COMMENT="$JIRA_COMMENT
  196. -1 @author. The patch appears to contain $authorTags @author tags which the Hadoop community has agreed to not allow in code contributions."
  197. return 1
  198. fi
  199. JIRA_COMMENT="$JIRA_COMMENT
  200. +1 @author. The patch does not contain any @author tags."
  201. return 0
  202. }
  203. ###############################################################################
  204. ### Check for tests in the patch
  205. checkTests () {
  206. echo ""
  207. echo ""
  208. echo "======================================================================"
  209. echo "======================================================================"
  210. echo " Checking there are new or changed tests in the patch."
  211. echo "======================================================================"
  212. echo "======================================================================"
  213. echo ""
  214. echo ""
  215. testReferences=`$GREP -c -i '/test' $PATCH_DIR/patch`
  216. echo "There appear to be $testReferences test files referenced in the patch."
  217. if [[ $testReferences == 0 ]] ; then
  218. if [[ $HUDSON == "true" ]] ; then
  219. patchIsDoc=`$GREP -c -i 'title="documentation' $PATCH_DIR/jira`
  220. if [[ $patchIsDoc != 0 ]] ; then
  221. echo "The patch appears to be a documentation patch that doesn't require tests."
  222. JIRA_COMMENT="$JIRA_COMMENT
  223. +0 tests included. The patch appears to be a documentation patch that doesn't require tests."
  224. return 0
  225. fi
  226. fi
  227. JIRA_COMMENT="$JIRA_COMMENT
  228. -1 tests included. The patch doesn't appear to include any new or modified tests.
  229. Please justify why no new tests are needed for this patch.
  230. Also please list what manual steps were performed to verify this patch."
  231. return 1
  232. fi
  233. JIRA_COMMENT="$JIRA_COMMENT
  234. +1 tests included. The patch appears to include $testReferences new or modified tests."
  235. return 0
  236. }
  237. cleanUpXml () {
  238. cd $BASEDIR/conf
  239. for file in `ls *.xml.template`
  240. do
  241. rm -f `basename $file .template`
  242. done
  243. cd $BASEDIR
  244. }
  245. ###############################################################################
  246. ### Attempt to apply the patch
  247. applyPatch () {
  248. echo ""
  249. echo ""
  250. echo "======================================================================"
  251. echo "======================================================================"
  252. echo " Applying patch."
  253. echo "======================================================================"
  254. echo "======================================================================"
  255. echo ""
  256. echo ""
  257. export PATCH
  258. $bindir/smart-apply-patch.sh $PATCH_DIR/patch
  259. if [[ $? != 0 ]] ; then
  260. echo "PATCH APPLICATION FAILED"
  261. JIRA_COMMENT="$JIRA_COMMENT
  262. -1 patch. The patch command could not apply the patch."
  263. return 1
  264. fi
  265. return 0
  266. }
  267. ###############################################################################
  268. ### Check there are no javadoc warnings
  269. checkJavadocWarnings () {
  270. echo ""
  271. echo ""
  272. echo "======================================================================"
  273. echo "======================================================================"
  274. echo " Determining number of patched javadoc warnings."
  275. echo "======================================================================"
  276. echo "======================================================================"
  277. echo ""
  278. echo ""
  279. echo "$ANT_HOME/bin/ant -Dversion="${VERSION}" -DHadoopPatchProcess= clean javadoc | tee $PATCH_DIR/patchJavadocWarnings.txt"
  280. (cd root; mvn install)
  281. (cd doclet; mvn install)
  282. #$ANT_HOME/bin/ant -Dversion="${VERSION}" -DHadoopPatchProcess= clean javadoc | tee $PATCH_DIR/patchJavadocWarnings.txt
  283. $MAVEN_HOME/bin/mvn clean compile javadoc:javadoc -DskipTests -Pdocs -D${PROJECT_NAME}PatchProcess > $PATCH_DIR/patchJavadocWarnings.txt 2>&1
  284. javadocWarnings=`$GREP '\[WARNING\]' $PATCH_DIR/patchJavadocWarnings.txt | awk '/Javadoc Warnings/,EOF' | $GREP -v 'Javadoc Warnings' | awk 'BEGIN {total = 0} {total += 1} END {print total}'`
  285. echo ""
  286. echo ""
  287. echo "There appear to be $javadocWarnings javadoc warnings generated by the patched build."
  288. ### if current warnings greater than OK_JAVADOC_WARNINGS
  289. if [[ $javadocWarnings > $OK_JAVADOC_WARNINGS ]] ; then
  290. JIRA_COMMENT="$JIRA_COMMENT
  291. -1 javadoc. The javadoc tool appears to have generated `expr $(($javadocWarnings-$OK_JAVADOC_WARNINGS))` warning messages."
  292. return 1
  293. fi
  294. JIRA_COMMENT="$JIRA_COMMENT
  295. +1 javadoc. The javadoc tool did not generate any warning messages."
  296. return 0
  297. }
  298. ###############################################################################
  299. ### Check there are no changes in the number of Javac warnings
  300. checkJavacWarnings () {
  301. echo ""
  302. echo ""
  303. echo "======================================================================"
  304. echo "======================================================================"
  305. echo " Determining number of patched javac warnings."
  306. echo "======================================================================"
  307. echo "======================================================================"
  308. echo ""
  309. echo ""
  310. #echo "$ANT_HOME/bin/ant -Dversion="${VERSION}" -Djavac.args="-Xlint -Xmaxwarns 1000" $ECLIPSE_PROPERTY -Dforrest.home=${FORREST_HOME} -DHadoopPatchProcess= clean tar > $PATCH_DIR/patchJavacWarnings.txt 2>&1"
  311. #$ANT_HOME/bin/ant -Dversion="${VERSION}" -Djavac.args="-Xlint -Xmaxwarns 1000" $ECLIPSE_PROPERTY -Dforrest.home=${FORREST_HOME} -DHadoopPatchProcess= clean tar > $PATCH_DIR/patchJavacWarnings.txt 2>&1
  312. $MAVEN_HOME/bin/mvn clean compile -DskipTests -D${PROJECT_NAME}PatchProcess -Ptest-patch > $PATCH_DIR/patchJavacWarnings.txt 2>&1
  313. if [[ $? != 0 ]] ; then
  314. JIRA_COMMENT="$JIRA_COMMENT
  315. -1 javac. The patch appears to cause tar ant target to fail."
  316. return 1
  317. fi
  318. ### Compare trunk and patch javac warning numbers
  319. if [[ -f $PATCH_DIR/patchJavacWarnings.txt ]] ; then
  320. trunkJavacWarnings=`$GREP '\[WARNING\]' $PATCH_DIR/trunkJavacWarnings.txt | awk 'BEGIN {total = 0} {total += 1} END {print total}'`
  321. patchJavacWarnings=`$GREP '\[WARNING\]' $PATCH_DIR/patchJavacWarnings.txt | awk 'BEGIN {total = 0} {total += 1} END {print total}'`
  322. echo "There appear to be $trunkJavacWarnings javac compiler warnings before the patch and $patchJavacWarnings javac compiler warnings after applying the patch."
  323. if [[ $patchJavacWarnings != "" && $trunkJavacWarnings != "" ]] ; then
  324. if [[ $patchJavacWarnings -gt $trunkJavacWarnings ]] ; then
  325. JIRA_COMMENT="$JIRA_COMMENT
  326. -1 javac. The applied patch generated $patchJavacWarnings javac compiler warnings (more than the trunk's current $trunkJavacWarnings warnings)."
  327. return 1
  328. fi
  329. fi
  330. fi
  331. JIRA_COMMENT="$JIRA_COMMENT
  332. +1 javac. The applied patch does not increase the total number of javac compiler warnings."
  333. return 0
  334. }
  335. ###############################################################################
  336. ### Check there are no changes in the number of release audit (RAT) warnings
  337. checkReleaseAuditWarnings () {
  338. echo ""
  339. echo ""
  340. echo "======================================================================"
  341. echo "======================================================================"
  342. echo " Determining number of patched release audit warnings."
  343. echo "======================================================================"
  344. echo "======================================================================"
  345. echo ""
  346. echo ""
  347. #echo "$ANT_HOME/bin/ant -Dversion="${VERSION}" -Dforrest.home=${FORREST_HOME} -DHadoopPatchProcess= releaseaudit > $PATCH_DIR/patchReleaseAuditWarnings.txt 2>&1"
  348. #$ANT_HOME/bin/ant -Dversion="${VERSION}" -Dforrest.home=${FORREST_HOME} -DHadoopPatchProcess= releaseaudit > $PATCH_DIR/patchReleaseAuditWarnings.txt 2>&1
  349. $MAVEN_HOME/bin/mvn apache-rat:check -D${PROJECT_NAME}PatchProcess 2>&1
  350. find . -name rat.txt | xargs cat > $PATCH_DIR/patchReleaseAuditWarnings.txt
  351. ### Compare trunk and patch release audit warning numbers
  352. if [[ -f $PATCH_DIR/patchReleaseAuditWarnings.txt ]] ; then
  353. patchReleaseAuditWarnings=`$GREP -c '\!?????' $PATCH_DIR/patchReleaseAuditWarnings.txt`
  354. echo ""
  355. echo ""
  356. echo "There appear to be $OK_RELEASEAUDIT_WARNINGS release audit warnings before the patch and $patchReleaseAuditWarnings release audit warnings after applying the patch."
  357. if [[ $patchReleaseAuditWarnings != "" && $OK_RELEASEAUDIT_WARNINGS != "" ]] ; then
  358. if [[ $patchReleaseAuditWarnings -gt $OK_RELEASEAUDIT_WARNINGS ]] ; then
  359. JIRA_COMMENT="$JIRA_COMMENT
  360. -1 release audit. The applied patch generated $patchReleaseAuditWarnings release audit warnings (more than the trunk's current $OK_RELEASEAUDIT_WARNINGS warnings)."
  361. $GREP '\!?????' $PATCH_DIR/patchReleaseAuditWarnings.txt > $PATCH_DIR/patchReleaseAuditProblems.txt
  362. echo "Lines that start with ????? in the release audit report indicate files that do not have an Apache license header." >> $PATCH_DIR/patchReleaseAuditProblems.txt
  363. JIRA_COMMENT_FOOTER="Release audit warnings: $BUILD_URL/artifact/trunk/patchprocess/patchReleaseAuditProblems.txt
  364. $JIRA_COMMENT_FOOTER"
  365. return 1
  366. fi
  367. fi
  368. fi
  369. JIRA_COMMENT="$JIRA_COMMENT
  370. +1 release audit. The applied patch does not increase the total number of release audit warnings."
  371. return 0
  372. }
  373. ###############################################################################
  374. ### Check there are no changes in the number of Checkstyle warnings
  375. checkStyle () {
  376. echo ""
  377. echo ""
  378. echo "======================================================================"
  379. echo "======================================================================"
  380. echo " Determining number of patched checkstyle warnings."
  381. echo "======================================================================"
  382. echo "======================================================================"
  383. echo ""
  384. echo ""
  385. echo "THIS IS NOT IMPLEMENTED YET"
  386. echo ""
  387. echo ""
  388. #echo "$ANT_HOME/bin/ant -Dversion="${VERSION}" -DHadoopPatchProcess= checkstyle"
  389. #$ANT_HOME/bin/ant -Dversion="${VERSION}" -DHadoopPatchProcess= checkstyle
  390. $MAVEN_HOME/bin/mvn compile checkstyle:checkstyle -D${PROJECT_NAME}PatchProcess
  391. JIRA_COMMENT_FOOTER="Checkstyle results: $BUILD_URL/artifact/trunk/build/test/checkstyle-errors.html
  392. $JIRA_COMMENT_FOOTER"
  393. ### TODO: calculate actual patchStyleErrors
  394. # patchStyleErrors=0
  395. # if [[ $patchStyleErrors != 0 ]] ; then
  396. # JIRA_COMMENT="$JIRA_COMMENT
  397. #
  398. # -1 checkstyle. The patch generated $patchStyleErrors code style errors."
  399. # return 1
  400. # fi
  401. # JIRA_COMMENT="$JIRA_COMMENT
  402. #
  403. # +1 checkstyle. The patch generated 0 code style errors."
  404. return 0
  405. }
  406. ###############################################################################
  407. ### Check there are no changes in the number of Findbugs warnings
  408. checkFindbugsWarnings () {
  409. findbugs_version=`${FINDBUGS_HOME}/bin/findbugs -version`
  410. echo ""
  411. echo ""
  412. echo "======================================================================"
  413. echo "======================================================================"
  414. echo " Determining number of patched Findbugs warnings."
  415. echo "======================================================================"
  416. echo "======================================================================"
  417. echo ""
  418. echo ""
  419. #echo "$ANT_HOME/bin/ant -Dversion="${VERSION}" -Dfindbugs.home=$FINDBUGS_HOME -Dforrest.home=${FORREST_HOME} -DHadoopPatchProcess= findbugs"
  420. #$ANT_HOME/bin/ant -Dversion="${VERSION}" -Dfindbugs.home=${FINDBUGS_HOME} -Dforrest.home=${FORREST_HOME} -DHadoopPatchProcess= findbugs
  421. $MAVEN_HOME/bin/mvn clean compile findbugs:findbugs -D${PROJECT_NAME}PatchProcess -X
  422. if [ $? != 0 ] ; then
  423. JIRA_COMMENT="$JIRA_COMMENT
  424. -1 findbugs. The patch appears to cause Findbugs (version ${findbugs_version}) to fail."
  425. return 1
  426. fi
  427. JIRA_COMMENT_FOOTER="Findbugs warnings: $BUILD_URL/artifact/trunk/target/newPatchFindbugsWarnings.html
  428. $JIRA_COMMENT_FOOTER"
  429. cp $BASEDIR/hadoop-common/target/findbugsXml.xml $PATCH_DIR/patchFindbugsWarnings.xml
  430. $FINDBUGS_HOME/bin/setBugDatabaseInfo -timestamp "01/01/2000" \
  431. $PATCH_DIR/patchFindbugsWarnings.xml \
  432. $PATCH_DIR/patchFindbugsWarnings.xml
  433. findbugsWarnings=`$FINDBUGS_HOME/bin/filterBugs -first "01/01/2000" $PATCH_DIR/patchFindbugsWarnings.xml \
  434. $PATCH_DIR/newPatchFindbugsWarnings.xml | /usr/bin/awk '{print $1}'`
  435. $FINDBUGS_HOME/bin/convertXmlToText -html \
  436. $PATCH_DIR/newPatchFindbugsWarnings.xml \
  437. $PATCH_DIR/newPatchFindbugsWarnings.html
  438. ### if current warnings greater than OK_FINDBUGS_WARNINGS
  439. if [[ $findbugsWarnings > $OK_FINDBUGS_WARNINGS ]] ; then
  440. JIRA_COMMENT="$JIRA_COMMENT
  441. -1 findbugs. The patch appears to introduce `expr $(($findbugsWarnings-$OK_FINDBUGS_WARNINGS))` new Findbugs (version ${findbugs_version}) warnings."
  442. return 1
  443. fi
  444. JIRA_COMMENT="$JIRA_COMMENT
  445. +1 findbugs. The patch does not introduce any new Findbugs (version ${findbugs_version}) warnings."
  446. return 0
  447. }
  448. ###############################################################################
  449. ### Run the test-core target
  450. runCoreTests () {
  451. echo ""
  452. echo ""
  453. echo "======================================================================"
  454. echo "======================================================================"
  455. echo " Running core tests."
  456. echo "======================================================================"
  457. echo "======================================================================"
  458. echo ""
  459. echo ""
  460. ### Kill any rogue build processes from the last attempt
  461. $PS auxwww | $GREP HadoopPatchProcess | /usr/bin/nawk '{print $2}' | /usr/bin/xargs -t -I {} /bin/kill -9 {} > /dev/null
  462. PreTestTarget=""
  463. if [[ $defect == MAPREDUCE-* ]] ; then
  464. PreTestTarget="create-c++-configure"
  465. fi
  466. #echo "$ANT_HOME/bin/ant -Dversion="${VERSION}" -DHadoopPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=no -Dcompile.c++=yes -Dforrest.home=$FORREST_HOME $PreTestTarget test-core"
  467. #$ANT_HOME/bin/ant -Dversion="${VERSION}" -DHadoopPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=no -Dcompile.c++=yes -Dforrest.home=$FORREST_HOME $PreTestTarget test-core
  468. $MAVEN_HOME/bin/mvn clean test -Pnative -DHadoopPatchProcess
  469. if [[ $? != 0 ]] ; then
  470. ### Find and format names of failed tests
  471. failed_tests=`grep -l -E "<failure|<error" $WORKSPACE/trunk/target/hadoop-common/surefire-reports/*.xml | sed -e "s|.*target/surefire-reports/TEST-| |g" | sed -e "s|\.xml||g"`
  472. JIRA_COMMENT="$JIRA_COMMENT
  473. -1 core tests. The patch failed these core unit tests:
  474. $failed_tests"
  475. return 1
  476. fi
  477. JIRA_COMMENT="$JIRA_COMMENT
  478. +1 core tests. The patch passed core unit tests."
  479. return 0
  480. }
  481. ###############################################################################
  482. ### Run the test-contrib target
  483. runContribTests () {
  484. echo ""
  485. echo ""
  486. echo "======================================================================"
  487. echo "======================================================================"
  488. echo " Running contrib tests."
  489. echo "======================================================================"
  490. echo "======================================================================"
  491. echo ""
  492. echo ""
  493. if [[ `$GREP -c 'test-contrib' build.xml` == 0 ]] ; then
  494. echo "No contrib tests in this project."
  495. return 0
  496. fi
  497. ### Kill any rogue build processes from the last attempt
  498. $PS auxwww | $GREP HadoopPatchProcess | /usr/bin/nawk '{print $2}' | /usr/bin/xargs -t -I {} /bin/kill -9 {} > /dev/null
  499. #echo "$ANT_HOME/bin/ant -Dversion="${VERSION}" $ECLIPSE_PROPERTY -DHadoopPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=no test-contrib"
  500. #$ANT_HOME/bin/ant -Dversion="${VERSION}" $ECLIPSE_PROPERTY -DHadoopPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=no test-contrib
  501. echo "NOP"
  502. if [[ $? != 0 ]] ; then
  503. JIRA_COMMENT="$JIRA_COMMENT
  504. -1 contrib tests. The patch failed contrib unit tests."
  505. return 1
  506. fi
  507. JIRA_COMMENT="$JIRA_COMMENT
  508. +1 contrib tests. The patch passed contrib unit tests."
  509. return 0
  510. }
  511. ###############################################################################
  512. ### Run the inject-system-faults target
  513. checkInjectSystemFaults () {
  514. echo ""
  515. echo ""
  516. echo "======================================================================"
  517. echo "======================================================================"
  518. echo " Checking the integrity of system test framework code."
  519. echo "======================================================================"
  520. echo "======================================================================"
  521. echo ""
  522. echo ""
  523. ### Kill any rogue build processes from the last attempt
  524. $PS auxwww | $GREP HadoopPatchProcess | /usr/bin/nawk '{print $2}' | /usr/bin/xargs -t -I {} /bin/kill -9 {} > /dev/null
  525. #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"
  526. #$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
  527. echo "NOP"
  528. if [[ $? != 0 ]] ; then
  529. JIRA_COMMENT="$JIRA_COMMENT
  530. -1 system test framework. The patch failed system test framework compile."
  531. return 1
  532. fi
  533. JIRA_COMMENT="$JIRA_COMMENT
  534. +1 system test framework. The patch passed system test framework compile."
  535. return 0
  536. }
  537. ###############################################################################
  538. ### Submit a comment to the defect's Jira
  539. submitJiraComment () {
  540. local result=$1
  541. ### Do not output the value of JIRA_COMMENT_FOOTER when run by a developer
  542. if [[ $HUDSON == "false" ]] ; then
  543. JIRA_COMMENT_FOOTER=""
  544. fi
  545. if [[ $result == 0 ]] ; then
  546. comment="+1 overall. $JIRA_COMMENT
  547. $JIRA_COMMENT_FOOTER"
  548. else
  549. comment="-1 overall. $JIRA_COMMENT
  550. $JIRA_COMMENT_FOOTER"
  551. fi
  552. ### Output the test result to the console
  553. echo "
  554. $comment"
  555. if [[ $HUDSON == "true" ]] ; then
  556. echo ""
  557. echo ""
  558. echo "======================================================================"
  559. echo "======================================================================"
  560. echo " Adding comment to Jira."
  561. echo "======================================================================"
  562. echo "======================================================================"
  563. echo ""
  564. echo ""
  565. ### Update Jira with a comment
  566. export USER=hudson
  567. $JIRACLI -s https://issues.apache.org/jira -a addcomment -u hadoopqa -p $JIRA_PASSWD --comment "$comment" --issue $defect
  568. $JIRACLI -s https://issues.apache.org/jira -a logout -u hadoopqa -p $JIRA_PASSWD
  569. fi
  570. }
  571. ###############################################################################
  572. ### Cleanup files
  573. cleanupAndExit () {
  574. local result=$1
  575. if [[ $HUDSON == "true" ]] ; then
  576. if [ -e "$PATCH_DIR" ] ; then
  577. mv $PATCH_DIR $BASEDIR
  578. fi
  579. fi
  580. echo ""
  581. echo ""
  582. echo "======================================================================"
  583. echo "======================================================================"
  584. echo " Finished build."
  585. echo "======================================================================"
  586. echo "======================================================================"
  587. echo ""
  588. echo ""
  589. exit $result
  590. }
  591. ###############################################################################
  592. ###############################################################################
  593. ###############################################################################
  594. JIRA_COMMENT=""
  595. JIRA_COMMENT_FOOTER="Console output: $BUILD_URL/console
  596. This message is automatically generated."
  597. ### Check if arguments to the script have been specified properly or not
  598. parseArgs $@
  599. cd $BASEDIR
  600. checkout
  601. RESULT=$?
  602. if [[ $HUDSON == "true" ]] ; then
  603. if [[ $RESULT != 0 ]] ; then
  604. exit 100
  605. fi
  606. fi
  607. setup
  608. checkAuthor
  609. RESULT=$?
  610. if [[ $HUDSON == "true" ]] ; then
  611. cleanUpXml
  612. fi
  613. checkTests
  614. (( RESULT = RESULT + $? ))
  615. applyPatch
  616. if [[ $? != 0 ]] ; then
  617. submitJiraComment 1
  618. cleanupAndExit 1
  619. fi
  620. checkJavadocWarnings
  621. (( RESULT = RESULT + $? ))
  622. checkJavacWarnings
  623. (( RESULT = RESULT + $? ))
  624. ### Checkstyle not implemented yet
  625. #checkStyle
  626. #(( RESULT = RESULT + $? ))
  627. checkFindbugsWarnings
  628. (( RESULT = RESULT + $? ))
  629. checkReleaseAuditWarnings
  630. (( RESULT = RESULT + $? ))
  631. ### Do not call these when run by a developer
  632. if [[ $HUDSON == "true" ]] ; then
  633. runCoreTests
  634. (( RESULT = RESULT + $? ))
  635. runContribTests
  636. (( RESULT = RESULT + $? ))
  637. fi
  638. checkInjectSystemFaults
  639. (( RESULT = RESULT + $? ))
  640. JIRA_COMMENT_FOOTER="Test results: $BUILD_URL/testReport/
  641. $JIRA_COMMENT_FOOTER"
  642. submitJiraComment $RESULT
  643. cleanupAndExit $RESULT