test-patch.sh 72 KB

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