Skip to content

Commit 8c785d7

Browse files
Add further spotbugs checker files
Signed-off-by: Andy Scherzinger <[email protected]>
1 parent c17a237 commit 8c785d7

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python3
2+
import argparse
3+
import defusedxml.ElementTree as ET
4+
import spotbugsSummary
5+
6+
7+
def print_comparison(old: dict, new: dict, link_base: str, link_new: str):
8+
all_keys = sorted(set(list(old.keys()) + list(new.keys())))
9+
10+
output = "<table><tr><th>Category</th>"
11+
old_header = f"<a href='{link_base}'>Base</a>" if link_base is not None else "Base"
12+
output += f"<th>{old_header}</th>"
13+
new_header = f"<a href='{link_new}'>New</a>" if link_new is not None else "New"
14+
output += f"<th>{new_header}</th>"
15+
output += "</tr>"
16+
17+
for category in all_keys:
18+
category_count_old = old[category] if category in old else 0
19+
category_count_new = new[category] if category in new else 0
20+
new_str = f"<b>{category_count_new}</b>" if category_count_new != category_count_old else str(category_count_new)
21+
output += "<tr>"
22+
output += f"<td>{category}</td>"
23+
output += f"<td>{category_count_old}</td>"
24+
output += f"<td>{new_str}</td>"
25+
output += "</tr>"
26+
27+
output += "<tr>"
28+
output += "<td><b>Total</b></td>"
29+
output += f"<td><b>{sum(old.values())}</b></td>"
30+
output += f"<td><b>{sum(new.values())}</b></td>"
31+
output += "</tr>"
32+
33+
output += "</table>"
34+
35+
print(output)
36+
37+
38+
if __name__ == "__main__":
39+
parser = argparse.ArgumentParser()
40+
parser.add_argument("base_file", help="base file for comparison")
41+
parser.add_argument("new_file", help="new file for comparison")
42+
parser.add_argument("--link-base", help="http link to base html report")
43+
parser.add_argument("--link-new", help="http link to new html report")
44+
args = parser.parse_args()
45+
46+
base_tree = ET.parse(args.base_file)
47+
base_summary = spotbugsSummary.get_counts(base_tree)
48+
49+
new_tree = ET.parse(args.new_file)
50+
new_summary = spotbugsSummary.get_counts(new_tree)
51+
52+
print_comparison(base_summary, new_summary, args.link_base, args.link_new)

scripts/analysis/spotbugsSummary.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python3
2+
import argparse
3+
import defusedxml.ElementTree as ET
4+
5+
6+
def get_counts(tree):
7+
category_counts = {}
8+
category_names = {}
9+
for child in tree.getroot():
10+
if child.tag == "BugInstance":
11+
category = child.attrib['category']
12+
if category in category_counts:
13+
category_counts[category] = category_counts[category] + 1
14+
else:
15+
category_counts[category] = 1
16+
elif child.tag == "BugCategory":
17+
category = child.attrib['category']
18+
category_names[category] = child[0].text
19+
20+
summary = {}
21+
for category in category_counts.keys():
22+
summary[category_names[category]] = category_counts[category]
23+
return summary
24+
25+
26+
def print_html(summary):
27+
output = "<table><tr><th>Category</th><th>Count</th></tr>"
28+
29+
categories = sorted(summary.keys())
30+
for category in categories:
31+
output += "<tr>"
32+
output += f"<td>{category}</td>"
33+
output += f"<td>{summary[category]}</td>"
34+
output += "</tr>"
35+
36+
output += "<tr>"
37+
output += "<td><b>Total</b></td>"
38+
output += f"<td><b>{sum(summary.values())}</b></td>"
39+
output += "</tr>"
40+
41+
output += "</table>"
42+
43+
print(output)
44+
45+
46+
def print_total(summary):
47+
print(sum(summary.values()))
48+
49+
50+
if __name__ == "__main__":
51+
parser = argparse.ArgumentParser()
52+
parser.add_argument("--total", help="print total count instead of summary HTML",
53+
action="store_true")
54+
parser.add_argument("--file", help="file to parse", default="app/build/reports/spotbugs/gplayDebug.xml")
55+
args = parser.parse_args()
56+
tree = ET.parse(args.file)
57+
summary = get_counts(tree)
58+
if args.total:
59+
print_total(summary)
60+
else:
61+
print_html(summary)

0 commit comments

Comments
 (0)