test-patch.sh 72 KB

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