test-patch.sh 78 KB

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