test-patch.sh 79 KB

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