YETUS-708. Clean up the source Signed-off-by: Allen Wittenauer <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/yetus/repo Commit: http://git-wip-us.apache.org/repos/asf/yetus/commit/9a2cd581 Tree: http://git-wip-us.apache.org/repos/asf/yetus/tree/9a2cd581 Diff: http://git-wip-us.apache.org/repos/asf/yetus/diff/9a2cd581 Branch: refs/heads/master Commit: 9a2cd5817d924fa712ca9575537ee1e95feca16b Parents: 492a20e Author: Allen Wittenauer <[email protected]> Authored: Wed Oct 10 22:06:48 2018 -0700 Committer: Allen Wittenauer <[email protected]> Committed: Thu Dec 13 08:16:35 2018 -0800 ---------------------------------------------------------------------- asf-site-src/source/contribute/releases.md | 2 +- hooks/build | 12 +- precommit/src/main/shell/core.d/00-yetuslib.sh | 43 +++- precommit/src/main/shell/core.d/01-common.sh | 20 +- .../src/main/shell/core.d/builtin-bugsystem.sh | 30 +-- precommit/src/main/shell/core.d/docker.sh | 14 +- precommit/src/main/shell/core.d/patchfiles.sh | 46 ++-- precommit/src/main/shell/core.d/reaper.sh | 4 +- precommit/src/main/shell/docker-cleanup.sh | 6 +- precommit/src/main/shell/personality/flink.sh | 9 +- precommit/src/main/shell/personality/hadoop.sh | 12 +- precommit/src/main/shell/personality/hbase.sh | 4 +- precommit/src/main/shell/personality/jmeter.sh | 4 +- precommit/src/main/shell/personality/kafka.sh | 4 +- precommit/src/main/shell/smart-apply-patch.sh | 40 ++-- precommit/src/main/shell/test-patch.d/ant.sh | 8 +- .../src/main/shell/test-patch.d/asflicense.sh | 19 +- .../src/main/shell/test-patch.d/autoconf.sh | 8 +- .../src/main/shell/test-patch.d/bugzilla.sh | 14 +- precommit/src/main/shell/test-patch.d/cc.sh | 10 +- .../src/main/shell/test-patch.d/checkstyle.sh | 25 ++- precommit/src/main/shell/test-patch.d/cmake.sh | 2 +- .../src/main/shell/test-patch.d/dupname.sh | 2 +- .../src/main/shell/test-patch.d/findbugs.sh | 57 ++--- precommit/src/main/shell/test-patch.d/github.sh | 29 ++- precommit/src/main/shell/test-patch.d/gradle.sh | 15 +- .../src/main/shell/test-patch.d/hadolint.sh | 16 +- .../src/main/shell/test-patch.d/htmlout.sh | 10 +- precommit/src/main/shell/test-patch.d/java.sh | 2 + precommit/src/main/shell/test-patch.d/jira.sh | 42 ++-- precommit/src/main/shell/test-patch.d/junit.sh | 6 +- precommit/src/main/shell/test-patch.d/make.sh | 2 +- precommit/src/main/shell/test-patch.d/maven.sh | 60 +++-- .../src/main/shell/test-patch.d/nobuild.sh | 4 + .../src/main/shell/test-patch.d/perlcritic.sh | 18 +- .../src/main/shell/test-patch.d/rubocop.sh | 24 +- .../src/main/shell/test-patch.d/ruby-lint.sh | 31 ++- precommit/src/main/shell/test-patch.d/scala.sh | 8 +- .../src/main/shell/test-patch.d/shellcheck.sh | 12 +- .../src/main/shell/test-patch.d/shelldocs.sh | 23 +- precommit/src/main/shell/test-patch.d/tap.sh | 2 + .../src/main/shell/test-patch.d/unitveto.sh | 2 + .../src/main/shell/test-patch.d/whitespace.sh | 9 +- precommit/src/main/shell/test-patch.d/xml.sh | 6 +- precommit/src/main/shell/test-patch.sh | 225 +++++++++---------- yetus-maven-plugin/pom.xml | 4 +- 46 files changed, 520 insertions(+), 425 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/asf-site-src/source/contribute/releases.md ---------------------------------------------------------------------- diff --git a/asf-site-src/source/contribute/releases.md b/asf-site-src/source/contribute/releases.md index f3c459e..6e802f8 100644 --- a/asf-site-src/source/contribute/releases.md +++ b/asf-site-src/source/contribute/releases.md @@ -359,7 +359,7 @@ If you've gone through all of the ASF required checks, you'll already have made ============================================================================ | 0 | reexec | 0m 0s | Docker mode activated. | +1 | hbaseanti | 0m 0s | Patch does not have any anti-patterns. - | +1 | @author | 0m 0s | The patch does not contain any @author + | +1 | @\author | 0m 0s | The patch does not contain any @\author | | | | tags. | +1 | test4tests | 0m 0s | The patch appears to include 2 new or | | | | modified test files. http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/hooks/build ---------------------------------------------------------------------- diff --git a/hooks/build b/hooks/build index 21876dc..531cf76 100755 --- a/hooks/build +++ b/hooks/build @@ -16,12 +16,12 @@ if [[ -n "${DOCKERFILE_PATH}" ]]; then docker build -t "${IMAGE_NAME}" \ - --build-arg DOCKER_TAG="${DOCKER_TAG}" \ - --build-arg DOCKER_REPO="${DOCKER_REPO}" \ - -f "${DOCKERFILE_PATH}" + --build-arg DOCKER_TAG="${DOCKER_TAG}" \ + --build-arg DOCKER_REPO="${DOCKER_REPO}" \ + -f "${DOCKERFILE_PATH}" else docker build -t "${IMAGE_NAME}" \ - --build-arg DOCKER_TAG="${DOCKER_TAG}" \ - --build-arg DOCKER_REPO="${DOCKER_REPO}" \ - . + --build-arg DOCKER_TAG="${DOCKER_TAG}" \ + --build-arg DOCKER_REPO="${DOCKER_REPO}" \ + . fi http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/core.d/00-yetuslib.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/core.d/00-yetuslib.sh b/precommit/src/main/shell/core.d/00-yetuslib.sh index 983dfe6..27d169f 100755 --- a/precommit/src/main/shell/core.d/00-yetuslib.sh +++ b/precommit/src/main/shell/core.d/00-yetuslib.sh @@ -123,6 +123,7 @@ function yetus_abs fi dir=$(cd -P -- "${dir}" >/dev/null 2>/dev/null && pwd -P) + #shellcheck disable=SC2181 if [[ $? = 0 ]]; then echo "${dir}${fn}" return 0 @@ -220,7 +221,7 @@ function yetus_generic_columnprinter giventext=$(echo "${tmpa[$i]}" | cut -f2 -d'@') while read -r line; do - printf "%-${maxoptsize}s %-s\n" "${option}" "${line}" + printf "%-${maxoptsize}s %-s\\n" "${option}" "${line}" option=" " done < <(echo "${giventext}"| fold -s -w ${foldsize}) ((i=i+1)) @@ -239,6 +240,7 @@ function yetus_comma_to_array declare string=$2 oldifs="${IFS}" + #shellcheck disable=SC2229 IFS=',' read -r -a "${var}" <<< "${string}" IFS="${oldifs}" } @@ -314,7 +316,7 @@ function yetus_sort_array oifs=${IFS} fi set -f - # shellcheck disable=SC2034 + # shellcheck disable=SC2034,SC2207 IFS=$'\n' sa=($(sort <<<"${array[*]}")) # shellcheck disable=SC1083 eval "${arrname}"=\(\"\${sa[@]}\"\) @@ -329,3 +331,40 @@ function yetus_sort_array set +f fi } + +## @description Sort and unique an array by its elements +## @audience public +## @stability stable +## @replaceable yes +## @param arrayvar +function yetus_sort_and_unique_array +{ + declare arrname=$1 + declare arrref="${arrname}[@]" + declare array=("${!arrref}") + + declare globstatus + declare oifs + declare -a sa + + globstatus=$(set -o | grep noglob | awk '{print $NF}') + + if [[ -n ${IFS} ]]; then + oifs=${IFS} + fi + set -f + # shellcheck disable=SC2034,SC2207 + IFS=$'\n' sa=($(sort -u <<<"${array[*]}")) + # shellcheck disable=SC1083 + eval "${arrname}"=\(\"\${sa[@]}\"\) + + if [[ -n "${oifs}" ]]; then + IFS=${oifs} + else + unset IFS + fi + + if [[ "${globstatus}" = off ]]; then + set +f + fi +} http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/core.d/01-common.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/core.d/01-common.sh b/precommit/src/main/shell/core.d/01-common.sh index 67d2e46..de027e5 100755 --- a/precommit/src/main/shell/core.d/01-common.sh +++ b/precommit/src/main/shell/core.d/01-common.sh @@ -219,14 +219,14 @@ function common_args # git apply or don't support all the # expected options version=$(${GIT} --version) - + # shellcheck disable=SC2181 if [[ $? != 0 ]]; then yetus_error "ERROR: ${GIT} failed during version detection." exit 1 fi # shellcheck disable=SC2016 - version=$(echo "${version}" | ${AWK} '{print $NF}') + version=$(echo "${version}" | "${AWK}" '{print $NF}') if [[ ${version} =~ ^0 || ${version} =~ ^1.[0-6] || ${version} =~ ^1.7.[0-2]$ @@ -249,9 +249,9 @@ function list_plugins ENABLED_PLUGINS="all" importplugins - printf "Reminder: every plug-in may be enabled via 'all'.\n\n" + printf "Reminder: every plug-in may be enabled via 'all'.\\n\\n" for plugintype in BUILDTOOLS TESTTYPES BUGSYSTEMS TESTFORMATS; do - printf "%s:\n\t" ${plugintype} + printf '%s:\n\t' ${plugintype} for name in ${!plugintype}; do printf "%s " ${name} done @@ -270,8 +270,7 @@ function parse_args_plugins for plugin in ${TESTTYPES} ${BUGSYSTEMS} ${TESTFORMATS} ${BUILDTOOLS}; do if declare -f ${plugin}_parse_args >/dev/null 2>&1; then yetus_debug "Running ${plugin}_parse_args" - #shellcheck disable=SC2086 - ${plugin}_parse_args "$@" + "${plugin}_parse_args" "$@" (( RESULT = RESULT + $? )) fi done @@ -288,8 +287,7 @@ function plugins_initialize for plugin in ${TESTTYPES} ${BUGSYSTEMS} ${TESTFORMATS} ${BUILDTOOL}; do if declare -f ${plugin}_initialize >/dev/null 2>&1; then yetus_debug "Running ${plugin}_initialize" - #shellcheck disable=SC2086 - ${plugin}_initialize + "${plugin}_initialize" (( RESULT = RESULT + $? )) fi done @@ -487,15 +485,19 @@ function importplugins local plugin local files=() + #BUG: this will break horribly if there are spaces in the paths. :( + if [[ ${LOAD_SYSTEM_PLUGINS} == "true" ]]; then if [[ -d "${BINDIR}/test-patch.d" ]]; then + #shellcheck disable=SC2206 files=(${BINDIR}/test-patch.d/*.sh) fi fi if [[ -n "${USER_PLUGIN_DIR}" && -d "${USER_PLUGIN_DIR}" ]]; then yetus_debug "Loading user provided plugins from ${USER_PLUGIN_DIR}" - files=("${files[@]}" ${USER_PLUGIN_DIR}/*.sh) + #shellcheck disable=SC2206 + files+=(${USER_PLUGIN_DIR}/*.sh) fi if [[ -n ${PERSONALITY} && ! -f ${PERSONALITY} ]]; then http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/core.d/builtin-bugsystem.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/core.d/builtin-bugsystem.sh b/precommit/src/main/shell/core.d/builtin-bugsystem.sh index 0aeddf1..a20ccc4 100755 --- a/precommit/src/main/shell/core.d/builtin-bugsystem.sh +++ b/precommit/src/main/shell/core.d/builtin-bugsystem.sh @@ -53,7 +53,7 @@ function console_finalreport if [[ ${result} == 0 ]]; then if [[ ${ROBOT} == false ]]; then - if declare -f ${PROJECT_NAME}_console_success >/dev/null; then + if declare -f "${PROJECT_NAME}_console_success" >/dev/null; then "${PROJECT_NAME}_console_success" > "${spcfx}" else { @@ -66,10 +66,10 @@ function console_finalreport } > "${spcfx}" fi fi - printf "\n\n+1 overall\n\n" + printf '\n\n+1 overall\n\n' else if [[ ${ROBOT} == false ]]; then - if declare -f ${PROJECT_NAME}_console_failure >/dev/null; then + if declare -f "${PROJECT_NAME}_console_failure" >/dev/null; then "${PROJECT_NAME}_console_failure" > "${spcfx}" else { @@ -81,13 +81,13 @@ function console_finalreport } > "${spcfx}" fi fi - printf "\n\n-1 overall\n\n" + printf '\n\n-1 overall\n\n' fi if [[ -f ${spcfx} ]]; then - if which base64 >/dev/null 2>&1; then + if command -v base64 >/dev/null 2>&1; then base64 --decode "${spcfx}" 2>/dev/null - elif which openssl >/dev/null 2>&1; then + elif command -v openssl >/dev/null 2>&1; then openssl enc -A -d -base64 -in "${spcfx}" 2>/dev/null fi echo @@ -103,11 +103,11 @@ function console_finalreport seccoladj=$((seccoladj + 2 )) i=0 until [[ $i -eq ${#TP_HEADER[@]} ]]; do - printf "%s\n" "${TP_HEADER[${i}]}" + printf '%s\n' "${TP_HEADER[${i}]}" ((i=i+1)) done - printf "| %s | %*s | %s | %s\n" "Vote" ${seccoladj} Subsystem Runtime "Comment" + printf '| %s | %*s | %s | %s\n' "Vote" ${seccoladj} Subsystem Runtime "Comment" echo "============================================================================" i=0 until [[ $i -eq ${#TP_VOTE_TABLE[@]} ]]; do @@ -123,13 +123,13 @@ function console_finalreport ${SED} -e '1d' "${commentfile1}" > "${commentfile2}" if [[ "${vote}" = "H" ]]; then - printf "| | %*s | |%-s\n" ${seccoladj} " " "${normaltop}" + printf '| | %*s | |%-s\n' ${seccoladj} " " "${normaltop}" else - printf "| %4s | %*s | %-10s |%-s\n" "${vote}" ${seccoladj} \ + printf '| %4s | %*s | %-10s |%-s\n' "${vote}" ${seccoladj} \ "${subs}" "${calctime}" "${normaltop}" fi while read -r line; do - printf "| | %*s | | %-s\n" ${seccoladj} " " "${line}" + printf '| | %*s | | %-s\n' ${seccoladj} " " "${line}" done < "${commentfile2}" ((i=i+1)) @@ -138,18 +138,18 @@ function console_finalreport if [[ ${#TP_TEST_TABLE[@]} -gt 0 ]]; then seccoladj=$(findlargest 1 "${TP_TEST_TABLE[@]}") - printf "\n\n%*s | Tests\n" "${seccoladj}" "Reason" + printf '\n\n%*s | Tests\n' "${seccoladj}" "Reason" i=0 until [[ $i -eq ${#TP_TEST_TABLE[@]} ]]; do ourstring=$(echo "${TP_TEST_TABLE[${i}]}" | tr -s ' ') vote=$(echo "${ourstring}" | cut -f2 -d\|) subs=$(echo "${ourstring}" | cut -f3 -d\|) - printf "%*s | %s\n" "${seccoladj}" "${vote}" "${subs}" + printf '%*s | %s\n' "${seccoladj}" "${vote}" "${subs}" ((i=i+1)) done fi - printf "\n\n|| Subsystem || Report/Notes ||\n" + printf '\n\n|| Subsystem || Report/Notes ||\n' echo "============================================================================" i=0 @@ -162,7 +162,7 @@ function console_finalreport comment=$(echo "${TP_FOOTER_TABLE[${i}]}" | ${SED} -e "s,@@BASE@@,${PATCH_DIR},g") fi - printf "%s\n" "${comment}" + printf '%s\n' "${comment}" ((i=i+1)) done http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/core.d/docker.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/core.d/docker.sh b/precommit/src/main/shell/core.d/docker.sh index a9d0745..794e610 100755 --- a/precommit/src/main/shell/core.d/docker.sh +++ b/precommit/src/main/shell/core.d/docker.sh @@ -15,7 +15,7 @@ # limitations under the License. DOCKERMODE=false -DOCKERCMD=$(command -v docker) +DOCKERCMD=$(command -v docker 2>/dev/null) DOCKER_ID=${RANDOM} DOCKER_DESTRUCTIVE=true DOCKERFILE_DEFAULT="${BINDIR}/test-patch-docker/Dockerfile" @@ -182,7 +182,7 @@ function docker_fileverify if [[ ${DOCKERMODE} = false && ${DOCKERSUPPORT} = true ]]; then if [[ -n "${DOCKERFILE}" ]]; then - pushd "${STARTINGDIR}" >/dev/null + pushd "${STARTINGDIR}" >/dev/null || return 1 if [[ -f ${DOCKERFILE} ]]; then DOCKERFILE=$(yetus_abs "${DOCKERFILE}") else @@ -201,7 +201,7 @@ function docker_fileverify cleanup_and_exit 1 fi fi - popd >/dev/null + popd >/dev/null || return 1 else DOCKERFILE=${DOCKERFILE_DEFAULT} fi @@ -450,9 +450,9 @@ function docker_image_maintenance # repostory:tag and send that to get removed. #shellcheck disable=SC2046,SC2016 - docker_image_maintenance_helper $(dockercmd images | ${GREP} -e ^yetus | grep tp- | ${AWK} '{print $1":"$2}') + docker_image_maintenance_helper $(dockercmd images | "${GREP}" -e ^yetus | "${GREP}" tp- | "${AWK}" '{print $1":"$2}') #shellcheck disable=SC2046,SC2016 - docker_image_maintenance_helper $(dockercmd images | ${GREP} -e ^yetus | ${GREP} -v hours | ${AWK} '{print $1":"$2}') + docker_image_maintenance_helper $(dockercmd images | "${GREP}" -e ^yetus | "${GREP}" -v hours | "${AWK}" '{print $1":"$2}') if [[ "${SENTINEL}" = false ]]; then return @@ -491,6 +491,10 @@ function docker_getfilerev | cut -f2 -d= } +## @description determine the docker version +## @stability stable +## @audience private +## @replaceable no function docker_version { declare vertype=$1 http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/core.d/patchfiles.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/core.d/patchfiles.sh b/precommit/src/main/shell/core.d/patchfiles.sh index 9a17876..381573c 100755 --- a/precommit/src/main/shell/core.d/patchfiles.sh +++ b/precommit/src/main/shell/core.d/patchfiles.sh @@ -31,10 +31,9 @@ function generic_locate_patch return 1 fi - ${CURL} --silent -L \ + if ! ${CURL} --silent -L \ --output "${output}" \ - "${input}" - if [[ $? != 0 ]]; then + "${input}"; then yetus_debug "generic_locate_patch: failed to download the patch." return 1 fi @@ -65,6 +64,7 @@ function guess_patch_file fi fileOutput=$(head -n 1 "${patch}" | "${GREP}" -E "^(From [a-z0-9]* Mon Sep 17 00:00:00 2001)|(diff .*)|(Index: .*)$") + #shellcheck disable=SC2181 if [[ $? == 0 ]]; then yetus_debug "first line looks like a patch file." return 0 @@ -107,9 +107,8 @@ function locate_patch else # run through the bug systems. maybe they know? for bugsys in ${BUGSYSTEMS}; do - if declare -f ${bugsys}_locate_patch >/dev/null 2>&1; then - "${bugsys}_locate_patch" "${PATCH_OR_ISSUE}" "${PATCH_DIR}/patch" - if [[ $? == 0 ]]; then + if declare -f "${bugsys}_locate_patch" >/dev/null 2>&1; then + if "${bugsys}_locate_patch" "${PATCH_OR_ISSUE}" "${PATCH_DIR}/patch"; then gotit=true PATCH_SYSTEM=${bugsys} fi @@ -122,8 +121,7 @@ function locate_patch # ok, none of the bug systems know. let's see how smart we are if [[ ${gotit} == false ]]; then - generic_locate_patch "${PATCH_OR_ISSUE}" "${PATCH_DIR}/patch" - if [[ $? != 0 ]]; then + if ! generic_locate_patch "${PATCH_OR_ISSUE}" "${PATCH_DIR}/patch"; then yetus_error "ERROR: Unsure how to process ${PATCH_OR_ISSUE}." cleanup_and_exit 1 fi @@ -135,8 +133,7 @@ function locate_patch if [[ ! -f "${PATCH_DIR}/patch" && -f "${patchfile}" ]]; then - cp "${patchfile}" "${PATCH_DIR}/patch" - if [[ $? == 0 ]] ; then + if cp "${patchfile}" "${PATCH_DIR}/patch"; then echo "Patch file ${patchfile} copied to ${PATCH_DIR}" else yetus_error "ERROR: Could not copy ${patchfile} to ${PATCH_DIR}" @@ -163,15 +160,15 @@ function patchfile_verify_zero # don't return /dev/null # shellcheck disable=SC2016 - changed_files1=$(${AWK} 'function p(s){if(s!~"^/dev/null"){print s}} + changed_files1=$("${AWK}" 'function p(s){if(s!~"^/dev/null"){print s}} /^diff --git / { p($3); p($4) } /^(\+\+\+|---) / { p($2) }' "${PATCH_DIR}/patch" | sort -u) # maybe we interpreted the patch wrong? check the log file # shellcheck disable=SC2016 - changed_files2=$(${GREP} -E '^[cC]heck' "${logfile}" \ - | ${AWK} '{print $3}' \ - | ${SED} -e 's,\.\.\.$,,g') + changed_files2=$("${GREP}" -E '^[cC]heck' "${logfile}" \ + | "${AWK}" '{print $3}' \ + | "${SED}" -e 's,\.\.\.$,,g') for filename in ${changed_files1} ${changed_files2}; do @@ -209,9 +206,8 @@ function gitapply_dryrun while [[ ${prefixsize} -lt 4 && -z ${PATCH_METHOD} ]]; do - yetus_run_and_redirect "${PATCH_DIR}/patch-dryrun.log" \ - "${GIT}" apply --binary -v --check "-p${prefixsize}" "${patchfile}" - if [[ $? == 0 ]]; then + if yetus_run_and_redirect "${PATCH_DIR}/patch-dryrun.log" \ + "${GIT}" apply --binary -v --check "-p${prefixsize}" "${patchfile}"; then PATCH_LEVEL=${prefixsize} PATCH_METHOD=gitapply break @@ -220,8 +216,7 @@ function gitapply_dryrun done if [[ ${prefixsize} -eq 0 ]]; then - patchfile_verify_zero "${PATCH_DIR}/patch-dryrun.log" - if [[ $? != 0 ]]; then + if ! patchfile_verify_zero "${PATCH_DIR}/patch-dryrun.log"; then PATCH_METHOD="" PATCH_LEVEL="" gitapply_dryrun "${patchfile}" 1 @@ -242,9 +237,8 @@ function patchcmd_dryrun while [[ ${prefixsize} -lt 4 && -z ${PATCH_METHOD} ]]; do # shellcheck disable=SC2153 - yetus_run_and_redirect "${PATCH_DIR}/patch-dryrun.log" \ - "${PATCH}" "-p${prefixsize}" -E --dry-run < "${patchfile}" - if [[ $? == 0 ]]; then + if yetus_run_and_redirect "${PATCH_DIR}/patch-dryrun.log" \ + "${PATCH}" "-p${prefixsize}" -E --dry-run < "${patchfile}"; then PATCH_LEVEL=${prefixsize} PATCH_METHOD=patchcmd break @@ -253,8 +247,7 @@ function patchcmd_dryrun done if [[ ${prefixsize} -eq 0 ]]; then - patchfile_verify_zero "${PATCH_DIR}/patch-dryrun.log" - if [[ $? != 0 ]]; then + if ! patchfile_verify_zero "${PATCH_DIR}/patch-dryrun.log"; then PATCH_METHOD="" PATCH_LEVEL="" patchcmd_dryrun "${patchfile}" 1 @@ -274,7 +267,7 @@ function patchfile_dryrun_driver #shellcheck disable=SC2153 for method in "${PATCH_METHODS[@]}"; do - if declare -f ${method}_dryrun >/dev/null; then + if declare -f "${method}_dryrun" >/dev/null; then "${method}_dryrun" "${patchfile}" fi if [[ -n ${PATCH_METHOD} ]]; then @@ -334,8 +327,7 @@ function patchfile_apply_driver declare gpg=$2 if declare -f ${PATCH_METHOD}_apply >/dev/null; then - "${PATCH_METHOD}_apply" "${patchfile}" "${gpg}" - if [[ $? -gt 0 ]]; then + if ! "${PATCH_METHOD}_apply" "${patchfile}" "${gpg}"; then return 1 fi else http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/core.d/reaper.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/core.d/reaper.sh b/precommit/src/main/shell/core.d/reaper.sh index ce48c25..8859274 100755 --- a/precommit/src/main/shell/core.d/reaper.sh +++ b/precommit/src/main/shell/core.d/reaper.sh @@ -194,14 +194,14 @@ function reaper_post_exec sleep 2 #shellcheck disable=SC2154,SC2086 - printf "reap\n%s\n%s\n" "${module}" "${myfile}" >&${reaper_coproc[1]} + printf 'reap\n%s\n%s\n' "${module}" "${myfile}" >&${reaper_coproc[1]} #shellcheck disable=SC2154,SC2086 read -r count <&${reaper_coproc[0]} if [[ ${count} -gt 0 ]]; then ((REAPER_TOTAL_COUNT=REAPER_TOTAL_COUNT+count)) - printf "\nFound%s %s left over processes\n\n" "${killmsg}" "${count}" + printf '\nFound%s %s left over processes\n\n' "${killmsg}" "${count}" REAPER_ZOMBIE_MODULES+=("${module}:${count}") REAPER_ZOMBIE_LOGS+=("@@BASE@@/${myfile}") return 1 http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/docker-cleanup.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/docker-cleanup.sh b/precommit/src/main/shell/docker-cleanup.sh index 1d17b1b..e6515e5 100755 --- a/precommit/src/main/shell/docker-cleanup.sh +++ b/precommit/src/main/shell/docker-cleanup.sh @@ -176,13 +176,13 @@ function big_console_header { local text="$*" local spacing=$(( (75+${#text}) /2 )) - printf "\n\n" + printf '\n\n' echo "============================================================================" echo "============================================================================" - printf "%*s\n" ${spacing} "${text}" + printf '%*s\n' ${spacing} "${text}" echo "============================================================================" echo "============================================================================" - printf "\n\n" + printf '\n\n' } trap "cleanup_and_exit 1" HUP INT QUIT TERM http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/personality/flink.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/personality/flink.sh b/precommit/src/main/shell/personality/flink.sh index a9c0fdf..971783a 100755 --- a/precommit/src/main/shell/personality/flink.sh +++ b/precommit/src/main/shell/personality/flink.sh @@ -75,10 +75,9 @@ function flinklib_rebuild return 0 fi - pushd "${BASEDIR}" >/dev/null - echo_and_redirect "${PATCH_DIR}/${repostatus}-flinklib-root.txt" \ - "${MAVEN}" "${MAVEN_ARGS[@]}" package -DskipTests -Dmaven.javadoc.skip=true -Ptest-patch - if [[ $? != 0 ]]; then + pushd "${BASEDIR}" >/dev/null || return 1 + if ! echo_and_redirect "${PATCH_DIR}/${repostatus}-flinklib-root.txt" \ + "${MAVEN}" "${MAVEN_ARGS[@]}" package -DskipTests -Dmaven.javadoc.skip=true -Ptest-patch; then add_vote_table -1 flinklib "Unable to determine flink libs in ${PATCH_BRANCH}." fi @@ -88,7 +87,7 @@ function flinklib_rebuild else FLINK_POST_LIB_FILES=$(flinklib_count) fi - popd >/dev/null + popd >/dev/null || return 1 if [[ "${BUILDMODE}" = full ]]; then if [[ ${FLINK_POST_LIB_FILES} -gt 0 ]]; then http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/personality/hadoop.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/personality/hadoop.sh b/precommit/src/main/shell/personality/hadoop.sh index 2ad4459..5323cc0 100755 --- a/precommit/src/main/shell/personality/hadoop.sh +++ b/precommit/src/main/shell/personality/hadoop.sh @@ -162,11 +162,11 @@ function hadoop_unittest_prereqs module="hadoop-common-project/hadoop-common" fn=$(module_file_fragment "${module}") flags="$(hadoop_native_flags) $(yarn_ui2_flag)" - pushd "${BASEDIR}/${module}" >/dev/null + pushd "${BASEDIR}/${module}" >/dev/null || return 1 # shellcheck disable=SC2086 echo_and_redirect "${PATCH_DIR}/maven-unit-prereq-${fn}-install.txt" \ "${MAVEN}" "${MAVEN_ARGS[@]}" install -DskipTests ${flags} - popd >/dev/null + popd >/dev/null || return 1 fi } @@ -328,11 +328,11 @@ function personality_modules for i in hadoop-project \ hadoop-common-project/hadoop-annotations; do fn=$(module_file_fragment "${i}") - pushd "${BASEDIR}/${i}" >/dev/null + pushd "${BASEDIR}/${i}" >/dev/null || return 1 echo "cd ${i}" echo_and_redirect "${PATCH_DIR}/maven-${fn}-install.txt" \ "${MAVEN}" "${MAVEN_ARGS[@]}" install - popd >/dev/null + popd >/dev/null || return 1 done fi extra="-Pdocs -DskipTests" @@ -537,7 +537,7 @@ function shadedclient_rebuild hadoop-client-modules/hadoop-client-integration-tests; do if [ -d "${module}" ]; then yetus_debug "hadoop personality: test module '${module}' is present." - modules=( ${modules[@]} -pl ${module} ) + modules+=(-pl "${module}") fi done if [ ${#modules[@]} -eq 0 ]; then @@ -552,7 +552,7 @@ function shadedclient_rebuild "${modules[@]}" \ -Dtest=NoUnitTests -Dmaven.javadoc.skip=true -Dcheckstyle.skip=true -Dfindbugs.skip=true - count=$(${GREP} -c '\[ERROR\]' "${logfile}") + count=$("${GREP}" -c '\[ERROR\]' "${logfile}") if [[ ${count} -gt 0 ]]; then add_vote_table -1 shadedclient "${repostatus} has errors when building and testing our client artifacts." return 1 http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/personality/hbase.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/personality/hbase.sh b/precommit/src/main/shell/personality/hbase.sh index b48691e..5de4305 100755 --- a/precommit/src/main/shell/personality/hbase.sh +++ b/precommit/src/main/shell/personality/hbase.sh @@ -275,13 +275,13 @@ function hbaseanti_patchfile start_clock - warnings=$(${GREP} 'new TreeMap<byte.*()' "${patchfile}") + warnings=$("${GREP}" 'new TreeMap<byte.*()' "${patchfile}") if [[ ${warnings} -gt 0 ]]; then add_vote_table -1 hbaseanti "" "The patch appears to have anti-pattern where BYTES_COMPARATOR was omitted: ${warnings}." ((result=result+1)) fi - warnings=$(${GREP} 'import org.apache.hadoop.classification' "${patchfile}") + warnings=$("${GREP}" 'import org.apache.hadoop.classification' "${patchfile}") if [[ ${warnings} -gt 0 ]]; then add_vote_table -1 hbaseanti "" "The patch appears use Hadoop classification instead of HBase: ${warnings}." ((result=result+1)) http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/personality/jmeter.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/personality/jmeter.sh b/precommit/src/main/shell/personality/jmeter.sh index b4e61b5..cb2cb1a 100755 --- a/precommit/src/main/shell/personality/jmeter.sh +++ b/precommit/src/main/shell/personality/jmeter.sh @@ -64,8 +64,8 @@ function jmeter_parse_args function jmeter_precheck { if [[ ${JMETER_DOWNLOAD_JARS} = true ]]; then - pushd "${BASEDIR}" >/dev/null + pushd "${BASEDIR}" >/dev/null || return 1 echo_and_redirect "${PATCH_DIR}/jmeter-branch-download-jars.txt" "${ANT}" download_jars - popd >/dev/null + popd >/dev/null || return 1 fi } http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/personality/kafka.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/personality/kafka.sh b/precommit/src/main/shell/personality/kafka.sh index 0c2f749..ceb2604 100755 --- a/precommit/src/main/shell/personality/kafka.sh +++ b/precommit/src/main/shell/personality/kafka.sh @@ -54,9 +54,9 @@ function personality_modules gradleboot) # kafka's bootstrap is broken if [[ ${testtype} == gradleboot ]]; then - pushd "${BASEDIR}" >/dev/null + pushd "${BASEDIR}" >/dev/null || return 1 echo_and_redirect "${PATCH_DIR}/kafka-configure-gradle.txt" gradle - popd >/dev/null + popd >/dev/null || return 1 fi ;; compile) http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/smart-apply-patch.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/smart-apply-patch.sh b/precommit/src/main/shell/smart-apply-patch.sh index a5dd09b..bf44a8f 100755 --- a/precommit/src/main/shell/smart-apply-patch.sh +++ b/precommit/src/main/shell/smart-apply-patch.sh @@ -28,22 +28,37 @@ BINDIR=$(cd -P -- "$(dirname -- "${this}")" >/dev/null && pwd -P) #shellcheck disable=SC2034 QATESTMODE=false -# dummy functions +## @description disable function +## @stability stable +## @audience private +## @replaceable no function add_vote_table { true } +## @description disable function +## @stability stable +## @audience private +## @replaceable no function add_footer_table { true } +## @description disable function +## @stability stable +## @audience private +## @replaceable no function big_console_header { true } +## @description disable function +## @stability stable +## @audience private +## @replaceable no function add_test { true @@ -127,7 +142,7 @@ function yetus_usage unset BUILDTOOLS for plugin in ${BUGSYSTEMS}; do - if declare -f ${plugin}_usage >/dev/null 2>&1; then + if declare -f "${plugin}_usage" >/dev/null 2>&1; then echo "" echo "${plugin} plugin usage options:" "${plugin}_usage" @@ -172,8 +187,7 @@ function parse_args done if [[ ! -d ${PATCH_DIR} ]]; then - mkdir -p "${PATCH_DIR}" - if [[ $? != 0 ]] ; then + if ! mkdir -p "${PATCH_DIR}"; then yetus_error "ERROR: Unable to create ${PATCH_DIR}" cleanup_and_exit 1 fi @@ -213,7 +227,7 @@ function gitam_apply yetus_run_and_redirect "${PATCH_DIR}/apply-patch-git-am.log" \ "${GIT}" am --signoff ${EXTRA_ARGS} --whitespace=fix "-p${PATCH_LEVEL}" "${patchfile}" RESULT=$? - ${GREP} -v "^Checking" "${PATCH_DIR}/apply-patch-git-am.log" + "${GREP}" -v "^Checking" "${PATCH_DIR}/apply-patch-git-am.log" # fallback if [[ ${RESULT} -gt 0 && ${PATCH_SYSTEM} == 'jira' ]]; then @@ -248,19 +262,19 @@ function gitapply_and_commit jsontmpfile="${PATCH_DIR}/jsontmpfile" # cannot set " as delimiter for cut command in script, so replace " with * - tr ',' '\n' < "${PATCH_DIR}/issue" | ${SED} 's/\"/*/g' > "${jsontmpfile}" + tr ',' '\n' < "${PATCH_DIR}/issue" | "${SED}" 's/\"/*/g' > "${jsontmpfile}" - assigneeline=$(${GREP} -n -E "^\*assignee\*:" "${jsontmpfile}" | cut -f1 -d":") + assigneeline=$("${GREP}" -n -E '^\*assignee\*:' "${jsontmpfile}" | cut -f1 -d":") assigneefile="${PATCH_DIR}/assigneefile" tail -n +"${assigneeline}" "${jsontmpfile}" | head -n 20 > "${assigneefile}" - name=$(${GREP} "displayName" "${assigneefile}" | cut -f4 -d"*") - email=$(${GREP} "emailAddress" "${assigneefile}" | cut -f4 -d"*" \ - | ${SED} 's/ at /@/g' | ${SED} 's/ dot /./g') + name=$("${GREP}" "displayName" "${assigneefile}" | cut -f4 -d"*") + email=$("${GREP}" "emailAddress" "${assigneefile}" | cut -f4 -d"*" \ + | "${SED}" 's/ at /@/g' | "${SED}" 's/ dot /./g') author="${name} <${email}>" - summary=$(${GREP} -E "^\*summary\*:" "${jsontmpfile}" | cut -f4 -d"*") + summary=$("${GREP}" -E '^\*summary\*:' "${jsontmpfile}" | cut -f4 -d"*") gitapply_apply "${patchfile}" - ${GIT} add --all + "${GIT}" add --all echo "Committing with author: ${author}, summary: ${summary}" yetus_run_and_redirect "${PATCH_DIR}/apply-patch-git-am-fallback.log" \ "${GIT}" commit ${EXTRA_ARGS} --signoff -m "${PATCH_OR_ISSUE}. ${summary}" \ @@ -302,7 +316,7 @@ plugins_initialize locate_patch if [[ ${COMMITMODE} = true ]]; then - status=$(${GIT} status --porcelain) + status=$("${GIT}" status --porcelain) if [[ "$status" != "" ]] ; then yetus_error "ERROR: Can't use --committer option in a workspace that contains the following modifications:" yetus_error "${status}" http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/test-patch.d/ant.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/test-patch.d/ant.sh b/precommit/src/main/shell/test-patch.d/ant.sh index 4c81741..9dd8240 100755 --- a/precommit/src/main/shell/test-patch.d/ant.sh +++ b/precommit/src/main/shell/test-patch.d/ant.sh @@ -46,7 +46,7 @@ function ant_parse_args # if we requested offline, pass that to ant if [[ ${OFFLINE} == "true" ]]; then - ANT_ARGS=("${ANT_ARGS[@]}" -Doffline=) + ANT_ARGS=("${ANT_ARGS[@]}" '-Doffline=') fi } @@ -144,8 +144,7 @@ function ant_javac_logfilter declare input=$1 declare output=$2 - #shellcheck disable=SC2016 - ${GREP} "\[javac\] /" "${input}" > "${output}" + "${GREP}" '\[javac\] /' "${input}" > "${output}" } ## @description Helper for generic_logfilter @@ -157,8 +156,7 @@ function ant_javadoc_logfilter declare input=$1 declare output=$2 - #shellcheck disable=SC2016 - ${GREP} "\[javadoc\] /" "${input}" > "${output}" + "${GREP}" '\[javadoc\] /' "${input}" > "${output}" } function ant_builtin_personality_modules http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/test-patch.d/asflicense.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/test-patch.d/asflicense.sh b/precommit/src/main/shell/test-patch.d/asflicense.sh index 593e4af..0c22070 100755 --- a/precommit/src/main/shell/test-patch.d/asflicense.sh +++ b/precommit/src/main/shell/test-patch.d/asflicense.sh @@ -14,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +# SHELLDOC-IGNORE add_test_type asflicense @@ -58,8 +59,9 @@ function asflicense_parse_args ## @return 1 on failure function asflicense_tests { - local numpatch - local btfails=true + declare numpatch + declare btfails=true + declare retval big_console_header "Determining number of ASF License errors" @@ -69,13 +71,16 @@ function asflicense_tests case ${BUILDTOOL} in ant) modules_workers patch asflicense releaseaudit + retval=$? ;; gradle) btfails=false modules_workers patch asflicense rat + retval=$? ;; maven) modules_workers patch asflicense -fn apache-rat:check + retval=$? btfails=false ;; *) @@ -92,19 +97,21 @@ function asflicense_tests -s "${PATCH_DIR}/asf.xsl" \ -E "${ASFLICENSE_RAT_EXCLUDES}" \ -d "${BASEDIR}" + retval=$? else echo_and_redirect "${PATCH_DIR}/patch-asflicense.txt" \ "${JAVA_HOME}/bin/java" \ -jar "${ASFLICENSE_RAT_JAR}" \ -s "${PATCH_DIR}/asf.xsl" \ "${BASEDIR}" + retval=$? fi ;; esac # RAT fails the build if there are license problems. # so let's take advantage of that a bit. - if [[ $? == 0 && ${btfails} = true ]]; then + if [[ ${retval} == 0 && ${btfails} = true ]]; then add_vote_table 1 asflicense "${BUILDMODEMSG} does not generate ASF License warnings." return 0 fi @@ -150,6 +157,12 @@ function asflicense_tests return 0 } +## @description when using the jar version, need an xsl file for it to use +## @audience private +## @stability evolving +## @replaceable no +## @return 0 on success +## @return 1 on failure function asflicense_writexsl { cat > "${1}" << EOF http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/test-patch.d/autoconf.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/test-patch.d/autoconf.sh b/precommit/src/main/shell/test-patch.d/autoconf.sh index b1e2e2b..bf9476d 100755 --- a/precommit/src/main/shell/test-patch.d/autoconf.sh +++ b/precommit/src/main/shell/test-patch.d/autoconf.sh @@ -117,10 +117,10 @@ function autoconf_precompile personality_modules "${repostatus}" autoreconf - pushd "${BASEDIR}" >/dev/null + pushd "${BASEDIR}" >/dev/null || return 1 echo_and_redirect "${PATCH_DIR}/${repostatus}-autoconf-autoreconf" autoreconf -fi result=$? - popd >/dev/null + popd >/dev/null || return 1 if [[ ${result} != 0 ]]; then if [[ "${repostatus}" = branch ]]; then @@ -142,7 +142,7 @@ function autoconf_precompile personality_modules "${repostatus}" configure - pushd "${BASEDIR}" >/dev/null + pushd "${BASEDIR}" >/dev/null || return 1 #shellcheck disable=SC2086 echo_and_redirect \ "${PATCH_DIR}/${repostatus}-autoconf-configure" \ @@ -150,7 +150,7 @@ function autoconf_precompile --prefix="${PATCH_DIR}/${repostatus}-install-dir" \ ${AUTOCONF_CONF_FLAGS} result=$? - popd >/dev/null + popd >/dev/null || return 1 if [[ ${result} != 0 ]]; then if [[ "${repostatus}" = branch ]]; then http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/test-patch.d/bugzilla.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/test-patch.d/bugzilla.sh b/precommit/src/main/shell/test-patch.d/bugzilla.sh index 9b7caeb..d7f8f17 100755 --- a/precommit/src/main/shell/test-patch.d/bugzilla.sh +++ b/precommit/src/main/shell/test-patch.d/bugzilla.sh @@ -81,7 +81,7 @@ function bugzilla_http_fetch return 1 fi - ${CURL} --silent --fail \ + "${CURL}" --silent --fail \ --output "${output}" \ --location \ "${BUGZILLA_BASE_URL}/${input}" @@ -98,8 +98,7 @@ function bugzilla_locate_patch return 1 fi - bugzilla_determine_issue "${input}" - if [[ $? != 0 || -z "${BUGZILLA_ISSUE}" ]]; then + if ! bugzilla_determine_issue "${input}" || [[ -z "${BUGZILLA_ISSUE}" ]]; then return 1 fi @@ -110,15 +109,13 @@ function bugzilla_locate_patch return 1 fi - bugzilla_http_fetch "show_bug.cgi?id=${BUGZILLA_ISSUE}" "${PATCH_DIR}/bugzilla" - - if [[ $? != 0 ]]; then + if ! bugzilla_http_fetch "show_bug.cgi?id=${BUGZILLA_ISSUE}" "${PATCH_DIR}/bugzilla"; then yetus_debug "bugzilla_locate_patch: not a Bugzilla." return 1 fi #shellcheck disable=SC2016 - relativeurl=$(${AWK} '/action=diff/ && match($0,"attachment\.cgi.id=[0-9]*"){print substr($0,RSTART,RLENGTH)}' \ + relativeurl=$("${AWK}" '/action=diff/ && match($0,"attachment\.cgi.id=[0-9]*"){print substr($0,RSTART,RLENGTH)}' \ "${PATCH_DIR}/bugzilla" | \ tail -1) PATCHURL="${BUGZILLA_BASE_URL}${relativeurl}" @@ -126,8 +123,7 @@ function bugzilla_locate_patch echo "${input} patch is being downloaded at $(date) from" echo "${PATCHURL}" add_footer_table "Bugzilla Patch URL" "${PATCHURL}" - bugzilla_http_fetch "${relativeurl}" "${fileloc}" - if [[ $? != 0 ]];then + if ! bugzilla_http_fetch "${relativeurl}" "${fileloc}"; then yetus_error "ERROR: ${input}/${PATCHURL} could not be downloaded." cleanup_and_exit 1 fi http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/test-patch.d/cc.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/test-patch.d/cc.sh b/precommit/src/main/shell/test-patch.d/cc.sh index 3241191..02bac8b 100755 --- a/precommit/src/main/shell/test-patch.d/cc.sh +++ b/precommit/src/main/shell/test-patch.d/cc.sh @@ -18,6 +18,12 @@ add_test_type cc CC_EXT_RE='(c|cc|cpp|cxx|c\+\+|h|hh|hpp|hxx|h\+\+)' +## @description discover files to check +## @audience private +## @stability stable +## @replaceable no +## @return 0 on success +## @return 1 on failure function cc_filefilter { declare filename=$1 @@ -61,6 +67,6 @@ function cc_logfilter declare input=$1 declare output=$2 - #shellcheck disable=SC2016,SC2046 - ${GREP} -i -E "^.*\.${CC_EXT_RE}\:[[:digit:]]*\:" "${input}" > "${output}" + #shellcheck disable=SC1117 + "${GREP}" -i -E "^.*\.${CC_EXT_RE}\:[[:digit:]]*\:" "${input}" > "${output}" } http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/test-patch.d/checkstyle.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/test-patch.d/checkstyle.sh b/precommit/src/main/shell/test-patch.d/checkstyle.sh index 5bfca02..59f3b97 100755 --- a/precommit/src/main/shell/test-patch.d/checkstyle.sh +++ b/precommit/src/main/shell/test-patch.d/checkstyle.sh @@ -14,6 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +# SHELLDOC-IGNORE + add_test_type checkstyle CHECKSTYLE_TIMER=0 @@ -106,13 +108,13 @@ function checkstyle_calcdiffs # so if only the error message numbers change # we do not report new error # shellcheck disable=SC2016 - cut -f3- -d: "${orig}" | awk -F'\1' '{ gsub("[0-9,]+", "", $2) ;print $1":"$2}' > "${tmp}.branch" + cut -f3- -d: "${orig}" | "${AWK}" -F'\1' '{ gsub("[0-9,]+", "", $2) ;print $1":"$2}' > "${tmp}.branch" # shellcheck disable=SC2016 - cut -f3- -d: "${new}" | awk -F'\1' '{ gsub("[0-9,]+", "", $2) ;print $1":"$2}' > "${tmp}.patch" + cut -f3- -d: "${new}" | "${AWK}" -F'\1' '{ gsub("[0-9,]+", "", $2) ;print $1":"$2}' > "${tmp}.patch" # compare the errors, generating a string of line # numbers. Sorry portability: GNU diff makes this too easy - ${DIFF} --unchanged-line-format="" \ + "${DIFF}" --unchanged-line-format="" \ --old-line-format="" \ --new-line-format="%dn " \ "${tmp}.branch" \ @@ -123,8 +125,7 @@ function checkstyle_calcdiffs # message which was needed for calculations # shellcheck disable=SC2013 for j in $(cat "${tmp}.lined"); do - # shellcheck disable=SC2086 - head -${j} "${new}" | tail -1 | tr -d $'\x01' + head -"${j}" "${new}" | tail -1 | tr -d $'\x01' done rm "${tmp}.branch" "${tmp}.patch" "${tmp}.lined" 2>/dev/null @@ -169,6 +170,8 @@ function checkstyle_runner buildtool_cwd "${i}" + #BUG - fix this + case ${BUILDTOOL} in ant) cmd="${ANT} \ @@ -198,7 +201,7 @@ function checkstyle_runner echo_and_redirect "${logfile}" ${cmd} cmdresult=$? - ${SED} -e 's,^\[ERROR\] ,,g' -e 's,^\[WARN\] ,,g' "${logfile}" \ + "${SED}" -e 's,^\[ERROR\] ,,g' -e 's,^\[WARN\] ,,g' "${logfile}" \ | ${GREP} ^/ \ | ${SED} -e "s,${BASEDIR},.,g" \ > "${tmp}" @@ -224,7 +227,7 @@ function checkstyle_runner # have to do later for j in "${CHANGED_FILES[@]}"; do - ${GREP} "${j}" "${tmp}" >> "${tmp}.1" + "${GREP}" "${j}" "${tmp}" >> "${tmp}.1" done # now that we have just the files we care about, @@ -246,7 +249,7 @@ function checkstyle_runner # file:linenum:code(:column)\x01:error # \x01 will later used to identify the begining # of the checkstyle error message - pushd "${BASEDIR}" >/dev/null + pushd "${BASEDIR}" >/dev/null || return 1 while read -r logline; do file=$(echo "${logline}" | cut -f1 -d:) linenum=$(echo "${logline}" | cut -f2 -d:) @@ -254,12 +257,12 @@ function checkstyle_runner codeline=$(head -n "+${linenum}" "${file}" | tail -1 ) { echo -n "${file}:${linenum}:${codeline}" - echo -ne "\x01" + echo -ne '\x01' echo ":${text}" } >> "${output}" done < <(cat "${tmp}.1") - popd >/dev/null + popd >/dev/null || return 1 # later on, calcdiff will turn this into code(:column):error # compare, and then put the file:line back onto it. else @@ -272,7 +275,7 @@ function checkstyle_runner #shellcheck disable=SC2034 MODULE_STATUS_TIMER[${i}]=${savestop} - popd >/dev/null + popd >/dev/null || return 1 ((i=i+1)) done http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/test-patch.d/cmake.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/test-patch.d/cmake.sh b/precommit/src/main/shell/test-patch.d/cmake.sh index 38a48c8..c3c72ab 100755 --- a/precommit/src/main/shell/test-patch.d/cmake.sh +++ b/precommit/src/main/shell/test-patch.d/cmake.sh @@ -78,7 +78,7 @@ function cmake_precheck return 1 fi # finally let folks know what version they'll be dealing with. - cmake_version=$(${CMAKE} --version 2>/dev/null | head -n 1 2>/dev/null) + cmake_version=$("${CMAKE}" --version 2>/dev/null | head -n 1 2>/dev/null) add_footer_table cmake "version: ${cmake_version}" make_precheck http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/test-patch.d/dupname.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/test-patch.d/dupname.sh b/precommit/src/main/shell/test-patch.d/dupname.sh index 6795308..fe77085 100755 --- a/precommit/src/main/shell/test-patch.d/dupname.sh +++ b/precommit/src/main/shell/test-patch.d/dupname.sh @@ -40,7 +40,7 @@ function dupname_icase_sort_array oifs=${IFS} fi set -f - # shellcheck disable=SC2034 + # shellcheck disable=SC2034,SC2207 IFS=$'\n' sa=($(sort -f <<<"${array[*]}")) # shellcheck disable=SC1083 eval "${arrname}"=\(\"\${sa[@]}\"\) http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/test-patch.d/findbugs.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/test-patch.d/findbugs.sh b/precommit/src/main/shell/test-patch.d/findbugs.sh index 84a807b..e21cfbd 100755 --- a/precommit/src/main/shell/test-patch.d/findbugs.sh +++ b/precommit/src/main/shell/test-patch.d/findbugs.sh @@ -14,6 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +# SHELLDOC-IGNORE FINDBUGS_HOME=${FINDBUGS_HOME:-} FINDBUGS_WARNINGS_FAIL_PRECHECK=false @@ -30,7 +31,7 @@ function findbugs_usage function findbugs_parse_args { - local i + declare i for i in "$@"; do case ${i} in @@ -60,7 +61,7 @@ function findbugs_initialize function findbugs_filefilter { - local filename=$1 + declare filename=$1 if [[ ${BUILDTOOL} == maven || ${BUILDTOOL} == ant ]]; then @@ -141,13 +142,15 @@ function findbugs_maven_skipper ## @param repostatus function findbugs_runner { - local name=$1 - local module - local result=0 - local fn - local warnings_file - local i=0 - local savestop + declare name=$1 + declare module + declare result=0 + declare fn + declare warnings_file + declare i=0 + declare savestop + declare retval + personality_modules "${name}" findbugs @@ -197,11 +200,14 @@ function findbugs_runner if [[ ${name} == branch ]]; then "${FINDBUGS_HOME}/bin/setBugDatabaseInfo" -name "${PATCH_BRANCH}" \ "${warnings_file}.xml" "${warnings_file}.xml" + retval=$? else "${FINDBUGS_HOME}/bin/setBugDatabaseInfo" -name patch \ "${warnings_file}.xml" "${warnings_file}.xml" + retval=$? fi - if [[ $? != 0 ]]; then + + if [[ ${retval} != 0 ]]; then savestop=$(stop_clock) MODULE_STATUS_TIMER[${i}]=${savestop} module_status ${i} -1 "" "${name}/${module} cannot run setBugDatabaseInfo from findbugs" @@ -210,10 +216,9 @@ function findbugs_runner continue fi - "${FINDBUGS_HOME}/bin/convertXmlToText" -html \ + if ! "${FINDBUGS_HOME}/bin/convertXmlToText" -html \ "${warnings_file}.xml" \ - "${warnings_file}.html" - if [[ $? != 0 ]]; then + "${warnings_file}.html"; then savestop=$(stop_clock) MODULE_STATUS_TIMER[${i}]=${savestop} module_status ${i} -1 "" "${name}/${module} cannot run convertXmlToText from findbugs" @@ -387,17 +392,16 @@ function findbugs_postinstall newbugsbase="${PATCH_DIR}/new-findbugs-${fn}" fixedbugsbase="${PATCH_DIR}/fixed-findbugs-${fn}" - "${FINDBUGS_HOME}/bin/computeBugHistory" -useAnalysisTimes -withMessages \ + if ! "${FINDBUGS_HOME}/bin/computeBugHistory" -useAnalysisTimes -withMessages \ -output "${combined_xml}" \ "${branchxml}" \ - "${patchxml}" - if [[ $? != 0 ]]; then - popd >/dev/null + "${patchxml}"; then module_status ${i} -1 "" "${module} cannot run computeBugHistory from findbugs" ((result=result+1)) savestop=$(stop_clock) MODULE_STATUS_TIMER[${i}]=${savestop} ((i=i+1)) + popd >/dev/null || return 1 continue fi @@ -411,40 +415,41 @@ function findbugs_postinstall #shellcheck disable=SC2016 add_warnings=$("${FINDBUGS_HOME}/bin/filterBugs" -first patch \ "${combined_xml}" "${newbugsbase}.xml" | ${AWK} '{print $1}') - if [[ $? != 0 ]]; then - popd >/dev/null + retval=$? + if [[ ${retval} != 0 ]]; then module_status ${i} -1 "" "${module} cannot run filterBugs (#1) from findbugs" ((result=result+1)) savestop=$(stop_clock) MODULE_STATUS_TIMER[${i}]=${savestop} ((i=i+1)) + popd >/dev/null || return 1 continue fi #shellcheck disable=SC2016 fixed_warnings=$("${FINDBUGS_HOME}/bin/filterBugs" -fixed patch \ "${combined_xml}" "${fixedbugsbase}.xml" | ${AWK} '{print $1}') - if [[ $? != 0 ]]; then - popd >/dev/null + retval=$? + if [[ ${retval} != 0 ]]; then module_status ${i} -1 "" "${module} cannot run filterBugs (#2) from findbugs" ((result=result+1)) savestop=$(stop_clock) MODULE_STATUS_TIMER[${i}]=${savestop} ((i=i+1)) + popd >/dev/null || return 1 continue fi statstring=$(generic_calcdiff_status "${branch_warnings}" "${patch_warnings}" "${add_warnings}") - "${FINDBUGS_HOME}/bin/convertXmlToText" -html "${newbugsbase}.xml" \ - "${newbugsbase}.html" - if [[ $? != 0 ]]; then - popd >/dev/null + if ! "${FINDBUGS_HOME}/bin/convertXmlToText" -html "${newbugsbase}.xml" \ + "${newbugsbase}.html"; then module_status ${i} -1 "" "${module} cannot run convertXmlToText from findbugs" ((result=result+1)) savestop=$(stop_clock) MODULE_STATUS_TIMER[${i}]=${savestop} ((i=i+1)) + popd >/dev/null || return 1 continue fi @@ -465,7 +470,7 @@ function findbugs_postinstall fi savestop=$(stop_clock) MODULE_STATUS_TIMER[${i}]=${savestop} - popd >/dev/null + popd >/dev/null || return 1 ((i=i+1)) done http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/test-patch.d/github.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/test-patch.d/github.sh b/precommit/src/main/shell/test-patch.d/github.sh index ce6fa2f..17df408 100755 --- a/precommit/src/main/shell/test-patch.d/github.sh +++ b/precommit/src/main/shell/test-patch.d/github.sh @@ -103,7 +103,7 @@ function github_jira_bridge declare urlfromjira # shellcheck disable=SC2016 - urlfromjira=$(${AWK} "match(\$0,\"${GITHUB_BASE_URL}/[^ ]*patch[ &\\\"]\"){url=substr(\$0,RSTART,RLENGTH-1)} + urlfromjira=$("${AWK}" "match(\$0,\"${GITHUB_BASE_URL}/[^ ]*patch[ &\\\"]\"){url=substr(\$0,RSTART,RLENGTH-1)} END{if (url) print url}" "${jsonloc}" ) if [[ -z $urlfromjira ]]; then # This is currently the expected path, as github pull requests are not common @@ -204,8 +204,7 @@ function github_determine_issue # if JIRA didn't call us, should we call it? if [[ ${GITHUB_BRIDGED} == false ]]; then - github_find_jira_title - if [[ $? == 0 ]]; then + if github_find_jira_title; then return 0 fi fi @@ -230,7 +229,7 @@ function github_determine_branch fi # shellcheck disable=SC2016 - PATCH_BRANCH=$(${AWK} 'match($0,"\"ref\": \""){print $2}' "${PATCH_DIR}/github-pull.json"\ + PATCH_BRANCH=$("${AWK}" 'match($0,"\"ref\": \""){print $2}' "${PATCH_DIR}/github-pull.json"\ | cut -f2 -d\"\ | tail -1 ) @@ -436,7 +435,7 @@ function github_linecomments fi if [[ -z "${GITHUB_COMMITSHA}" ]]; then - GITHUB_COMMITSHA=$(${GREP} \"sha\" "${PATCH_DIR}/github-pull.json" 2>/dev/null \ + GITHUB_COMMITSHA=$("${GREP}" \"sha\" "${PATCH_DIR}/github-pull.json" 2>/dev/null \ | head -1 \ | cut -f4 -d\") fi @@ -449,7 +448,7 @@ function github_linecomments { printf "{\"body\":\"" echo "${plugin}: ${text}" \ - | ${SED} -e 's,\\,\\\\,g' \ + | "${SED}" -e 's,\\,\\\\,g' \ -e 's,\",\\\",g' \ -e 's,$,\\r\\n,g' \ | tr -d '\n' @@ -498,7 +497,7 @@ function github_write_comment { printf "{\"body\":\"" - ${SED} -e 's,\\,\\\\,g' \ + "${SED}" -e 's,\\,\\\\,g' \ -e 's,\",\\\",g' \ -e 's,$,\\r\\n,g' "${commentfile}" \ | tr -d '\n' @@ -555,17 +554,16 @@ function github_finalreport else echo ":broken_heart: **-1 overall**" >> "${commentfile}" fi - - printf "\n\n\n\n" >> "${commentfile}" + printf '\n\n\n\n' >> "${commentfile}" i=0 until [[ ${i} -eq ${#TP_HEADER[@]} ]]; do - printf "%s\n\n" "${TP_HEADER[${i}]}" >> "${commentfile}" + printf '%s\n\n' "${TP_HEADER[${i}]}" >> "${commentfile}" ((i=i+1)) done { - printf "\n\n" + printf '\n\n' echo "| Vote | Subsystem | Runtime | Comment |" echo "|:----:|----------:|--------:|:--------|" } >> "${commentfile}" @@ -586,7 +584,7 @@ function github_finalreport if [[ ${#TP_TEST_TABLE[@]} -gt 0 ]]; then { - printf "\n\n" + printf '\n\n' echo "| Reason | Tests |" echo "|-------:|:------|" } >> "${commentfile}" @@ -598,7 +596,7 @@ function github_finalreport fi { - printf "\n\n" + printf '\n\n' echo "| Subsystem | Report/Notes |" echo "|----------:|:-------------|" } >> "${commentfile}" @@ -607,11 +605,10 @@ function github_finalreport until [[ $i -eq ${#TP_FOOTER_TABLE[@]} ]]; do comment=$(echo "${TP_FOOTER_TABLE[${i}]}" | ${SED} -e "s,@@BASE@@,${BUILD_URL}${BUILD_URL_ARTIFACTS},g") - printf "%s\n" "${comment}" >> "${commentfile}" + printf '%s\n' "${comment}" >> "${commentfile}" ((i=i+1)) done - - printf "\n\nThis message was automatically generated.\n\n" >> "${commentfile}" + printf '\n\nThis message was automatically generated.\n\n' >> "${commentfile}" github_write_comment "${commentfile}" } http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/test-patch.d/gradle.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/test-patch.d/gradle.sh b/precommit/src/main/shell/test-patch.d/gradle.sh index 8c78ab4..6c580ba 100755 --- a/precommit/src/main/shell/test-patch.d/gradle.sh +++ b/precommit/src/main/shell/test-patch.d/gradle.sh @@ -59,7 +59,7 @@ function gradle_precheck return 1 fi # finally let folks know what version they'll be dealing with. - gradle_version=$(${GRADLE} --version 2>/dev/null | grep Gradle 2>/dev/null) + gradle_version=$("${GRADLE}" --version 2>/dev/null | grep Gradle 2>/dev/null) add_footer_table gradle "version: ${gradle_version}" return 0 } @@ -129,9 +129,9 @@ function gradle_precompile personality_modules "${repostatus}" gradleboot - pushd "${BASEDIR}" >/dev/null + pushd "${BASEDIR}" >/dev/null || return 1 echo_and_redirect "${PATCH_DIR}/${repostatus}-gradle-bootstrap.txt" gradle -b bootstrap.gradle - popd >/dev/null + popd >/dev/null || return 1 modules_workers "${repostatus}" gradleboot result=$? @@ -151,8 +151,7 @@ function gradle_javac_logfilter declare input=$1 declare output=$2 - #shellcheck disable=SC2016,SC2046 - ${GREP} "\.java" "${input}" > "${output}" + "${GREP}" '\.java' "${input}" > "${output}" } ## @description Helper for generic_logfilter @@ -164,8 +163,7 @@ function gradle_javadoc_logfilter declare input=$1 declare output=$2 - #shellcheck disable=SC2016,SC2046 - ${GREP} "javadoc.*\.java" "${input}" > "${output}" + "${GREP}" 'javadoc.*\.java' "${input}" > "${output}" } ## @description Helper for generic_logfilter @@ -177,8 +175,7 @@ function gradle_scaladoc_logfilter declare input=$1 declare output=$2 - #shellcheck disable=SC2016,SC2046 - ${GREP} "^\[ant:scaladoc\] /.*\.scala" "${input}" > "${output}" + "${GREP}" '^\[ant:scaladoc\] /.*\.scala' "${input}" > "${output}" } function gradle_modules_worker http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/test-patch.d/hadolint.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/test-patch.d/hadolint.sh b/precommit/src/main/shell/test-patch.d/hadolint.sh index 804bd4a..b5e068b 100755 --- a/precommit/src/main/shell/test-patch.d/hadolint.sh +++ b/precommit/src/main/shell/test-patch.d/hadolint.sh @@ -80,7 +80,6 @@ function hadolint_logic for i in "${HADOLINT_CHECKFILES[@]}"; do if [[ -f "${i}" ]]; then - echo " * ${i}" "${HADOLINT}" "${i}" >> "${PATCH_DIR}/${repostatus}-hadolint-result.txt" fi done @@ -114,12 +113,12 @@ function hadolint_calcdiffs # first, pull out just the errors # shellcheck disable=SC2016 - ${AWK} -F: '{print $NF}' "${branch}" | cut -d' ' -f2- > "${tmp}.branch" + "${AWK}" -F: '{print $NF}' "${branch}" | cut -d' ' -f2- > "${tmp}.branch" # shellcheck disable=SC2016 - ${AWK} -F: '{print $NF}' "${patch}" | cut -d' ' -f2- > "${tmp}.patch" + "${AWK}" -F: '{print $NF}' "${patch}" | cut -d' ' -f2- > "${tmp}.patch" - ${DIFF} --unchanged-line-format="" \ + "${DIFF}" --unchanged-line-format="" \ --old-line-format="" \ --new-line-format="%dn " \ "${tmp}.branch" \ @@ -128,8 +127,7 @@ function hadolint_calcdiffs # now, pull out those lines of the raw output # shellcheck disable=SC2013 for j in $(cat "${tmp}.lined"); do - # shellcheck disable=SC2086 - head -${j} "${patch}" | tail -1 + head -"${j}" "${patch}" | tail -1 done rm "${tmp}.branch" "${tmp}.patch" "${tmp}.lined" 2>/dev/null @@ -165,13 +163,13 @@ function hadolint_postapply > "${PATCH_DIR}/diff-patch-hadolint.txt" # shellcheck disable=SC2016 - numPrepatch=$(wc -l "${PATCH_DIR}/branch-hadolint-result.txt" | ${AWK} '{print $1}') + numPrepatch=$(wc -l "${PATCH_DIR}/branch-hadolint-result.txt" | "${AWK}" '{print $1}') # shellcheck disable=SC2016 - numPostpatch=$(wc -l "${PATCH_DIR}/patch-hadolint-result.txt" | ${AWK} '{print $1}') + numPostpatch=$(wc -l "${PATCH_DIR}/patch-hadolint-result.txt" | "${AWK}" '{print $1}') # shellcheck disable=SC2016 - diffPostpatch=$(wc -l "${PATCH_DIR}/diff-patch-hadolint.txt" | ${AWK} '{print $1}') + diffPostpatch=$(wc -l "${PATCH_DIR}/diff-patch-hadolint.txt" | "${AWK}" '{print $1}') ((fixedpatch=numPrepatch-numPostpatch+diffPostpatch)) http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/test-patch.d/htmlout.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/test-patch.d/htmlout.sh b/precommit/src/main/shell/test-patch.d/htmlout.sh index 9439412..ef44cb0 100755 --- a/precommit/src/main/shell/test-patch.d/htmlout.sh +++ b/precommit/src/main/shell/test-patch.d/htmlout.sh @@ -107,7 +107,7 @@ function htmlout_finalreport until [[ $i -eq ${#TP_HEADER[@]} ]]; do ourstring=$(echo "${TP_HEADER[${i}]}" | tr -s ' ') comment=$(echo "${ourstring}" | cut -f2 -d\|) - printf "<tr><td>%s</td></tr>\n" "${comment}" + printf '<tr><td>%s</td></tr>\n' "${comment}" ((i=i+1)) done @@ -133,10 +133,10 @@ function htmlout_finalreport if [[ "${vote}" = "H" ]]; then { echo "<tr>" - printf "\t\t<td></td>" + printf '\t\t<td></td>' printf "<td></td>" printf "<td></td>" - printf "<td><font color=\"%s\">%s</font></td>\n" "brown" "${comment}" + printf '<td><font color=\"%s\">%s</font></td>\n' "brown" "${comment}" echo "</tr>" } >> "${commentfile}" ((i=i+1)) @@ -173,10 +173,10 @@ function htmlout_finalreport { echo "<tr>" - printf "\t\t<td><font color=\"%s\">%s</font></td>" "${color}" "${vote}" + printf '\t\t<td><font color=\"%s\">%s</font></td>' "${color}" "${vote}" printf "<td><font color=\"%s\">%s</font></td>" "${color}" "${subs}" printf "<td><font color=\"%s\">%s</font></td>" "${color}" "${calctime}" - printf "<td><font color=\"%s\">%s</font></td>\n" "${color}" "${comment}" + printf '<td><font color=\"%s\">%s</font></td>\n' "${color}" "${comment}" echo "</tr>" } >> "${commentfile}" ((i=i+1)) http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/test-patch.d/java.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/test-patch.d/java.sh b/precommit/src/main/shell/test-patch.d/java.sh index 8515650..2482189 100755 --- a/precommit/src/main/shell/test-patch.d/java.sh +++ b/precommit/src/main/shell/test-patch.d/java.sh @@ -14,6 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +# SHELLDOC-IGNORE + add_test_type javac add_test_type javadoc http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/test-patch.d/jira.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/test-patch.d/jira.sh b/precommit/src/main/shell/test-patch.d/jira.sh index c01587e..00c7a54 100755 --- a/precommit/src/main/shell/test-patch.d/jira.sh +++ b/precommit/src/main/shell/test-patch.d/jira.sh @@ -91,7 +91,7 @@ function jira_determine_issue fi # shellcheck disable=SC2016 - patchnamechunk=$(echo "${input}" | ${AWK} -F/ '{print $NF}') + patchnamechunk=$(echo "${input}" | "${AWK}" -F/ '{print $NF}') maybeissue=$(echo "${patchnamechunk}" | cut -f1,2 -d-) @@ -115,13 +115,13 @@ function jira_http_fetch yetus_debug "jira_http_fetch: ${JIRA_URL}/${input}" if [[ -n "${JIRA_USER}" && -n "${JIRA_PASSWD}" ]]; then - ${CURL} --silent --fail \ + "${CURL}" --silent --fail \ --user "${JIRA_USER}:${JIRA_PASSWD}" \ --output "${output}" \ --location \ "${JIRA_URL}/${input}" else - ${CURL} --silent --fail \ + "${CURL}" --silent --fail \ --output "${output}" \ --location \ "${JIRA_URL}/${input}" @@ -165,8 +165,7 @@ function jira_locate_patch return 1 fi - jira_http_fetch "browse/${input}" "${PATCH_DIR}/jira" - if [[ $? != 0 ]]; then + if ! jira_http_fetch "browse/${input}" "${PATCH_DIR}/jira"; then yetus_debug "jira_locate_patch: not a JIRA." return 1 fi @@ -180,8 +179,7 @@ function jira_locate_patch jira_http_fetch "rest/api/2/issue/${input}" "${jsonloc}" # Parse the downloaded information to check if the issue is # just a pointer to GitHub. - github_jira_bridge "${fileloc}" "${jsonloc}" - if [[ $? -eq 0 ]]; then + if github_jira_bridge "${fileloc}" "${jsonloc}"; then echo "${input} appears to be a Github PR. Switching Modes." return 0 fi @@ -189,7 +187,7 @@ function jira_locate_patch fi # Not reached if there is a successful github plugin return - if [[ $(${GREP} -c "${JIRA_STATUS_RE}" "${PATCH_DIR}/jira") == 0 ]]; then + if [[ $("${GREP}" -c "${JIRA_STATUS_RE}" "${PATCH_DIR}/jira") == 0 ]]; then if [[ ${ROBOT} == true ]]; then yetus_error "ERROR: ${input} issue status is not matched with \"${JIRA_STATUS_RE}\"." cleanup_and_exit 1 @@ -204,9 +202,9 @@ function jira_locate_patch # ascending order. so bigger # == newer file #shellcheck disable=SC2016 tr '>' '\n' < "${PATCH_DIR}/jira" \ - | ${AWK} 'match($0,"/secure/attachment/[0-9]*/[^\"]*"){print substr($0,RSTART,RLENGTH)}' \ - | ${GREP} -v -e 'htm[l]*$' \ - | ${SED} -e 's,[ ]*$,,g' \ + | "${AWK}" 'match($0,"/secure/attachment/[0-9]*/[^\"]*"){print substr($0,RSTART,RLENGTH)}' \ + | "${GREP}" -v -e 'htm[l]*$' \ + | "${SED}" -e 's,[ ]*$,,g' \ | sort -n -r -k4 -t/ \ | uniq \ > "${PATCH_DIR}/jira-attachments.txt" @@ -237,8 +235,7 @@ function jira_locate_patch fi if [[ ! ${PATCHURL} =~ \.patch$ ]]; then - guess_patch_file "${fileloc}" - if [[ $? == 0 ]]; then + if guess_patch_file "${fileloc}"; then yetus_debug "The patch ${PATCHURL} was not named properly, but it looks like a patch file. Proceeding, but issue/branch matching might go awry." add_vote_table 0 patch "The patch file was not named according to ${PROJECT_NAME}'s naming conventions. Please see ${PATCH_NAMING_RULE} for instructions." else @@ -280,7 +277,7 @@ function jira_determine_branch yetus_debug "Determine branch: starting with ${hinttype}" patchnamechunk=$(echo "${hinttype}" \ - | ${SED} -e 's,.*/\(.*\)$,\1,' \ + | "${SED}" -e 's,.*/\(.*\)$,\1,' \ -e 's,\.txt,.,' \ -e 's,.patch,.,g' \ -e 's,.diff,.,g' \ @@ -369,14 +366,14 @@ function jira_write_comment # RESTify the comment { echo "{\"body\":\"" - ${SED} -e 's,\\,\\\\,g' \ + "${SED}" -e 's,\\,\\\\,g' \ -e 's,\",\\\",g' \ -e 's,$,\\r\\n,g' "${commentfile}" \ | tr -d '\n' echo "\"}" } > "${PATCH_DIR}/jiracomment.$$" - ${CURL} -X POST \ + "${CURL}" -X POST \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -u "${JIRA_USER}:${JIRA_PASSWD}" \ @@ -434,7 +431,7 @@ function jira_finalreport i=0 until [[ $i -eq ${#TP_HEADER[@]} ]]; do - printf "%s\n" "${TP_HEADER[${i}]}" >> "${commentfile}" + printf '%s\n' "${TP_HEADER[${i}]}" >> "${commentfile}" ((i=i+1)) done @@ -488,8 +485,7 @@ function jira_finalreport ;; esac fi - - printf "| {color:%s}%s{color} | {color:%s}%s{color} | {color:%s}%s{color} | {color:%s}%s{color} |\n" \ + printf '| {color:%s}%s{color} | {color:%s}%s{color} | {color:%s}%s{color} | {color:%s}%s{color} |\n' \ "${color}" "${vote}" \ "${color}" "${subs}" \ "${color}" "${calctime}" \ @@ -504,7 +500,7 @@ function jira_finalreport echo "|| Reason || Tests ||" >> "${commentfile}" i=0 until [[ $i -eq ${#TP_TEST_TABLE[@]} ]]; do - printf "%s\n" "${TP_TEST_TABLE[${i}]}" >> "${commentfile}" + printf '%s\n' "${TP_TEST_TABLE[${i}]}" >> "${commentfile}" ((i=i+1)) done fi @@ -515,12 +511,12 @@ function jira_finalreport i=0 until [[ $i -eq ${#TP_FOOTER_TABLE[@]} ]]; do comment=$(echo "${TP_FOOTER_TABLE[${i}]}" | - ${SED} -e "s,@@BASE@@,${BUILD_URL}${BUILD_URL_ARTIFACTS},g") - printf "%s\n" "${comment}" >> "${commentfile}" + "${SED}" -e "s,@@BASE@@,${BUILD_URL}${BUILD_URL_ARTIFACTS},g") + printf '%s\n' "${comment}" >> "${commentfile}" ((i=i+1)) done - printf "\n\nThis message was automatically generated.\n\n" >> "${commentfile}" + printf '\n\nThis message was automatically generated.\n\n' >> "${commentfile}" jira_write_comment "${commentfile}" } http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/test-patch.d/junit.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/test-patch.d/junit.sh b/precommit/src/main/shell/test-patch.d/junit.sh index 0bbe23e..fe9c2a3 100755 --- a/precommit/src/main/shell/test-patch.d/junit.sh +++ b/precommit/src/main/shell/test-patch.d/junit.sh @@ -14,6 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +# SHELLDOC-IGNORE + add_test_format junit JUNIT_TEST_TIMEOUTS="" @@ -54,7 +56,7 @@ function junit_process_tests declare module_failed_tests # shellcheck disable=SC2016 - module_test_timeouts=$(${AWK} '/^Running / { array[$NF] = 1 } /^Tests run: .* in / { delete array[$NF] } END { for (x in array) { print x } }' "${buildlogfile}") + module_test_timeouts=$("${AWK}" '/^Running / { array[$NF] = 1 } /^Tests run: .* in / { delete array[$NF] } END { for (x in array) { print x } }' "${buildlogfile}") if [[ -n "${module_test_timeouts}" ]] ; then JUNIT_TEST_TIMEOUTS="${JUNIT_TEST_TIMEOUTS} ${module_test_timeouts}" ((result=result+1)) @@ -63,7 +65,7 @@ function junit_process_tests #shellcheck disable=SC2026,SC2038,SC2016 module_failed_tests=$(find "${JUNIT_TEST_OUTPUT_DIR}" -name 'TEST*.xml'\ | xargs "${GREP}" -l -E "<failure|<error"\ - | ${AWK} -F/ '{sub("'"TEST-${JUNIT_TEST_PREFIX}"'",""); sub(".xml",""); print $NF}') + | "${AWK}" -F/ '{sub("'"TEST-${JUNIT_TEST_PREFIX}"'",""); sub(".xml",""); print $NF}') if [[ -n "${module_failed_tests}" ]] ; then JUNIT_FAILED_TESTS="${JUNIT_FAILED_TESTS} ${module_failed_tests}" ((result=result+1)) http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/test-patch.d/make.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/test-patch.d/make.sh b/precommit/src/main/shell/test-patch.d/make.sh index 6fb2b59..76ab6af 100755 --- a/precommit/src/main/shell/test-patch.d/make.sh +++ b/precommit/src/main/shell/test-patch.d/make.sh @@ -16,7 +16,7 @@ add_build_tool make -MAKE=make +MAKE=$(command -v make 2>/dev/null) MAKEFILE=Makefile ## @description make usage hook http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/test-patch.d/maven.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/test-patch.d/maven.sh b/precommit/src/main/shell/test-patch.d/maven.sh index 13e2867..7741254 100755 --- a/precommit/src/main/shell/test-patch.d/maven.sh +++ b/precommit/src/main/shell/test-patch.d/maven.sh @@ -69,6 +69,9 @@ function maven_ws_replace fi } +## @description maven usage message +## @audience private +## @stability evolving function maven_usage { maven_ws_replace @@ -216,8 +219,7 @@ function maven_precheck if [[ ! -d "${MAVEN_LOCAL_REPO}" ]]; then yetus_debug "Creating ${MAVEN_LOCAL_REPO}" - mkdir -p "${MAVEN_LOCAL_REPO}" - if [[ $? -ne 0 ]]; then + if ! mkdir -p "${MAVEN_LOCAL_REPO}"; then yetus_error "ERROR: Unable to create ${MAVEN_LOCAL_REPO}" return 1 fi @@ -251,6 +253,9 @@ function maven_precheck add_footer_table maven "version: ${maven_version}" } +## @description maven trigger +## @audience private +## @stability evolving function maven_filefilter { declare filename=$1 @@ -261,16 +266,25 @@ function maven_filefilter fi } +## @description maven build file +## @audience private +## @stability evolving function maven_buildfile { echo "pom.xml" } +## @description execute maven +## @audience private +## @stability evolving function maven_executor { echo "${MAVEN}" "${MAVEN_ARGS[@]}" } +## @description mvn site trigger +## @audience private +## @stability evolving function mvnsite_filefilter { local filename=$1 @@ -331,6 +345,9 @@ function maven_modules_worker esac } +## @description process javac output from maven +## @audience private +## @stability evolving function maven_javac_logfilter { declare input=$1 @@ -365,17 +382,14 @@ function maven_javac_calcdiffs declare orig=$1 declare new=$2 declare tmp=${PATCH_DIR}/pl.$$.${RANDOM} - declare j # first, strip :[line # this keeps file,column in an attempt to increase # accuracy in case of multiple, repeated errors # since the column number shouldn't change # if the line of code hasn't been touched - # shellcheck disable=SC2016 - ${SED} -e 's#:\[[0-9]*,#:#' "${orig}" > "${tmp}.branch" - # shellcheck disable=SC2016 - ${SED} -e 's#:\[[0-9]*,#:#' "${new}" > "${tmp}.patch" + "${SED}" -e 's#:\[[0-9]*,#:#' "${orig}" > "${tmp}.branch" + "${SED}" -e 's#:\[[0-9]*,#:#' "${new}" > "${tmp}.patch" # compare the errors, generating a string of line # numbers. Sorry portability: GNU diff makes this too easy @@ -388,8 +402,7 @@ function maven_javac_calcdiffs # now, pull out those lines of the raw output # shellcheck disable=SC2013 for j in $(cat "${tmp}.lined"); do - # shellcheck disable=SC2086 - head -${j} "${new}" | tail -1 + head -"${j}" "${new}" | tail -1 done rm "${tmp}.branch" "${tmp}.patch" "${tmp}.lined" 2>/dev/null @@ -407,15 +420,12 @@ function maven_javadoc_calcdiffs declare orig=$1 declare new=$2 declare tmp=${PATCH_DIR}/pl.$$.${RANDOM} - declare j # can't use the generic handler for this because of the # [WARNING], etc headers. # strip :linenum from the output, keeping the filename - # shellcheck disable=SC2016 - ${SED} -e 's#:[0-9]*:#:#' "${orig}" > "${tmp}.branch" - # shellcheck disable=SC2016 - ${SED} -e 's#:[0-9]*:#:#' "${new}" > "${tmp}.patch" + "${SED}" -e 's#:[0-9]*:#:#' "${orig}" > "${tmp}.branch" + "${SED}" -e 's#:[0-9]*:#:#' "${new}" > "${tmp}.patch" # compare the errors, generating a string of line # numbers. Sorry portability: GNU diff makes this too easy @@ -428,18 +438,21 @@ function maven_javadoc_calcdiffs # now, pull out those lines of the raw output # shellcheck disable=SC2013 for j in $(cat "${tmp}.lined"); do - # shellcheck disable=SC2086 - head -${j} "${new}" | tail -1 + head -"${j}" "${new}" | tail -1 done rm "${tmp}.branch" "${tmp}.patch" "${tmp}.lined" 2>/dev/null } + +## @description maven personality handler +## @audience private +## @stability evolving +## @replaceable yes function maven_builtin_personality_modules { declare repostatus=$1 declare testtype=$2 - declare module yetus_debug "Using builtin personality_modules" @@ -461,6 +474,10 @@ function maven_builtin_personality_modules done } +## @description maven default test triggers +## @audience private +## @stability evolving +## @replaceable yes function maven_builtin_personality_file_tests { local filename=$1 @@ -621,6 +638,10 @@ function maven_precompile return 0 } +## @description set volumes as appropriate for maven +## @audience private +## @stability evolving +## @replaceable yes function maven_docker_support { DOCKER_EXTRAARGS=("${DOCKER_EXTRAARGS[@]}" "-v" "${HOME}/.m2:/home/${USER_NAME}/.m2") @@ -657,7 +678,7 @@ function maven_reorder_module_process done fn=$(module_file_fragment "${CHANGED_UNION_MODULES}") - pushd "${BASEDIR}/${CHANGED_UNION_MODULES}" >/dev/null + pushd "${BASEDIR}/${CHANGED_UNION_MODULES}" >/dev/null || return 1 # get the module directory list in the correct order based on maven dependencies # shellcheck disable=SC2046 @@ -675,7 +696,7 @@ function maven_reorder_module_process fi done done < "${PATCH_DIR}/maven-${repostatus}-dirlist-${fn}.txt" - popd >/dev/null + popd >/dev/null || return 1 if [[ "${needroot}" = true ]]; then newlist=("${newlist[@]}" ".") @@ -764,5 +785,6 @@ function maven_reorder_modules fi fi + # shellcheck disable=SC2046 echo "Elapsed: $(clock_display $(stop_clock))" } http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/test-patch.d/nobuild.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/test-patch.d/nobuild.sh b/precommit/src/main/shell/test-patch.d/nobuild.sh index cf5a2ad..a049f98 100755 --- a/precommit/src/main/shell/test-patch.d/nobuild.sh +++ b/precommit/src/main/shell/test-patch.d/nobuild.sh @@ -14,6 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +# SHELLDOC-IGNORE + +# A simple build system that doesn't actually build anything + add_build_tool nobuild function nobuild_buildfile http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/test-patch.d/perlcritic.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/test-patch.d/perlcritic.sh b/precommit/src/main/shell/test-patch.d/perlcritic.sh index 291e94e..f2ee183 100755 --- a/precommit/src/main/shell/test-patch.d/perlcritic.sh +++ b/precommit/src/main/shell/test-patch.d/perlcritic.sh @@ -14,11 +14,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +# SHELLDOC-IGNORE + add_test_type perlcritic PERLCRITIC_TIMER=0 -PERLCRITIC=${PERLCRITIC:-$(which perlcritic 2>/dev/null)} +PERLCRITIC=${PERLCRITIC:-$(command -v perlcritic 2>/dev/null)} function perlcritic_usage { @@ -69,13 +71,13 @@ function perlcritic_preapply start_clock echo "Running perlcritic against identified perl scripts/modules." - pushd "${BASEDIR}" >/dev/null + pushd "${BASEDIR}" >/dev/null || return 1 for i in "${CHANGED_FILES[@]}"; do if [[ ${i} =~ \.p[lm]$ && -f ${i} ]]; then ${PERLCRITIC} -1 --verbose 1 "${i}" 2>/dev/null >> "${PATCH_DIR}/branch-perlcritic-result.txt" fi done - popd >/dev/null + popd >/dev/null || return 1 # keep track of how much as elapsed for us already PERLCRITIC_TIMER=$(stop_clock) return 0 @@ -116,13 +118,13 @@ function perlcritic_postapply echo "Running perlcritic against identified perl scripts/modules." # we re-check this in case one has been added - pushd "${BASEDIR}" >/dev/null + pushd "${BASEDIR}" >/dev/null || return 1 for i in "${CHANGED_FILES[@]}"; do if [[ ${i} =~ \.p[lm]$ && -f ${i} ]]; then ${PERLCRITIC} -1 --verbose 1 "${i}" 2>/dev/null >> "${PATCH_DIR}/patch-perlcritic-result.txt" fi done - popd >/dev/null + popd >/dev/null || return 1 PERLCRITIC_VERSION=$(${PERLCRITIC} --version 2>/dev/null) add_footer_table perlcritic "v${PERLCRITIC_VERSION}" @@ -134,13 +136,13 @@ function perlcritic_postapply > "${PATCH_DIR}/diff-patch-perlcritic.txt" # shellcheck disable=SC2016 - numPrepatch=$(wc -l "${PATCH_DIR}/branch-perlcritic-result.txt" | ${AWK} '{print $1}') + numPrepatch=$(wc -l "${PATCH_DIR}/branch-perlcritic-result.txt" | "${AWK}" '{print $1}') # shellcheck disable=SC2016 - numPostpatch=$(wc -l "${PATCH_DIR}/patch-perlcritic-result.txt" | ${AWK} '{print $1}') + numPostpatch=$(wc -l "${PATCH_DIR}/patch-perlcritic-result.txt" | "${AWK}" '{print $1}') # shellcheck disable=SC2016 - diffPostpatch=$(wc -l "${PATCH_DIR}/diff-patch-perlcritic.txt" | ${AWK} '{print $1}') + diffPostpatch=$(wc -l "${PATCH_DIR}/diff-patch-perlcritic.txt" | "${AWK}" '{print $1}') ((fixedpatch=numPrepatch-numPostpatch+diffPostpatch)) http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/test-patch.d/rubocop.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/test-patch.d/rubocop.sh b/precommit/src/main/shell/test-patch.d/rubocop.sh index 828bea1..490c985 100755 --- a/precommit/src/main/shell/test-patch.d/rubocop.sh +++ b/precommit/src/main/shell/test-patch.d/rubocop.sh @@ -14,11 +14,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +# SHELLDOC-IGNORE + add_test_type rubocop RUBOCOP_TIMER=0 -RUBOCOP=${RUBOCOP:-$(which rubocop 2>/dev/null)} +RUBOCOP=${RUBOCOP:-$(command -v rubocop 2>/dev/null)} function rubocop_usage { @@ -69,13 +71,13 @@ function rubocop_preapply start_clock echo "Running rubocop against identified ruby scripts." - pushd "${BASEDIR}" >/dev/null + pushd "${BASEDIR}" >/dev/null || return 1 for i in "${CHANGED_FILES[@]}"; do if [[ ${i} =~ \.rb$ && -f ${i} ]]; then - ${RUBOCOP} -f e "${i}" | ${AWK} '!/[0-9]* files? inspected/' >> "${PATCH_DIR}/branch-rubocop-result.txt" + "${RUBOCOP}" -f e "${i}" | "${AWK}" '!/[0-9]* files? inspected/' >> "${PATCH_DIR}/branch-rubocop-result.txt" fi done - popd >/dev/null + popd >/dev/null || return 1 # keep track of how much as elapsed for us already RUBOCOP_TIMER=$(stop_clock) return 0 @@ -116,16 +118,16 @@ function rubocop_postapply echo "Running rubocop against identified ruby scripts." # we re-check this in case one has been added - pushd "${BASEDIR}" >/dev/null + pushd "${BASEDIR}" >/dev/null || return 1 for i in "${CHANGED_FILES[@]}"; do if [[ ${i} =~ \.rb$ && -f ${i} ]]; then - ${RUBOCOP} -f e "${i}" | ${AWK} '!/[0-9]* files? inspected/' >> "${PATCH_DIR}/patch-rubocop-result.txt" + "${RUBOCOP}" -f e "${i}" | "${AWK}" '!/[0-9]* files? inspected/' >> "${PATCH_DIR}/patch-rubocop-result.txt" fi done - popd >/dev/null + popd >/dev/null || return 1 # shellcheck disable=SC2016 - RUBOCOP_VERSION=$(${RUBOCOP} -v | ${AWK} '{print $NF}') + RUBOCOP_VERSION=$("${RUBOCOP}" -v | "${AWK}" '{print $NF}') add_footer_table rubocop "v${RUBOCOP_VERSION}" calcdiffs \ @@ -133,13 +135,13 @@ function rubocop_postapply "${PATCH_DIR}/patch-rubocop-result.txt" \ rubocop \ > "${PATCH_DIR}/diff-patch-rubocop.txt" - diffPostpatch=$(${AWK} -F: 'BEGIN {sum=0} 4<NF {sum+=1} END {print sum}' "${PATCH_DIR}/diff-patch-rubocop.txt") + diffPostpatch=$("${AWK}" -F: 'BEGIN {sum=0} 4<NF {sum+=1} END {print sum}' "${PATCH_DIR}/diff-patch-rubocop.txt") # shellcheck disable=SC2016 - numPrepatch=$(${AWK} -F: 'BEGIN {sum=0} 4<NF {sum+=1} END {print sum}' "${PATCH_DIR}/branch-rubocop-result.txt") + numPrepatch=$("${AWK}" -F: 'BEGIN {sum=0} 4<NF {sum+=1} END {print sum}' "${PATCH_DIR}/branch-rubocop-result.txt") # shellcheck disable=SC2016 - numPostpatch=$(${AWK} -F: 'BEGIN {sum=0} 4<NF {sum+=1} END {print sum}' "${PATCH_DIR}/patch-rubocop-result.txt") + numPostpatch=$("${AWK}" -F: 'BEGIN {sum=0} 4<NF {sum+=1} END {print sum}' "${PATCH_DIR}/patch-rubocop-result.txt") ((fixedpatch=numPrepatch-numPostpatch+diffPostpatch)) http://git-wip-us.apache.org/repos/asf/yetus/blob/9a2cd581/precommit/src/main/shell/test-patch.d/ruby-lint.sh ---------------------------------------------------------------------- diff --git a/precommit/src/main/shell/test-patch.d/ruby-lint.sh b/precommit/src/main/shell/test-patch.d/ruby-lint.sh index 78be7b6..50c2d7b 100755 --- a/precommit/src/main/shell/test-patch.d/ruby-lint.sh +++ b/precommit/src/main/shell/test-patch.d/ruby-lint.sh @@ -14,11 +14,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +# SHELLDOC-IGNORE + add_test_type ruby_lint RUBY_LINT_TIMER=0 -RUBY_LINT=${RUBY_LINT:-$(which ruby-lint 2>/dev/null)} +RUBY_LINT=${RUBY_LINT:-$(command -v ruby-lint 2>/dev/null)} function ruby_lint_usage { @@ -68,13 +70,13 @@ function ruby_lint_preapply start_clock echo "Running ruby-lint against identified ruby scripts." - pushd "${BASEDIR}" >/dev/null + pushd "${BASEDIR}" >/dev/null || return 1 for i in "${CHANGED_FILES[@]}"; do if [[ ${i} =~ \.rb$ && -f ${i} ]]; then - ${RUBY_LINT} -p syntastic "${i}" | sort -t : -k 1,1 -k 3,3n -k 4,4n >> "${PATCH_DIR}/branch-ruby-lint-result.txt" + "${RUBY_LINT}" -p syntastic "${i}" | sort -t : -k 1,1 -k 3,3n -k 4,4n >> "${PATCH_DIR}/branch-ruby-lint-result.txt" fi done - popd >/dev/null + popd >/dev/null || return 1 # keep track of how much as elapsed for us already RUBY_LINT_TIMER=$(stop_clock) return 0 @@ -100,14 +102,12 @@ function ruby_lint_calcdiffs # accuracy in case of multiple, repeated errors # since the column number shouldn't change # if the line of code hasn't been touched - # shellcheck disable=SC2016 cut -f4- -d: "${orig}" > "${tmp}.branch" - # shellcheck disable=SC2016 cut -f4- -d: "${new}" > "${tmp}.patch" # compare the errors, generating a string of line # numbers. Sorry portability: GNU diff makes this too easy - ${DIFF} --unchanged-line-format="" \ + "${DIFF}" --unchanged-line-format="" \ --old-line-format="" \ --new-line-format="%dn " \ "${tmp}.branch" \ @@ -116,8 +116,7 @@ function ruby_lint_calcdiffs # now, pull out those lines of the raw output # shellcheck disable=SC2013 for j in $(cat "${tmp}.lined"); do - # shellcheck disable=SC2086 - head -${j} "${new}" | tail -1 + head -"${j}" "${new}" | tail -1 done rm "${tmp}.branch" "${tmp}.patch" "${tmp}.lined" 2>/dev/null @@ -146,16 +145,16 @@ function ruby_lint_postapply echo "Running ruby-lint against identified ruby scripts." # we re-check this in case one has been added - pushd "${BASEDIR}" >/dev/null + pushd "${BASEDIR}" >/dev/null || return 1 for i in "${CHANGED_FILES[@]}"; do if [[ ${i} =~ \.rb$ && -f ${i} ]]; then - ${RUBY_LINT} -p syntastic "${i}" | sort -t : -k 1,1 -k 3,3n -k 4,4n >> "${PATCH_DIR}/patch-ruby-lint-result.txt" + "${RUBY_LINT}" -p syntastic "${i}" | sort -t : -k 1,1 -k 3,3n -k 4,4n >> "${PATCH_DIR}/patch-ruby-lint-result.txt" fi done - popd >/dev/null + popd >/dev/null || return 1 # shellcheck disable=SC2016 - RUBY_LINT_VERSION=$(${RUBY_LINT} -v | ${AWK} '{print $2}') + RUBY_LINT_VERSION=$("${RUBY_LINT}" -v | "${AWK}" '{print $2}') add_footer_table ruby-lint "${RUBY_LINT_VERSION}" calcdiffs \ @@ -163,13 +162,13 @@ function ruby_lint_postapply "${PATCH_DIR}/patch-ruby-lint-result.txt" \ ruby_lint \ > "${PATCH_DIR}/diff-patch-ruby-lint.txt" - diffPostpatch=$(${AWK} -F: 'BEGIN {sum=0} 4<NF {sum+=1} END {print sum}' "${PATCH_DIR}/diff-patch-ruby-lint.txt") + diffPostpatch=$("${AWK}" -F: 'BEGIN {sum=0} 4<NF {sum+=1} END {print sum}' "${PATCH_DIR}/diff-patch-ruby-lint.txt") # shellcheck disable=SC2016 - numPrepatch=$(${AWK} -F: 'BEGIN {sum=0} 4<NF {sum+=1} END {print sum}' "${PATCH_DIR}/branch-ruby-lint-result.txt") + numPrepatch=$("${AWK}" -F: 'BEGIN {sum=0} 4<NF {sum+=1} END {print sum}' "${PATCH_DIR}/branch-ruby-lint-result.txt") # shellcheck disable=SC2016 - numPostpatch=$(${AWK} -F: 'BEGIN {sum=0} 4<NF {sum+=1} END {print sum}' "${PATCH_DIR}/patch-ruby-lint-result.txt") + numPostpatch=$("${AWK}" -F: 'BEGIN {sum=0} 4<NF {sum+=1} END {print sum}' "${PATCH_DIR}/patch-ruby-lint-result.txt") ((fixedpatch=numPrepatch-numPostpatch+diffPostpatch))
