Browse Source

add ktlint

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 5 years ago
parent
commit
90d9600418

+ 0 - 1
.drone.yml

@@ -65,7 +65,6 @@ steps:
       - ./gradlew combinedTestReport
       - curl -o codecov.sh https://codecov.io/bash
       - bash ./codecov.sh -t fc506ba4-33c3-43e4-a760-aada38c24fd5
-        - scripts/uploadArtifact.sh $LOG_USERNAME $LOG_PASSWORD $DRONE_BUILD_NUMBER $DRONE_PULL_REQUEST $GIT_USERNAME $GIT_TOKEN
   - name: notify
     image: drillster/drone-email
     settings:

+ 27 - 7
build.gradle

@@ -37,13 +37,17 @@ apply plugin: 'pmd'
 apply plugin: 'jacoco-android'
 apply plugin: "com.github.spotbugs"
 
-configurations.all {
-    exclude group: 'com.google.firebase', module: 'firebase-core'
-    exclude group: 'com.google.firebase', module: 'firebase-analytics'
-    exclude group: 'com.google.firebase', module: 'firebase-measurement-connector'
+configurations {
+    ktlint
 
-    // check for updates every build
-    resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
+    all {
+        exclude group: 'com.google.firebase', module: 'firebase-core'
+        exclude group: 'com.google.firebase', module: 'firebase-analytics'
+        exclude group: 'com.google.firebase', module: 'firebase-measurement-connector'
+
+        // check for updates every build
+        resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
+    }
 }
 
 ext {
@@ -225,7 +229,7 @@ android {
         }
     }
 
-    check.dependsOn 'checkstyle', 'spotbugs', 'pmd', 'lint'
+    check.dependsOn 'checkstyle', 'spotbugs', 'pmd', 'lint', 'ktlint'
 
     compileOptions {
         sourceCompatibility JavaVersion.VERSION_1_8
@@ -286,6 +290,8 @@ dependencies {
     compileOnly "org.projectlombok:lombok:1.18.8"
     annotationProcessor "org.projectlombok:lombok:1.18.8"
 
+    ktlint "com.pinterest:ktlint:0.32.0"
+
     // dependencies for local unit tests
     testImplementation 'junit:junit:4.12'
     testImplementation 'org.mockito:mockito-core:2.27.0'
@@ -357,3 +363,17 @@ tasks.register("combinedTestReport", JacocoReport) {
         'jacoco/testGplayDebugUnitTest.exec', 'outputs/code-coverage/connected/flavors/GPLAY/*coverage.ec'
     ])
 }
+
+task ktlint(type: JavaExec, group: "verification") {
+    description = "Check Kotlin code style."
+    main = "com.pinterest.ktlint.Main"
+    classpath = configurations.ktlint
+    args "--reporter=plain,output=${buildDir}/ktlint.txt,src/**/*.kt"
+}
+
+task ktlintFormat(type: JavaExec, group: "formatting") {
+    description = "Fix Kotlin code style deviations."
+    main = "com.pinterest.ktlint.Main"
+    classpath = configurations.ktlint
+    args "-F", "src/**/*.kt"
+}

+ 14 - 1
scripts/analysis/analysis-wrapper.sh

@@ -17,6 +17,9 @@ lintValue=$?
 ruby scripts/analysis/findbugs-up.rb $1 $2 $3
 findbugsValue=$?
 
+./gradlew ktlint
+ktlintValue=$?
+
 # exit codes:
 # 0: count was reduced
 # 1: count was increased
@@ -120,6 +123,12 @@ else
         findbugsMessage="<h1>SpotBugs increased!</h1>"
     fi
 
+    if ( [ $ktlintValue -eq 1 ] ) ; then
+        sed -i ':a;N;$!ba;s#\n#<br />#g;s#^<br />##g' build/ktlint.txt
+        curl -u $4:$5 -X PUT https://nextcloud.kaminsky.me/remote.php/webdav/android-ktlint/$6.html --upload-file build/ktlint.txt
+        ktlintMessage="<h1>Kotlin lint found errors</h1><a href='https://www.kaminsky.me/nc-dev/android-ktlint/$6.html'>Lint</a>"
+    fi
+
     # check gplay limitation: all changelog files must only have 500 chars
     gplayLimitation=$(scripts/checkGplayLimitation.sh)
 
@@ -127,7 +136,7 @@ else
         gplayLimitation="<h1>Following files are beyond 500 char limit:</h1><br><br>"$gplayLimitation
     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 \" }"
+    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 $ktlintMessage $gplayLimitation \" }"
 
     if [ ! -z "$gplayLimitation" ]; then
         exit 1
@@ -141,6 +150,10 @@ else
         exit $lintValue
     fi
 
+    if [ $ktlintValue -eq 1 ]; then
+        exit 1
+    fi
+
     if [ $findbugsValue -eq 2 ]; then
         exit 0
     else

+ 2 - 3
src/test/java/com/nextcloud/client/network/ConnectivityServiceTest.kt

@@ -33,7 +33,8 @@ import com.owncloud.android.lib.common.OwnCloudClient
 import com.owncloud.android.lib.resources.status.OwnCloudVersion
 import org.apache.commons.httpclient.HttpStatus
 import org.apache.commons.httpclient.methods.GetMethod
-import org.junit.Assert.*
+import org.junit.Assert.assertFalse
+import org.junit.Assert.assertTrue
 import org.junit.Before
 import org.junit.Test
 import org.junit.runner.RunWith
@@ -194,7 +195,6 @@ class ConnectivityServiceTest {
             verify(requestBuilder).invoke(urlCaptor.capture())
             assertTrue("Invalid URL used to check status", urlCaptor.value.endsWith("/status.php"))
         }
-
     }
 
     internal class WifiConnectionWalledStatus : Base() {
@@ -234,5 +234,4 @@ class ConnectivityServiceTest {
             assertTrue("Invalid URL used to check status", urlCaptor.value.endsWith("/index.php/204"))
         }
     }
-
 }