diff --git a/app/build.gradle b/app/build.gradle index 62163bec0..baa11bd20 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 @@ -82,11 +83,53 @@ 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/**' + + // 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', { @@ -165,4 +208,4 @@ static String getGitWorkingBranch() { // git was not found return "" } -} \ No newline at end of file +} diff --git a/app/src/androidTest/java/org/schabi/newpipe/database/AppDatabaseTest.kt b/app/src/androidTest/java/org/schabi/newpipe/database/AppDatabaseTest.kt index 2b7dcdf7c..917a83bf2 100644 --- a/app/src/androidTest/java/org/schabi/newpipe/database/AppDatabaseTest.kt +++ b/app/src/androidTest/java/org/schabi/newpipe/database/AppDatabaseTest.kt @@ -30,8 +30,9 @@ class AppDatabaseTest { private const val DEFAULT_SECOND_URL = "https://www.youtube.com/watch?v=ncQU6iBn5Fc" } - @get:Rule val testHelper = MigrationTestHelper(InstrumentationRegistry.getInstrumentation(), - AppDatabase::class.java.canonicalName, FrameworkSQLiteOpenHelperFactory()); + @get:Rule + val testHelper = MigrationTestHelper(InstrumentationRegistry.getInstrumentation(), + AppDatabase::class.java.canonicalName, FrameworkSQLiteOpenHelperFactory()) @Test fun migrateDatabaseFrom2to3() { @@ -72,7 +73,7 @@ class AppDatabaseTest { } testHelper.runMigrationsAndValidate(AppDatabase.DATABASE_NAME, Migrations.DB_VER_3, - true, Migrations.MIGRATION_2_3); + true, Migrations.MIGRATION_2_3) val migratedDatabaseV3 = getMigratedDatabase() val listFromDB = migratedDatabaseV3.streamDAO().all.blockingFirst() diff --git a/app/src/androidTest/java/org/schabi/newpipe/report/ErrorInfoTest.java b/app/src/androidTest/java/org/schabi/newpipe/report/ErrorInfoTest.java index 6e51136c0..ab20d2ff3 100644 --- a/app/src/androidTest/java/org/schabi/newpipe/report/ErrorInfoTest.java +++ b/app/src/androidTest/java/org/schabi/newpipe/report/ErrorInfoTest.java @@ -1,8 +1,9 @@ package org.schabi.newpipe.report; import android.os.Parcel; -import androidx.test.filters.LargeTest; + import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.filters.LargeTest; import org.junit.Test; import org.junit.runner.RunWith; @@ -12,15 +13,16 @@ import org.schabi.newpipe.report.ErrorActivity.ErrorInfo; import static org.junit.Assert.assertEquals; /** - * Instrumented tests for {@link ErrorInfo} + * Instrumented tests for {@link ErrorInfo}. */ @RunWith(AndroidJUnit4.class) @LargeTest public class ErrorInfoTest { @Test - public void errorInfo_testParcelable() { - ErrorInfo info = ErrorInfo.make(UserAction.USER_REPORT, "youtube", "request", R.string.general_error); + public void errorInfoTestParcelable() { + ErrorInfo info = ErrorInfo.make(UserAction.USER_REPORT, "youtube", "request", + R.string.general_error); // Obtain a Parcel object and write the parcelable object to it: Parcel parcel = Parcel.obtain(); info.writeToParcel(parcel, 0); @@ -34,4 +36,4 @@ public class ErrorInfoTest { parcel.recycle(); } -} \ No newline at end of file +} diff --git a/app/src/debug/java/org/schabi/newpipe/DebugApp.java b/app/src/debug/java/org/schabi/newpipe/DebugApp.java index 66f73d1e9..4d763aeb1 100644 --- a/app/src/debug/java/org/schabi/newpipe/DebugApp.java +++ b/app/src/debug/java/org/schabi/newpipe/DebugApp.java @@ -3,6 +3,7 @@ package org.schabi.newpipe; import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; + import androidx.annotation.NonNull; import androidx.multidex.MultiDex; @@ -26,7 +27,7 @@ public class DebugApp extends App { private static final String TAG = DebugApp.class.toString(); @Override - protected void attachBaseContext(Context base) { + protected void attachBaseContext(final Context base) { super.attachBaseContext(base); MultiDex.install(this); } diff --git a/app/src/main/java/androidx/fragment/app/FragmentStatePagerAdapterMenuWorkaround.java b/app/src/main/java/androidx/fragment/app/FragmentStatePagerAdapterMenuWorkaround.java index 9fd32b735..11f457b6c 100644 --- a/app/src/main/java/androidx/fragment/app/FragmentStatePagerAdapterMenuWorkaround.java +++ b/app/src/main/java/androidx/fragment/app/FragmentStatePagerAdapterMenuWorkaround.java @@ -38,12 +38,15 @@ import java.util.ArrayList; * This is a copy from {@link androidx.fragment.app.FragmentStatePagerAdapter}. *

* It includes a workaround to fix the menu visibility when the adapter is restored. + *

*

* When restoring the state of this adapter, all the fragments' menu visibility were set to false, - * effectively disabling the menu from the user until he switched pages or another event that triggered the - * menu to be visible again happened. + * effectively disabling the menu from the user until he switched pages or another event + * that triggered the menu to be visible again happened. + *

*

- *
Check out the changes in: + * Check out the changes in: + *

*