Skip to content

Commit d705e3b

Browse files
wip
Signed-off-by: tobiasKaminsky <[email protected]>
1 parent f24d2d5 commit d705e3b

File tree

6 files changed

+110
-181
lines changed

6 files changed

+110
-181
lines changed

build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ buildscript {
1717
}
1818
dependencies {
1919
classpath 'com.android.tools.build:gradle:8.13.2'
20-
classpath 'com.github.spotbugs.snom:spotbugs-gradle-plugin:6.4.8'
2120
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
2221
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.23.8"
2322
}
@@ -31,6 +30,5 @@ allprojects {
3130
}
3231
}
3332

34-
apply plugin: "com.github.spotbugs"
3533
apply plugin: "io.gitlab.arturbosch.detekt"
3634
apply plugin: 'maven-publish' // needed for JitPack.io

gradle/verification-metadata.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8522,6 +8522,16 @@
85228522
<sha256 value="a36a5f4b7289b643d422372a2e92dbe56c27219514eb10e483edb09a9babec27" origin="Generated by Gradle" reason="A key couldn't be downloaded"/>
85238523
</artifact>
85248524
</component>
8525+
<component group="com.mebigfatguy.fb-contrib" name="fb-contrib" version="7.7.3">
8526+
<artifact name="fb-contrib-7.7.3.jar">
8527+
<sha256 value="f97f9d3cc5166b1d9745342d23f3d97fe353dfe426d6c3d31fb315d784f92b06"
8528+
origin="Generated by Gradle" reason="A key couldn't be downloaded" />
8529+
</artifact>
8530+
<artifact name="fb-contrib-7.7.3.pom">
8531+
<sha256 value="02503912009e6d5b9e2fe589982c367e5133fb9cdeabe5751681cb2362ec3af7"
8532+
origin="Generated by Gradle" reason="A key couldn't be downloaded" />
8533+
</artifact>
8534+
</component>
85258535
<component group="com.pinterest" name="ktlint" version="0.51.0-FINAL">
85268536
<artifact name="ktlint-0.51.0-FINAL.pom">
85278537
<sha256 value="62609714173a8e0fc63ddb2990c8e1d261e0ff2eb10650f296d10f0a421b61a5" origin="Generated by Gradle" reason="A key couldn't be downloaded"/>

lib/build.gradle

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ import com.github.spotbugs.snom.Effort
1111
import com.github.spotbugs.snom.SpotBugsTask
1212
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
1313

14+
buildscript {
15+
ext {
16+
junit_version = '4.13.2'
17+
}
18+
dependencies {
19+
classpath 'com.github.spotbugs.snom:spotbugs-gradle-plugin:6.4.8'
20+
}
21+
}
1422

1523
plugins {
1624
id "com.diffplug.spotless" version "8.1.0"
@@ -84,13 +92,13 @@ android {
8492
}
8593
}
8694

87-
tasks.withType(SpotBugsTask).configureEach { task ->
95+
tasks.withType(SpotBugsTask) { task ->
8896
String variantNameCap = task.name.replace("spotbugs", "")
89-
97+
String variantName = variantNameCap.substring(0, 1).toLowerCase() + variantNameCap.substring(1)
9098
dependsOn "compile${variantNameCap}Sources"
9199

92-
excludeFilter.set(file("${project.rootDir}/spotbugs-filter.xml"))
93-
classes = fileTree("$project.layout.buildDirectory/intermediates/javac/debug/classes/")
100+
classes = files("$project.buildDir/intermediates/javac/${variantName}")
101+
excludeFilter = file("${project.rootDir}/spotbugs-filter.xml")
94102
reports {
95103
xml {
96104
required = true
@@ -141,7 +149,7 @@ dependencies {
141149
implementation 'com.squareup.okhttp3:okhttp:5.3.2'
142150

143151
spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.14.0'
144-
spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.7.2'
152+
spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.7.3'
145153

146154
ktlint "com.pinterest.ktlint:ktlint-cli:1.8.0"
147155

scripts/analysis/analysis-wrapper.sh

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,76 +14,72 @@ stableBranch="main"
1414
repository="android-singleSignOn"
1515
codacyProject=160903
1616

17-
ruby scripts/analysis/findbugs-up.rb $1 $2 $3
18-
findbugsValue=$?
17+
curl "https://www.kaminsky.me/nc-dev/$repository-findbugs/$stableBranch.xml" -o "/tmp/$stableBranch.xml"
18+
ruby scripts/analysis/spotbugs-up.rb "$stableBranch"
19+
spotbugsValue=$?
1920

2021
# exit codes:
2122
# 0: count was reduced
2223
# 1: count was increased
2324
# 2: count stayed the same
2425

25-
echo "Branch: $1"
26+
source scripts/lib.sh
2627

27-
if [ $1 = $stableBranch ]; then
28-
echo "New findbugs result for $stableBranch at: https://www.kaminsky.me/nc-dev/$repository-findbugs/$stableBranch.html"
29-
curl -u "${LOG_USERNAME}:${LOG_PASSWORD}" -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/$stableBranch.html --upload-file lib/build/reports/spotbugs/spotbugs.html
28+
echo "Branch: $BRANCH"
3029

31-
summary=$(sed -n "/<h1>Summary<\/h1>/,/<h1>Warnings<\/h1>/p" lib/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")
32-
curl -u "${LOG_USERNAME}:${LOG_PASSWORD}" -X PUT -d "$summary" https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/findbugs-summary-$stableBranch.html
30+
if [ "$BRANCH" = $stableBranch ]; then
31+
echo "New spotbugs result for $stableBranch at: https://www.kaminsky.me/nc-dev/$repository-findbugs/$stableBranch.html"
32+
curl -u "${LOG_USERNAME}:${LOG_PASSWORD}" -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/$stableBranch.html --upload-file library/build/reports/spotbugs/spotbugs.html
33+
curl 2>/dev/null -u "${LOG_USERNAME}:${LOG_PASSWORD}" -X PUT "https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/$stableBranch.xml" --upload-file library/build/reports/spotbugs/debug.xml
3334
else
34-
if [ -e $6 ]; then
35-
name=$stableBranch"-"$(date +%F)
36-
else
37-
name=$6;
35+
if [ -e "${BUILD_NUMBER}" ]; then
36+
6=$stableBranch"-"$(date +%F)
3837
fi
3938

40-
echo "New findbugs results at https://www.kaminsky.me/nc-dev/$repository-findbugs/$name.html"
41-
curl 2>/dev/null -u "${LOG_USERNAME}:${LOG_PASSWORD}" -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/$name.html --upload-file lib/build/reports/spotbugs/spotbugs.html
39+
echo "New spotbugs results at https://www.kaminsky.me/nc-dev/$repository-findbugs/${BUILD_NUMBER}.html"
40+
curl 2>/dev/null -u "${LOG_USERNAME}:${LOG_PASSWORD}" -X PUT "https://nextcloud.kaminsky.me/remote.php/webdav/$repository-findbugs/${BUILD_NUMBER}.html" --upload-file library/build/reports/spotbugs/spotbugs.html
4241

4342
# delete all old comments, starting with Codacy
44-
oldComments=$(curl 2>/dev/null -u $1:$2 -X GET https://api.github.com/repos/nextcloud/$repository/issues/$7/comments | jq '.[] | (.id |tostring) + "|" + (.user.login | test("nextcloud-android-bot") | tostring) + "|" + (.body | test("<h1>Codacy.*") | tostring)' | grep "true|true" | tr -d "\"" | cut -f1 -d"|")
43+
oldComments=$(curl_gh -X GET "https://api.github.com/repos/nextcloud/$repository/issues/${PR_NUMBER}/comments" | jq '.[] | select((.user.login | contains("github-actions")) and (.body | test("<h1>Codacy.*"))) | .id')
4544

46-
echo $oldComments | while read comment ; do
47-
curl 2>/dev/null -u "${LOG_USERNAME}:${LOG_PASSWORD}" -X DELETE https://api.github.com/repos/nextcloud/$repository/issues/comments/$comment
45+
echo "$oldComments" | while read -r comment ; do
46+
curl_gh -X DELETE "https://api.github.com/repos/nextcloud/$repository/issues/comments/$comment"
4847
done
4948

50-
# findbugs file must exist
51-
if [ ! -s lib/build/reports/spotbugs/spotbugs.html ] ; then
49+
# spotbugs file must exist
50+
if [ ! -s library/build/reports/spotbugs/spotbugs.html ] ; then
5251
echo "spotbugs.html file is missing!"
5352
exit 1
5453
fi
5554

5655
# add comment with results
57-
if [ $stableBranch = "master" ] ; then
58-
codacyValue=$(curl 2>/dev/null https://app.codacy.com/dashboards/breakdown\?projectId\=$codacyProject | grep "total issues" | cut -d">" -f3 | cut -d"<" -f1)
59-
codacyResult="<h1>Codacy</h1>$codacyValue"
60-
else
61-
codacyResult=""
62-
fi
56+
spotbugsResult="<h1>SpotBugs</h1>$(scripts/analysis/spotbugsComparison.py "/tmp/$stableBranch.xml" library/build/reports/spotbugs/debug.xml --link-new "https://www.kaminsky.me/nc-dev/$repository-findbugs/${BUILD_NUMBER}.html" --link-base "https://www.kaminsky.me/nc-dev/$repository-findbugs/$stableBranch.html")"
6357

64-
findbugsResultNew=$(sed -n "/<h1>Summary<\/h1>/,/<h1>Warnings<\/h1>/p" lib/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/$name.html\">SpotBugs</a> (new)#" | tr "\"" "\'" | tr -d "\n")
65-
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")
66-
67-
if ( [ $findbugsValue -eq 1 ] ) ; then
68-
findbugsMessage="<h1>SpotBugs increased!</h1>"
58+
if ( [ $spotbugsValue -eq 1 ] ) ; then
59+
spotbugsMessage="<h1>SpotBugs increased!</h1>"
60+
fi
61+
62+
# check for NotNull
63+
if [[ $(grep org.jetbrains.annotations library/src/main/* -irl | wc -l) -gt 0 ]] ; then
64+
notNull="org.jetbrains.annotations.* is used. Please use androidx.annotation.* instead.<br><br>"
6965
fi
7066

71-
# check gplay limitation: all changelog files must only have 500 chars
72-
gplayLimitation=$(scripts/checkGplayLimitation.sh)
67+
bodyContent="$spotbugsResult $spotbugsMessage $gplayLimitation $notNull"
68+
echo "$bodyContent" >> "$GITHUB_STEP_SUMMARY"
69+
payload="{ \"body\" : \"$bodyContent\" }"
70+
curl_gh -X POST "https://api.github.com/repos/nextcloud/$repository/issues/${PR_NUMBER}/comments" -d "$payload"
7371

7472
if [ ! -z "$gplayLimitation" ]; then
75-
gplayLimitation="<h1>Following files are beyond 500 char limit:</h1><br><br>"$gplayLimitation
73+
exit 1
7674
fi
7775

78-
curl -u $1:$2 -X POST https://api.github.com/repos/nextcloud/$repository/issues/$7/comments -d "{ \"body\" : \"$codacyResult $findbugsResultNew $findbugsResultOld $findbugsMessage $gplayLimitation \" }"
79-
80-
if [ ! -z "$gplayLimitation" ]; then
76+
if [ -n "$notNull" ]; then
8177
exit 1
8278
fi
8379

84-
if [ $findbugsValue -eq 2 ]; then
80+
if [ $spotbugsValue -eq 2 ]; then
8581
exit 0
8682
else
87-
exit $findbugsValue
83+
exit $spotbugsValue
8884
fi
8985
fi

scripts/analysis/findbugs-up.rb

Lines changed: 0 additions & 136 deletions
This file was deleted.

scripts/analysis/spotbugs-up.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
## Script originally from https://github.com/tir38/android-lint-entropy-reducer at 07.05.2017
2+
# heavily modified since then
3+
4+
# SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
5+
# SPDX-FileCopyrightText: 2017 Jason Atwood
6+
# SPDX-FileCopyrightText: 2017 Tobias Kaminsky <[email protected]>
7+
# SPDX-License-Identifier: GPL-3.0-or-later
8+
9+
Encoding.default_external = Encoding::UTF_8
10+
Encoding.default_internal = Encoding::UTF_8
11+
12+
puts "=================== starting Android Spotbugs Entropy Reducer ===================="
13+
14+
# get args
15+
base_branch = ARGV[0]
16+
17+
require 'fileutils'
18+
require 'pathname'
19+
require 'open3'
20+
21+
# run Spotbugs
22+
puts "running Spotbugs..."
23+
system './gradlew spotbugsDebug'
24+
25+
# find number of warnings
26+
current_warning_count = `./scripts/analysis/spotbugsSummary.py --file library/build/reports/spotbugs/debug.xml --total`.to_i
27+
puts "found warnings: " + current_warning_count.to_s
28+
29+
# get warning counts from target branch
30+
previous_xml = "/tmp/#{base_branch}.xml"
31+
previous_results = File.file?(previous_xml)
32+
33+
if previous_results == true
34+
previous_warning_count = `./scripts/analysis/spotbugsSummary.py --total --file #{previous_xml}`.to_i
35+
puts "previous warnings: " + previous_warning_count.to_s
36+
end
37+
38+
# compare previous warning count with current warning count
39+
if previous_results == true && current_warning_count > previous_warning_count
40+
puts "FAIL: warning count increased"
41+
exit 1
42+
end
43+
44+
# check if warning and error count stayed the same
45+
if previous_results == true && current_warning_count == previous_warning_count
46+
puts "SUCCESS: count stayed the same"
47+
exit 0
48+
end
49+
50+
# warning count DECREASED
51+
if previous_results == true && current_warning_count < previous_warning_count
52+
puts "SUCCESS: count decreased from " + previous_warning_count.to_s + " to " + current_warning_count.to_s
53+
end

0 commit comments

Comments
 (0)