2011-10-24 16:07:11 -04:00
#!/usr/bin/env bash
# Licensed 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.
#set -x
### Setup some variables.
2014-11-18 10:55:41 -05:00
### GIT_COMMIT and BUILD_URL are set by Hudson if it is run by patch process
2011-10-24 16:07:11 -04:00
### Read variables from properties file
bindir = $( dirname $0 )
# Defaults
if [ -z " $MAVEN_HOME " ] ; then
2014-03-21 16:59:34 -04:00
MVN = mvn
2011-10-24 16:07:11 -04:00
else
2014-03-21 16:59:34 -04:00
MVN = $MAVEN_HOME /bin/mvn
2011-10-24 16:07:11 -04:00
fi
2014-11-18 10:55:41 -05:00
NEWLINE = $'\n'
2012-02-10 18:53:08 -05:00
PROJECT_NAME = HBase
2011-10-24 16:07:11 -04:00
JENKINS = false
PATCH_DIR = /tmp
BASEDIR = $( pwd )
PS = ${ PS :- ps }
AWK = ${ AWK :- awk }
WGET = ${ WGET :- wget }
GREP = ${ GREP :- grep }
2013-12-18 13:25:51 -05:00
EGREP = ${ EGREP :- egrep }
2011-10-24 16:07:11 -04:00
PATCH = ${ PATCH :- patch }
JIRACLI = ${ JIRA :- jira }
FINDBUGS_HOME = ${ FINDBUGS_HOME }
FORREST_HOME = ${ FORREST_HOME }
ECLIPSE_HOME = ${ ECLIPSE_HOME }
2014-11-18 10:55:41 -05:00
GIT = ${ GIT :- git }
2011-10-24 16:07:11 -04:00
###############################################################################
printUsage( ) {
echo " Usage: $0 [options] patch-file | defect-number "
echo
echo "Where:"
echo " patch-file is a local patch file containing the changes to test"
echo " defect-number is a JIRA defect number (e.g. 'HADOOP-1234') to test (Jenkins only)"
echo
echo "Options:"
echo "--patch-dir=<dir> The directory for working and output files (default '/tmp')"
echo "--basedir=<dir> The directory to apply the patch to (default current directory)"
echo "--mvn-cmd=<cmd> The 'mvn' command to use (default \$MAVEN_HOME/bin/mvn, or 'mvn')"
echo "--ps-cmd=<cmd> The 'ps' command to use (default 'ps')"
echo "--awk-cmd=<cmd> The 'awk' command to use (default 'awk')"
echo "--grep-cmd=<cmd> The 'grep' command to use (default 'grep')"
echo "--patch-cmd=<cmd> The 'patch' command to use (default 'patch')"
echo "--findbugs-home=<path> Findbugs home directory (default FINDBUGS_HOME environment variable)"
echo "--forrest-home=<path> Forrest home directory (default FORREST_HOME environment variable)"
2014-11-18 10:55:41 -05:00
echo "--dirty-workspace Allow the local workspace to have uncommitted changes"
echo "--git-cmd=<cmd> The 'git' command to use (default 'git')"
2011-10-24 16:07:11 -04:00
echo
echo "Jenkins-only options:"
echo "--jenkins Run by Jenkins (runs tests and posts results to JIRA)"
echo "--wget-cmd=<cmd> The 'wget' command to use (default 'wget')"
echo "--jira-cmd=<cmd> The 'jira' command to use (default 'jira')"
echo "--jira-password=<pw> The password for the 'jira' command"
echo "--eclipse-home=<path> Eclipse home directory (default ECLIPSE_HOME environment variable)"
}
###############################################################################
parseArgs( ) {
for i in $*
do
case $i in
--jenkins)
JENKINS = true
; ;
--patch-dir= *)
PATCH_DIR = ${ i #*= }
; ;
--basedir= *)
BASEDIR = ${ i #*= }
; ;
--mvn-cmd= *)
MVN = ${ i #*= }
; ;
--ps-cmd= *)
PS = ${ i #*= }
; ;
--awk-cmd= *)
AWK = ${ i #*= }
; ;
--wget-cmd= *)
WGET = ${ i #*= }
; ;
--grep-cmd= *)
GREP = ${ i #*= }
; ;
--patch-cmd= *)
PATCH = ${ i #*= }
; ;
--jira-cmd= *)
JIRACLI = ${ i #*= }
; ;
--jira-password= *)
JIRA_PASSWD = ${ i #*= }
; ;
--findbugs-home= *)
FINDBUGS_HOME = ${ i #*= }
; ;
--forrest-home= *)
FORREST_HOME = ${ i #*= }
; ;
--eclipse-home= *)
ECLIPSE_HOME = ${ i #*= }
; ;
--dirty-workspace)
DIRTY_WORKSPACE = true
; ;
2014-11-18 10:55:41 -05:00
--git-cmd= *)
GIT = ${ i #*= }
; ;
2011-10-24 16:07:11 -04:00
*)
PATCH_OR_DEFECT = $i
; ;
esac
done
if [ -z " $PATCH_OR_DEFECT " ] ; then
printUsage
exit 1
fi
if [ [ $JENKINS = = "true" ] ] ; then
echo "Running in Jenkins mode"
defect = $PATCH_OR_DEFECT
ECLIPSE_PROPERTY = " -Declipse.home= $ECLIPSE_HOME "
else
echo "Running in developer mode"
JENKINS = false
### PATCH_FILE contains the location of the patchfile
PATCH_FILE = $PATCH_OR_DEFECT
if [ [ ! -e " $PATCH_FILE " ] ] ; then
echo " Unable to locate the patch file $PATCH_FILE "
cleanupAndExit 0
fi
### Check if $PATCH_DIR exists. If it does not exist, create a new directory
if [ [ ! -e " $PATCH_DIR " ] ] ; then
mkdir " $PATCH_DIR "
if [ [ $? = = 0 ] ] ; then
echo " $PATCH_DIR has been created "
else
echo " Unable to create $PATCH_DIR "
cleanupAndExit 0
fi
fi
### Obtain the patch filename to append it to the version number
defect = ` basename $PATCH_FILE `
fi
}
###############################################################################
checkout ( ) {
echo ""
echo ""
echo "======================================================================"
echo "======================================================================"
echo " Testing patch for ${ defect } . "
echo "======================================================================"
echo "======================================================================"
echo ""
echo ""
### When run by a developer, if the workspace contains modifications, do not continue
### unless the --dirty-workspace option was set
if [ [ $JENKINS = = "false" ] ] ; then
2014-11-18 10:55:41 -05:00
if [ [ -z $DIRTY_WORKSPACE ] ] ; then
# Ref http://stackoverflow.com/a/2659808 for details on checking dirty status
${ GIT } diff-index --quiet HEAD
if [ [ $? -ne 0 ] ] ; then
uncommitted = ` ${ GIT } diff --name-only HEAD`
uncommitted = " You have the following files with uncommitted changes: ${ NEWLINE } ${ uncommitted } "
fi
untracked = " $( ${ GIT } ls-files --exclude-standard --others) " && test -z " ${ untracked } "
if [ [ $? -ne 0 ] ] ; then
untracked = " You have untracked and unignored files: ${ NEWLINE } ${ untracked } "
fi
if [ [ $uncommitted || $untracked ] ] ; then
echo "ERROR: can't run in a workspace that contains modifications."
echo "Pass the '--dirty-workspace' flag to bypass."
echo ""
echo " ${ uncommitted } "
echo ""
echo " ${ untracked } "
cleanupAndExit 1
fi
2011-10-24 16:07:11 -04:00
fi
echo
fi
return $?
}
###############################################################################
setup ( ) {
### Download latest patch file (ignoring .htm and .html) when run from patch process
if [ [ $JENKINS = = "true" ] ] ; then
$WGET -q -O $PATCH_DIR /jira http://issues.apache.org/jira/browse/$defect
if [ [ ` $GREP -c 'Patch Available' $PATCH_DIR /jira` = = 0 ] ] ; then
echo " $defect is not \"Patch Available\". Exiting. "
cleanupAndExit 0
fi
2013-12-18 13:25:51 -05:00
relativePatchURL = ` $GREP -o '"/jira/secure/attachment/[0-9]*/[^"]*' $PATCH_DIR /jira | $EGREP '(\.txt$|\.patch$|\.diff$)' | sort | tail -1 | $GREP -o '/jira/secure/attachment/[0-9]*/[^"]*' `
2011-10-24 16:07:11 -04:00
patchURL = " http://issues.apache.org ${ relativePatchURL } "
patchNum = ` echo $patchURL | $GREP -o '[0-9]*/' | $GREP -o '[0-9]*' `
2013-12-18 13:25:51 -05:00
# ensure attachment has not already been tested
ATTACHMENT_ID = $( basename $( dirname $patchURL ) )
if grep -q " ATTACHMENT ID: $ATTACHMENT_ID " $PATCH_DIR /jira
then
echo " Attachment $ATTACHMENT_ID is already tested for $defect "
exit 1
fi
2011-10-24 16:07:11 -04:00
echo " $defect patch is being downloaded at `date` from "
echo " $patchURL "
$WGET -q -O $PATCH_DIR /patch $patchURL
2014-11-18 10:55:41 -05:00
VERSION = ${ GIT_COMMIT } _${ defect } _PATCH-${ patchNum }
2011-10-24 16:07:11 -04:00
JIRA_COMMENT = " Here are the results of testing the latest attachment
$patchURL
2014-11-18 10:55:41 -05:00
against master branch at commit ${ GIT_COMMIT } .
2013-12-18 13:25:51 -05:00
ATTACHMENT ID: ${ ATTACHMENT_ID } "
2011-10-24 16:07:11 -04:00
### Copy the patch file to $PATCH_DIR
else
VERSION = PATCH-${ defect }
cp $PATCH_FILE $PATCH_DIR /patch
if [ [ $? = = 0 ] ] ; then
echo " Patch file $PATCH_FILE copied to $PATCH_DIR "
else
echo " Could not copy $PATCH_FILE to $PATCH_DIR "
cleanupAndExit 0
fi
fi
. $BASEDIR /dev-support/test-patch.properties
### exit if warnings are NOT defined in the properties file
2012-12-17 20:14:47 -05:00
if [ -z " $OK_FINDBUGS_WARNINGS " ] || [ [ -z " $OK_JAVADOC_WARNINGS " ] ] || [ [ -z $OK_RELEASEAUDIT_WARNINGS ] ] ; then
2011-10-24 16:07:11 -04:00
echo "Please define the following properties in test-patch.properties file"
echo "OK_FINDBUGS_WARNINGS"
echo "OK_RELEASEAUDIT_WARNINGS"
2012-12-17 20:14:47 -05:00
echo "OK_JAVADOC_WARNINGS"
2011-10-24 16:07:11 -04:00
cleanupAndExit 1
fi
echo ""
echo ""
echo "======================================================================"
echo "======================================================================"
2014-11-18 10:55:41 -05:00
echo " Pre-build master to verify stability and javac warnings"
2011-10-24 16:07:11 -04:00
echo "======================================================================"
echo "======================================================================"
echo ""
echo ""
2014-10-15 13:28:45 -04:00
echo " $MVN clean package checkstyle:checkstyle-aggregate -DskipTests -D ${ PROJECT_NAME } PatchProcess > $PATCH_DIR /trunkJavacWarnings.txt 2>&1 "
2012-02-10 18:53:08 -05:00
export MAVEN_OPTS = " ${ MAVEN_OPTS } "
2012-04-26 18:57:43 -04:00
# build core and tests
2014-10-15 13:28:45 -04:00
$MVN clean package checkstyle:checkstyle-aggregate -DskipTests -D${ PROJECT_NAME } PatchProcess > $PATCH_DIR /trunkJavacWarnings.txt 2>& 1
2011-10-24 16:07:11 -04:00
if [ [ $? != 0 ] ] ; then
2013-11-26 17:46:15 -05:00
ERR = ` $GREP -A 5 'Compilation failure' $PATCH_DIR /trunkJavacWarnings.txt`
2013-11-26 13:51:25 -05:00
echo " Trunk compilation is broken?
{ code} $ERR { code} "
2011-10-24 16:07:11 -04:00
cleanupAndExit 1
fi
2014-10-15 13:28:45 -04:00
mv target/checkstyle-result.xml $PATCH_DIR /trunkCheckstyle.xml
2011-10-24 16:07:11 -04:00
}
###############################################################################
### Check for @author tags in the patch
checkAuthor ( ) {
echo ""
echo ""
echo "======================================================================"
echo "======================================================================"
echo " Checking there are no @author tags in the patch."
echo "======================================================================"
echo "======================================================================"
echo ""
echo ""
authorTags = ` $GREP -c -i '@author' $PATCH_DIR /patch`
echo " There appear to be $authorTags @author tags in the patch. "
if [ [ $authorTags != 0 ] ] ; then
JIRA_COMMENT = " $JIRA_COMMENT
2012-09-29 23:25:28 -04:00
{ color:red} -1 @author{ color} . The patch appears to contain $authorTags @author tags which the Hadoop community has agreed to not allow in code contributions."
2011-10-24 16:07:11 -04:00
return 1
fi
JIRA_COMMENT = " $JIRA_COMMENT
2012-09-29 23:25:28 -04:00
{ color:green} +1 @author{ color} . The patch does not contain any @author tags."
2011-10-24 16:07:11 -04:00
return 0
}
###############################################################################
### Check for tests in the patch
checkTests ( ) {
echo ""
echo ""
echo "======================================================================"
echo "======================================================================"
echo " Checking there are new or changed tests in the patch."
echo "======================================================================"
echo "======================================================================"
echo ""
echo ""
testReferences = ` $GREP -c -i '/test' $PATCH_DIR /patch`
echo " There appear to be $testReferences test files referenced in the patch. "
if [ [ $testReferences = = 0 ] ] ; then
if [ [ $JENKINS = = "true" ] ] ; then
patchIsDoc = ` $GREP -c -i 'title="documentation' $PATCH_DIR /jira`
if [ [ $patchIsDoc != 0 ] ] ; then
echo "The patch appears to be a documentation patch that doesn't require tests."
JIRA_COMMENT = " $JIRA_COMMENT
2012-09-29 23:25:28 -04:00
{ color:green} +0 tests included{ color} . The patch appears to be a documentation patch that doesn' t require tests."
2011-10-24 16:07:11 -04:00
return 0
fi
fi
JIRA_COMMENT = " $JIRA_COMMENT
2012-09-29 23:25:28 -04:00
{ color:red} -1 tests included{ color} . The patch doesn' t appear to include any new or modified tests.
2011-10-24 16:07:11 -04:00
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
JIRA_COMMENT = " $JIRA_COMMENT
2012-09-29 23:25:28 -04:00
{ color:green} +1 tests included{ color} . The patch appears to include $testReferences new or modified tests."
2011-10-24 16:07:11 -04:00
return 0
}
2014-05-02 18:12:26 -04:00
###############################################################################
### Check there are no compilation errors, passing a file to be parsed.
checkCompilationErrors( ) {
local file = $1
COMPILATION_ERROR = false
eval $( awk '/ERROR/ {print "COMPILATION_ERROR=true"}' $file )
if $COMPILATION_ERROR ; then
ERRORS = $( $AWK '/ERROR/ { print $0 }' $file )
2014-05-11 13:05:04 -04:00
echo "======================================================================"
echo "There are compilation errors."
echo "======================================================================"
echo " $ERRORS "
2014-05-02 18:12:26 -04:00
JIRA_COMMENT = " $JIRA_COMMENT
{ color:red} -1 javac{ color} . The patch appears to cause mvn compile goal to fail.
Compilation errors resume:
$ERRORS
"
2014-07-04 10:43:54 -04:00
submitJiraComment 1
2014-05-02 18:12:26 -04:00
cleanupAndExit 1
fi
}
2014-06-19 19:46:22 -04:00
###############################################################################
### Check there are no protoc compilation errors, passing a file to be parsed.
checkProtocCompilationErrors( ) {
local file = $1
COMPILATION_ERROR = false
eval $( awk '/\[ERROR/ {print "COMPILATION_ERROR=true"}' $file )
if $COMPILATION_ERROR ; then
ERRORS = $( $AWK '/\[ERROR/ { print $0 }' $file )
echo "======================================================================"
echo "There are Protoc compilation errors."
echo "======================================================================"
echo " $ERRORS "
JIRA_COMMENT = " $JIRA_COMMENT
{ color:red} -1 javac{ color} . The patch appears to cause mvn compile-protobuf profile to fail.
Protoc Compilation errors resume:
$ERRORS
"
cleanupAndExit 1
fi
}
2011-10-24 16:07:11 -04:00
###############################################################################
### Attempt to apply the patch
applyPatch ( ) {
echo ""
echo ""
echo "======================================================================"
echo "======================================================================"
echo " Applying patch."
echo "======================================================================"
echo "======================================================================"
echo ""
echo ""
2012-04-06 17:40:15 -04:00
export PATCH
$BASEDIR /dev-support/smart-apply-patch.sh $PATCH_DIR /patch
2011-10-24 16:07:11 -04:00
if [ [ $? != 0 ] ] ; then
echo "PATCH APPLICATION FAILED"
JIRA_COMMENT = " $JIRA_COMMENT
2012-09-29 23:25:28 -04:00
{ color:red} -1 patch{ color} . The patch command could not apply the patch."
2011-10-24 16:07:11 -04:00
return 1
fi
return 0
}
2013-11-07 15:58:09 -05:00
###############################################################################
### Check against known anti-patterns
checkAntiPatterns ( ) {
echo ""
echo ""
echo "======================================================================"
echo "======================================================================"
echo " Checking against known anti-patterns."
echo "======================================================================"
echo "======================================================================"
echo ""
echo ""
warnings = ` $GREP 'new TreeMap<byte.*()' $PATCH_DIR /patch`
if [ [ $warnings != "" ] ] ; then
JIRA_COMMENT = " $JIRA_COMMENT
{ color:red} -1 Anti-pattern{ color} . The patch appears to have anti-pattern where BYTES_COMPARATOR was omitted:
$warnings ."
return 1
fi
return 0
}
2011-10-24 16:07:11 -04:00
###############################################################################
### Check there are no javadoc warnings
checkJavadocWarnings ( ) {
echo ""
echo ""
echo "======================================================================"
echo "======================================================================"
echo " Determining number of patched javadoc warnings."
echo "======================================================================"
echo "======================================================================"
echo ""
echo ""
2012-09-18 15:10:03 -04:00
echo " $MVN clean package javadoc:javadoc -DskipTests -D ${ PROJECT_NAME } PatchProcess > $PATCH_DIR /patchJavadocWarnings.txt 2>&1 "
2012-02-10 18:53:08 -05:00
export MAVEN_OPTS = " ${ MAVEN_OPTS } "
2012-09-18 15:10:03 -04:00
$MVN clean package javadoc:javadoc -DskipTests -D${ PROJECT_NAME } PatchProcess > $PATCH_DIR /patchJavadocWarnings.txt 2>& 1
2012-12-17 20:14:47 -05:00
javadocWarnings = ` $GREP '\[WARNING\]' $PATCH_DIR /patchJavadocWarnings.txt | $AWK '/Javadoc Warnings/,EOF' | $GREP warning | $AWK 'BEGIN {total = 0} {total += 1} END {print total}' `
2011-10-24 16:07:11 -04:00
echo ""
echo ""
2012-12-17 20:14:47 -05:00
echo " There appear to be $javadocWarnings javadoc warnings generated by the patched build. "
2011-10-24 16:07:11 -04:00
2012-12-17 20:14:47 -05:00
### if current warnings greater than OK_JAVADOC_WARNINGS
if [ [ $javadocWarnings -gt $OK_JAVADOC_WARNINGS ] ] ; then
2011-10-24 16:07:11 -04:00
JIRA_COMMENT = " $JIRA_COMMENT
2012-12-17 20:14:47 -05:00
{ color:red} -1 javadoc{ color} . The javadoc tool appears to have generated ` expr $(( $javadocWarnings - $OK_JAVADOC_WARNINGS )) ` warning messages."
2014-10-01 19:04:02 -04:00
# Add javadoc output url
2014-10-12 18:17:09 -04:00
JIRA_COMMENT_FOOTER = " Javadoc warnings: $BUILD_URL /artifact/patchprocess/patchJavadocWarnings.txt
2014-10-01 19:04:02 -04:00
$JIRA_COMMENT_FOOTER "
2011-10-24 16:07:11 -04:00
return 1
fi
JIRA_COMMENT = " $JIRA_COMMENT
2012-12-17 20:14:47 -05:00
{ color:green} +1 javadoc{ color} . The javadoc tool did not generate any warning messages."
2011-10-24 16:07:11 -04:00
return 0
}
###############################################################################
### Check there are no changes in the number of Javac warnings
checkJavacWarnings ( ) {
echo ""
echo ""
echo "======================================================================"
echo "======================================================================"
echo " Determining number of patched javac warnings."
echo "======================================================================"
echo "======================================================================"
echo ""
echo ""
2012-09-18 15:10:03 -04:00
echo " $MVN clean package -DskipTests -D ${ PROJECT_NAME } PatchProcess > $PATCH_DIR /patchJavacWarnings.txt 2>&1 "
2012-02-10 18:53:08 -05:00
export MAVEN_OPTS = " ${ MAVEN_OPTS } "
2012-09-18 15:10:03 -04:00
$MVN clean package -DskipTests -D${ PROJECT_NAME } PatchProcess > $PATCH_DIR /patchJavacWarnings.txt 2>& 1
2014-05-02 18:12:26 -04:00
checkCompilationErrors $PATCH_DIR /patchJavacWarnings.txt
2011-10-24 16:07:11 -04:00
### Compare trunk and patch javac warning numbers
if [ [ -f $PATCH_DIR /patchJavacWarnings.txt ] ] ; then
trunkJavacWarnings = ` $GREP '\[WARNING\]' $PATCH_DIR /trunkJavacWarnings.txt | $AWK 'BEGIN {total = 0} {total += 1} END {print total}' `
patchJavacWarnings = ` $GREP '\[WARNING\]' $PATCH_DIR /patchJavacWarnings.txt | $AWK 'BEGIN {total = 0} {total += 1} END {print total}' `
echo " There appear to be $trunkJavacWarnings javac compiler warnings before the patch and $patchJavacWarnings javac compiler warnings after applying the patch. "
if [ [ $patchJavacWarnings != "" && $trunkJavacWarnings != "" ] ] ; then
if [ [ $patchJavacWarnings -gt $trunkJavacWarnings ] ] ; then
JIRA_COMMENT = " $JIRA_COMMENT
2014-11-18 10:55:41 -05:00
{ color:red} -1 javac{ color} . The applied patch generated $patchJavacWarnings javac compiler warnings ( more than the master' s current $trunkJavacWarnings warnings) ."
2011-10-24 16:07:11 -04:00
return 1
fi
fi
fi
JIRA_COMMENT = " $JIRA_COMMENT
2012-09-29 23:25:28 -04:00
{ color:green} +1 javac{ color} . The applied patch does not increase the total number of javac compiler warnings."
2011-10-24 16:07:11 -04:00
return 0
}
2014-10-15 13:28:45 -04:00
checkCheckstyleErrors( ) {
echo ""
echo ""
echo "======================================================================"
echo "======================================================================"
echo " Determining number of patched Checkstyle errors."
echo "======================================================================"
echo "======================================================================"
echo ""
echo ""
if [ [ -f $PATCH_DIR /trunkCheckstyle.xml ] ] ; then
$MVN package -DskipTests checkstyle:checkstyle-aggregate > /dev/null 2>& 1
mv target/checkstyle-result.xml $PATCH_DIR /patchCheckstyle.xml
mv target/site/checkstyle-aggregate.html $PATCH_DIR
mv target/site/checkstyle.css $PATCH_DIR
trunkCheckstyleErrors = ` $GREP '<error' $PATCH_DIR /trunkCheckstyle.xml | $AWK 'BEGIN {total = 0} {total += 1} END {print total}' `
patchCheckstyleErrors = ` $GREP '<error' $PATCH_DIR /patchCheckstyle.xml | $AWK 'BEGIN {total = 0} {total += 1} END {print total}' `
if [ [ $patchCheckstyleErrors -gt $trunkCheckstyleErrors ] ] ; then
JIRA_COMMENT_FOOTER = " Checkstyle Errors: $BUILD_URL /artifact/patchprocess/checkstyle-aggregate.html
$JIRA_COMMENT_FOOTER "
JIRA_COMMENT = " $JIRA_COMMENT
2014-11-18 10:55:41 -05:00
{ color:red} -1 checkstyle{ color} . The applied patch generated $patchCheckstyleErrors checkstyle errors ( more than the master' s current $trunkCheckstyleErrors errors) ."
2014-10-15 13:28:45 -04:00
return 1
fi
echo " There were $patchCheckstyleErrors checkstyle errors in this patch compared to $trunkCheckstyleErrors on master. "
fi
2014-10-17 14:34:20 -04:00
JIRA_COMMENT_FOOTER = " Checkstyle Errors: $BUILD_URL /artifact/patchprocess/checkstyle-aggregate.html
$JIRA_COMMENT_FOOTER "
2014-10-15 13:28:45 -04:00
JIRA_COMMENT = " $JIRA_COMMENT
2014-10-17 14:34:20 -04:00
{ color:green} +1 checkstyle{ color} . The applied patch does not increase the total number of checkstyle errors"
2014-10-15 13:28:45 -04:00
return 0
}
2014-06-19 19:46:22 -04:00
###############################################################################
checkProtocErrors ( ) {
echo ""
echo ""
echo "======================================================================"
echo "======================================================================"
echo " Determining whether there is patched protoc error."
echo "======================================================================"
echo "======================================================================"
echo ""
echo ""
echo " $MVN clean install -DskipTests -Pcompile-protobuf -X -D ${ PROJECT_NAME } PatchProcess > $PATCH_DIR /patchProtocErrors.txt 2>&1 "
export MAVEN_OPTS = " ${ MAVEN_OPTS } "
$MVN clean install -DskipTests -Pcompile-protobuf -X -D${ PROJECT_NAME } PatchProcess > $PATCH_DIR /patchProtocErrors.txt 2>& 1
checkProtocCompilationErrors $PATCH_DIR /patchProtocErrors.txt
JIRA_COMMENT = " $JIRA_COMMENT
{ color:green} +1 javac{ color} . The applied patch does not increase the total number of javac compiler warnings."
return 0
}
2011-10-24 16:07:11 -04:00
###############################################################################
### Check there are no changes in the number of release audit (RAT) warnings
checkReleaseAuditWarnings ( ) {
echo ""
echo ""
echo "======================================================================"
echo "======================================================================"
echo " Determining number of patched release audit warnings."
echo "======================================================================"
echo "======================================================================"
echo ""
echo ""
echo " $MVN apache-rat:check -D ${ PROJECT_NAME } PatchProcess 2>&1 "
2012-02-10 18:53:08 -05:00
export MAVEN_OPTS = " ${ MAVEN_OPTS } "
2011-10-24 16:07:11 -04:00
$MVN apache-rat:check -D${ PROJECT_NAME } PatchProcess 2>& 1
find $BASEDIR -name rat.txt | xargs cat > $PATCH_DIR /patchReleaseAuditWarnings.txt
### Compare trunk and patch release audit warning numbers
if [ [ -f $PATCH_DIR /patchReleaseAuditWarnings.txt ] ] ; then
patchReleaseAuditWarnings = ` $GREP -c '\!?????' $PATCH_DIR /patchReleaseAuditWarnings.txt`
echo ""
echo ""
echo " There appear to be $OK_RELEASEAUDIT_WARNINGS release audit warnings before the patch and $patchReleaseAuditWarnings release audit warnings after applying the patch. "
if [ [ $patchReleaseAuditWarnings != "" && $OK_RELEASEAUDIT_WARNINGS != "" ] ] ; then
if [ [ $patchReleaseAuditWarnings -gt $OK_RELEASEAUDIT_WARNINGS ] ] ; then
JIRA_COMMENT = " $JIRA_COMMENT
2014-11-18 10:55:41 -05:00
{ color:red} -1 release audit{ color} . The applied patch generated $patchReleaseAuditWarnings release audit warnings ( more than the master' s current $OK_RELEASEAUDIT_WARNINGS warnings) ."
2011-10-24 16:07:11 -04:00
$GREP '\!?????' $PATCH_DIR /patchReleaseAuditWarnings.txt > $PATCH_DIR /patchReleaseAuditProblems.txt
echo "Lines that start with ????? in the release audit report indicate files that do not have an Apache license header." >> $PATCH_DIR /patchReleaseAuditProblems.txt
2014-10-21 19:35:06 -04:00
JIRA_COMMENT_FOOTER = " Release audit warnings: $BUILD_URL /artifact/patchprocess/patchReleaseAuditWarnings.txt
2011-10-24 16:07:11 -04:00
$JIRA_COMMENT_FOOTER "
return 1
fi
fi
fi
JIRA_COMMENT = " $JIRA_COMMENT
2012-09-29 23:25:28 -04:00
{ color:green} +1 release audit{ color} . The applied patch does not increase the total number of release audit warnings."
2011-10-24 16:07:11 -04:00
return 0
}
###############################################################################
### Check there are no changes in the number of Findbugs warnings
checkFindbugsWarnings ( ) {
findbugs_version = ` ${ FINDBUGS_HOME } /bin/findbugs -version`
echo ""
echo ""
echo "======================================================================"
echo "======================================================================"
echo " Determining number of patched Findbugs warnings."
echo "======================================================================"
echo "======================================================================"
echo ""
echo ""
2012-09-18 15:10:03 -04:00
echo " $MVN clean package findbugs:findbugs -D ${ PROJECT_NAME } PatchProcess "
2012-02-10 18:53:08 -05:00
export MAVEN_OPTS = " ${ MAVEN_OPTS } "
2012-09-18 15:10:03 -04:00
$MVN clean package findbugs:findbugs -D${ PROJECT_NAME } PatchProcess -DskipTests < /dev/null
2011-10-24 16:07:11 -04:00
if [ $? != 0 ] ; then
JIRA_COMMENT = " $JIRA_COMMENT
2012-09-29 23:25:28 -04:00
{ color:red} -1 findbugs{ color} . The patch appears to cause Findbugs ( version ${ findbugs_version } ) to fail."
2011-10-24 16:07:11 -04:00
return 1
fi
findbugsWarnings = 0
for file in $( find $BASEDIR -name findbugsXml.xml)
do
relative_file = ${ file # $BASEDIR / } # strip leading $BASEDIR prefix
if [ ! $relative_file = = "target/findbugsXml.xml" ] ; then
module_suffix = ${ relative_file %/target/findbugsXml.xml } # strip trailing path
module_suffix = ` basename ${ module_suffix } `
fi
cp $file $PATCH_DIR /patchFindbugsWarnings${ module_suffix } .xml
$FINDBUGS_HOME /bin/setBugDatabaseInfo -timestamp "01/01/2000" \
$PATCH_DIR /patchFindbugsWarnings${ module_suffix } .xml \
$PATCH_DIR /patchFindbugsWarnings${ module_suffix } .xml
newFindbugsWarnings = ` $FINDBUGS_HOME /bin/filterBugs -first "01/01/2000" $PATCH_DIR /patchFindbugsWarnings${ module_suffix } .xml \
$PATCH_DIR /newPatchFindbugsWarnings${ module_suffix } .xml | $AWK '{print $1}' `
echo " Found $newFindbugsWarnings Findbugs warnings ( $file ) "
findbugsWarnings = $(( findbugsWarnings+newFindbugsWarnings))
2014-07-03 19:17:27 -04:00
echo " $FINDBUGS_HOME /bin/convertXmlToText -html $PATCH_DIR /newPatchFindbugsWarnings ${ module_suffix } .xml $PATCH_DIR /newPatchFindbugsWarnings ${ module_suffix } .html "
$FINDBUGS_HOME /bin/convertXmlToText -html $PATCH_DIR /newPatchFindbugsWarnings${ module_suffix } .xml $PATCH_DIR /newPatchFindbugsWarnings${ module_suffix } .html
file $PATCH_DIR /newPatchFindbugsWarnings${ module_suffix } .xml $PATCH_DIR /newPatchFindbugsWarnings${ module_suffix } .html
JIRA_COMMENT_FOOTER = " Findbugs warnings: $BUILD_URL /artifact/patchprocess/newPatchFindbugsWarnings ${ module_suffix } .html
2011-10-24 16:07:11 -04:00
$JIRA_COMMENT_FOOTER "
done
### if current warnings greater than OK_FINDBUGS_WARNINGS
2012-03-12 17:49:37 -04:00
if [ [ $findbugsWarnings -gt $OK_FINDBUGS_WARNINGS ] ] ; then
2011-10-24 16:07:11 -04:00
JIRA_COMMENT = " $JIRA_COMMENT
2012-09-29 23:25:28 -04:00
{ color:red} -1 findbugs{ color} . The patch appears to introduce ` expr $(( $findbugsWarnings - $OK_FINDBUGS_WARNINGS )) ` new Findbugs ( version ${ findbugs_version } ) warnings."
2011-10-24 16:07:11 -04:00
return 1
fi
JIRA_COMMENT = " $JIRA_COMMENT
2012-09-29 23:25:28 -04:00
{ color:green} +1 findbugs{ color} . The patch does not introduce any new Findbugs ( version ${ findbugs_version } ) warnings."
2011-10-24 16:07:11 -04:00
return 0
}
2012-12-26 17:06:20 -05:00
###############################################################################
### Check line lengths
checkLineLengths ( ) {
echo ""
echo ""
echo "======================================================================"
echo "======================================================================"
echo " Checking that no line have length > $MAX_LINE_LENGTH "
echo "======================================================================"
echo "======================================================================"
echo ""
echo ""
#see http://en.wikipedia.org/wiki/Diff#Unified_format
MAX_LINE_LENGTH_PATCH = ` expr $MAX_LINE_LENGTH + 1`
2014-04-01 22:20:39 -04:00
lines = ` cat $PATCH_DIR /patch | grep "^+" | grep -v "^@@" | grep -v "^+++" | grep -v "import" | grep -v "org.apache.thrift." | grep -v "com.google.protobuf." | grep -v "hbase.protobuf.generated" | awk -v len = " $MAX_LINE_LENGTH_PATCH " 'length ($0) > len' | head -n 10`
2013-08-01 14:43:42 -04:00
ll = ` echo " $lines " | wc -l`
2013-12-30 11:28:49 -05:00
if [ [ " $ll " -gt "1" ] ] ; then
2012-12-26 17:06:20 -05:00
JIRA_COMMENT = " $JIRA_COMMENT
2013-08-01 14:43:42 -04:00
{ color:red} -1 lineLengths{ color} . The patch introduces the following lines longer than $MAX_LINE_LENGTH :
$lines "
2012-12-26 17:06:20 -05:00
return 1
fi
JIRA_COMMENT = " $JIRA_COMMENT
{ color:green} +1 lineLengths{ color} . The patch does not introduce lines longer than $MAX_LINE_LENGTH "
return 0
}
2011-10-24 16:07:11 -04:00
###############################################################################
### Run the tests
runTests ( ) {
echo ""
echo ""
echo "======================================================================"
echo "======================================================================"
echo " Running tests."
echo "======================================================================"
echo "======================================================================"
echo ""
echo ""
2013-01-14 11:40:40 -05:00
### kill any process remaining from another test, maybe even another project
jps | grep surefirebooter | cut -d ' ' -f 1 | xargs kill -9 2>/dev/null
2011-10-24 16:07:11 -04:00
failed_tests = ""
### Kill any rogue build processes from the last attempt
2012-12-13 19:11:09 -05:00
condemnedCount = ` $PS auxwww | $GREP ${ PROJECT_NAME } PatchProcess | $AWK '{print $2}' | $AWK 'BEGIN {total = 0} {total += 1} END {print total}' `
echo " WARNING: $condemnedCount rogue build processes detected, terminating. "
2011-10-24 16:07:11 -04:00
$PS auxwww | $GREP ${ PROJECT_NAME } PatchProcess | $AWK '{print $2}' | /usr/bin/xargs -t -I { } /bin/kill -9 { } > /dev/null
2014-11-06 15:06:28 -05:00
echo " $MVN clean test -Dsurefire.rerunFailingTestsCount=2 -P runAllTests -D ${ PROJECT_NAME } PatchProcess "
2012-02-10 18:53:08 -05:00
export MAVEN_OPTS = " ${ MAVEN_OPTS } "
2011-12-09 13:55:38 -05:00
ulimit -a
2014-11-06 15:06:28 -05:00
$MVN clean test -Dsurefire.rerunFailingTestsCount= 2 -P runAllTests -D${ PROJECT_NAME } PatchProcess
2011-10-24 16:07:11 -04:00
if [ [ $? != 0 ] ] ; then
### Find and format names of failed tests
failed_tests = ` find . -name 'TEST*.xml' | xargs $GREP -l -E "<failure|<error" | sed -e "s|.*target/surefire-reports/TEST-| |g" | sed -e "s|\.xml||g" `
JIRA_COMMENT = " $JIRA_COMMENT
2012-09-29 23:25:28 -04:00
{ color:red} -1 core tests{ color} . The patch failed these unit tests:
2011-10-24 16:07:11 -04:00
$failed_tests "
2012-12-14 08:13:19 -05:00
BAD = 1
2011-10-24 16:07:11 -04:00
else
2012-12-14 08:13:19 -05:00
JIRA_COMMENT = " $JIRA_COMMENT
2011-10-24 16:07:11 -04:00
2012-09-29 23:25:28 -04:00
{ color:green} +1 core tests{ color} . The patch passed unit tests in $modules ."
2012-12-14 08:13:19 -05:00
BAD = 0
fi
ZOMBIE_TESTS_COUNT = ` jps | grep surefirebooter | wc -l`
2012-12-14 10:08:36 -05:00
if [ [ $ZOMBIE_TESTS_COUNT != 0 ] ] ; then
2012-12-23 08:15:21 -05:00
#It seems sometimes the tests are not dying immediately. Let's give them 30s
echo "Suspicious java process found - waiting 30s to see if there are just slow to stop"
sleep 30
ZOMBIE_TESTS_COUNT = ` jps | grep surefirebooter | wc -l`
if [ [ $ZOMBIE_TESTS_COUNT != 0 ] ] ; then
echo " There are $ZOMBIE_TESTS_COUNT zombie tests, they should have been killed by surefire but survived "
echo "************ BEGIN zombies jstack extract"
ZB_STACK = ` jps | grep surefirebooter | cut -d ' ' -f 1 | xargs -n 1 jstack | grep ".test" | grep "\.java" `
jps | grep surefirebooter | cut -d ' ' -f 1 | xargs -n 1 jstack
echo "************ END zombies jstack extract"
JIRA_COMMENT = " $JIRA_COMMENT
{ color:red} -1 core zombie tests{ color} . There are ${ ZOMBIE_TESTS_COUNT } zombie test( s) : ${ ZB_STACK } "
BAD = 1
2013-01-14 11:40:40 -05:00
jps | grep surefirebooter | cut -d ' ' -f 1 | xargs kill -9
2012-12-23 08:15:21 -05:00
else
echo "We're ok: there is no zombie test, but some tests took some time to stop"
fi
2012-12-14 08:13:19 -05:00
else
2012-12-23 08:15:21 -05:00
echo "We're ok: there is no zombie test"
2011-10-24 16:07:11 -04:00
fi
2012-12-14 08:13:19 -05:00
return $BAD
2011-10-24 16:07:11 -04:00
}
2013-03-08 15:56:02 -05:00
###############################################################################
### Check docbook site xml
checkSiteXml ( ) {
echo ""
echo ""
echo "======================================================================"
echo "======================================================================"
echo " Checking Site generation"
echo "======================================================================"
echo "======================================================================"
echo ""
echo ""
2014-10-15 13:28:45 -04:00
echo " $MVN package site -DskipTests -D ${ PROJECT_NAME } PatchProcess > $PATCH_DIR /patchSiteOutput.txt 2>&1 "
2013-03-08 15:56:02 -05:00
export MAVEN_OPTS = " ${ MAVEN_OPTS } "
2014-10-15 13:28:45 -04:00
$MVN package site -DskipTests -D${ PROJECT_NAME } PatchProcess > $PATCH_DIR /patchSiteOutput.txt 2>& 1
2013-03-08 15:56:02 -05:00
if [ [ $? != 0 ] ] ; then
JIRA_COMMENT = " $JIRA_COMMENT
{ color:red} -1 site{ color} . The patch appears to cause mvn site goal to fail."
return 1
fi
JIRA_COMMENT = " $JIRA_COMMENT
{ color:green} +1 site{ color} . The mvn site goal succeeds with this patch."
return 0
}
2011-10-24 16:07:11 -04:00
###############################################################################
### Run the inject-system-faults target
checkInjectSystemFaults ( ) {
echo ""
echo ""
echo "======================================================================"
echo "======================================================================"
echo " Checking the integrity of system test framework code."
echo "======================================================================"
echo "======================================================================"
echo ""
echo ""
### Kill any rogue build processes from the last attempt
$PS auxwww | $GREP ${ PROJECT_NAME } PatchProcess | $AWK '{print $2}' | /usr/bin/xargs -t -I { } /bin/kill -9 { } > /dev/null
#echo "$ANT_HOME/bin/ant -Dversion="${VERSION}" -DHadoopPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=no -Dcompile.c++=yes -Dforrest.home=$FORREST_HOME inject-system-faults"
#$ANT_HOME/bin/ant -Dversion="${VERSION}" -DHadoopPatchProcess= -Dtest.junit.output.format=xml -Dtest.output=no -Dcompile.c++=yes -Dforrest.home=$FORREST_HOME inject-system-faults
echo "NOP"
return 0
if [ [ $? != 0 ] ] ; then
JIRA_COMMENT = " $JIRA_COMMENT
2012-09-29 23:25:28 -04:00
{ color:red} -1 system test framework{ color} . The patch failed system test framework compile."
2011-10-24 16:07:11 -04:00
return 1
fi
JIRA_COMMENT = " $JIRA_COMMENT
2012-09-29 23:25:28 -04:00
{ color:green} +1 system test framework{ color} . The patch passed system test framework compile."
2011-10-24 16:07:11 -04:00
return 0
}
###############################################################################
### Submit a comment to the defect's Jira
submitJiraComment ( ) {
local result = $1
### Do not output the value of JIRA_COMMENT_FOOTER when run by a developer
if [ [ $JENKINS = = "false" ] ] ; then
JIRA_COMMENT_FOOTER = ""
fi
if [ [ $result = = 0 ] ] ; then
2012-09-29 23:25:28 -04:00
comment = " {color:green}+1 overall{color}. $JIRA_COMMENT
2011-10-24 16:07:11 -04:00
$JIRA_COMMENT_FOOTER "
else
2012-09-29 23:25:28 -04:00
comment = " {color:red}-1 overall{color}. $JIRA_COMMENT
2011-10-24 16:07:11 -04:00
$JIRA_COMMENT_FOOTER "
fi
### Output the test result to the console
echo "
$comment "
if [ [ $JENKINS = = "true" ] ] ; then
echo ""
echo ""
echo "======================================================================"
echo "======================================================================"
echo " Adding comment to Jira."
echo "======================================================================"
echo "======================================================================"
echo ""
echo ""
### Update Jira with a comment
export USER = hudson
$JIRACLI -s https://issues.apache.org/jira -a addcomment -u hadoopqa -p $JIRA_PASSWD --comment " $comment " --issue $defect
$JIRACLI -s https://issues.apache.org/jira -a logout -u hadoopqa -p $JIRA_PASSWD
fi
}
###############################################################################
### Cleanup files
cleanupAndExit ( ) {
local result = $1
if [ [ $JENKINS = = "true" ] ] ; then
if [ -e " $PATCH_DIR " ] ; then
mv $PATCH_DIR $BASEDIR
fi
fi
echo ""
echo ""
echo "======================================================================"
echo "======================================================================"
echo " Finished build."
echo "======================================================================"
echo "======================================================================"
echo ""
echo ""
exit $result
}
###############################################################################
###############################################################################
###############################################################################
JIRA_COMMENT = ""
JIRA_COMMENT_FOOTER = " Console output: $BUILD_URL /console
This message is automatically generated."
### Check if arguments to the script have been specified properly or not
parseArgs $@
cd $BASEDIR
checkout
RESULT = $?
if [ [ $JENKINS = = "true" ] ] ; then
if [ [ $RESULT != 0 ] ] ; then
exit 100
fi
fi
setup
checkAuthor
RESULT = $?
checkTests
( ( RESULT = RESULT + $? ) )
applyPatch
if [ [ $? != 0 ] ] ; then
submitJiraComment 1
cleanupAndExit 1
fi
2012-04-26 18:57:43 -04:00
2013-11-07 15:58:09 -05:00
checkAntiPatterns
( ( RESULT = RESULT + $? ) )
2011-10-24 16:07:11 -04:00
checkJavacWarnings
( ( RESULT = RESULT + $? ) )
2014-06-19 19:46:22 -04:00
checkProtocErrors
( ( RESULT = RESULT + $? ) )
2014-05-02 18:12:26 -04:00
checkJavadocWarnings
( ( RESULT = RESULT + $? ) )
2014-10-15 13:28:45 -04:00
checkCheckstyleErrors
( ( RESULT = RESULT + $? ) )
2011-10-24 16:07:11 -04:00
checkFindbugsWarnings
( ( RESULT = RESULT + $? ) )
checkReleaseAuditWarnings
( ( RESULT = RESULT + $? ) )
2012-12-26 17:06:20 -05:00
checkLineLengths
( ( RESULT = RESULT + $? ) )
2013-03-08 15:56:02 -05:00
checkSiteXml
( ( RESULT = RESULT + $? ) )
2011-10-24 16:07:11 -04:00
### Do not call these when run by a developer
if [ [ $JENKINS = = "true" ] ] ; then
runTests
( ( RESULT = RESULT + $? ) )
JIRA_COMMENT_FOOTER = " Test results: $BUILD_URL /testReport/
$JIRA_COMMENT_FOOTER "
fi
submitJiraComment $RESULT
cleanupAndExit $RESULT