Browse Source

add findbugs to drone
show summary as comment

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>

tobiasKaminsky 6 years ago
parent
commit
0e9367330e

+ 6 - 6
.drone.yml

@@ -5,7 +5,7 @@ pipeline:
       # uncomment gplay for Gplay
       - sh -c "if [ '${FLAVOR}' = 'Gplay' ]; then sed -i '/.*com.google.*/s/^.*\\/\\///g' build.gradle; fi"
       # build app and assemble APK
-      - sh -c "if [ '${FLAVOR}' != 'Lint' ]; then ./gradlew assemble${FLAVOR}; fi"
+      - sh -c "if [ '${FLAVOR}' != 'Analysis' ]; then ./gradlew assemble${FLAVOR}; fi"
     when:
       matrix:
         FLAVOR: [Generic, Gplay]
@@ -27,17 +27,17 @@ pipeline:
       matrix:
         FLAVOR: Gplay
 
-  lint:
+  analysis:
     image: nextcloudci/android:android-35
     commands:
       # needs gplay
       - sed -i '/.*com.google.*/s/^.*\\/\\///g' build.gradle
-      - export BRANCH=$(scripts/lint/getBranchName.sh $GIT_USERNAME $GIT_TOKEN $DRONE_PULL_REQUEST)
-      - scripts/lint/lint-up-wrapper.sh $GIT_USERNAME $GIT_TOKEN $BRANCH $LOG_USERNAME $LOG_PASSWORD $DRONE_BUILD_NUMBER
+      - export BRANCH=$(scripts/analysis/getBranchName.sh $GIT_USERNAME $GIT_TOKEN $DRONE_PULL_REQUEST)
+      - scripts/analysis/analysis-wrapper.sh $GIT_USERNAME $GIT_TOKEN $BRANCH $LOG_USERNAME $LOG_PASSWORD $DRONE_BUILD_NUMBER $DRONE_PULL_REQUEST
     secrets: [ GIT_USERNAME, GIT_TOKEN, LOG_USERNAME, LOG_PASSWORD ]
     when:
       matrix:
-        FLAVOR: Lint
+        FLAVOR: Analysis
         
   notify:
       image: drillster/drone-email
@@ -58,7 +58,7 @@ matrix:
   FLAVOR:
     - Generic
     - Gplay
-    - Lint
+    - Analysis
 
 services:
   server:

+ 11 - 6
build.gradle

@@ -178,10 +178,12 @@ android {
     task findbugs(type: FindBugs) {
         ignoreFailures = false
         effort = "max"
-        reportLevel = "high"
-        classes = files("$project.buildDir/intermediates/classes")
-        excludeFilter = new File("${project.rootDir}/findbugs-filter.xml")
-        source 'src'
+        reportLevel = "medium"
+        classes = fileTree("$project.buildDir/intermediates/classes/gplay/debug/com/owncloud")
+        excludeFilter = file("${project.rootDir}/findbugs-filter.xml")
+        source = fileTree('src/main/java')
+        pluginClasspath = project.configurations.findbugsPlugins
+        classpath = files()
         include '**/*.java'
         exclude '**/gen/**'
 
@@ -189,11 +191,11 @@ android {
             xml.enabled = false
             html.enabled = true
             html {
-                destination  = file("$project.buildDir/reports/findbugs/findbugs.html")
+                destination = file("$project.buildDir/reports/findbugs/findbugs.html")
             }
         }
-        classpath = files()
     }
+
     check.dependsOn 'checkstyle', 'findbugs', 'pmd', 'lint'
 
     compileOptions {
@@ -261,6 +263,9 @@ dependencies {
     implementation 'org.jetbrains:annotations:15.0'
 
     androidTestImplementation 'tools.fastlane:screengrab:1.0.0'
+
+    findbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.4.4'
+    findbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.2'
     
 //    jacocoAnt "org.jacoco:org.jacoco.ant:${jacocoVersion}"
 //    jacocoAgent "org.jacoco:org.jacoco.agent:${jacocoVersion}"

+ 55 - 0
scripts/analysis/analysis-wrapper.sh

@@ -0,0 +1,55 @@
+#!/bin/sh
+
+#1: GIT_USERNAME
+#2: GIT_TOKEN
+#3: BRANCH
+#4: LOG_USERNAME
+#5: LOG_PASSWORD
+#6: DRONE_BUILD_NUMBER
+#7: PULL_REQUEST_NUMBER
+
+ruby scripts/analysis/lint-up.rb $1 $2 $3
+lintValue=$?
+
+./gradlew findbugs
+
+# exit codes:
+# 0: count was reduced
+# 1: count was increased
+# 2: count stayed the same
+
+echo "Branch: $3"
+
+if [ $3 = "master" ]; then
+    echo "New findbugs result for master at: https://nextcloud.kaminsky.me/index.php/s/fYZa7NeBsnmFZQD"
+    curl -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/findbugs/master.html --upload-file build/reports/findbugs/findbugs.html
+    
+    summary=$(sed -n "/<h1>Summary<\/h1>/,/<h1>Warnings<\/h1>/p" build/reports/findbugs/findbugs.html |head -n-1)
+    curl -u $4:$5 -X PUT -d $summary  http://localhost/nc/remote.php/webdav/findbugs/findbugs.html
+    
+    if [ $lintValue -ne 1 ]; then
+        echo "New lint result for master at: https://nextcloud.kaminsky.me/index.php/s/tXwtChzyqMj6I8v"
+        curl -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/droneLogs/master.html --upload-file build/reports/lint/lint.html
+        exit 0
+    fi
+else
+    if [ -e $6 ]; then
+        6="master-"$(date +%F)
+    fi
+    echo "New lint results at https://nextcloud.kaminsky.me/index.php/s/tXwtChzyqMj6I8v ->" $6.html
+    curl -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/droneLogs/$6.html --upload-file build/reports/lint/lint.html
+    
+    echo "New findbugs results at https://nextcloud.kaminsky.me/index.php/s/fYZa7NeBsnmFZQD ->" $6.html
+    curl -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/findbugs/$6.html --upload-file build/reports/findbugs/findbugs.html
+    
+    # add comment with results
+    lintResult="<h1>Lint</h1><table width='500' cellpadding='5' cellspacing='2'><tr class='tablerow0'><td>"$(tail -n1 scripts/analysis/lint-results.txt | cut -f2 -d':' |cut -f1 -d'<')"</td></tr></table>"
+    findbugsResult=$(sed -n "/<h1>Summary<\/h1>/,/<h1>Warnings<\/h1>/p" build/reports/findbugs/findbugs.html |head -n-1 | sed s'/<\/a>//'g | sed s'/<a.*>//'g | sed s'/Summary/FindBugs/' | tr "\"" "\'" | tr -d "\n")
+    curl -u $1:$2 -X POST https://api.github.com/repos/nextcloud/android/issues/$7/comments -d "{ \"body\" : \"$lintResult $findbugsResult \" }"
+    
+    if [ $lintValue -eq 2 ]; then
+        exit 0
+    else
+        exit $lintValue
+    fi  
+fi

+ 0 - 0
scripts/lint/getBranchName.sh → scripts/analysis/getBranchName.sh


+ 0 - 0
scripts/lint/lint-results.txt → scripts/analysis/lint-results.txt


+ 1 - 1
scripts/lint/lint-up.rb → scripts/analysis/lint-up.rb

@@ -21,7 +21,7 @@ TRAVIS_GIT_USERNAME = String.new("Drone CI server")
 LINT_REPORT_FILE = String.new("build/reports/lint/lint.html")
 
 # File name and relative path of previous results of this script.
-PREVIOUS_LINT_RESULTS_FILE=String.new("scripts/lint/lint-results.txt")
+PREVIOUS_LINT_RESULTS_FILE=String.new("scripts/analysis/lint-results.txt")
 
 # Flag to evaluate warnings. true = check warnings; false = ignore warnings
 CHECK_WARNINGS = true

+ 0 - 36
scripts/lint/lint-up-wrapper.sh

@@ -1,36 +0,0 @@
-#!/bin/sh
-
-#1: GIT_USERNAME
-#2: GIT_TOKEN
-#3: BRANCH
-#4: LOG_USERNAME
-#5: LOG_PASSWORD
-#6: DRONE_BUILD_NUMBER
-
-ruby scripts/lint/lint-up.rb $1 $2 $3
-returnValue=$?
-
-# exit codes:
-# 0: count was reduced
-# 1: count was increased
-# 2: count stayed the same
-
-echo "Branch: $3"
-
-if [ $3 = "master" -a $returnValue -ne 1 ]; then
-    echo "New master at: https://nextcloud.kaminsky.me/index.php/s/tXwtChzyqMj6I8v"
-    curl -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/droneLogs/master.html --upload-file build/reports/lint/lint.html
-    exit 0
-else
-    if [ -e $6 ]; then
-        6="master-"$(date +%F)
-    fi
-    echo "New results at https://nextcloud.kaminsky.me/index.php/s/tXwtChzyqMj6I8v ->" $6.html
-    curl -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/droneLogs/$6.html --upload-file build/reports/lint/lint.html
-    
-    if [ $returnValue -eq 2 ]; then
-        exit 0
-    else
-        exit $returnValue
-    fi  
-fi