From 819e52cab3823c4a8e900f0f5ece87fcb8a34d4c Mon Sep 17 00:00:00 2001 From: wb9688 Date: Fri, 27 Mar 2020 20:45:26 +0100 Subject: [PATCH] Check code style with Checkstyle --- app/build.gradle | 46 +++++++++++- checkstyle.xml | 184 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 229 insertions(+), 1 deletion(-) create mode 100644 checkstyle.xml diff --git a/app/build.gradle b/app/build.gradle index 92c00c372..893885c6d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,6 +2,7 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' +apply plugin: 'checkstyle' android { compileSdkVersion 28 @@ -81,11 +82,54 @@ ext { icepickLibVersion = '3.2.0' stethoLibVersion = '1.5.0' markwonVersion = '4.2.1' + checkstyleVersion = '8.31' } +checkstyle { + configFile rootProject.file('checkstyle.xml') + ignoreFailures false + showViolations true + toolVersion = "${checkstyleVersion}" +} + +task runCheckstyle(type: Checkstyle) { + source 'src' + include '**/*.java' + exclude '**/gen/**' + exclude '**/R.java' + exclude '**/BuildConfig.java' + exclude 'main/java/us/shandian/giga/**' + exclude 'main/java/org/schabi/newpipe/streams/**' + + // empty classpath + classpath = files() + + showViolations true + + reports { + xml.enabled true + html.enabled true + } +} + +tasks.withType(Checkstyle).each { + checkstyleTask -> checkstyleTask.doLast { + reports.all { report -> + def outputFile = report.destination + if (outputFile.exists() && outputFile.text.contains("severity=\"error\"")) { + throw new GradleException("There were checkstyle errors! For more info check $outputFile") + } + } + } +} + +preBuild.dependsOn runCheckstyle + dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation "com.puppycrawl.tools:checkstyle:${checkstyleVersion}" + androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation "android.arch.persistence.room:testing:1.1.1" androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', { @@ -164,4 +208,4 @@ static String getGitWorkingBranch() { // git was not found return "" } -} \ No newline at end of file +} diff --git a/checkstyle.xml b/checkstyle.xml new file mode 100644 index 000000000..8968d57c6 --- /dev/null +++ b/checkstyle.xml @@ -0,0 +1,184 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +