test-patch.sh 70 KB

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