http://git-wip-us.apache.org/repos/asf/yetus/blob/6f38afa5/precommit/test-patch.d/rubocop.sh ---------------------------------------------------------------------- diff --git a/precommit/test-patch.d/rubocop.sh b/precommit/test-patch.d/rubocop.sh new file mode 100755 index 0000000..c0fa2ac --- /dev/null +++ b/precommit/test-patch.d/rubocop.sh @@ -0,0 +1,151 @@ +#!/usr/bin/env bash +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +add_test_type rubocop + +RUBOCOP_TIMER=0 + +RUBOCOP=${RUBOCOP:-$(which rubocop 2>/dev/null)} + +function rubocop_usage +{ + echo "Rubocop specific:" + echo "--rubocop=<path> path to rubocop executable" +} + +function rubocop_parse_args +{ + local i + + for i in "$@"; do + case ${i} in + --rubocop=*) + RUBOCOP=${i#*=} + ;; + esac + done +} + +function rubocop_filefilter +{ + local filename=$1 + + if [[ ${filename} =~ \.rb$ ]]; then + add_test rubocop + fi +} + +function rubocop_preapply +{ + local i + + verify_needed_test rubocop + if [[ $? == 0 ]]; then + return 0 + fi + + big_console_header "rubocop plugin: prepatch" + + if [[ ! -x ${RUBOCOP} ]]; then + yetus_error "${RUBOCOP} does not exist." + return 0 + fi + + start_clock + + echo "Running rubocop against modified ruby scripts." + pushd "${BASEDIR}" >/dev/null + 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" + fi + done + popd >/dev/null + # keep track of how much as elapsed for us already + RUBOCOP_TIMER=$(stop_clock) + return 0 +} + +function rubocop_postapply +{ + local i + local numPrepatch + local numPostpatch + local diffPostpatch + + verify_needed_test rubocop + if [[ $? == 0 ]]; then + return 0 + fi + + big_console_header "rubocop plugin: postpatch" + + if [[ ! -x ${RUBOCOP} ]]; then + yetus_error "${RUBOCOP} is not available." + add_vote_table 0 rubocop "Rubocop was not available." + return 0 + fi + + start_clock + + # add our previous elapsed to our new timer + # by setting the clock back + offset_clock "${RUBOCOP_TIMER}" + + echo "Running rubocop against modified ruby scripts." + # we re-check this in case one has been added + pushd "${BASEDIR}" >/dev/null + 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" + fi + done + popd >/dev/null + + # shellcheck disable=SC2016 + RUBOCOP_VERSION=$(${RUBOCOP} -v | ${AWK} '{print $NF}') + add_footer_table rubocop "v${RUBOCOP_VERSION}" + + calcdiffs "${PATCH_DIR}/branch-rubocop-result.txt" "${PATCH_DIR}/patch-rubocop-result.txt" > "${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") + + if [[ ${diffPostpatch} -gt 0 ]] ; then + # shellcheck disable=SC2016 + 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") + + add_vote_table -1 rubocop "The applied patch generated "\ + "${diffPostpatch} new rubocop issues (total was ${numPrepatch}, now ${numPostpatch})." + add_footer_table rubocop "@@BASE@@/diff-patch-rubocop.txt" + return 1 + fi + + add_vote_table +1 rubocop "There were no new rubocop issues." + return 0 +} + +function rubocop_postcompile +{ + declare repostatus=$1 + + if [[ "${repostatus}" = branch ]]; then + rubocop_preapply + else + rubocop_postapply + fi +}
http://git-wip-us.apache.org/repos/asf/yetus/blob/6f38afa5/precommit/test-patch.d/ruby-lint.sh ---------------------------------------------------------------------- diff --git a/precommit/test-patch.d/ruby-lint.sh b/precommit/test-patch.d/ruby-lint.sh new file mode 100755 index 0000000..aa18f58 --- /dev/null +++ b/precommit/test-patch.d/ruby-lint.sh @@ -0,0 +1,151 @@ +#!/usr/bin/env bash +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +add_test_type ruby_lint + +RUBY_LINT_TIMER=0 + +RUBY_LINT=${RUBY_LINT:-$(which ruby-lint 2>/dev/null)} + +function ruby_lint_usage +{ + echo "Ruby-lint specific:" + echo "--ruby-lint=<path> path to ruby-lint executable" +} + +function ruby_lint_parse_args +{ + local i + + for i in "$@"; do + case ${i} in + --ruby-lint=*) + RUBY_LINT=${i#*=} + ;; + esac + done +} + +function ruby_lint_filefilter +{ + local filename=$1 + + if [[ ${filename} =~ \.rb$ ]]; then + add_test ruby_lint + fi +} + +function ruby_lint_preapply +{ + local i + + verify_needed_test ruby_lint + if [[ $? == 0 ]]; then + return 0 + fi + + big_console_header "ruby-lint plugin: prepatch" + + if [[ ! -x ${RUBY_LINT} ]]; then + yetus_error "${RUBY_LINT} does not exist." + return 0 + fi + + start_clock + + echo "Running ruby-lint against modified ruby scripts." + pushd "${BASEDIR}" >/dev/null + 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" + fi + done + popd >/dev/null + # keep track of how much as elapsed for us already + RUBY_LINT_TIMER=$(stop_clock) + return 0 +} + +function ruby_lint_postapply +{ + local i + local numPrepatch + local numPostpatch + local diffPostpatch + + verify_needed_test ruby_lint + if [[ $? == 0 ]]; then + return 0 + fi + + big_console_header "ruby-lint plugin: postpatch" + + if [[ ! -x ${RUBY_LINT} ]]; then + yetus_error "${RUBY_LINT} is not available." + add_vote_table 0 ruby-lint "Ruby-lint was not available." + return 0 + fi + + start_clock + + # add our previous elapsed to our new timer + # by setting the clock back + offset_clock "${RUBY_LINT_TIMER}" + + echo "Running ruby-lint against modified ruby scripts." + # we re-check this in case one has been added + pushd "${BASEDIR}" >/dev/null + 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" + fi + done + popd >/dev/null + + # shellcheck disable=SC2016 + RUBY_LINT_VERSION=$(${RUBY_LINT} -v | ${AWK} '{print $2}') + add_footer_table ruby-lint "${RUBY_LINT_VERSION}" + + calcdiffs "${PATCH_DIR}/branch-ruby-lint-result.txt" "${PATCH_DIR}/patch-ruby-lint-result.txt" > "${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") + + if [[ ${diffPostpatch} -gt 0 ]] ; then + # shellcheck disable=SC2016 + 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") + + add_vote_table -1 ruby-lint "The applied patch generated "\ + "${diffPostpatch} new ruby-lint issues (total was ${numPrepatch}, now ${numPostpatch})." + add_footer_table ruby-lint "@@BASE@@/diff-patch-ruby-lint.txt" + return 1 + fi + + add_vote_table +1 ruby-lint "There were no new ruby-lint issues." + return 0 +} + +function ruby_lint_postcompile +{ + declare repostatus=$1 + + if [[ "${repostatus}" = branch ]]; then + ruby_lint_preapply + else + ruby_lint_postapply + fi +} http://git-wip-us.apache.org/repos/asf/yetus/blob/6f38afa5/precommit/test-patch.d/scala.sh ---------------------------------------------------------------------- diff --git a/precommit/test-patch.d/scala.sh b/precommit/test-patch.d/scala.sh new file mode 100755 index 0000000..06aa86f --- /dev/null +++ b/precommit/test-patch.d/scala.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +add_test_type scalac +add_test_type scaladoc + +function scalac_filefilter +{ + declare filename=$1 + + if [[ ${filename} =~ \.scala$ ]]; then + yetus_debug "tests/scalac: ${filename}" + add_test scalac + add_test compile + fi +} + +function scaladoc_filefilter +{ + local filename=$1 + + if [[ ${filename} =~ \.scala$ ]]; then + yetus_debug "tests/scaladoc: ${filename}" + add_test scaladoc + fi +} + +## @description +## @audience private +## @stability stable +## @replaceable no +## @return 0 on success +## @return 1 on failure +function scalac_compile +{ + declare codebase=$1 + declare multijdkmode=$2 + + verify_needed_test scalac + if [[ $? = 0 ]]; then + return 0 + fi + + if [[ ${codebase} = patch ]]; then + generic_postlog_compare compile scalac "${multijdkmode}" + fi +} + +## @description Count and compare the number of ScalaDoc warnings pre- and post- patch +## @audience private +## @stability evolving +## @replaceable no +## @return 0 on success +## @return 1 on failure +function scaladoc_rebuild +{ + declare codebase=$1 + + if [[ "${codebase}" = branch ]]; then + generic_pre_handler scaladoc false + else + generic_post_handler scaladoc scaladoc false true + fi +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/yetus/blob/6f38afa5/precommit/test-patch.d/shellcheck.sh ---------------------------------------------------------------------- diff --git a/precommit/test-patch.d/shellcheck.sh b/precommit/test-patch.d/shellcheck.sh new file mode 100755 index 0000000..d50d212 --- /dev/null +++ b/precommit/test-patch.d/shellcheck.sh @@ -0,0 +1,176 @@ +#!/usr/bin/env bash +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +add_test_type shellcheck + +SHELLCHECK_TIMER=0 + +SHELLCHECK=${SHELLCHECK:-$(which shellcheck 2>/dev/null)} + +SHELLCHECK_SPECIFICFILES="" + +# if it ends in an explicit .sh, then this is shell code. +# if it doesn't have an extension, we assume it is shell code too +function shellcheck_filefilter +{ + local filename=$1 + + if [[ ${filename} =~ \.sh$ ]]; then + add_test shellcheck + SHELLCHECK_SPECIFICFILES="${SHELLCHECK_SPECIFICFILES} ./${filename}" + fi + + if [[ ! ${filename} =~ \. ]]; then + add_test shellcheck + fi +} + +function shellcheck_private_findbash +{ + local i + local value + local list + + while read line; do + value=$(find "${line}" ! -name '*.cmd' -type f \ + | ${GREP} -E -v '(.orig$|.rej$)') + + for i in ${value}; do + if [[ ! ${i} =~ \.sh(\.|$) + && ! $(head -n 1 "${i}") =~ ^#! ]]; then + yetus_debug "Shellcheck skipped: ${i}" + continue + fi + list="${list} ${i}" + done + done < <(find . -type d -name bin -o -type d -name sbin -o -type d -name scripts -o -type d -name libexec -o -type d -name shellprofile.d) + # shellcheck disable=SC2086 + echo ${list} ${SHELLCHECK_SPECIFICFILES} | tr ' ' '\n' | sort -u +} + +function shellcheck_preapply +{ + local i + + verify_needed_test shellcheck + if [[ $? == 0 ]]; then + return 0 + fi + + big_console_header "shellcheck plugin: prepatch" + + if [[ ! -x "${SHELLCHECK}" ]]; then + yetus_error "shellcheck is not available." + return 0 + fi + + start_clock + + echo "Running shellcheck against all identifiable shell scripts" + pushd "${BASEDIR}" >/dev/null + for i in $(shellcheck_private_findbash); do + if [[ -f ${i} ]]; then + ${SHELLCHECK} -f gcc "${i}" >> "${PATCH_DIR}/branch-shellcheck-result.txt" + fi + done + popd > /dev/null + # keep track of how much as elapsed for us already + SHELLCHECK_TIMER=$(stop_clock) + return 0 +} + +function shellcheck_postapply +{ + local i + local msg + local numPrepatch + local numPostpatch + local diffPostpatch + + verify_needed_test shellcheck + if [[ $? == 0 ]]; then + return 0 + fi + + big_console_header "shellcheck plugin: postpatch" + + if [[ ! -x "${SHELLCHECK}" ]]; then + yetus_error "shellcheck is not available." + add_vote_table 0 shellcheck "Shellcheck was not available." + return 0 + fi + + start_clock + + # add our previous elapsed to our new timer + # by setting the clock back + offset_clock "${SHELLCHECK_TIMER}" + + echo "Running shellcheck against all identifiable shell scripts" + # we re-check this in case one has been added + for i in $(shellcheck_private_findbash); do + if [[ -f ${i} ]]; then + ${SHELLCHECK} -f gcc "${i}" >> "${PATCH_DIR}/patch-shellcheck-result.txt" + fi + done + + if [[ ! -f "${PATCH_DIR}/branch-shellcheck-result.txt" ]]; then + touch "${PATCH_DIR}/branch-shellcheck-result.txt" + fi + + # shellcheck disable=SC2016 + SHELLCHECK_VERSION=$(${SHELLCHECK} --version | ${GREP} version: | ${AWK} '{print $NF}') + msg="v${SHELLCHECK_VERSION}" + if [[ ${SHELLCHECK_VERSION} =~ 0.[0-3].[0-5] ]]; then + msg="${msg} (This is an old version that has serious bugs. Consider upgrading.)" + fi + add_footer_table shellcheck "${msg}" + + calcdiffs \ + "${PATCH_DIR}/branch-shellcheck-result.txt" \ + "${PATCH_DIR}/patch-shellcheck-result.txt" \ + > "${PATCH_DIR}/diff-patch-shellcheck.txt" + # shellcheck disable=SC2016 + diffPostpatch=$(wc -l "${PATCH_DIR}/diff-patch-shellcheck.txt" | ${AWK} '{print $1}') + + if [[ ${diffPostpatch} -gt 0 ]] ; then + # shellcheck disable=SC2016 + numPrepatch=$(wc -l "${PATCH_DIR}/branch-shellcheck-result.txt" | ${AWK} '{print $1}') + + # shellcheck disable=SC2016 + numPostpatch=$(wc -l "${PATCH_DIR}/patch-shellcheck-result.txt" | ${AWK} '{print $1}') + + add_vote_table -1 shellcheck "The applied patch generated "\ + "${diffPostpatch} new shellcheck issues (total was ${numPrepatch}, now ${numPostpatch})." + add_footer_table shellcheck "@@BASE@@/diff-patch-shellcheck.txt" + bugsystem_linecomments "shellcheck" "${PATCH_DIR}/diff-patch-shellcheck.txt" + return 1 + fi + + add_vote_table +1 shellcheck "There were no new shellcheck issues." + return 0 +} + +function shellcheck_postcompile +{ + declare repostatus=$1 + + if [[ "${repostatus}" = branch ]]; then + shellcheck_preapply + else + shellcheck_postapply + fi +} http://git-wip-us.apache.org/repos/asf/yetus/blob/6f38afa5/precommit/test-patch.d/tap.sh ---------------------------------------------------------------------- diff --git a/precommit/test-patch.d/tap.sh b/precommit/test-patch.d/tap.sh new file mode 100755 index 0000000..7ced908 --- /dev/null +++ b/precommit/test-patch.d/tap.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +add_test_format tap + +TAP_FAILED_TESTS="" +TAP_LOG_DIR="target/tap" + +function tap_process_args +{ + declare i + + for i in "$@"; do + case ${i} in + --tap-log-dir=*) + TAP_LOG_DIR=${i#=*} + ;; + esac + done +} + +function tap_usage +{ + echo "TAP Options:" + echo "--tap-log-dir=<dir> Directory relative to the module for tap output (default: \"target/tap\")" +} + +function tap_process_tests +{ + # shellcheck disable=SC2034 + declare module=$1 + # shellcheck disable=SC2034 + declare buildlogfile=$2 + declare filefrag=$3 + declare result=0 + declare module_failed_tests + declare filenames + + filenames=$(find "${TAP_LOG_DIR}" -type f -exec "${GREP}" -l -E "^not ok" {} \;) + + if [[ -n "${filenames}" ]]; then + module_failed_tests=$(echo "${filenames}" \ + | ${SED} -e "s,${TAP_LOG_DIR},,g" -e s,^/,,g ) + # shellcheck disable=SC2086 + cat ${filenames} >> "${PATCH_DIR}/patch-${filefrag}.tap" + TAP_LOGS="${TAP_LOGS} @@BASE@@/patch-${filefrag}.tap" + TAP_FAILED_TESTS="${TAP_FAILED_TESTS} ${module_failed_tests}" + ((result=result+1)) + fi + + if [[ ${result} -gt 0 ]]; then + return 1 + fi + return 0 +} + +function tap_finalize_results +{ + declare jdk=$1 + + if [[ -n "${TAP_FAILED_TESTS}" ]] ; then + # shellcheck disable=SC2086 + populate_test_table "${jdk}Failed TAP tests" ${TAP_FAILED_TESTS} + TAP_FAILED_TESTS="" + add_footer_table "TAP logs" "${TAP_LOGS}" + fi +} http://git-wip-us.apache.org/repos/asf/yetus/blob/6f38afa5/precommit/test-patch.d/test4tests.sh ---------------------------------------------------------------------- diff --git a/precommit/test-patch.d/test4tests.sh b/precommit/test-patch.d/test4tests.sh new file mode 100755 index 0000000..94b9b7f --- /dev/null +++ b/precommit/test-patch.d/test4tests.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +add_test_type test4tests + +## @description Check the patch file for changed/new tests +## @audience private +## @stability evolving +## @replaceable no +## @return 0 on success +## @return 1 on failure +function test4tests_patchfile +{ + declare testReferences=0 + declare i + + big_console_header "Checking there are new or changed tests in the patch." + + verify_needed_test unit + + if [[ $? == 0 ]]; then + echo "Patch does not appear to need new or modified tests." + return 0 + fi + + start_clock + + for i in ${CHANGED_FILES}; do + if [[ ${i} =~ (^|/)test/ ]]; then + ((testReferences=testReferences + 1)) + fi + done + + echo "There appear to be ${testReferences} test file(s) referenced in the patch." + if [[ ${testReferences} == 0 ]] ; then + add_vote_table -1 "test4tests" \ + "The patch doesn't appear to include any new or modified tests. " \ + "Please justify why no new tests are needed for this patch." \ + "Also please list what manual steps were performed to verify this patch." + return 1 + fi + add_vote_table +1 "test4tests" \ + "The patch appears to include ${testReferences} new or modified test files." + return 0 +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/yetus/blob/6f38afa5/precommit/test-patch.d/whitespace.sh ---------------------------------------------------------------------- diff --git a/precommit/test-patch.d/whitespace.sh b/precommit/test-patch.d/whitespace.sh new file mode 100755 index 0000000..32c5f42 --- /dev/null +++ b/precommit/test-patch.d/whitespace.sh @@ -0,0 +1,92 @@ +#!/usr/bin/env bash +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +add_test_type whitespace + +function whitespace_linecomment_reporter +{ + declare file=$1 + shift + declare comment=$* + declare tmpfile="${PATCH_DIR}/wlr.$$.${RANDOM}" + + while read -r line; do + { + # shellcheck disable=SC2086 + printf "%s" "$(echo ${line} | cut -f1-2 -d:)" + echo "${comment}" + } >> "${tmpfile}" + done < "${file}" + + bugsystem_linecomments "whitespace:" "${tmpfile}" + rm "${tmpfile}" +} + +function whitespace_postcompile +{ + declare repostatus=$1 + declare count + declare result=0 + + if [[ "${repostatus}" = branch ]]; then + return 0 + fi + + big_console_header "Checking for whitespace at the end of lines" + start_clock + + pushd "${BASEDIR}" >/dev/null + # shellcheck disable=SC2016 + ${AWK} '/\t/ {print $0}' \ + "${GITDIFFCONTENT}" \ + | ${GREP} -v Makefile: >> "${PATCH_DIR}/whitespace-tabs.txt" + + ${GREP} -E '[[:blank:]]$' \ + "${GITDIFFCONTENT}" \ + >> "${PATCH_DIR}/whitespace-eol.txt" + + # shellcheck disable=SC2016 + count=$(wc -l "${PATCH_DIR}/whitespace-eol.txt" | ${AWK} '{print $1}') + + if [[ ${count} -gt 0 ]]; then + add_vote_table -1 whitespace "The patch has ${count}"\ + " line(s) that end in whitespace. Use git apply --whitespace=fix." + + whitespace_linecomment_reporter "${PATCH_DIR}/whitespace-eol.txt" "end of line" + add_footer_table whitespace "@@BASE@@/whitespace-eol.txt" + ((result=result+1)) + fi + + # shellcheck disable=SC2016 + count=$(wc -l "${PATCH_DIR}/whitespace-tabs.txt" | ${AWK} '{print $1}') + + if [[ ${count} -gt 0 ]]; then + add_vote_table -1 whitespace "The patch has ${count}"\ + " line(s) with tabs." + add_footer_table whitespace "@@BASE@@/whitespace-tabs.txt" + whitespace_linecomment_reporter "${PATCH_DIR}/whitespace-tabs.txt" "tabs in line" + ((result=result+1)) + fi + + if [[ ${result} -gt 0 ]]; then + popd >/dev/null + return 1 + fi + + popd >/dev/null + add_vote_table +1 whitespace "Patch has no whitespace issues." + return 0 +} http://git-wip-us.apache.org/repos/asf/yetus/blob/6f38afa5/precommit/test-patch.d/xml.sh ---------------------------------------------------------------------- diff --git a/precommit/test-patch.d/xml.sh b/precommit/test-patch.d/xml.sh new file mode 100755 index 0000000..b04a2f3 --- /dev/null +++ b/precommit/test-patch.d/xml.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +add_test_type xml + +function xml_filefilter +{ + declare filename=$1 + + if [[ ${filename} =~ \.xml$ ]]; then + add_test xml + fi +} + +function xml_postcompile +{ + declare repostatus=$1 + declare js + declare i + declare count + + verify_needed_test xml + if [[ $? == 0 ]]; then + return 0 + fi + + if [[ "${repostatus}" = branch ]]; then + return 0 + fi + + big_console_header "Checking if XML files are well-formed" + + js="${JAVA_HOME}/bin/jrunscript" + if [[ ! -x ${js} ]]; then + yetus_error "${js} does not exist" + return 0 + fi + + start_clock + + pushd "${BASEDIR}" >/dev/null + for i in ${CHANGED_FILES}; do + if [[ ${i} =~ \.xml$ && -f ${i} ]]; then + ${js} -e "XMLDocument(arguments[0])" "${i}" >> "${PATCH_DIR}/xml.txt" 2>&1 + if [[ $? != 0 ]]; then + ((count=count+1)) + fi + fi + done + + if [[ ${count} -gt 0 ]]; then + add_vote_table -1 xml "The patch has ${count} ill-formed XML file(s)." + add_footer_table xml "@@BASE@@/xml.txt" + popd >/dev/null + return 1 + fi + + popd >/dev/null + add_vote_table +1 xml "The patch has no ill-formed XML file." + return 0 +}
