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>
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]
36 path
= x
.attrib
['name']
37 return path
[path
.find('hbase-'):]
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)
52 for child
in master
.getroot().getchildren():
53 if child
.tag
!= 'file':
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
61 master_dict
[(file, error
)] = 1
63 for child
in patch
.getroot().getchildren():
64 if child
.tag
!= 'file':
66 temp_dict
= defaultdict(int)
67 for error_tag
in child
.getchildren():
68 error
= error_name(error_tag
)
69 if error
in temp_dict
:
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
)