test-patch.sh 72 KB

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