From 97acf5a505813ac1d19e2bd9d77d3f1e653ca869 Mon Sep 17 00:00:00 2001 From: Apekshit Date: Wed, 2 Dec 2015 18:29:52 -0800 Subject: [PATCH] HBASE-14916 Add checkstyle_report.py to other branches (currently only in master) because it is now used in test-patch.sh to detech checkstyle errors. (Apekshit) --- dev-support/checkstyle_report.py | 80 ++++++++++++++++++++++++++++++++++++++++ dev-support/test-patch.sh | 17 +++++---- 2 files changed, 89 insertions(+), 8 deletions(-) create mode 100755 dev-support/checkstyle_report.py diff --git a/dev-support/checkstyle_report.py b/dev-support/checkstyle_report.py new file mode 100755 index 0000000..0b700b9 --- /dev/null +++ b/dev-support/checkstyle_report.py @@ -0,0 +1,80 @@ +#!/usr/bin/python +## +# 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. + +## +# script to diff results of checkstyle-result.xml output. Find the result files +# under $buildRoot/target +# +# usage: ./checkstyle_report.py +# + +import os +import sys +import xml.etree.ElementTree as etree +from collections import defaultdict + +if len(sys.argv) != 3 : + print "usage: %s checkstyle-result-master.xml checkstyle-result-patch.xml" % sys.argv[0] + exit(1) + +def path_key(x): + path = x.attrib['name'] + return path[path.find('hbase-'):] + +def error_name(x): + error_class = x.attrib['source'] + return error_class[error_class.rfind(".") + 1:] + +def print_row(path, error, master_errors, patch_errors): + print '%s\t%s\t%s\t%s' % (path,error, master_errors,patch_errors) + +master = etree.parse(sys.argv[1]) +patch = etree.parse(sys.argv[2]) + +master_dict = defaultdict(int) +ret_value = 0 + +for child in master.getroot().getchildren(): + if child.tag != 'file': + continue + file = path_key(child) + for error_tag in child.getchildren(): + error = error_name(error_tag) + if (file, error) in master_dict: + master_dict[(file, error)] += 1 + else: + master_dict[(file, error)] = 1 + +for child in patch.getroot().getchildren(): + if child.tag != 'file': + continue + temp_dict = defaultdict(int) + for error_tag in child.getchildren(): + error = error_name(error_tag) + if error in temp_dict: + temp_dict[error] += 1 + else: + temp_dict[error] = 1 + + file = path_key(child) + for error, count in temp_dict.iteritems(): + if count > master_dict[(file, error)]: + print_row(file, error, master_dict[(file, error)], count) + ret_value = 1 + +sys.exit(ret_value) diff --git a/dev-support/test-patch.sh b/dev-support/test-patch.sh index bb26e95..073d0f3 100755 --- a/dev-support/test-patch.sh +++ b/dev-support/test-patch.sh @@ -532,25 +532,26 @@ checkCheckstyleErrors() { 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 '