test-patch.sh 72 KB

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