test-patch.sh 66 KB

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