test-patch.sh 77 KB

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