test-patch.sh 66 KB

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