-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1309 from nextcloud/sb-contrib
sb-contrib for SpotBugs
- Loading branch information
Showing
7 changed files
with
267 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
## Script originally from https://github.com/tir38/android-lint-entropy-reducer at 07.05.2017 | ||
# heavily modified since then | ||
|
||
Encoding.default_external = Encoding::UTF_8 | ||
Encoding.default_internal = Encoding::UTF_8 | ||
|
||
puts "=================== starting Android Spotbugs Entropy Reducer ====================" | ||
|
||
# get args | ||
base_branch = ARGV[0] | ||
|
||
require 'fileutils' | ||
require 'pathname' | ||
require 'open3' | ||
|
||
# run Spotbugs | ||
puts "running Spotbugs..." | ||
system './gradlew spotbugsDebug 1>/dev/null 2>&1' | ||
|
||
# find number of warnings | ||
current_warning_count = `./scripts/analysis/spotbugsSummary.py --file library/build/reports/spotbugs/debug.xml --total`.to_i | ||
puts "found warnings: " + current_warning_count.to_s | ||
|
||
# get warning counts from target branch | ||
previous_xml = "/tmp/#{base_branch}.xml" | ||
previous_results = File.file?(previous_xml) | ||
|
||
if previous_results == true | ||
previous_warning_count = `./scripts/analysis/spotbugsSummary.py --total --file #{previous_xml}`.to_i | ||
puts "previous warnings: " + previous_warning_count.to_s | ||
end | ||
|
||
# compare previous warning count with current warning count | ||
if previous_results == true && current_warning_count > previous_warning_count | ||
puts "FAIL: warning count increased" | ||
exit 1 | ||
end | ||
|
||
# check if warning and error count stayed the same | ||
if previous_results == true && current_warning_count == previous_warning_count | ||
puts "SUCCESS: count stayed the same" | ||
exit 0 | ||
end | ||
|
||
# warning count DECREASED | ||
if previous_results == true && current_warning_count < previous_warning_count | ||
puts "SUCCESS: count decreased from " + previous_warning_count.to_s + " to " + current_warning_count.to_s | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env python3 | ||
import argparse | ||
import defusedxml.ElementTree as ET | ||
|
||
import spotbugsSummary | ||
|
||
|
||
def print_comparison(old: dict, new: dict, link_base: str, link_new: str): | ||
all_keys = sorted(set(list(old.keys()) + list(new.keys()))) | ||
|
||
output = "<table><tr><th>Category</th>" | ||
old_header = f"<a href='{link_base}'>Base</a>" if link_base is not None else "Base" | ||
output += f"<th>{old_header}</th>" | ||
new_header = f"<a href='{link_new}'>New</a>" if link_new is not None else "New" | ||
output += f"<th>{new_header}</th>" | ||
output += "</tr>" | ||
|
||
for category in all_keys: | ||
category_count_old = old[category] if category in old else 0 | ||
category_count_new = new[category] if category in new else 0 | ||
new_str = f"<b>{category_count_new}</b>" if category_count_new != category_count_old else str( | ||
category_count_new) | ||
output += "<tr>" | ||
output += f"<td>{category}</td>" | ||
output += f"<td>{category_count_old}</td>" | ||
output += f"<td>{new_str}</td>" | ||
output += "</tr>" | ||
|
||
output += "<tr>" | ||
output += "<td><b>Total</b></td>" | ||
output += f"<td><b>{sum(old.values())}</b></td>" | ||
output += f"<td><b>{sum(new.values())}</b></td>" | ||
output += "</tr>" | ||
|
||
output += "</table>" | ||
|
||
print(output) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("base_file", help="base file for comparison") | ||
parser.add_argument("new_file", help="new file for comparison") | ||
parser.add_argument("--link-base", help="http link to base html report") | ||
parser.add_argument("--link-new", help="http link to new html report") | ||
args = parser.parse_args() | ||
|
||
base_tree = ET.parse(args.base_file) | ||
base_summary = spotbugsSummary.get_counts(base_tree) | ||
|
||
new_tree = ET.parse(args.new_file) | ||
new_summary = spotbugsSummary.get_counts(new_tree) | ||
|
||
print_comparison(base_summary, new_summary, args.link_base, args.link_new) |
Oops, something went wrong.