Generate spotbugs summary from xml
Signed-off-by: Álvaro Brey Vilas <alvaro.brey@nextcloud.com>
This commit is contained in:
parent
c850d14fc0
commit
21a432dc9e
@ -449,7 +449,7 @@ tasks.withType(SpotBugsTask){task ->
|
||||
classes = fileTree("$project.buildDir/intermediates/javac/${variantName}/classes/")
|
||||
reports {
|
||||
xml {
|
||||
required = false
|
||||
required = true
|
||||
}
|
||||
html {
|
||||
required = true
|
||||
|
@ -27,9 +27,7 @@ echo "Branch: $3"
|
||||
if [ $3 = $stableBranch ]; then
|
||||
echo "New findbugs result for $stableBranch at: https://www.kaminsky.me/nc-dev/$repository-findbugs/$stableBranch.html"
|
||||
curl -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/$stableBranch.html --upload-file app/build/reports/spotbugs/spotbugs.html
|
||||
|
||||
summary=$(sed -n "/<h1>Summary<\/h1>/,/<h1>Warnings<\/h1>/p" app/build/reports/spotbugs/spotbugs.html | head -n-1 | sed s'/<\/a>//'g | sed s'/<a.*>//'g | sed s"/Summary/SpotBugs ($stableBranch)/" | tr "\"" "\'" | tr -d "\r\n")
|
||||
curl -u $4:$5 -X PUT -d "$summary" https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/findbugs-summary-$stableBranch.html
|
||||
curl 2>/dev/null -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/$stableBranch.xml --upload-file app/build/reports/spotbugs/gplayDebug.xml
|
||||
|
||||
if [ $lintValue -ne 1 ]; then
|
||||
echo "New lint result for $stableBranch at: https://www.kaminsky.me/nc-dev/$repository-lint/$stableBranch.html"
|
||||
@ -108,9 +106,9 @@ else
|
||||
fi
|
||||
|
||||
lintResult="<h1>Lint</h1><table width='500' cellpadding='5' cellspacing='2'><tr class='tablerow0'><td>Type</td><td><a href='https://www.kaminsky.me/nc-dev/"$repository"-lint/"$stableBranch".html'>$stableBranch</a></td><td><a href='https://www.kaminsky.me/nc-dev/"$repository"-lint/"$6".html'>PR</a></td></tr><tr class='tablerow1'><td>Warnings</td><td>"$lintWarningOld"</td><td>"$lintWarningNew"</td></tr><tr class='tablerow0'><td>Errors</td><td>"$lintErrorOld"</td><td>"$lintErrorNew"</td></tr></table>"
|
||||
findbugsResultNew=$(sed -n "/<h1>Summary<\/h1>/,/<h1>Warnings<\/h1>/p" app/build/reports/spotbugs/spotbugs.html |head -n-1 | sed s'/<\/a>//'g | sed s'/<a.*>//'g | sed s"#Summary#<a href=\"https://www.kaminsky.me/nc-dev/$repository-findbugs/$6.html\">SpotBugs</a> (new)#" | tr "\"" "\'" | tr -d "\n")
|
||||
findbugsResultOld=$(curl 2>/dev/null https://www.kaminsky.me/nc-dev/$repository-findbugs/findbugs-summary-$stableBranch.html | tr "\"" "\'" | tr -d "\r\n" | sed s"#SpotBugs#<a href=\"https://www.kaminsky.me/nc-dev/$repository-findbugs/$stableBranch.html\">SpotBugs</a>#" | tr "\"" "\'" | tr -d "\n")
|
||||
|
||||
curl 2>/dev/null "https://www.kaminsky.me/nc-dev/$repository-findbugs/$stableBranch.xml" -o "$stableBranch.xml"
|
||||
findbugsResult="<h1>SpotBugs</h1>$(scripts/analysis/spotbugsComparison.py "$stableBranch.xml" app/build/reports/spotbugs/gplayDebug.xml --link-new "https://www.kaminsky.me/nc-dev/$repository-findbugs/$6.html" --link-base "https://www.kaminsky.me/nc-dev/$repository-findbugs/$stableBranch.html")"
|
||||
|
||||
if ( [ $lintValue -eq 1 ] ) ; then
|
||||
lintMessage="<h1>Lint increased!</h1>"
|
||||
@ -132,7 +130,8 @@ else
|
||||
notNull="org.jetbrains.annotations.NotNull is used. Please use androidx.annotation.NonNull instead.<br><br>"
|
||||
fi
|
||||
|
||||
curl -u $1:$2 -X POST https://api.github.com/repos/nextcloud/android/issues/$7/comments -d "{ \"body\" : \"$codacyResult $lintResult $findbugsResultNew $findbugsResultOld $checkLibraryMessage $lintMessage $findbugsMessage $gplayLimitation $notNull\" }"
|
||||
payload="{ \"body\" : \"$codacyResult $lintResult $findbugsResult $checkLibraryMessage $lintMessage $findbugsMessage $gplayLimitation $notNull\" }"
|
||||
curl -u $1:$2 -X POST https://api.github.com/repos/nextcloud/android/issues/$7/comments -d "$payload"
|
||||
|
||||
if [ ! -z "$gplayLimitation" ]; then
|
||||
exit 1
|
||||
|
@ -58,7 +58,7 @@ end
|
||||
findbugs_report = String.new(findbugs_reports[0])
|
||||
|
||||
# find number of warnings
|
||||
current_warning_count = `grep -A 3 "<b>Total</b>" app/build/reports/spotbugs/spotbugs.html | tail -n1 | cut -f2 -d">" | cut -f1 -d"<"`.to_i
|
||||
current_warning_count = `./scripts/analysis/spotbugsSummary.py --total`.to_i
|
||||
puts "found warnings: " + current_warning_count.to_s
|
||||
|
||||
# get warning counts from last successful build
|
||||
|
52
scripts/analysis/spotbugsComparison.py
Executable file
52
scripts/analysis/spotbugsComparison.py
Executable file
@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import xml.etree.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)
|
60
scripts/analysis/spotbugsSummary.py
Executable file
60
scripts/analysis/spotbugsSummary.py
Executable file
@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
|
||||
def get_counts(tree):
|
||||
category_counts = {}
|
||||
category_names = {}
|
||||
for child in tree.getroot():
|
||||
if child.tag == "BugInstance":
|
||||
category = child.attrib['category']
|
||||
if category in category_counts:
|
||||
category_counts[category] = category_counts[category] + 1
|
||||
else:
|
||||
category_counts[category] = 1
|
||||
elif child.tag == "BugCategory":
|
||||
category = child.attrib['category']
|
||||
category_names[category] = child[0].text
|
||||
|
||||
summary = {}
|
||||
for category in category_counts.keys():
|
||||
summary[category_names[category]] = category_counts[category]
|
||||
return summary
|
||||
|
||||
|
||||
def print_html(summary):
|
||||
output = "<table><tr><th>Category</th><th>Count</th></tr>"
|
||||
|
||||
categories = sorted(summary.keys())
|
||||
for category in categories:
|
||||
output += "<tr>"
|
||||
output += f"<td>{category}</td>"
|
||||
output += f"<td>{summary[category]}</td>"
|
||||
output += "</tr>"
|
||||
|
||||
output += "<tr>"
|
||||
output += "<td><b>Total</b></td>"
|
||||
output += f"<td><b>{sum(summary.values())}</b></td>"
|
||||
output += "</tr>"
|
||||
|
||||
output += "</table>"
|
||||
|
||||
print(output)
|
||||
|
||||
|
||||
def print_total(summary):
|
||||
print(sum(summary.values()))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--total", help="print total count instead of summary HTML",
|
||||
action="store_true")
|
||||
args = parser.parse_args()
|
||||
tree = ET.parse("app/build/reports/spotbugs/gplayDebug.xml")
|
||||
summary = get_counts(tree)
|
||||
if args.total:
|
||||
print_total(summary)
|
||||
else:
|
||||
print_html(summary)
|
Loading…
x
Reference in New Issue
Block a user