|
@@ -0,0 +1,130 @@
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+Encoding.default_external = Encoding::UTF_8
|
|
|
|
+Encoding.default_internal = Encoding::UTF_8
|
|
|
|
+
|
|
|
|
+puts "=================== starting Android FindBugs Entropy Reducer ===================="
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+git_user, git_token, git_branch = ARGV
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+TRAVIS_GIT_USERNAME = String.new("Drone CI server")
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+FINDBUGS_REPORT_FILE = String.new("build/reports/findbugs/findbugs.html")
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+PREVIOUS_FINDBUGS_RESULTS_FILE=String.new("scripts/analysis/findbugs-results.txt")
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+CHECK_WARNINGS = true
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+CUSTOM_FINDBUGS_FILE = String.new("")
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+require 'fileutils'
|
|
|
|
+require 'pathname'
|
|
|
|
+require 'open3'
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ gem "xml-simple"
|
|
|
|
+ rescue LoadError
|
|
|
|
+ system("gem install xml-simple")
|
|
|
|
+ Gem.clear_paths
|
|
|
|
+end
|
|
|
|
+
|
|
|
|
+require 'xmlsimple'
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+puts "running FindBugs..."
|
|
|
|
+system './gradlew findbugs'
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+findbugs_reports = Dir.glob(FINDBUGS_REPORT_FILE)
|
|
|
|
+if findbugs_reports.length == 0
|
|
|
|
+ puts "Findbugs HTML report not found."
|
|
|
|
+ exit 1
|
|
|
|
+end
|
|
|
|
+findbugs_report = String.new(findbugs_reports[0])
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+current_warning_count = `grep -A 3 "<b>Total</b>" build/reports/findbugs/findbugs.html | tail -n1 | cut -f2 -d">" | cut -f1 -d"<"`.to_i
|
|
|
|
+puts "found warnings: " + current_warning_count.to_s
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+previous_results = false
|
|
|
|
+
|
|
|
|
+previous_findbugs_reports = Dir.glob(PREVIOUS_FINDBUGS_RESULTS_FILE)
|
|
|
|
+if previous_findbugs_reports.nil? || previous_findbugs_reports.length == 0
|
|
|
|
+ previous_findbugs_report = File.new(PREVIOUS_FINDBUGS_RESULTS_FILE, "w")
|
|
|
|
+else
|
|
|
|
+ previous_findbugs_report = String.new(previous_findbugs_reports[0])
|
|
|
|
+
|
|
|
|
+ previous_warning_count = File.open(previous_findbugs_report, &:readline).match(/[0-9]*/)[0].to_i
|
|
|
|
+
|
|
|
|
+ if previous_warning_count.nil?
|
|
|
|
+ previous_results = false
|
|
|
|
+ else
|
|
|
|
+ previous_results = true
|
|
|
|
+
|
|
|
|
+ puts "previous warnings: " + previous_warning_count.to_s
|
|
|
|
+ end
|
|
|
|
+end
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+if previous_results == true && current_warning_count > previous_warning_count
|
|
|
|
+ puts "FAIL: warning count increased"
|
|
|
|
+ exit 1
|
|
|
|
+end
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+if previous_results == true && current_warning_count == previous_warning_count
|
|
|
|
+ puts "SUCCESS: count stayed the same"
|
|
|
|
+ exit 2
|
|
|
|
+end
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+puts "SUCCESS: count decreased from " + previous_warning_count.to_s + " to " + current_warning_count.to_s
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+File.write(previous_findbugs_report, current_warning_count)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+previous_git_username, _ = Open3.capture2('git config user.name')
|
|
|
|
+previous_git_username = previous_git_username.strip
|
|
|
|
+
|
|
|
|
+previous_git_email, _ = Open3.capture3('git config user.email')
|
|
|
|
+previous_git_email = previous_git_email.strip
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+system ("git config --local user.name '" + git_user + "'")
|
|
|
|
+system ("git config --local user.email '.'")
|
|
|
|
+system ("git remote rm origin")
|
|
|
|
+system ("git remote add origin https://" + git_user + ":" + git_token + "@github.com/nextcloud/android")
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+system ('git add ' + PREVIOUS_FINDBUGS_RESULTS_FILE)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+system ('git commit -m "Drone: update FindBugs results to reflect reduced error/warning count [skip ci]" ')
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+system ('git push origin HEAD:' + git_branch)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+system("git config --local user.name '#{previous_git_username}'")
|
|
|
|
+system("git config --local user.email '#{previous_git_email}'")
|
|
|
|
+
|
|
|
|
+puts "SUCCESS: count was reduced"
|
|
|
|
+exit 0
|