test-patch.sh 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581
  1. #!/usr/bin/env bash
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. ### BUILD_URL is set by Hudson if it is run by patch process
  17. this="${BASH_SOURCE-$0}"
  18. BINDIR=$(cd -P -- "$(dirname -- "${this}")" >/dev/null && pwd -P)
  19. CWD=$(pwd)
  20. USER_PARAMS=("$@")
  21. GLOBALTIMER=$(date +"%s")
  22. ## @description Setup the default global variables
  23. ## @audience public
  24. ## @stability stable
  25. ## @replaceable no
  26. function setup_defaults
  27. {
  28. if [[ -z "${MAVEN_HOME:-}" ]]; then
  29. MVN=mvn
  30. else
  31. MVN=${MAVEN_HOME}/bin/mvn
  32. fi
  33. PROJECT_NAME=hadoop
  34. HOW_TO_CONTRIBUTE="https://wiki.apache.org/hadoop/HowToContribute"
  35. JENKINS=false
  36. PATCH_DIR=/tmp/${PROJECT_NAME}-test-patch/$$
  37. BASEDIR=$(pwd)
  38. FINDBUGS_HOME=${FINDBUGS_HOME:-}
  39. ECLIPSE_HOME=${ECLIPSE_HOME:-}
  40. BUILD_NATIVE=${BUILD_NATIVE:-true}
  41. PATCH_BRANCH=""
  42. PATCH_BRANCH_DEFAULT="trunk"
  43. CHANGED_MODULES=""
  44. USER_MODULE_LIST=""
  45. OFFLINE=false
  46. CHANGED_FILES=""
  47. REEXECED=false
  48. RESETREPO=false
  49. ISSUE=""
  50. ISSUE_RE='^(HADOOP|YARN|MAPREDUCE|HDFS)-[0-9]+$'
  51. TIMER=$(date +"%s")
  52. PATCHURL=""
  53. OSTYPE=$(uname -s)
  54. # Solaris needs POSIX, not SVID
  55. case ${OSTYPE} in
  56. SunOS)
  57. PS=${PS:-ps}
  58. AWK=${AWK:-/usr/xpg4/bin/awk}
  59. SED=${SED:-/usr/xpg4/bin/sed}
  60. WGET=${WGET:-wget}
  61. GIT=${GIT:-git}
  62. EGREP=${EGREP:-/usr/xpg4/bin/egrep}
  63. GREP=${GREP:-/usr/xpg4/bin/grep}
  64. PATCH=${PATCH:-patch}
  65. DIFF=${DIFF:-/usr/gnu/bin/diff}
  66. JIRACLI=${JIRA:-jira}
  67. FILE=${FILE:-file}
  68. ;;
  69. *)
  70. PS=${PS:-ps}
  71. AWK=${AWK:-awk}
  72. SED=${SED:-sed}
  73. WGET=${WGET:-wget}
  74. GIT=${GIT:-git}
  75. EGREP=${EGREP:-egrep}
  76. GREP=${GREP:-grep}
  77. PATCH=${PATCH:-patch}
  78. DIFF=${DIFF:-diff}
  79. JIRACLI=${JIRA:-jira}
  80. FILE=${FILE:-file}
  81. ;;
  82. esac
  83. declare -a JIRA_COMMENT_TABLE
  84. declare -a JIRA_FOOTER_TABLE
  85. declare -a JIRA_HEADER
  86. declare -a JIRA_TEST_TABLE
  87. JFC=0
  88. JTC=0
  89. JTT=0
  90. RESULT=0
  91. }
  92. ## @description Print a message to stderr
  93. ## @audience public
  94. ## @stability stable
  95. ## @replaceable no
  96. ## @param string
  97. function hadoop_error
  98. {
  99. echo "$*" 1>&2
  100. }
  101. ## @description Print a message to stderr if --debug is turned on
  102. ## @audience public
  103. ## @stability stable
  104. ## @replaceable no
  105. ## @param string
  106. function hadoop_debug
  107. {
  108. if [[ -n "${HADOOP_SHELL_SCRIPT_DEBUG}" ]]; then
  109. echo "[$(date) DEBUG]: $*" 1>&2
  110. fi
  111. }
  112. ## @description Activate the local timer
  113. ## @audience public
  114. ## @stability stable
  115. ## @replaceable no
  116. function start_clock
  117. {
  118. hadoop_debug "Start clock"
  119. TIMER=$(date +"%s")
  120. }
  121. ## @description Print the elapsed time in seconds since the start of the local timer
  122. ## @audience public
  123. ## @stability stable
  124. ## @replaceable no
  125. function stop_clock
  126. {
  127. local -r stoptime=$(date +"%s")
  128. local -r elapsed=$((stoptime-TIMER))
  129. hadoop_debug "Stop clock"
  130. echo ${elapsed}
  131. }
  132. ## @description Print the elapsed time in seconds since the start of the global timer
  133. ## @audience private
  134. ## @stability stable
  135. ## @replaceable no
  136. function stop_global_clock
  137. {
  138. local -r stoptime=$(date +"%s")
  139. local -r elapsed=$((stoptime-GLOBALTIMER))
  140. hadoop_debug "Stop global clock"
  141. echo ${elapsed}
  142. }
  143. ## @description Add time to the local timer
  144. ## @audience public
  145. ## @stability stable
  146. ## @replaceable no
  147. ## @param seconds
  148. function offset_clock
  149. {
  150. ((TIMER=TIMER-$1))
  151. }
  152. ## @description Add to the header of the display
  153. ## @audience public
  154. ## @stability stable
  155. ## @replaceable no
  156. ## @param string
  157. function add_jira_header
  158. {
  159. JIRA_HEADER[${JHC}]="| $* |"
  160. JHC=$(( JHC+1 ))
  161. }
  162. ## @description Add to the output table. If the first parameter is a number
  163. ## @description that is the vote for that column and calculates the elapsed time
  164. ## @description based upon the last start_clock(). If it the string null, then it is
  165. ## @description a special entry that signifies extra
  166. ## @description content for the final column. The second parameter is the reporting
  167. ## @description subsystem (or test) that is providing the vote. The second parameter
  168. ## @description is always required. The third parameter is any extra verbage that goes
  169. ## @description with that subsystem.
  170. ## @audience public
  171. ## @stability stable
  172. ## @replaceable no
  173. ## @param +1/0/-1/null
  174. ## @param subsystem
  175. ## @param string
  176. ## @return Elapsed time display
  177. function add_jira_table
  178. {
  179. local value=$1
  180. local subsystem=$2
  181. shift 2
  182. local color
  183. local calctime=0
  184. local -r elapsed=$(stop_clock)
  185. if [[ ${elapsed} -lt 0 ]]; then
  186. calctime="N/A"
  187. else
  188. printf -v calctime "%3sm %02ss" $((elapsed/60)) $((elapsed%60))
  189. fi
  190. echo ""
  191. echo "Elapsed time: ${calctime}"
  192. echo ""
  193. case ${value} in
  194. 1|+1)
  195. value="+1"
  196. color="green"
  197. ;;
  198. -1)
  199. color="red"
  200. ;;
  201. 0)
  202. color="blue"
  203. ;;
  204. null)
  205. ;;
  206. esac
  207. if [[ -z ${color} ]]; then
  208. JIRA_COMMENT_TABLE[${JTC}]="| | ${subsystem} | | ${*:-} |"
  209. JTC=$(( JTC+1 ))
  210. else
  211. JIRA_COMMENT_TABLE[${JTC}]="| {color:${color}}${value}{color} | ${subsystem} | ${calctime} | $* |"
  212. JTC=$(( JTC+1 ))
  213. fi
  214. }
  215. ## @description Put the final environment information at the bottom
  216. ## @description of the footer table
  217. ## @stability stable
  218. ## @audience private
  219. ## @replaceable yes
  220. function close_jira_footer
  221. {
  222. # shellcheck disable=SC2016
  223. local -r javaversion=$("${JAVA_HOME}/bin/java" -version 2>&1 | head -1 | ${AWK} '{print $NF}' | tr -d \")
  224. local -r unamea=$(uname -a)
  225. add_jira_footer "Java" "${javaversion}"
  226. add_jira_footer "uname" "${unamea}"
  227. }
  228. ## @description Put the final elapsed time at the bottom of the table.
  229. ## @audience private
  230. ## @stability stable
  231. ## @replaceable no
  232. function close_jira_table
  233. {
  234. local -r elapsed=$(stop_global_clock)
  235. if [[ ${elapsed} -lt 0 ]]; then
  236. calctime="N/A"
  237. else
  238. printf -v calctime "%3sm %02ss" $((elapsed/60)) $((elapsed%60))
  239. fi
  240. echo ""
  241. echo "Total Elapsed time: ${calctime}"
  242. echo ""
  243. JIRA_COMMENT_TABLE[${JTC}]="| | | ${calctime} | |"
  244. JTC=$(( JTC+1 ))
  245. }
  246. ## @description Add to the footer of the display. @@BASE@@ will get replaced with the
  247. ## @description correct location for the local filesystem in dev mode or the URL for
  248. ## @description Jenkins mode.
  249. ## @audience public
  250. ## @stability stable
  251. ## @replaceable no
  252. ## @param subsystem
  253. ## @param string
  254. function add_jira_footer
  255. {
  256. local subsystem=$1
  257. shift 1
  258. JIRA_FOOTER_TABLE[${JFC}]="| ${subsystem} | $* |"
  259. JFC=$(( JFC+1 ))
  260. }
  261. ## @description Special table just for unit test failures
  262. ## @audience public
  263. ## @stability stable
  264. ## @replaceable no
  265. ## @param failurereason
  266. ## @param testlist
  267. function add_jira_test_table
  268. {
  269. local failure=$1
  270. shift 1
  271. JIRA_TEST_TABLE[${JTT}]="| ${failure} | $* |"
  272. JTT=$(( JTT+1 ))
  273. }
  274. ## @description Large display for the user console
  275. ## @audience public
  276. ## @stability stable
  277. ## @replaceable no
  278. ## @param string
  279. ## @return large chunk of text
  280. function big_console_header
  281. {
  282. local text="$*"
  283. local spacing=$(( (75+${#text}) /2 ))
  284. printf "\n\n"
  285. echo "============================================================================"
  286. echo "============================================================================"
  287. printf "%*s\n" ${spacing} "${text}"
  288. echo "============================================================================"
  289. echo "============================================================================"
  290. printf "\n\n"
  291. }
  292. ## @description Remove {color} tags from a string
  293. ## @audience public
  294. ## @stability stable
  295. ## @replaceable no
  296. ## @param string
  297. ## @return string
  298. function colorstripper
  299. {
  300. local string=$1
  301. shift 1
  302. local green=""
  303. local white=""
  304. local red=""
  305. local blue=""
  306. echo "${string}" | \
  307. ${SED} -e "s,{color:red},${red},g" \
  308. -e "s,{color:green},${green},g" \
  309. -e "s,{color:blue},${blue},g" \
  310. -e "s,{color},${white},g"
  311. }
  312. ## @description Find the largest size of a column of an array
  313. ## @audience private
  314. ## @stability evolving
  315. ## @replaceable no
  316. ## @return size
  317. function findlargest
  318. {
  319. local column=$1
  320. shift
  321. local a=("$@")
  322. local sizeofa=${#a[@]}
  323. local i=0
  324. until [[ ${i} -gt ${sizeofa} ]]; do
  325. # shellcheck disable=SC2086
  326. string=$( echo ${a[$i]} | cut -f$((column + 1)) -d\| )
  327. if [[ ${#string} -gt $maxlen ]]; then
  328. maxlen=${#string}
  329. fi
  330. i=$((i+1))
  331. done
  332. echo "${maxlen}"
  333. }
  334. ## @description Verify that ${JAVA_HOME} is defined
  335. ## @audience public
  336. ## @stability stable
  337. ## @replaceable no
  338. ## @return 1 - no JAVA_HOME
  339. ## @return 0 - JAVA_HOME defined
  340. function find_java_home
  341. {
  342. start_clock
  343. if [[ -z ${JAVA_HOME:-} ]]; then
  344. case $(uname -s) in
  345. Darwin)
  346. if [[ -z "${JAVA_HOME}" ]]; then
  347. if [[ -x /usr/libexec/java_home ]]; then
  348. JAVA_HOME="$(/usr/libexec/java_home)"
  349. export JAVA_HOME
  350. else
  351. export JAVA_HOME=/Library/Java/Home
  352. fi
  353. fi
  354. ;;
  355. *)
  356. ;;
  357. esac
  358. fi
  359. if [[ -z ${JAVA_HOME:-} ]]; then
  360. echo "JAVA_HOME is not defined."
  361. add_jira_table -1 pre-patch "JAVA_HOME is not defined."
  362. return 1
  363. fi
  364. return 0
  365. }
  366. ## @description Write the contents of a file to jenkins
  367. ## @params filename
  368. ## @stability stable
  369. ## @audience public
  370. ## @returns ${JIRACLI} exit code
  371. function write_to_jira
  372. {
  373. local -r commentfile=${1}
  374. shift
  375. local retval
  376. if [[ ${OFFLINE} == false
  377. && ${JENKINS} == true ]]; then
  378. export USER=hudson
  379. # shellcheck disable=SC2086
  380. ${JIRACLI} --comment "$(cat ${commentfile})" \
  381. -s https://issues.apache.org/jira \
  382. -a addcomment -u hadoopqa \
  383. -p "${JIRA_PASSWD}" \
  384. --issue "${ISSUE}"
  385. retval=$?
  386. ${JIRACLI} -s https://issues.apache.org/jira \
  387. -a logout -u hadoopqa \
  388. -p "${JIRA_PASSWD}"
  389. fi
  390. return ${retval}
  391. }
  392. ## @description Verify that the patch directory is still in working order
  393. ## @description since bad actors on some systems wipe it out. If not,
  394. ## @description recreate it and then exit
  395. ## @audience private
  396. ## @stability evolving
  397. ## @replaceable yes
  398. ## @returns may exit on failure
  399. function verify_patchdir_still_exists
  400. {
  401. local -r commentfile=/tmp/testpatch.$$.${RANDOM}
  402. local extra=""
  403. if [[ ! -d ${PATCH_DIR} ]]; then
  404. rm "${commentfile}" 2>/dev/null
  405. echo "(!) The patch artifact directory has been removed! " > "${commentfile}"
  406. echo "This is a fatal error for test-patch.sh. Aborting. " >> "${commentfile}"
  407. echo
  408. cat ${commentfile}
  409. echo
  410. if [[ ${JENKINS} == true ]]; then
  411. if [[ -n ${NODE_NAME} ]]; then
  412. extra=" (node ${NODE_NAME})"
  413. fi
  414. echo "Jenkins${extra} information at ${BUILD_URL} may provide some hints. " >> "${commentfile}"
  415. write_to_jira ${commentfile}
  416. fi
  417. rm "${commentfile}"
  418. cleanup_and_exit ${RESULT}
  419. fi
  420. }
  421. ## @description generate a list of all files and line numbers that
  422. ## @description that were added/changed in the source repo
  423. ## @audience private
  424. ## @stability stable
  425. ## @params filename
  426. ## @replaceable no
  427. function compute_gitdiff
  428. {
  429. local outfile=$1
  430. local file
  431. local line
  432. local startline
  433. local counter
  434. local numlines
  435. local actual
  436. pushd "${BASEDIR}" >/dev/null
  437. while read line; do
  438. if [[ ${line} =~ ^\+\+\+ ]]; then
  439. file="./"$(echo "${line}" | cut -f2- -d/)
  440. continue
  441. elif [[ ${line} =~ ^@@ ]]; then
  442. startline=$(echo "${line}" | cut -f3 -d' ' | cut -f1 -d, | tr -d + )
  443. numlines=$(echo "${line}" | cut -f3 -d' ' | cut -s -f2 -d, )
  444. # if this is empty, then just this line
  445. # if it is 0, then no lines were added and this part of the patch
  446. # is strictly a delete
  447. if [[ ${numlines} == 0 ]]; then
  448. continue
  449. elif [[ -z ${numlines} ]]; then
  450. numlines=1
  451. fi
  452. counter=0
  453. until [[ ${counter} -gt ${numlines} ]]; do
  454. ((actual=counter+startline))
  455. echo "${file}:${actual}:" >> "${outfile}"
  456. ((counter=counter+1))
  457. done
  458. fi
  459. done < <("${GIT}" diff --unified=0 --no-color)
  460. popd >/dev/null
  461. }
  462. ## @description Print the command to be executing to the screen. Then
  463. ## @description run the command, sending stdout and stderr to the given filename
  464. ## @description This will also ensure that any directories in ${BASEDIR} have
  465. ## @description the exec bit set as a pre-exec step.
  466. ## @audience public
  467. ## @stability stable
  468. ## @param filename
  469. ## @param command
  470. ## @param [..]
  471. ## @replaceable no
  472. ## @returns $?
  473. function echo_and_redirect
  474. {
  475. local logfile=$1
  476. shift
  477. verify_patchdir_still_exists
  478. find "${BASEDIR}" -type d -exec chmod +x {} \;
  479. echo "${*} > ${logfile} 2>&1"
  480. "${@}" > "${logfile}" 2>&1
  481. }
  482. ## @description is PATCH_DIR relative to BASEDIR?
  483. ## @audience public
  484. ## @stability stable
  485. ## @replaceable yes
  486. ## @returns 1 - no, PATCH_DIR
  487. ## @returns 0 - yes, PATCH_DIR - BASEDIR
  488. function relative_patchdir
  489. {
  490. local p=${PATCH_DIR#${BASEDIR}}
  491. if [[ ${#p} -eq ${#PATCH_DIR} ]]; then
  492. echo ${p}
  493. return 1
  494. fi
  495. p=${p#/}
  496. echo ${p}
  497. return 0
  498. }
  499. ## @description Print the usage information
  500. ## @audience public
  501. ## @stability stable
  502. ## @replaceable no
  503. function hadoop_usage
  504. {
  505. local -r up=$(echo ${PROJECT_NAME} | tr '[:lower:]' '[:upper:]')
  506. echo "Usage: test-patch.sh [options] patch-file | issue-number | http"
  507. echo
  508. echo "Where:"
  509. echo " patch-file is a local patch file containing the changes to test"
  510. echo " issue-number is a 'Patch Available' JIRA defect number (e.g. '${up}-9902') to test"
  511. echo " http is an HTTP address to download the patch file"
  512. echo
  513. echo "Options:"
  514. echo "--basedir=<dir> The directory to apply the patch to (default current directory)"
  515. echo "--branch=<ref> Forcibly set the branch"
  516. echo "--branch-default=<ref> If the branch isn't forced and we don't detect one in the patch name, use this branch (default 'trunk')"
  517. echo "--build-native=<bool> If true, then build native components (default 'true')"
  518. echo "--contrib-guide=<url> URL to point new users towards project conventions. (default Hadoop's wiki)"
  519. echo "--debug If set, then output some extra stuff to stderr"
  520. echo "--dirty-workspace Allow the local git workspace to have uncommitted changes"
  521. echo "--findbugs-home=<path> Findbugs home directory (default FINDBUGS_HOME environment variable)"
  522. echo "--modulelist=<list> Specify additional modules to test (comma delimited)"
  523. echo "--offline Avoid connecting to the Internet"
  524. echo "--patch-dir=<dir> The directory for working and output files (default '/tmp/${PROJECT_NAME}-test-patch/pid')"
  525. echo "--resetrepo Forcibly clean the repo"
  526. echo "--run-tests Run all relevant tests below the base directory"
  527. echo "--testlist=<list> Specify which subsystem tests to use (comma delimited)"
  528. echo "Shell binary overrides:"
  529. echo "--awk-cmd=<cmd> The 'awk' command to use (default 'awk')"
  530. echo "--diff-cmd=<cmd> The GNU-compatible 'diff' command to use (default 'diff')"
  531. echo "--file-cmd=<cmd> The 'file' command to use (default 'file')"
  532. echo "--git-cmd=<cmd> The 'git' command to use (default 'git')"
  533. echo "--grep-cmd=<cmd> The 'grep' command to use (default 'grep')"
  534. echo "--mvn-cmd=<cmd> The 'mvn' command to use (default \${MAVEN_HOME}/bin/mvn, or 'mvn')"
  535. echo "--patch-cmd=<cmd> The 'patch' command to use (default 'patch')"
  536. echo "--ps-cmd=<cmd> The 'ps' command to use (default 'ps')"
  537. echo "--sed-cmd=<cmd> The 'sed' command to use (default 'sed')"
  538. echo
  539. echo "Jenkins-only options:"
  540. echo "--jenkins Run by Jenkins (runs tests and posts results to JIRA)"
  541. echo "--eclipse-home=<path> Eclipse home directory (default ECLIPSE_HOME environment variable)"
  542. echo "--jira-cmd=<cmd> The 'jira' command to use (default 'jira')"
  543. echo "--jira-password=<pw> The password for the 'jira' command"
  544. echo "--wget-cmd=<cmd> The 'wget' command to use (default 'wget')"
  545. }
  546. ## @description Interpret the command line parameters
  547. ## @audience private
  548. ## @stability stable
  549. ## @replaceable no
  550. ## @params $@
  551. ## @return May exit on failure
  552. function parse_args
  553. {
  554. local i
  555. local j
  556. for i in "$@"; do
  557. case ${i} in
  558. --awk-cmd=*)
  559. AWK=${i#*=}
  560. ;;
  561. --basedir=*)
  562. BASEDIR=${i#*=}
  563. ;;
  564. --branch=*)
  565. PATCH_BRANCH=${i#*=}
  566. ;;
  567. --branch-default=*)
  568. PATCH_BRANCH_DEFAULT=${i#*=}
  569. ;;
  570. --build-native=*)
  571. BUILD_NATIVE=${i#*=}
  572. ;;
  573. --contrib-guide=*)
  574. HOW_TO_CONTRIBUTE=${i#*=}
  575. ;;
  576. --debug)
  577. HADOOP_SHELL_SCRIPT_DEBUG=true
  578. ;;
  579. --diff-cmd=*)
  580. DIFF=${i#*=}
  581. ;;
  582. --dirty-workspace)
  583. DIRTY_WORKSPACE=true
  584. ;;
  585. --eclipse-home=*)
  586. ECLIPSE_HOME=${i#*=}
  587. ;;
  588. --file-cmd=*)
  589. FILE=${i#*=}
  590. ;;
  591. --findbugs-home=*)
  592. FINDBUGS_HOME=${i#*=}
  593. ;;
  594. --git-cmd=*)
  595. GIT=${i#*=}
  596. ;;
  597. --grep-cmd=*)
  598. GREP=${i#*=}
  599. ;;
  600. --help|-help|-h|help|--h|--\?|-\?|\?)
  601. hadoop_usage
  602. exit 0
  603. ;;
  604. --java-home)
  605. JAVA_HOME=${i#*=}
  606. ;;
  607. --jenkins)
  608. JENKINS=true
  609. ;;
  610. --jira-cmd=*)
  611. JIRACLI=${i#*=}
  612. ;;
  613. --jira-password=*)
  614. JIRA_PASSWD=${i#*=}
  615. ;;
  616. --modulelist=*)
  617. USER_MODULE_LIST=${i#*=}
  618. USER_MODULE_LIST=${USER_MODULE_LIST//,/ }
  619. hadoop_debug "Manually forcing modules ${USER_MODULE_LIST}"
  620. ;;
  621. --mvn-cmd=*)
  622. MVN=${i#*=}
  623. ;;
  624. --offline)
  625. OFFLINE=true
  626. ;;
  627. --patch-cmd=*)
  628. PATCH=${i#*=}
  629. ;;
  630. --patch-dir=*)
  631. PATCH_DIR=${i#*=}
  632. ;;
  633. --ps-cmd=*)
  634. PS=${i#*=}
  635. ;;
  636. --reexec)
  637. REEXECED=true
  638. start_clock
  639. add_jira_table 0 reexec "dev-support patch detected."
  640. ;;
  641. --resetrepo)
  642. RESETREPO=true
  643. ;;
  644. --run-tests)
  645. RUN_TESTS=true
  646. ;;
  647. --testlist=*)
  648. testlist=${i#*=}
  649. testlist=${testlist//,/ }
  650. for j in ${testlist}; do
  651. hadoop_debug "Manually adding patch test subsystem ${j}"
  652. add_test "${j}"
  653. done
  654. ;;
  655. --wget-cmd=*)
  656. WGET=${i#*=}
  657. ;;
  658. *)
  659. PATCH_OR_ISSUE=${i}
  660. ;;
  661. esac
  662. done
  663. # we need absolute dir for ${BASEDIR}
  664. cd "${CWD}"
  665. BASEDIR=$(cd -P -- "${BASEDIR}" >/dev/null && pwd -P)
  666. if [[ ${BUILD_NATIVE} == "true" ]] ; then
  667. NATIVE_PROFILE=-Pnative
  668. REQUIRE_TEST_LIB_HADOOP=-Drequire.test.libhadoop
  669. fi
  670. if [[ -z "${PATCH_OR_ISSUE}" ]]; then
  671. hadoop_usage
  672. exit 1
  673. fi
  674. if [[ ${JENKINS} == "true" ]] ; then
  675. echo "Running in Jenkins mode"
  676. ISSUE=${PATCH_OR_ISSUE}
  677. RESETREPO=true
  678. # shellcheck disable=SC2034
  679. ECLIPSE_PROPERTY="-Declipse.home=${ECLIPSE_HOME}"
  680. else
  681. if [[ ${RESETREPO} == "true" ]] ; then
  682. echo "Running in destructive (--resetrepo) developer mode"
  683. else
  684. echo "Running in developer mode"
  685. fi
  686. JENKINS=false
  687. fi
  688. cd "${CWD}"
  689. if [[ ! -d ${PATCH_DIR} ]]; then
  690. mkdir -p "${PATCH_DIR}"
  691. if [[ $? == 0 ]] ; then
  692. echo "${PATCH_DIR} has been created"
  693. else
  694. echo "Unable to create ${PATCH_DIR}"
  695. cleanup_and_exit 1
  696. fi
  697. fi
  698. # we need absolute dir for PATCH_DIR
  699. PATCH_DIR=$(cd -P -- "${PATCH_DIR}" >/dev/null && pwd -P)
  700. GITDIFFLINES=${PATCH_DIR}/gitdifflines.txt
  701. }
  702. ## @description Locate the pom.xml file for a given directory
  703. ## @audience private
  704. ## @stability stable
  705. ## @replaceable no
  706. ## @return directory containing the pom.xml
  707. function find_pom_dir
  708. {
  709. local dir
  710. dir=$(dirname "$1")
  711. hadoop_debug "Find pom dir for: ${dir}"
  712. while builtin true; do
  713. if [[ -f "${dir}/pom.xml" ]];then
  714. echo "${dir}"
  715. hadoop_debug "Found: ${dir}"
  716. return
  717. else
  718. dir=$(dirname "${dir}")
  719. fi
  720. done
  721. }
  722. ## @description List of files that ${PATCH_DIR}/patch modifies
  723. ## @audience private
  724. ## @stability stable
  725. ## @replaceable no
  726. ## @return None; sets ${CHANGED_FILES}
  727. function find_changed_files
  728. {
  729. # get a list of all of the files that have been changed,
  730. # except for /dev/null (which would be present for new files).
  731. # Additionally, remove any a/ b/ patterns at the front
  732. # of the patch filenames and any revision info at the end
  733. # shellcheck disable=SC2016
  734. CHANGED_FILES=$(${GREP} -E '^(\+\+\+|---) ' "${PATCH_DIR}/patch" \
  735. | ${SED} \
  736. -e 's,^....,,' \
  737. -e 's,^[ab]/,,' \
  738. | ${GREP} -v /dev/null \
  739. | ${AWK} '{print $1}' \
  740. | sort -u)
  741. }
  742. ## @description Find the modules of the maven build that ${PATCH_DIR}/patch modifies
  743. ## @audience private
  744. ## @stability stable
  745. ## @replaceable no
  746. ## @return None; sets ${CHANGED_MODULES}
  747. function find_changed_modules
  748. {
  749. # Come up with a list of changed files into ${TMP}
  750. local pomdirs
  751. local module
  752. local pommods
  753. # Now find all the modules that were changed
  754. for file in ${CHANGED_FILES}; do
  755. #shellcheck disable=SC2086
  756. pomdirs="${pomdirs} $(find_pom_dir ${file})"
  757. done
  758. # Filter out modules without code
  759. for module in ${pomdirs}; do
  760. ${GREP} "<packaging>pom</packaging>" "${module}/pom.xml" > /dev/null
  761. if [[ "$?" != 0 ]]; then
  762. pommods="${pommods} ${module}"
  763. fi
  764. done
  765. #shellcheck disable=SC2086
  766. CHANGED_MODULES=$(echo ${pommods} ${USER_MODULE_LIST} | tr ' ' '\n' | sort -u)
  767. }
  768. ## @description git checkout the appropriate branch to test. Additionally, this calls
  769. ## @description 'determine_issue' and 'determine_branch' based upon the context provided
  770. ## @description in ${PATCH_DIR} and in git after checkout.
  771. ## @audience private
  772. ## @stability stable
  773. ## @replaceable no
  774. ## @return 0 on success. May exit on failure.
  775. function git_checkout
  776. {
  777. local currentbranch
  778. local exemptdir
  779. big_console_header "Confirming git environment"
  780. cd "${BASEDIR}"
  781. if [[ ! -d .git ]]; then
  782. hadoop_error "ERROR: ${BASEDIR} is not a git repo."
  783. cleanup_and_exit 1
  784. fi
  785. if [[ ${RESETREPO} == "true" ]] ; then
  786. ${GIT} reset --hard
  787. if [[ $? != 0 ]]; then
  788. hadoop_error "ERROR: git reset is failing"
  789. cleanup_and_exit 1
  790. fi
  791. # if PATCH_DIR is in BASEDIR, then we don't want
  792. # git wiping it out.
  793. exemptdir=$(relative_patchdir)
  794. if [[ $? == 1 ]]; then
  795. ${GIT} clean -xdf
  796. else
  797. # we do, however, want it emptied of all _files_.
  798. # we need to leave _directories_ in case we are in
  799. # re-exec mode (which places a directory full of stuff in it)
  800. hadoop_debug "Exempting ${exemptdir} from clean"
  801. rm "${PATCH_DIR}/*" 2>/dev/null
  802. ${GIT} clean -xdf -e "${exemptdir}"
  803. fi
  804. if [[ $? != 0 ]]; then
  805. hadoop_error "ERROR: git clean is failing"
  806. cleanup_and_exit 1
  807. fi
  808. ${GIT} checkout --force "${PATCH_BRANCH_DEFAULT}"
  809. if [[ $? != 0 ]]; then
  810. hadoop_error "ERROR: git checkout --force ${PATCH_BRANCH_DEFAULT} is failing"
  811. cleanup_and_exit 1
  812. fi
  813. determine_branch
  814. if [[ ${PATCH_BRANCH} =~ ^git ]]; then
  815. PATCH_BRANCH=$(echo "${PATCH_BRANCH}" | cut -dt -f2)
  816. fi
  817. # we need to explicitly fetch in case the
  818. # git ref hasn't been brought in tree yet
  819. if [[ ${OFFLINE} == false ]]; then
  820. ${GIT} pull --rebase
  821. if [[ $? != 0 ]]; then
  822. hadoop_error "ERROR: git pull is failing"
  823. cleanup_and_exit 1
  824. fi
  825. fi
  826. # forcibly checkout this branch or git ref
  827. ${GIT} checkout --force "${PATCH_BRANCH}"
  828. if [[ $? != 0 ]]; then
  829. hadoop_error "ERROR: git checkout ${PATCH_BRANCH} is failing"
  830. cleanup_and_exit 1
  831. fi
  832. # if we've selected a feature branch that has new changes
  833. # since our last build, we'll need to rebase to see those changes.
  834. if [[ ${OFFLINE} == false ]]; then
  835. ${GIT} pull --rebase
  836. if [[ $? != 0 ]]; then
  837. hadoop_error "ERROR: git pull is failing"
  838. cleanup_and_exit 1
  839. fi
  840. fi
  841. else
  842. status=$(${GIT} status --porcelain)
  843. if [[ "${status}" != "" && -z ${DIRTY_WORKSPACE} ]] ; then
  844. hadoop_error "ERROR: --dirty-workspace option not provided."
  845. hadoop_error "ERROR: can't run in a workspace that contains the following modifications"
  846. hadoop_error "${status}"
  847. cleanup_and_exit 1
  848. fi
  849. determine_branch
  850. if [[ ${PATCH_BRANCH} =~ ^git ]]; then
  851. PATCH_BRANCH=$(echo "${PATCH_BRANCH}" | cut -dt -f2)
  852. fi
  853. currentbranch=$(${GIT} rev-parse --abbrev-ref HEAD)
  854. if [[ "${currentbranch}" != "${PATCH_BRANCH}" ]];then
  855. echo "WARNING: Current git branch is ${currentbranch} but patch is built for ${PATCH_BRANCH}."
  856. echo "WARNING: Continuing anyway..."
  857. PATCH_BRANCH=${currentbranch}
  858. fi
  859. fi
  860. determine_issue
  861. GIT_REVISION=$(${GIT} rev-parse --verify --short HEAD)
  862. # shellcheck disable=SC2034
  863. VERSION=${GIT_REVISION}_${ISSUE}_PATCH-${patchNum}
  864. if [[ "${ISSUE}" == 'Unknown' ]]; then
  865. echo "Testing patch on ${PATCH_BRANCH}."
  866. else
  867. echo "Testing ${ISSUE} patch on ${PATCH_BRANCH}."
  868. fi
  869. add_jira_footer "git revision" "${PATCH_BRANCH} / ${GIT_REVISION}"
  870. if [[ ! -f ${BASEDIR}/pom.xml ]]; then
  871. hadoop_error "ERROR: This verison of test-patch.sh only supports Maven-based builds. Aborting."
  872. add_jira_table -1 pre-patch "Unsupported build system."
  873. output_to_jira 1
  874. cleanup_and_exit 1
  875. fi
  876. return 0
  877. }
  878. ## @description Confirm the source environment is compilable
  879. ## @audience private
  880. ## @stability stable
  881. ## @replaceable no
  882. ## @return 0 on success
  883. ## @return 1 on failure
  884. function precheck_without_patch
  885. {
  886. local -r mypwd=$(pwd)
  887. big_console_header "Pre-patch ${PATCH_BRANCH} Java verification"
  888. start_clock
  889. verify_needed_test javac
  890. if [[ $? == 1 ]]; then
  891. echo "Compiling ${mypwd}"
  892. echo_and_redirect "${PATCH_DIR}/${PATCH_BRANCH}JavacWarnings.txt" "${MVN}" clean test -DskipTests -D${PROJECT_NAME}PatchProcess -Ptest-patch
  893. if [[ $? != 0 ]] ; then
  894. echo "${PATCH_BRANCH} compilation is broken?"
  895. add_jira_table -1 pre-patch "${PATCH_BRANCH} compilation may be broken."
  896. return 1
  897. fi
  898. else
  899. echo "Patch does not appear to need javac tests."
  900. fi
  901. verify_needed_test javadoc
  902. if [[ $? == 1 ]]; then
  903. echo "Javadoc'ing ${mypwd}"
  904. echo_and_redirect "${PATCH_DIR}/${PATCH_BRANCH}JavadocWarnings.txt" "${MVN}" clean test javadoc:javadoc -DskipTests -Pdocs -D${PROJECT_NAME}PatchProcess
  905. if [[ $? != 0 ]] ; then
  906. echo "Pre-patch ${PATCH_BRANCH} javadoc compilation is broken?"
  907. add_jira_table -1 pre-patch "Pre-patch ${PATCH_BRANCH} JavaDoc compilation may be broken."
  908. return 1
  909. fi
  910. else
  911. echo "Patch does not appear to need javadoc tests."
  912. fi
  913. verify_needed_test site
  914. if [[ $? == 1 ]]; then
  915. echo "site creation for ${mypwd}"
  916. echo_and_redirect "${PATCH_DIR}/${PATCH_BRANCH}SiteWarnings.txt" "${MVN}" clean site site:stage -DskipTests -Dmaven.javadoc.skip=true -D${PROJECT_NAME}PatchProcess
  917. if [[ $? != 0 ]] ; then
  918. echo "Pre-patch ${PATCH_BRANCH} site compilation is broken?"
  919. add_jira_table -1 pre-patch "Pre-patch ${PATCH_BRANCH} site compilation may be broken."
  920. return 1
  921. fi
  922. else
  923. echo "Patch does not appear to need site tests."
  924. fi
  925. add_jira_table 0 pre-patch "Pre-patch ${PATCH_BRANCH} compilation is healthy."
  926. return 0
  927. }
  928. ## @description Confirm the given branch is a member of the list of space
  929. ## @description delimited branches or a git ref
  930. ## @audience private
  931. ## @stability evolving
  932. ## @replaceable no
  933. ## @param branch
  934. ## @param branchlist
  935. ## @return 0 on success
  936. ## @return 1 on failure
  937. function verify_valid_branch
  938. {
  939. local branches=$1
  940. local check=$2
  941. local i
  942. # shortcut some common
  943. # non-resolvable names
  944. if [[ -z ${check} ]]; then
  945. return 1
  946. fi
  947. if [[ ${check} == patch ]]; then
  948. return 1
  949. fi
  950. if [[ ${check} =~ ^git ]]; then
  951. ref=$(echo "${check}" | cut -f2 -dt)
  952. count=$(echo "${ref}" | wc -c | tr -d ' ')
  953. if [[ ${count} == 8 || ${count} == 41 ]]; then
  954. return 0
  955. fi
  956. return 1
  957. fi
  958. for i in ${branches}; do
  959. if [[ "${i}" == "${check}" ]]; then
  960. return 0
  961. fi
  962. done
  963. return 1
  964. }
  965. ## @description Try to guess the branch being tested using a variety of heuristics
  966. ## @audience private
  967. ## @stability evolving
  968. ## @replaceable no
  969. ## @return 0 on success, with PATCH_BRANCH updated appropriately
  970. ## @return 1 on failure, with PATCH_BRANCH updated to PATCH_BRANCH_DEFAULT
  971. function determine_branch
  972. {
  973. local allbranches
  974. local patchnamechunk
  975. hadoop_debug "Determine branch"
  976. # something has already set this, so move on
  977. if [[ -n ${PATCH_BRANCH} ]]; then
  978. return
  979. fi
  980. pushd "${BASEDIR}" > /dev/null
  981. # developer mode, existing checkout, whatever
  982. if [[ "${DIRTY_WORKSPACE}" == true ]];then
  983. PATCH_BRANCH=$(${GIT} rev-parse --abbrev-ref HEAD)
  984. echo "dirty workspace mode; applying against existing branch"
  985. return
  986. fi
  987. allbranches=$(${GIT} branch -r | tr -d ' ' | ${SED} -e s,origin/,,g)
  988. for j in "${PATCHURL}" "${PATCH_OR_ISSUE}"; do
  989. hadoop_debug "Determine branch: starting with ${j}"
  990. # shellcheck disable=SC2016
  991. patchnamechunk=$(echo "${j}" | ${AWK} -F/ '{print $NF}')
  992. # ISSUE.branch.##.patch
  993. hadoop_debug "Determine branch: ISSUE.branch.##.patch"
  994. PATCH_BRANCH=$(echo "${patchnamechunk}" | cut -f2 -d. )
  995. verify_valid_branch "${allbranches}" "${PATCH_BRANCH}"
  996. if [[ $? == 0 ]]; then
  997. return
  998. fi
  999. # ISSUE-branch-##.patch
  1000. hadoop_debug "Determine branch: ISSUE-branch-##.patch"
  1001. PATCH_BRANCH=$(echo "${patchnamechunk}" | cut -f3- -d- | cut -f1,2 -d-)
  1002. verify_valid_branch "${allbranches}" "${PATCH_BRANCH}"
  1003. if [[ $? == 0 ]]; then
  1004. return
  1005. fi
  1006. # ISSUE-##.patch.branch
  1007. hadoop_debug "Determine branch: ISSUE-##.patch.branch"
  1008. # shellcheck disable=SC2016
  1009. PATCH_BRANCH=$(echo "${patchnamechunk}" | ${AWK} -F. '{print $NF}')
  1010. verify_valid_branch "${allbranches}" "${PATCH_BRANCH}"
  1011. if [[ $? == 0 ]]; then
  1012. return
  1013. fi
  1014. # ISSUE-branch.##.patch
  1015. hadoop_debug "Determine branch: ISSUE-branch.##.patch"
  1016. # shellcheck disable=SC2016
  1017. PATCH_BRANCH=$(echo "${patchnamechunk}" | cut -f3- -d- | ${AWK} -F. '{print $(NF-2)}' 2>/dev/null)
  1018. verify_valid_branch "${allbranches}" "${PATCH_BRANCH}"
  1019. if [[ $? == 0 ]]; then
  1020. return
  1021. fi
  1022. done
  1023. PATCH_BRANCH="${PATCH_BRANCH_DEFAULT}"
  1024. popd >/dev/null
  1025. }
  1026. ## @description Try to guess the issue being tested using a variety of heuristics
  1027. ## @audience private
  1028. ## @stability evolving
  1029. ## @replaceable no
  1030. ## @return 0 on success, with ISSUE updated appropriately
  1031. ## @return 1 on failure, with ISSUE updated to "Unknown"
  1032. function determine_issue
  1033. {
  1034. local patchnamechunk
  1035. local maybeissue
  1036. hadoop_debug "Determine issue"
  1037. # we can shortcut jenkins
  1038. if [[ ${JENKINS} == true ]]; then
  1039. ISSUE=${PATCH_OR_ISSUE}
  1040. fi
  1041. # shellcheck disable=SC2016
  1042. patchnamechunk=$(echo "${PATCH_OR_ISSUE}" | ${AWK} -F/ '{print $NF}')
  1043. maybeissue=$(echo "${patchnamechunk}" | cut -f1,2 -d-)
  1044. if [[ ${maybeissue} =~ ${ISSUE_RE} ]]; then
  1045. ISSUE=${maybeissue}
  1046. return 0
  1047. fi
  1048. ISSUE="Unknown"
  1049. return 1
  1050. }
  1051. ## @description Add the given test type
  1052. ## @audience public
  1053. ## @stability stable
  1054. ## @replaceable yes
  1055. ## @param test
  1056. function add_test
  1057. {
  1058. local testname=$1
  1059. hadoop_debug "Testing against ${testname}"
  1060. if [[ -z ${NEEDED_TESTS} ]]; then
  1061. hadoop_debug "Setting tests to ${testname}"
  1062. NEEDED_TESTS=${testname}
  1063. elif [[ ! ${NEEDED_TESTS} =~ ${testname} ]] ; then
  1064. hadoop_debug "Adding ${testname}"
  1065. NEEDED_TESTS="${NEEDED_TESTS} ${testname}"
  1066. fi
  1067. }
  1068. ## @description Verify if a given test was requested
  1069. ## @audience public
  1070. ## @stability stable
  1071. ## @replaceable yes
  1072. ## @param test
  1073. ## @return 1 = yes
  1074. ## @return 0 = no
  1075. function verify_needed_test
  1076. {
  1077. local i=$1
  1078. if [[ ${NEEDED_TESTS} =~ $i ]]; then
  1079. return 1
  1080. fi
  1081. return 0
  1082. }
  1083. ## @description Use some heuristics to determine which long running
  1084. ## @description tests to run
  1085. ## @audience private
  1086. ## @stability stable
  1087. ## @replaceable no
  1088. function determine_needed_tests
  1089. {
  1090. local i
  1091. for i in ${CHANGED_FILES}; do
  1092. if [[ ${i} =~ src/main/webapp ]]; then
  1093. hadoop_debug "tests/webapp: ${i}"
  1094. elif [[ ${i} =~ \.sh
  1095. || ${i} =~ \.cmd
  1096. ]]; then
  1097. hadoop_debug "tests/shell: ${i}"
  1098. elif [[ ${i} =~ \.md$
  1099. || ${i} =~ \.md\.vm$
  1100. || ${i} =~ src/site
  1101. || ${i} =~ src/main/docs
  1102. ]]; then
  1103. hadoop_debug "tests/site: ${i}"
  1104. add_test site
  1105. elif [[ ${i} =~ \.c$
  1106. || ${i} =~ \.cc$
  1107. || ${i} =~ \.h$
  1108. || ${i} =~ \.hh$
  1109. || ${i} =~ \.proto$
  1110. || ${i} =~ src/test
  1111. || ${i} =~ \.cmake$
  1112. || ${i} =~ CMakeLists.txt
  1113. ]]; then
  1114. hadoop_debug "tests/units: ${i}"
  1115. add_test javac
  1116. add_test unit
  1117. elif [[ ${i} =~ pom.xml$
  1118. || ${i} =~ \.java$
  1119. || ${i} =~ src/main
  1120. ]]; then
  1121. hadoop_debug "tests/javadoc+units: ${i}"
  1122. add_test javadoc
  1123. add_test javac
  1124. add_test unit
  1125. fi
  1126. if [[ ${i} =~ \.java$ ]]; then
  1127. add_test findbugs
  1128. fi
  1129. for plugin in ${PLUGINS}; do
  1130. if declare -f ${plugin}_filefilter >/dev/null 2>&1; then
  1131. "${plugin}_filefilter" "${i}"
  1132. fi
  1133. done
  1134. done
  1135. add_jira_footer "Optional Tests" "${NEEDED_TESTS}"
  1136. }
  1137. ## @description Given ${PATCH_ISSUE}, determine what type of patch file is in use, and do the
  1138. ## @description necessary work to place it into ${PATCH_DIR}/patch.
  1139. ## @audience private
  1140. ## @stability evolving
  1141. ## @replaceable no
  1142. ## @return 0 on success
  1143. ## @return 1 on failure, may exit
  1144. function locate_patch
  1145. {
  1146. local notSureIfPatch=false
  1147. hadoop_debug "locate patch"
  1148. if [[ -f ${PATCH_OR_ISSUE} ]]; then
  1149. PATCH_FILE="${PATCH_OR_ISSUE}"
  1150. else
  1151. if [[ ${PATCH_OR_ISSUE} =~ ^http ]]; then
  1152. echo "Patch is being downloaded at $(date) from"
  1153. PATCHURL="${PATCH_OR_ISSUE}"
  1154. else
  1155. ${WGET} -q -O "${PATCH_DIR}/jira" "http://issues.apache.org/jira/browse/${PATCH_OR_ISSUE}"
  1156. if [[ $? != 0 ]];then
  1157. hadoop_error "ERROR: Unable to determine what ${PATCH_OR_ISSUE} may reference."
  1158. cleanup_and_exit 1
  1159. fi
  1160. if [[ $(${GREP} -c 'Patch Available' "${PATCH_DIR}/jira") == 0 ]] ; then
  1161. if [[ ${JENKINS} == true ]]; then
  1162. hadoop_error "ERROR: ${PATCH_OR_ISSUE} is not \"Patch Available\"."
  1163. cleanup_and_exit 1
  1164. else
  1165. hadoop_error "WARNING: ${PATCH_OR_ISSUE} is not \"Patch Available\"."
  1166. fi
  1167. fi
  1168. 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]*/[^"]*')
  1169. PATCHURL="http://issues.apache.org${relativePatchURL}"
  1170. if [[ ! ${PATCHURL} =~ \.patch$ ]]; then
  1171. notSureIfPatch=true
  1172. fi
  1173. patchNum=$(echo "${PATCHURL}" | ${GREP} -o '[0-9]*/' | ${GREP} -o '[0-9]*')
  1174. echo "${ISSUE} patch is being downloaded at $(date) from"
  1175. fi
  1176. echo "${PATCHURL}"
  1177. add_jira_footer "Patch URL" "${PATCHURL}"
  1178. ${WGET} -q -O "${PATCH_DIR}/patch" "${PATCHURL}"
  1179. if [[ $? != 0 ]];then
  1180. hadoop_error "ERROR: ${PATCH_OR_ISSUE} could not be downloaded."
  1181. cleanup_and_exit 1
  1182. fi
  1183. PATCH_FILE="${PATCH_DIR}/patch"
  1184. fi
  1185. if [[ ! -f "${PATCH_DIR}/patch" ]]; then
  1186. cp "${PATCH_FILE}" "${PATCH_DIR}/patch"
  1187. if [[ $? == 0 ]] ; then
  1188. echo "Patch file ${PATCH_FILE} copied to ${PATCH_DIR}"
  1189. else
  1190. hadoop_error "ERROR: Could not copy ${PATCH_FILE} to ${PATCH_DIR}"
  1191. cleanup_and_exit 1
  1192. fi
  1193. fi
  1194. if [[ ${notSureIfPatch} == "true" ]]; then
  1195. guess_patch_file "${PATCH_DIR}/patch"
  1196. if [[ $? != 0 ]]; then
  1197. hadoop_error "ERROR: ${PATCHURL} is not a patch file."
  1198. cleanup_and_exit 1
  1199. else
  1200. hadoop_debug "The patch ${PATCHURL} was not named properly, but it looks like a patch file. proceeding, but issue/branch matching might go awry."
  1201. add_jira_table 0 patch "The patch file was not named according to ${PROJECT_NAME}'s naming conventions. Please see ${HOW_TO_CONTRIBUTE} for instructions."
  1202. fi
  1203. fi
  1204. }
  1205. ## @description Given a possible patch file, guess if it's a patch file without using smart-apply-patch
  1206. ## @audience private
  1207. ## @stability evolving
  1208. ## @param path to patch file to test
  1209. ## @return 0 we think it's a patch file
  1210. ## @return 1 we think it's not a patch file
  1211. function guess_patch_file
  1212. {
  1213. local patch=$1
  1214. local fileOutput
  1215. hadoop_debug "Trying to guess is ${patch} is a patch file."
  1216. fileOutput=$("${FILE}" "${patch}")
  1217. if [[ $fileOutput =~ \ diff\ ]]; then
  1218. hadoop_debug "file magic says it's a diff."
  1219. return 0
  1220. fi
  1221. fileOutput=$(head -n 1 "${patch}" | "${EGREP}" "^(From [a-z0-9]* Mon Sep 17 00:00:00 2001)|(diff .*)|(Index: .*)$")
  1222. if [[ $? == 0 ]]; then
  1223. hadoop_debug "first line looks like a patch file."
  1224. return 0
  1225. fi
  1226. return 1
  1227. }
  1228. ## @description Given ${PATCH_DIR}/patch, verify the patch is good using ${BINDIR}/smart-apply-patch.sh
  1229. ## @description in dryrun mode.
  1230. ## @audience private
  1231. ## @stability evolving
  1232. ## @replaceable no
  1233. ## @return 0 on success
  1234. ## @return 1 on failure
  1235. function verify_patch_file
  1236. {
  1237. # Before building, check to make sure that the patch is valid
  1238. export PATCH
  1239. "${BINDIR}/smart-apply-patch.sh" "${PATCH_DIR}/patch" dryrun
  1240. if [[ $? != 0 ]] ; then
  1241. echo "PATCH APPLICATION FAILED"
  1242. add_jira_table -1 patch "The patch command could not apply the patch during dryrun."
  1243. return 1
  1244. else
  1245. return 0
  1246. fi
  1247. }
  1248. ## @description Given ${PATCH_DIR}/patch, apply the patch using ${BINDIR}/smart-apply-patch.sh
  1249. ## @audience private
  1250. ## @stability evolving
  1251. ## @replaceable no
  1252. ## @return 0 on success
  1253. ## @return exit on failure
  1254. function apply_patch_file
  1255. {
  1256. big_console_header "Applying patch"
  1257. export PATCH
  1258. "${BINDIR}/smart-apply-patch.sh" "${PATCH_DIR}/patch"
  1259. if [[ $? != 0 ]] ; then
  1260. echo "PATCH APPLICATION FAILED"
  1261. ((RESULT = RESULT + 1))
  1262. add_jira_table -1 patch "The patch command could not apply the patch."
  1263. output_to_console 1
  1264. output_to_jira 1
  1265. cleanup_and_exit 1
  1266. fi
  1267. return 0
  1268. }
  1269. ## @description If this patches actually patches test-patch.sh, then
  1270. ## @description run with the patched version for the test.
  1271. ## @audience private
  1272. ## @stability evolving
  1273. ## @replaceable no
  1274. ## @return none; otherwise relaunches
  1275. function check_reexec
  1276. {
  1277. local commentfile=${PATCH_DIR}/tp.${RANDOM}
  1278. if [[ ${REEXECED} == true ]]; then
  1279. big_console_header "Re-exec mode detected. Continuing."
  1280. return
  1281. fi
  1282. if [[ ! ${CHANGED_FILES} =~ dev-support/test-patch
  1283. || ${CHANGED_FILES} =~ dev-support/smart-apply ]] ; then
  1284. return
  1285. fi
  1286. big_console_header "dev-support patch detected"
  1287. printf "\n\nRe-executing against patched versions to test.\n\n"
  1288. apply_patch_file
  1289. if [[ ${JENKINS} == true ]]; then
  1290. rm "${commentfile}" 2>/dev/null
  1291. echo "(!) A patch to test-patch or smart-apply-patch has been detected. " > "${commentfile}"
  1292. echo "Re-executing against the patched versions to perform further tests. " >> "${commentfile}"
  1293. echo "The console is at ${BUILD_URL}console in case of problems." >> "${commentfile}"
  1294. write_to_jira "${commentfile}"
  1295. rm "${commentfile}"
  1296. fi
  1297. cd "${CWD}"
  1298. mkdir -p "${PATCH_DIR}/dev-support-test"
  1299. cp -pr "${BASEDIR}"/dev-support/test-patch* "${PATCH_DIR}/dev-support-test"
  1300. cp -pr "${BASEDIR}"/dev-support/smart-apply* "${PATCH_DIR}/dev-support-test"
  1301. big_console_header "exec'ing test-patch.sh now..."
  1302. exec "${PATCH_DIR}/dev-support-test/test-patch.sh" \
  1303. --reexec \
  1304. --branch "${PATCH_BRANCH}" \
  1305. --patch-dir="${PATCH_DIR}" \
  1306. "${USER_PARAMS[@]}"
  1307. }
  1308. ## @description Check the current directory for @author tags
  1309. ## @audience private
  1310. ## @stability evolving
  1311. ## @replaceable no
  1312. ## @return 0 on success
  1313. ## @return 1 on failure
  1314. function check_author
  1315. {
  1316. local authorTags
  1317. big_console_header "Checking there are no @author tags in the patch."
  1318. start_clock
  1319. if [[ ${CHANGED_FILES} =~ dev-support/test-patch ]]; then
  1320. add_jira_table 0 @author "Skipping @author checks as test-patch has been patched."
  1321. return 0
  1322. fi
  1323. authorTags=$("${GREP}" -c -i '^[^-].*@author' "${PATCH_DIR}/patch")
  1324. echo "There appear to be ${authorTags} @author tags in the patch."
  1325. if [[ ${authorTags} != 0 ]] ; then
  1326. add_jira_table -1 @author \
  1327. "The patch appears to contain ${authorTags} @author tags which the Hadoop" \
  1328. " community has agreed to not allow in code contributions."
  1329. return 1
  1330. fi
  1331. add_jira_table +1 @author "The patch does not contain any @author tags."
  1332. return 0
  1333. }
  1334. ## @description Check the patch file for changed/new tests
  1335. ## @audience private
  1336. ## @stability evolving
  1337. ## @replaceable no
  1338. ## @return 0 on success
  1339. ## @return 1 on failure
  1340. function check_modified_unittests
  1341. {
  1342. local testReferences=0
  1343. local i
  1344. verify_needed_test unit
  1345. if [[ $? == 0 ]]; then
  1346. return 0
  1347. fi
  1348. big_console_header "Checking there are new or changed tests in the patch."
  1349. start_clock
  1350. for i in ${CHANGED_FILES}; do
  1351. if [[ ${i} =~ /test/ ]]; then
  1352. ((testReferences=testReferences + 1))
  1353. fi
  1354. done
  1355. echo "There appear to be ${testReferences} test file(s) referenced in the patch."
  1356. if [[ ${testReferences} == 0 ]] ; then
  1357. add_jira_table -1 "tests included" \
  1358. "The patch doesn't appear to include any new or modified tests. " \
  1359. "Please justify why no new tests are needed for this patch." \
  1360. "Also please list what manual steps were performed to verify this patch."
  1361. return 1
  1362. fi
  1363. add_jira_table +1 "tests included" \
  1364. "The patch appears to include ${testReferences} new or modified test files."
  1365. return 0
  1366. }
  1367. ## @description Helper for check_javadoc
  1368. ## @audience private
  1369. ## @stability evolving
  1370. ## @replaceable no
  1371. ## @return 0 on success
  1372. ## @return 1 on failure
  1373. function count_javadoc_warns
  1374. {
  1375. local warningfile=$1
  1376. #shellcheck disable=SC2016,SC2046
  1377. return $(${EGREP} "^[0-9]+ warnings$" "${warningfile}" | ${AWK} '{sum+=$1} END {print sum}')
  1378. }
  1379. ## @description Count and compare the number of JavaDoc warnings pre- and post- patch
  1380. ## @audience private
  1381. ## @stability evolving
  1382. ## @replaceable no
  1383. ## @return 0 on success
  1384. ## @return 1 on failure
  1385. function check_javadoc
  1386. {
  1387. local numBranchJavadocWarnings
  1388. local numPatchJavadocWarnings
  1389. verify_needed_test javadoc
  1390. if [[ $? == 0 ]]; then
  1391. echo "This patch does not appear to need javadoc checks."
  1392. return 0
  1393. fi
  1394. big_console_header "Determining number of patched javadoc warnings"
  1395. start_clock
  1396. if [[ -d hadoop-project ]]; then
  1397. (cd hadoop-project; "${MVN}" install > /dev/null 2>&1)
  1398. fi
  1399. if [[ -d hadoop-common-project/hadoop-annotations ]]; then
  1400. (cd hadoop-common-project/hadoop-annotations; "${MVN}" install > /dev/null 2>&1)
  1401. fi
  1402. echo_and_redirect "${PATCH_DIR}/patchJavadocWarnings.txt" "${MVN}" clean test javadoc:javadoc -DskipTests -Pdocs -D${PROJECT_NAME}PatchProcess
  1403. count_javadoc_warns "${PATCH_DIR}/${PATCH_BRANCH}JavadocWarnings.txt"
  1404. numBranchJavadocWarnings=$?
  1405. count_javadoc_warns "${PATCH_DIR}/patchJavadocWarnings.txt"
  1406. numPatchJavadocWarnings=$?
  1407. echo "There appear to be ${numBranchJavadocWarnings} javadoc warnings before the patch and ${numPatchJavadocWarnings} javadoc warnings after applying the patch."
  1408. if [[ ${numBranchJavadocWarnings} != "" && ${numPatchJavadocWarnings} != "" ]] ; then
  1409. if [[ ${numPatchJavadocWarnings} -gt ${numBranchJavadocWarnings} ]] ; then
  1410. ${GREP} -i warning "${PATCH_DIR}/${PATCH_BRANCH}JavadocWarnings.txt" > "${PATCH_DIR}/${PATCH_BRANCH}JavadocWarningsFiltered.txt"
  1411. ${GREP} -i warning "${PATCH_DIR}/patchJavadocWarnings.txt" > "${PATCH_DIR}/patchJavadocWarningsFiltered.txt"
  1412. ${DIFF} -u "${PATCH_DIR}/${PATCH_BRANCH}JavadocWarningsFiltered.txt" \
  1413. "${PATCH_DIR}/patchJavadocWarningsFiltered.txt" \
  1414. > "${PATCH_DIR}/diffJavadocWarnings.txt"
  1415. rm -f "${PATCH_DIR}/${PATCH_BRANCH}JavadocWarningsFiltered.txt" "${PATCH_DIR}/patchJavadocWarningsFiltered.txt"
  1416. add_jira_table -1 javadoc "The applied patch generated "\
  1417. "$((numPatchJavadocWarnings-numBranchJavadocWarnings))" \
  1418. " additional warning messages."
  1419. add_jira_footer javadoc "@@BASE@@/diffJavadocWarnings.txt"
  1420. return 1
  1421. fi
  1422. fi
  1423. add_jira_table +1 javadoc "There were no new javadoc warning messages."
  1424. return 0
  1425. }
  1426. ## @description Make sure site still compiles
  1427. ## @audience private
  1428. ## @stability evolving
  1429. ## @replaceable no
  1430. ## @return 0 on success
  1431. ## @return 1 on failure
  1432. function check_site
  1433. {
  1434. local -r mypwd=$(pwd)
  1435. verify_needed_test site
  1436. if [[ $? == 0 ]]; then
  1437. echo "This patch does not appear to need site checks."
  1438. return 0
  1439. fi
  1440. big_console_header "Determining if patched site still builds"
  1441. start_clock
  1442. echo "site creation for ${mypwd}"
  1443. echo_and_redirect "${PATCH_DIR}/patchSiteWarnings.txt" "${MVN}" clean site site:stage -DskipTests -Dmaven.javadoc.skip=true -D${PROJECT_NAME}PatchProcess
  1444. if [[ $? != 0 ]] ; then
  1445. echo "Site compilation is broken"
  1446. add_jira_table -1 site "Site compilation is broken."
  1447. add_jira_footer site "@@BASE@@/patchSiteWarnings.txt"
  1448. return 1
  1449. fi
  1450. add_jira_table +1 site "Site still builds."
  1451. return 0
  1452. }
  1453. ## @description Helper for check_javac
  1454. ## @audience private
  1455. ## @stability evolving
  1456. ## @replaceable no
  1457. ## @return 0 on success
  1458. ## @return 1 on failure
  1459. function count_javac_warns
  1460. {
  1461. local warningfile=$1
  1462. #shellcheck disable=SC2016,SC2046
  1463. return $(${AWK} 'BEGIN {total = 0} {total += 1} END {print total}' "${warningfile}")
  1464. }
  1465. ## @description Count and compare the number of javac warnings pre- and post- patch
  1466. ## @audience private
  1467. ## @stability evolving
  1468. ## @replaceable no
  1469. ## @return 0 on success
  1470. ## @return 1 on failure
  1471. function check_javac
  1472. {
  1473. local branchJavacWarnings
  1474. local patchJavacWarnings
  1475. verify_needed_test javac
  1476. if [[ $? == 0 ]]; then
  1477. echo "This patch does not appear to need javac checks."
  1478. return 0
  1479. fi
  1480. big_console_header "Determining number of patched javac warnings."
  1481. start_clock
  1482. echo_and_redirect "${PATCH_DIR}/patchJavacWarnings.txt" "${MVN}" clean test -DskipTests -D${PROJECT_NAME}PatchProcess ${NATIVE_PROFILE} -Ptest-patch
  1483. if [[ $? != 0 ]] ; then
  1484. add_jira_table -1 javac "The patch appears to cause the build to fail."
  1485. return 2
  1486. fi
  1487. ### Compare ${PATCH_BRANCH} and patch javac warning numbers
  1488. if [[ -f ${PATCH_DIR}/patchJavacWarnings.txt ]] ; then
  1489. ${GREP} '\[WARNING\]' "${PATCH_DIR}/${PATCH_BRANCH}JavacWarnings.txt" > "${PATCH_DIR}/filtered${PATCH_BRANCH}JavacWarnings.txt"
  1490. ${GREP} '\[WARNING\]' "${PATCH_DIR}/patchJavacWarnings.txt" > "${PATCH_DIR}/filteredPatchJavacWarnings.txt"
  1491. count_javac_warns "${PATCH_DIR}/filtered${PATCH_BRANCH}JavacWarnings.txt"
  1492. branchJavacWarnings=$?
  1493. count_javac_warns "${PATCH_DIR}/filteredPatchJavacWarnings.txt"
  1494. patchJavacWarnings=$?
  1495. echo "There appear to be ${branchJavacWarnings} javac compiler warnings before the patch and ${patchJavacWarnings} javac compiler warnings after applying the patch."
  1496. if [[ ${patchJavacWarnings} != "" && ${branchJavacWarnings} != "" ]] ; then
  1497. if [[ ${patchJavacWarnings} -gt ${branchJavacWarnings} ]] ; then
  1498. ${DIFF} "${PATCH_DIR}/filtered${PATCH_BRANCH}JavacWarnings.txt" \
  1499. "${PATCH_DIR}/filteredPatchJavacWarnings.txt" \
  1500. > "${PATCH_DIR}/diffJavacWarnings.txt"
  1501. add_jira_table -1 javac "The applied patch generated "\
  1502. "$((patchJavacWarnings-${PATCH_BRANCH}JavacWarnings))" \
  1503. " additional warning messages."
  1504. add_jira_footer javac "@@BASE@@/diffJavacWarnings.txt"
  1505. return 1
  1506. fi
  1507. fi
  1508. fi
  1509. add_jira_table +1 javac "There were no new javac warning messages."
  1510. return 0
  1511. }
  1512. ## @description Verify all files have an Apache License
  1513. ## @audience private
  1514. ## @stability evolving
  1515. ## @replaceable no
  1516. ## @return 0 on success
  1517. ## @return 1 on failure
  1518. function check_apachelicense
  1519. {
  1520. big_console_header "Determining number of patched release audit warnings."
  1521. start_clock
  1522. echo_and_redirect "${PATCH_DIR}/patchReleaseAuditOutput.txt" "${MVN}" apache-rat:check -D${PROJECT_NAME}PatchProcess
  1523. #shellcheck disable=SC2038
  1524. find "${BASEDIR}" -name rat.txt | xargs cat > "${PATCH_DIR}/patchReleaseAuditWarnings.txt"
  1525. ### Compare ${PATCH_BRANCH} and patch release audit warning numbers
  1526. if [[ -f ${PATCH_DIR}/patchReleaseAuditWarnings.txt ]] ; then
  1527. patchReleaseAuditWarnings=$("${GREP}" -c '\!?????' "${PATCH_DIR}/patchReleaseAuditWarnings.txt")
  1528. echo ""
  1529. echo ""
  1530. echo "There appear to be ${patchReleaseAuditWarnings} release audit warnings after applying the patch."
  1531. if [[ ${patchReleaseAuditWarnings} != "" ]] ; then
  1532. if [[ ${patchReleaseAuditWarnings} -gt 0 ]] ; then
  1533. add_jira_table -1 "release audit" "The applied patch generated ${patchReleaseAuditWarnings} release audit warnings."
  1534. ${GREP} '\!?????' "${PATCH_DIR}/patchReleaseAuditWarnings.txt" \
  1535. > "${PATCH_DIR}/patchReleaseAuditProblems.txt"
  1536. echo "Lines that start with ????? in the release audit "\
  1537. "report indicate files that do not have an Apache license header." \
  1538. >> "${PATCH_DIR}/patchReleaseAuditProblems.txt"
  1539. add_jira_footer "Release Audit" "@@BASE@@/patchReleaseAuditProblems.txt"
  1540. return 1
  1541. fi
  1542. fi
  1543. fi
  1544. add_jira_table 1 "release audit" "The applied patch does not increase the total number of release audit warnings."
  1545. return 0
  1546. }
  1547. ## @description Verify mvn install works
  1548. ## @audience private
  1549. ## @stability evolving
  1550. ## @replaceable no
  1551. ## @return 0 on success
  1552. ## @return 1 on failure
  1553. function check_mvn_install
  1554. {
  1555. local retval
  1556. verify_needed_test javadoc
  1557. retval=$?
  1558. verify_needed_test javac
  1559. ((retval = retval + $? ))
  1560. if [[ ${retval} == 0 ]]; then
  1561. echo "This patch does not appear to need mvn install checks."
  1562. return 0
  1563. fi
  1564. big_console_header "Installing all of the jars"
  1565. start_clock
  1566. echo_and_redirect "${PATCH_DIR}/jarinstall.txt" "${MVN}" install -Dmaven.javadoc.skip=true -DskipTests -D${PROJECT_NAME}PatchProcess
  1567. retval=$?
  1568. if [[ ${retval} != 0 ]]; then
  1569. add_jira_table -1 install "The patch causes mvn install to fail."
  1570. else
  1571. add_jira_table +1 install "mvn install still works."
  1572. fi
  1573. return ${retval}
  1574. }
  1575. ## @description Verify patch does not trigger any findbugs warnings
  1576. ## @audience private
  1577. ## @stability evolving
  1578. ## @replaceable no
  1579. ## @return 0 on success
  1580. ## @return 1 on failure
  1581. function check_findbugs
  1582. {
  1583. local findbugs_version
  1584. local modules=${CHANGED_MODULES}
  1585. local rc=0
  1586. local module_suffix
  1587. local findbugsWarnings=0
  1588. local relative_file
  1589. local newFindbugsWarnings
  1590. local findbugsWarnings
  1591. local line
  1592. local firstpart
  1593. local secondpart
  1594. big_console_header "Determining number of patched Findbugs warnings."
  1595. verify_needed_test findbugs
  1596. if [[ $? == 0 ]]; then
  1597. echo "Patch does not touch any java files. Skipping findbugs."
  1598. return 0
  1599. fi
  1600. start_clock
  1601. if [[ ! -e "${FINDBUGS_HOME}/bin/findbugs" ]]; then
  1602. printf "\n\n%s is not executable.\n\n" "${FINDBUGS_HOME}/bin/findbugs"
  1603. add_jira_table -1 findbugs "Findbugs is not installed."
  1604. return 1
  1605. fi
  1606. findbugs_version=$("${FINDBUGS_HOME}/bin/findbugs" -version)
  1607. for module in ${modules}
  1608. do
  1609. pushd "${module}" >/dev/null
  1610. echo " Running findbugs in ${module}"
  1611. module_suffix=$(basename "${module}")
  1612. echo_and_redirect "${PATCH_DIR}/patchFindBugsOutput${module_suffix}.txt" "${MVN}" clean test findbugs:findbugs -DskipTests -D${PROJECT_NAME}PatchProcess \
  1613. < /dev/null
  1614. (( rc = rc + $? ))
  1615. popd >/dev/null
  1616. done
  1617. if [[ ${rc} -ne 0 ]]; then
  1618. add_jira_table -1 findbugs "The patch appears to cause Findbugs (version ${findbugs_version}) to fail."
  1619. return 1
  1620. fi
  1621. while read file
  1622. do
  1623. relative_file=${file#${BASEDIR}/} # strip leading ${BASEDIR} prefix
  1624. if [[ ${relative_file} != "target/findbugsXml.xml" ]]; then
  1625. module_suffix=${relative_file%/target/findbugsXml.xml} # strip trailing path
  1626. module_suffix=$(basename "${module_suffix}")
  1627. fi
  1628. cp "${file}" "${PATCH_DIR}/patchFindbugsWarnings${module_suffix}.xml"
  1629. "${FINDBUGS_HOME}/bin/setBugDatabaseInfo" -timestamp "01/01/2000" \
  1630. "${PATCH_DIR}/patchFindbugsWarnings${module_suffix}.xml" \
  1631. "${PATCH_DIR}/patchFindbugsWarnings${module_suffix}.xml"
  1632. #shellcheck disable=SC2016
  1633. newFindbugsWarnings=$("${FINDBUGS_HOME}/bin/filterBugs" \
  1634. -first "01/01/2000" "${PATCH_DIR}/patchFindbugsWarnings${module_suffix}.xml" \
  1635. "${PATCH_DIR}/newPatchFindbugsWarnings${module_suffix}.xml" \
  1636. | ${AWK} '{print $1}')
  1637. echo "Found $newFindbugsWarnings Findbugs warnings ($file)"
  1638. findbugsWarnings=$((findbugsWarnings+newFindbugsWarnings))
  1639. "${FINDBUGS_HOME}/bin/convertXmlToText" -html \
  1640. "${PATCH_DIR}/newPatchFindbugsWarnings${module_suffix}.xml" \
  1641. "${PATCH_DIR}/newPatchFindbugsWarnings${module_suffix}.html"
  1642. if [[ ${newFindbugsWarnings} -gt 0 ]] ; then
  1643. populate_test_table FindBugs "module:${module_suffix}"
  1644. while read line; do
  1645. firstpart=$(echo "${line}" | cut -f2 -d:)
  1646. secondpart=$(echo "${line}" | cut -f9- -d' ')
  1647. add_jira_test_table "" "${firstpart}:${secondpart}"
  1648. done < <("${FINDBUGS_HOME}/bin/convertXmlToText" \
  1649. "${PATCH_DIR}/newPatchFindbugsWarnings${module_suffix}.xml")
  1650. add_jira_footer "Findbugs warnings" "@@BASE@@/newPatchFindbugsWarnings${module_suffix}.html"
  1651. fi
  1652. done < <(find "${BASEDIR}" -name findbugsXml.xml)
  1653. if [[ ${findbugsWarnings} -gt 0 ]] ; then
  1654. add_jira_table -1 findbugs "The patch appears to introduce ${findbugsWarnings} new Findbugs (version ${findbugs_version}) warnings."
  1655. return 1
  1656. fi
  1657. add_jira_table +1 findbugs "The patch does not introduce any new Findbugs (version ${findbugs_version}) warnings."
  1658. return 0
  1659. }
  1660. ## @description Make sure Maven's eclipse generation works.
  1661. ## @audience private
  1662. ## @stability evolving
  1663. ## @replaceable no
  1664. ## @return 0 on success
  1665. ## @return 1 on failure
  1666. function check_mvn_eclipse
  1667. {
  1668. big_console_header "Running mvn eclipse:eclipse."
  1669. verify_needed_test javac
  1670. if [[ $? == 0 ]]; then
  1671. echo "Patch does not touch any java files. Skipping mvn eclipse:eclipse"
  1672. return 0
  1673. fi
  1674. start_clock
  1675. echo_and_redirect "${PATCH_DIR}/patchEclipseOutput.txt" "${MVN}" eclipse:eclipse -D${PROJECT_NAME}PatchProcess
  1676. if [[ $? != 0 ]] ; then
  1677. add_jira_table -1 eclipse:eclipse "The patch failed to build with eclipse:eclipse."
  1678. return 1
  1679. fi
  1680. add_jira_table +1 eclipse:eclipse "The patch built with eclipse:eclipse."
  1681. return 0
  1682. }
  1683. ## @description Utility to push many tests into the failure list
  1684. ## @audience private
  1685. ## @stability evolving
  1686. ## @replaceable no
  1687. ## @param testdesc
  1688. ## @param testlist
  1689. function populate_test_table
  1690. {
  1691. local reason=$1
  1692. shift
  1693. local first=""
  1694. local i
  1695. for i in "$@"; do
  1696. if [[ -z "${first}" ]]; then
  1697. add_jira_test_table "${reason}" "${i}"
  1698. first="${reason}"
  1699. else
  1700. add_jira_test_table " " "${i}"
  1701. fi
  1702. done
  1703. }
  1704. ## @description Run and verify the output of the appropriate unit tests
  1705. ## @audience private
  1706. ## @stability evolving
  1707. ## @replaceable no
  1708. ## @return 0 on success
  1709. ## @return 1 on failure
  1710. function check_unittests
  1711. {
  1712. verify_needed_test unit
  1713. if [[ $? == 0 ]]; then
  1714. echo "Existing unit tests do not test patched files. Skipping."
  1715. return 0
  1716. fi
  1717. big_console_header "Running unit tests"
  1718. start_clock
  1719. local failed_tests=""
  1720. local modules=${CHANGED_MODULES}
  1721. local building_common=0
  1722. local hdfs_modules
  1723. local ordered_modules=""
  1724. local failed_test_builds=""
  1725. local test_timeouts=""
  1726. local test_logfile
  1727. local test_build_result
  1728. local module_test_timeouts=""
  1729. local result
  1730. local totalresult=0
  1731. local module_prefix
  1732. #
  1733. # If we are building hadoop-hdfs-project, we must build the native component
  1734. # of hadoop-common-project first. In order to accomplish this, we move the
  1735. # hadoop-hdfs subprojects to the end of the list so that common will come
  1736. # first.
  1737. #
  1738. # Of course, we may not be building hadoop-common at all-- in this case, we
  1739. # explicitly insert a mvn compile -Pnative of common, to ensure that the
  1740. # native libraries show up where we need them.
  1741. #
  1742. for module in ${modules}; do
  1743. if [[ ${module} == hadoop-hdfs-project* ]]; then
  1744. hdfs_modules="${hdfs_modules} ${module}"
  1745. elif [[ ${module} == hadoop-common-project* ]]; then
  1746. ordered_modules="${ordered_modules} ${module}"
  1747. building_common=1
  1748. else
  1749. ordered_modules="${ordered_modules} ${module}"
  1750. fi
  1751. done
  1752. if [[ -n "${hdfs_modules}" ]]; then
  1753. ordered_modules="${ordered_modules} ${hdfs_modules}"
  1754. if [[ ${building_common} -eq 0 ]]; then
  1755. echo " Building hadoop-common with -Pnative in order to provide libhadoop.so to the hadoop-hdfs unit tests."
  1756. echo_and_redirect "${PATCH_DIR}/testrun_native.txt" "${MVN}" compile ${NATIVE_PROFILE} "-D${PROJECT_NAME}PatchProcess"
  1757. if [[ $? != 0 ]]; then
  1758. add_jira_table -1 "native" "Failed to build the native portion " \
  1759. "of hadoop-common prior to running the unit tests in ${ordered_modules}"
  1760. return 1
  1761. else
  1762. add_jira_table +1 "native" "Pre-build of native portion"
  1763. fi
  1764. fi
  1765. fi
  1766. for module in ${ordered_modules}; do
  1767. result=0
  1768. start_clock
  1769. pushd "${module}" >/dev/null
  1770. module_suffix=$(basename "${module}")
  1771. module_prefix=$(echo "${module}" | cut -f2 -d- )
  1772. test_logfile=${PATCH_DIR}/testrun_${module_suffix}.txt
  1773. echo " Running tests in ${module_suffix}"
  1774. echo_and_redirect "${test_logfile}" "${MVN}" clean install -fae ${NATIVE_PROFILE} ${REQUIRE_TEST_LIB_HADOOP} -D${PROJECT_NAME}PatchProcess
  1775. test_build_result=$?
  1776. add_jira_footer "${module_suffix} test log" "@@BASE@@/testrun_${module_suffix}.txt"
  1777. # shellcheck disable=2016
  1778. module_test_timeouts=$(${AWK} '/^Running / { if (last) { print last } last=$2 } /^Tests run: / { last="" }' "${test_logfile}")
  1779. if [[ -n "${module_test_timeouts}" ]] ; then
  1780. test_timeouts="${test_timeouts} ${module_test_timeouts}"
  1781. result=1
  1782. fi
  1783. #shellcheck disable=SC2026,SC2038,SC2016
  1784. module_failed_tests=$(find . -name 'TEST*.xml'\
  1785. | xargs "${GREP}" -l -E "<failure|<error"\
  1786. | ${AWK} -F/ '{sub("TEST-org.apache.",""); sub(".xml",""); print $NF}')
  1787. if [[ -n "${module_failed_tests}" ]] ; then
  1788. failed_tests="${failed_tests} ${module_failed_tests}"
  1789. result=1
  1790. fi
  1791. if [[ ${test_build_result} != 0 && -z "${module_failed_tests}" && -z "${module_test_timeouts}" ]] ; then
  1792. failed_test_builds="${failed_test_builds} ${module_suffix}"
  1793. result=1
  1794. fi
  1795. popd >/dev/null
  1796. if [[ $result == 1 ]]; then
  1797. add_jira_table -1 "${module_prefix} tests" "Tests failed in ${module_suffix}."
  1798. else
  1799. add_jira_table +1 "${module_prefix} tests" "Tests passed in ${module_suffix}."
  1800. fi
  1801. ((totalresult = totalresult + result))
  1802. done
  1803. if [[ -n "${failed_tests}" ]] ; then
  1804. # shellcheck disable=SC2086
  1805. populate_test_table "Failed unit tests" ${failed_tests}
  1806. fi
  1807. if [[ -n "${test_timeouts}" ]] ; then
  1808. # shellcheck disable=SC2086
  1809. populate_test_table "Timed out tests" ${test_timeouts}
  1810. fi
  1811. if [[ -n "${failed_test_builds}" ]] ; then
  1812. # shellcheck disable=SC2086
  1813. populate_test_table "Failed build" ${failed_test_builds}
  1814. fi
  1815. if [[ ${JENKINS} == true ]]; then
  1816. add_jira_footer "Test Results" "${BUILD_URL}testReport/"
  1817. fi
  1818. if [[ ${totalresult} -gt 0 ]]; then
  1819. return 1
  1820. else
  1821. return 0
  1822. fi
  1823. }
  1824. ## @description Print out the finished details on the console
  1825. ## @audience private
  1826. ## @stability evolving
  1827. ## @replaceable no
  1828. ## @param runresult
  1829. ## @return 0 on success
  1830. ## @return 1 on failure
  1831. function output_to_console
  1832. {
  1833. local result=$1
  1834. shift
  1835. local i
  1836. local ourstring
  1837. local vote
  1838. local subs
  1839. local ela
  1840. local comment
  1841. local commentfile1="${PATCH_DIR}/comment.1"
  1842. local commentfile2="${PATCH_DIR}/comment.2"
  1843. local normaltop
  1844. local line
  1845. local seccoladj=0
  1846. local spcfx=${PATCH_DIR}/spcl.txt
  1847. if [[ ${result} == 0 ]]; then
  1848. if [[ ${JENKINS} == false ]]; then
  1849. {
  1850. printf "IF9fX19fX19fX18gCjwgU3VjY2VzcyEgPgogLS0tLS0tLS0tLSAKIFwgICAg";
  1851. printf "IC9cICBfX18gIC9cCiAgXCAgIC8vIFwvICAgXC8gXFwKICAgICAoKCAgICBP";
  1852. printf "IE8gICAgKSkKICAgICAgXFwgLyAgICAgXCAvLwogICAgICAgXC8gIHwgfCAg";
  1853. printf "XC8gCiAgICAgICAgfCAgfCB8ICB8ICAKICAgICAgICB8ICB8IHwgIHwgIAog";
  1854. printf "ICAgICAgIHwgICBvICAgfCAgCiAgICAgICAgfCB8ICAgfCB8ICAKICAgICAg";
  1855. printf "ICB8bXwgICB8bXwgIAo"
  1856. } > "${spcfx}"
  1857. fi
  1858. printf "\n\n+1 overall\n\n"
  1859. else
  1860. if [[ ${JENKINS} == false ]]; then
  1861. {
  1862. printf "IF9fX19fICAgICBfIF8gICAgICAgICAgICAgICAgXyAKfCAgX19ffF8gXyhf";
  1863. printf "KSB8XyAgIF8gXyBfXyBfX198IHwKfCB8XyAvIF9gIHwgfCB8IHwgfCB8ICdf";
  1864. printf "Xy8gXyBcIHwKfCAgX3wgKF98IHwgfCB8IHxffCB8IHwgfCAgX18vX3wKfF98";
  1865. printf "ICBcX18sX3xffF98XF9fLF98X3wgIFxfX18oXykKICAgICAgICAgICAgICAg";
  1866. printf "ICAgICAgICAgICAgICAgICAK"
  1867. } > "${spcfx}"
  1868. fi
  1869. printf "\n\n-1 overall\n\n"
  1870. fi
  1871. if [[ -f ${spcfx} ]]; then
  1872. if which base64 >/dev/null 2>&1; then
  1873. base64 --decode "${spcfx}" 2>/dev/null
  1874. elif which openssl >/dev/null 2>&1; then
  1875. openssl enc -A -d -base64 -in "${spcfx}" 2>/dev/null
  1876. fi
  1877. echo
  1878. echo
  1879. rm "${spcfx}"
  1880. fi
  1881. seccoladj=$(findlargest 2 "${JIRA_COMMENT_TABLE[@]}")
  1882. if [[ ${seccoladj} -lt 10 ]]; then
  1883. seccoladj=10
  1884. fi
  1885. seccoladj=$((seccoladj + 2 ))
  1886. i=0
  1887. until [[ $i -eq ${#JIRA_HEADER[@]} ]]; do
  1888. printf "%s\n" "${JIRA_HEADER[${i}]}"
  1889. ((i=i+1))
  1890. done
  1891. printf "| %s | %*s | %s | %s\n" "Vote" ${seccoladj} Subsystem Runtime "Comment"
  1892. echo "============================================================================"
  1893. i=0
  1894. until [[ $i -eq ${#JIRA_COMMENT_TABLE[@]} ]]; do
  1895. ourstring=$(echo "${JIRA_COMMENT_TABLE[${i}]}" | tr -s ' ')
  1896. vote=$(echo "${ourstring}" | cut -f2 -d\|)
  1897. vote=$(colorstripper "${vote}")
  1898. subs=$(echo "${ourstring}" | cut -f3 -d\|)
  1899. ela=$(echo "${ourstring}" | cut -f4 -d\|)
  1900. comment=$(echo "${ourstring}" | cut -f5 -d\|)
  1901. echo "${comment}" | fold -s -w $((78-seccoladj-22)) > "${commentfile1}"
  1902. normaltop=$(head -1 "${commentfile1}")
  1903. ${SED} -e '1d' "${commentfile1}" > "${commentfile2}"
  1904. printf "| %4s | %*s | %-10s |%-s\n" "${vote}" ${seccoladj} \
  1905. "${subs}" "${ela}" "${normaltop}"
  1906. while read line; do
  1907. printf "| | %*s | | %-s\n" ${seccoladj} " " "${line}"
  1908. done < "${commentfile2}"
  1909. ((i=i+1))
  1910. rm "${commentfile2}" "${commentfile1}" 2>/dev/null
  1911. done
  1912. if [[ ${#JIRA_TEST_TABLE[@]} -gt 0 ]]; then
  1913. seccoladj=$(findlargest 1 "${JIRA_TEST_TABLE[@]}")
  1914. printf "\n\n%*s | Tests\n" "${seccoladj}" "Reason"
  1915. i=0
  1916. until [[ $i -eq ${#JIRA_TEST_TABLE[@]} ]]; do
  1917. ourstring=$(echo "${JIRA_TEST_TABLE[${i}]}" | tr -s ' ')
  1918. vote=$(echo "${ourstring}" | cut -f2 -d\|)
  1919. subs=$(echo "${ourstring}" | cut -f3 -d\|)
  1920. printf "%*s | %s\n" "${seccoladj}" "${vote}" "${subs}"
  1921. ((i=i+1))
  1922. done
  1923. fi
  1924. printf "\n\n|| Subsystem || Report/Notes ||\n"
  1925. echo "============================================================================"
  1926. i=0
  1927. until [[ $i -eq ${#JIRA_FOOTER_TABLE[@]} ]]; do
  1928. comment=$(echo "${JIRA_FOOTER_TABLE[${i}]}" |
  1929. ${SED} -e "s,@@BASE@@,${PATCH_DIR},g")
  1930. printf "%s\n" "${comment}"
  1931. ((i=i+1))
  1932. done
  1933. }
  1934. ## @description Print out the finished details to the JIRA issue
  1935. ## @audience private
  1936. ## @stability evolving
  1937. ## @replaceable no
  1938. ## @param runresult
  1939. function output_to_jira
  1940. {
  1941. local result=$1
  1942. local i
  1943. local commentfile=${PATCH_DIR}/commentfile
  1944. local comment
  1945. rm "${commentfile}" 2>/dev/null
  1946. if [[ ${JENKINS} != "true" ]] ; then
  1947. return 0
  1948. fi
  1949. big_console_header "Adding comment to JIRA"
  1950. add_jira_footer "Console output" "${BUILD_URL}console"
  1951. if [[ ${result} == 0 ]]; then
  1952. add_jira_header "(/) *{color:green}+1 overall{color}*"
  1953. else
  1954. add_jira_header "(x) *{color:red}-1 overall{color}*"
  1955. fi
  1956. { echo "\\\\" ; echo "\\\\"; } >> "${commentfile}"
  1957. i=0
  1958. until [[ $i -eq ${#JIRA_HEADER[@]} ]]; do
  1959. printf "%s\n" "${JIRA_HEADER[${i}]}" >> "${commentfile}"
  1960. ((i=i+1))
  1961. done
  1962. { echo "\\\\" ; echo "\\\\"; } >> "${commentfile}"
  1963. echo "|| Vote || Subsystem || Runtime || Comment ||" >> "${commentfile}"
  1964. i=0
  1965. until [[ $i -eq ${#JIRA_COMMENT_TABLE[@]} ]]; do
  1966. printf "%s\n" "${JIRA_COMMENT_TABLE[${i}]}" >> "${commentfile}"
  1967. ((i=i+1))
  1968. done
  1969. if [[ ${#JIRA_TEST_TABLE[@]} -gt 0 ]]; then
  1970. { echo "\\\\" ; echo "\\\\"; } >> "${commentfile}"
  1971. echo "|| Reason || Tests ||" >> "${commentfile}"
  1972. i=0
  1973. until [[ $i -eq ${#JIRA_TEST_TABLE[@]} ]]; do
  1974. printf "%s\n" "${JIRA_TEST_TABLE[${i}]}" >> "${commentfile}"
  1975. ((i=i+1))
  1976. done
  1977. fi
  1978. { echo "\\\\" ; echo "\\\\"; } >> "${commentfile}"
  1979. echo "|| Subsystem || Report/Notes ||" >> "${commentfile}"
  1980. i=0
  1981. until [[ $i -eq ${#JIRA_FOOTER_TABLE[@]} ]]; do
  1982. comment=$(echo "${JIRA_FOOTER_TABLE[${i}]}" |
  1983. ${SED} -e "s,@@BASE@@,${BUILD_URL}artifact/patchprocess,g")
  1984. printf "%s\n" "${comment}" >> "${commentfile}"
  1985. ((i=i+1))
  1986. done
  1987. printf "\n\nThis message was automatically generated.\n\n" >> "${commentfile}"
  1988. write_to_jira "${commentfile}"
  1989. }
  1990. ## @description Clean the filesystem as appropriate and then exit
  1991. ## @audience private
  1992. ## @stability evolving
  1993. ## @replaceable no
  1994. ## @param runresult
  1995. function cleanup_and_exit
  1996. {
  1997. local result=$1
  1998. if [[ ${JENKINS} == "true" ]] ; then
  1999. if [[ -e "${PATCH_DIR}" ]] ; then
  2000. if [[ -d "${PATCH_DIR}" ]]; then
  2001. # if PATCH_DIR is already inside BASEDIR, then
  2002. # there is no need to move it since we assume that
  2003. # Jenkins or whatever already knows where it is at
  2004. # since it told us to put it there!
  2005. relative_patchdir >/dev/null
  2006. if [[ $? == 1 ]]; then
  2007. hadoop_debug "mv ${PATCH_DIR} ${BASEDIR}"
  2008. mv "${PATCH_DIR}" "${BASEDIR}"
  2009. fi
  2010. fi
  2011. fi
  2012. fi
  2013. big_console_header "Finished build."
  2014. # shellcheck disable=SC2086
  2015. exit ${result}
  2016. }
  2017. ## @description Driver to execute _postcheckout routines
  2018. ## @audience private
  2019. ## @stability evolving
  2020. ## @replaceable no
  2021. function postcheckout
  2022. {
  2023. local routine
  2024. local plugin
  2025. for routine in find_java_home verify_patch_file
  2026. do
  2027. verify_patchdir_still_exists
  2028. hadoop_debug "Running ${routine}"
  2029. ${routine}
  2030. (( RESULT = RESULT + $? ))
  2031. if [[ ${RESULT} != 0 ]] ; then
  2032. output_to_console 1
  2033. output_to_jira 1
  2034. cleanup_and_exit 1
  2035. fi
  2036. done
  2037. for plugin in ${PLUGINS}; do
  2038. verify_patchdir_still_exists
  2039. if declare -f ${plugin}_postcheckout >/dev/null 2>&1; then
  2040. hadoop_debug "Running ${plugin}_postcheckout"
  2041. #shellcheck disable=SC2086
  2042. ${plugin}_postcheckout
  2043. (( RESULT = RESULT + $? ))
  2044. if [[ ${RESULT} != 0 ]] ; then
  2045. output_to_console 1
  2046. output_to_jira 1
  2047. cleanup_and_exit 1
  2048. fi
  2049. fi
  2050. done
  2051. }
  2052. ## @description Driver to execute _preapply routines
  2053. ## @audience private
  2054. ## @stability evolving
  2055. ## @replaceable no
  2056. function preapply
  2057. {
  2058. local routine
  2059. local plugin
  2060. for routine in precheck_without_patch check_author \
  2061. check_modified_unittests
  2062. do
  2063. verify_patchdir_still_exists
  2064. hadoop_debug "Running ${routine}"
  2065. ${routine}
  2066. (( RESULT = RESULT + $? ))
  2067. done
  2068. for plugin in ${PLUGINS}; do
  2069. verify_patchdir_still_exists
  2070. if declare -f ${plugin}_preapply >/dev/null 2>&1; then
  2071. hadoop_debug "Running ${plugin}_preapply"
  2072. #shellcheck disable=SC2086
  2073. ${plugin}_preapply
  2074. (( RESULT = RESULT + $? ))
  2075. fi
  2076. done
  2077. }
  2078. ## @description Driver to execute _postapply routines
  2079. ## @audience private
  2080. ## @stability evolving
  2081. ## @replaceable no
  2082. function postapply
  2083. {
  2084. local routine
  2085. local plugin
  2086. local retval
  2087. compute_gitdiff "${GITDIFFLINES}"
  2088. check_javac
  2089. retval=$?
  2090. if [[ ${retval} -gt 1 ]] ; then
  2091. output_to_console 1
  2092. output_to_jira 1
  2093. cleanup_and_exit 1
  2094. fi
  2095. ((RESULT = RESULT + retval))
  2096. for routine in check_javadoc check_apachelicense check_site
  2097. do
  2098. verify_patchdir_still_exists
  2099. hadoop_debug "Running ${routine}"
  2100. $routine
  2101. (( RESULT = RESULT + $? ))
  2102. done
  2103. for plugin in ${PLUGINS}; do
  2104. verify_patchdir_still_exists
  2105. if declare -f ${plugin}_postapply >/dev/null 2>&1; then
  2106. hadoop_debug "Running ${plugin}_postapply"
  2107. #shellcheck disable=SC2086
  2108. ${plugin}_postapply
  2109. (( RESULT = RESULT + $? ))
  2110. fi
  2111. done
  2112. }
  2113. ## @description Driver to execute _postinstall routines
  2114. ## @audience private
  2115. ## @stability evolving
  2116. ## @replaceable no
  2117. function postinstall
  2118. {
  2119. local routine
  2120. local plugin
  2121. for routine in check_mvn_eclipse check_findbugs
  2122. do
  2123. verify_patchdir_still_exists
  2124. hadoop_debug "Running ${routine}"
  2125. ${routine}
  2126. (( RESULT = RESULT + $? ))
  2127. done
  2128. for plugin in ${PLUGINS}; do
  2129. verify_patchdir_still_exists
  2130. if declare -f ${plugin}_postinstall >/dev/null 2>&1; then
  2131. hadoop_debug "Running ${plugin}_postinstall"
  2132. #shellcheck disable=SC2086
  2133. ${plugin}_postinstall
  2134. (( RESULT = RESULT + $? ))
  2135. fi
  2136. done
  2137. }
  2138. ## @description Driver to execute _tests routines
  2139. ## @audience private
  2140. ## @stability evolving
  2141. ## @replaceable no
  2142. function runtests
  2143. {
  2144. local plugin
  2145. ### Run tests for Jenkins or if explictly asked for by a developer
  2146. if [[ ${JENKINS} == "true" || ${RUN_TESTS} == "true" ]] ; then
  2147. verify_patchdir_still_exists
  2148. check_unittests
  2149. (( RESULT = RESULT + $? ))
  2150. fi
  2151. for plugin in ${PLUGINS}; do
  2152. verify_patchdir_still_exists
  2153. if declare -f ${plugin}_tests >/dev/null 2>&1; then
  2154. hadoop_debug "Running ${plugin}_tests"
  2155. #shellcheck disable=SC2086
  2156. ${plugin}_tests
  2157. (( RESULT = RESULT + $? ))
  2158. fi
  2159. done
  2160. }
  2161. ## @description Import content from test-patch.d
  2162. ## @audience private
  2163. ## @stability evolving
  2164. ## @replaceable no
  2165. function importplugins
  2166. {
  2167. local i
  2168. local files
  2169. if [[ -d "${BINDIR}/test-patch.d" ]]; then
  2170. files=(${BINDIR}/test-patch.d/*.sh)
  2171. fi
  2172. for i in "${files[@]}"; do
  2173. hadoop_debug "Importing ${i}"
  2174. . "${i}"
  2175. done
  2176. }
  2177. ## @description Register test-patch.d plugins
  2178. ## @audience public
  2179. ## @stability stable
  2180. ## @replaceable no
  2181. function add_plugin
  2182. {
  2183. PLUGINS="${PLUGINS} $1"
  2184. }
  2185. ###############################################################################
  2186. ###############################################################################
  2187. ###############################################################################
  2188. big_console_header "Bootstrapping test harness"
  2189. setup_defaults
  2190. parse_args "$@"
  2191. importplugins
  2192. locate_patch
  2193. find_changed_files
  2194. determine_needed_tests
  2195. # from here on out, we'll be in ${BASEDIR} for cwd
  2196. # routines need to pushd/popd if they change.
  2197. git_checkout
  2198. RESULT=$?
  2199. if [[ ${JENKINS} == "true" ]] ; then
  2200. if [[ ${RESULT} != 0 ]] ; then
  2201. exit 100
  2202. fi
  2203. fi
  2204. check_reexec
  2205. postcheckout
  2206. find_changed_modules
  2207. preapply
  2208. apply_patch_file
  2209. postapply
  2210. check_mvn_install
  2211. postinstall
  2212. runtests
  2213. close_jira_footer
  2214. close_jira_table
  2215. output_to_console ${RESULT}
  2216. output_to_jira ${RESULT}
  2217. cleanup_and_exit ${RESULT}