test-patch.sh 78 KB

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