Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions dev-support/test-patch.d/checkstyle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/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_plugin checkstyle

CHECKSTYLE_TIMER=0

function checkstyle_preapply
{

big_console_header "checkstyle plugin: prepatch"

start_clock
echo "${MVN} test checkstyle:checkstyle-aggregate -DskipTests -D${PROJECT_NAME}PatchProcess > ${PATCH_DIR}/${PATCH_BRANCH}checkstyle.txt 2>&1"
${MVN} test checkstyle:checkstyle-aggregate -DskipTests "-D${PROJECT_NAME}PatchProcess" > "${PATCH_DIR}/${PATCH_BRANCH}checkstyle.txt" 2>&1
if [[ $? != 0 ]] ; then
echo "Pre-patch ${PATCH_BRANCH} checkstyle compilation is broken?"
add_jira_table -1 checkstyle "Pre-patch ${PATCH_BRANCH} checkstyle compilation may be broken."
return 1
fi

# shellcheck disable=SC2016
CHECKSTYLE_PREPATCH=$(wc -l target/checkstyle-result.xml | ${AWK} '{print $1}')

# keep track of how much as elapsed for us already
CHECKSTYLE_TIMER=$(stop_clock)
return 0
}

function checkstyle_postapply
{

big_console_header "checkstyle plugin: postpatch"

start_clock

# add our previous elapsed to our new timer
# by setting the clock back
offset_clock "${CHECKSTYLE_TIMER}"

echo "${MVN} test checkstyle:checkstyle-aggregate -DskipTests -D${PROJECT_NAME}PatchProcess > ${PATCH_DIR}/patchcheckstyle.txt 2>&1"
${MVN} test checkstyle:checkstyle-aggregate -DskipTests "-D${PROJECT_NAME}PatchProcess" > "${PATCH_DIR}/patchcheckstyle.txt" 2>&1
if [[ $? != 0 ]] ; then
echo "Post-patch checkstyle compilation is broken."
add_jira_table -1 checkstyle "Post-patch checkstyle compilation is broken."
return 1
fi

# shellcheck disable=SC2016
CHECKSTYLE_POSTPATCH=$(wc -l target/checkstyle-result.xml | ${AWK} '{print $1}')

if [[ ${CHECKSTYLE_POSTPATCH} != "" && ${CHECKSTYLE_PREPATCH} != "" ]] ; then
if [[ ${CHECKSTYLE_POSTPATCH} -gt ${CHECKSTYLE_PREPATCH} ]] ; then

cp -pr ${BASEDIR}/target/checkstyle-result.xml "${PATCH_DIR}"

add_jira_table -1 checkstyle "The applied patch generated "\
"$((CHECKSTYLE_POSTPATCH-CHECKSTYLE_PREPATCH))" \
" additional checkstyle issues."
add_jira_footer checkstyle "@@BASE@@/checkstyle.xml"
return 1
fi
fi
add_jira_table +1 checkstyle "There were no new checkstyle issues."
return 0
}
100 changes: 100 additions & 0 deletions dev-support/test-patch.d/shellcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#!/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_plugin shellcheck

SHELLCHECK_TIMER=0

SHELLCHECK=${SHELLCHECK:-$(which shellcheck)}

function shellcheck_private_findbash
{
local i

while read line; do
find "${line}" ! -name '*.cmd' -type f
done < <(find . -d -name bin -o -name sbin)
}

function shellcheck_preapply
{
local i

big_console_header "shellcheck plugin: prepatch"

if [[ -z "${SHELLCHECK}" ]]; then
hadoop_error "shellcheck is not available."
fi

start_clock

echo "Running shellcheck against all identifiable shell scripts"
for i in $(shellcheck_private_findbash | sort); do
${SHELLCHECK} -f gcc "${i}" >> "${PATCH_DIR}/${PATCH_BRANCH}shellcheck-result.txt"
done

# keep track of how much as elapsed for us already
SHELLCHECK_TIMER=$(stop_clock)
return 0
}

function shellcheck_postapply
{
local i

big_console_header "shellcheck plugin: postpatch"

if [[ -z "${SHELLCHECK}" ]]; then
hadoop_error "shellcheck is not available."
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 | sort); do
${SHELLCHECK} -f gcc "${i}" >> "${PATCH_DIR}/patchshellcheck-result.txt"
done

# shellcheck disable=SC2016
numPrepatch=$(wc -l "${PATCH_DIR}/${PATCH_BRANCH}shellcheck-result.txt" | ${AWK} '{print $1}')
# shellcheck disable=SC2016
numPostpatch=$(wc -l "${PATCH_DIR}/patchshellcheck-result.txt" | ${AWK} '{print $1}')

if [[ ${numPostpatch} != "" && ${numPrepatch} != "" ]] ; then
if [[ ${numPostpatch} -gt ${numPrepatch} ]] ; then

${DIFF} -u "${PATCH_DIR}/${PATCH_BRANCH}shellcheck-result.txt" \
"${PATCH_DIR}/patchshellcheck-result.txt" \
> "${PATCH_DIR}/diffpatchshellcheck.txt"

rm -f "${PATCH_DIR}/${PATCH_BRANCH}shellcheck-result.txt" \
"${PATCH_DIR}/patchshellcheck-result.txt" 2>/dev/null

add_jira_table -1 shellcheck "The applied patch generated "\
"$((numPostpatch-numPrepatch))" \
" additional shellcheck issues."
add_jira_footer shellcheck "@@BASE@@/diffpatchshellcheck.txt"
return 1
fi
fi
add_jira_table +1 shellcheck "There were no new shellcheck issues."
return 0
}
Loading