HBASE-22033 Update to maven-javadoc-plugin 3.2.0 and switch to non-forking aggregate...
[hbase.git] / dev-support / checkstyle_report.py
blob0b700b9789c520a226eb8eee0f83064fe4273e9f
1 #!/usr/bin/python
2 ##
3 # Licensed to the Apache Software Foundation (ASF) under one
4 # or more contributor license agreements. See the NOTICE file
5 # distributed with this work for additional information
6 # regarding copyright ownership. The ASF licenses this file
7 # to you under the Apache License, Version 2.0 (the
8 # "License"); you may not use this file except in compliance
9 # with the License. You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
20 # script to diff results of checkstyle-result.xml output. Find the result files
21 # under $buildRoot/target
23 # usage: ./checkstyle_report.py <master-result.xml> <patch-result.xml>
26 import os
27 import sys
28 import xml.etree.ElementTree as etree
29 from collections import defaultdict
31 if len(sys.argv) != 3 :
32 print "usage: %s checkstyle-result-master.xml checkstyle-result-patch.xml" % sys.argv[0]
33 exit(1)
35 def path_key(x):
36 path = x.attrib['name']
37 return path[path.find('hbase-'):]
39 def error_name(x):
40 error_class = x.attrib['source']
41 return error_class[error_class.rfind(".") + 1:]
43 def print_row(path, error, master_errors, patch_errors):
44 print '%s\t%s\t%s\t%s' % (path,error, master_errors,patch_errors)
46 master = etree.parse(sys.argv[1])
47 patch = etree.parse(sys.argv[2])
49 master_dict = defaultdict(int)
50 ret_value = 0
52 for child in master.getroot().getchildren():
53 if child.tag != 'file':
54 continue
55 file = path_key(child)
56 for error_tag in child.getchildren():
57 error = error_name(error_tag)
58 if (file, error) in master_dict:
59 master_dict[(file, error)] += 1
60 else:
61 master_dict[(file, error)] = 1
63 for child in patch.getroot().getchildren():
64 if child.tag != 'file':
65 continue
66 temp_dict = defaultdict(int)
67 for error_tag in child.getchildren():
68 error = error_name(error_tag)
69 if error in temp_dict:
70 temp_dict[error] += 1
71 else:
72 temp_dict[error] = 1
74 file = path_key(child)
75 for error, count in temp_dict.iteritems():
76 if count > master_dict[(file, error)]:
77 print_row(file, error, master_dict[(file, error)], count)
78 ret_value = 1
80 sys.exit(ret_value)