test-patch.sh 73 KB

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