test-patch.sh 72 KB

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