test-patch.sh 72 KB

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