//import com.github.spotbugs.SpotBugsTask

/*
 * Copyright 2017 Adam Feinstein
 *
 * This file is part of MTG Familiar.
 *
 * MTG Familiar is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * MTG Familiar is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with MTG Familiar.  If not, see <http://www.gnu.org/licenses/>.
 */

apply plugin: 'com.android.application'
apply plugin: 'pmd'
apply plugin: 'checkstyle'
//apply plugin: 'com.github.spotbugs'

check.dependsOn 'pmdMain', 'checkstyleMain' //, 'spotbugsMain'

def configDir = "${project.rootDir}/config"

repositories {
    maven { url 'https://jitpack.io' }
}
//sourceSets {
//    // we define `main` sourceSet here, so SpotBugs Gradle Plugin generates `spotbugsMain` task
//    main {
//        java.srcDirs = ['src/main/java']
//    }
//}
//
//task compileJava(overwrite: true) {
//    dependsOn 'compileDebugJavaWithJavac'
//    group = "build"
//}
//
//spotbugs {
//    toolVersion = '3.1.9'
//    ignoreFailures = true
//    effort = "max"
//    reportLevel = "high"
//    excludeFilter = new File("$configDir/findbugs/findbugs.filter.xml")
//}
//
//tasks.withType(SpotBugsTask) {
//    dependsOn 'assembleDebug'
//    group = "verification"
//
//    classes = files("${project.rootDir}/mobile/build/intermediates/javac")
//    ignoreFailures = true
//
//    // configure automatically generated tasks
//    reports {
//        xml.enabled = false
//        html.enabled = true
//        html {
//            destination file("$project.buildDir/reports/spotbugs.html")
//        }
//    }
//}

tasks.register('checkstyleMain', Checkstyle) {
    ignoreFailures = true
    configFile file("$configDir/checkstyle/checkstyle.xml")
    configProperties.checkstyleSuppressionsPath = file("$configDir/checkstyle/suppressions.xml").absolutePath
    source 'src'
    include '**/*.java'
    exclude '**/gen/**'
    classpath = files()
}

tasks.register('pmdMain', Pmd) {
    ignoreFailures = true
    ruleSetFiles = files("$configDir/pmd/pmd.xml")
    reports {
        html {
            destination file("$project.buildDir/reports/pmd.html")
        }
    }
    source 'src'
    include '**/*.java'
    exclude '**/gen/**'
}

def gitVersion = providers.exec {
    commandLine("git", "rev-parse", "--short", "HEAD")
}.standardOutput.asText.get().trim()

android {
    compileSdk 35
    defaultConfig {
        applicationId "com.gelakinetic.mtgfam"
        minSdkVersion 21
        targetSdk 35
        versionCode 96
        versionName "3.9.13"
        vectorDrawables.useSupportLibrary true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        archivesBaseName = "$applicationId" + "_$versionName" + "_" + "$gitVersion"
    }
    signingConfigs {
        release {
            storeFile file(System.getenv("SIGNING_KEY_STORE_PATH"))
            storePassword System.getenv('SIGNING_STORE_PASSWORD')
            keyAlias System.getenv('SIGNING_KEY_ALIAS')
            keyPassword System.getenv('SIGNING_KEY_PASSWORD')
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
            //findbugs
        }
        debug {
            minifyEnabled false
            debuggable true
            applicationIdSuffix '.debug'
            versionNameSuffix '-DEBUG'
        }
    }
    packagingOptions {
        jniLibs {
            excludes += ['META-INF/*']
        }
        resources {
            excludes += ['META-INF/*']
        }
    }
    compileOptions {
        // Flag to enable support for the new language APIs
        coreLibraryDesugaringEnabled true
        encoding "UTF-8"
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    lint {
        abortOnError false
        disable 'MissingTranslation'
    }
    namespace 'com.gelakinetic.mtgfam'
    buildFeatures {
        buildConfig true
    }
    dependenciesInfo {
        // Disables dependency metadata when building APKs.
        includeInApk = false
        // Disables dependency metadata when building Android App Bundles.
        includeInBundle = false
    }
}

dependencies {
// Desugar to make APIs backwards compatible
    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs_nio:2.1.5'

// AndroidX
    annotationProcessor 'androidx.annotation:annotation:1.9.1'
    implementation 'androidx.appcompat:appcompat:1.7.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.fragment:fragment:1.8.6'
    implementation 'androidx.gridlayout:gridlayout:1.0.0'
    implementation 'com.google.android.material:material:1.12.0'

// Third-party
    implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
    implementation 'com.github.castorflex.smoothprogressbar:library:1.1.0'
    implementation 'com.github.woxthebox:draglistview:1.7.3'
    implementation 'org.jetbrains:annotations:26.0.2'
    implementation 'com.google.code.gson:gson:2.12.1'
    implementation 'com.jpardogo.materialtabstrip:library:1.1.1'
    implementation 'com.code-troopers.betterpickers:library:3.1.0'
    implementation 'com.github.machinarius:preferencefragment:0.1.2'
    implementation 'org.jsoup:jsoup:1.19.1'
    implementation 'com.splitwise:tokenautocomplete:3.0.2'
    implementation 'com.google.code.findbugs:annotations:3.0.1', {
        // Need to exclude these, or build is broken by:
        //   com.android.dex.DexException: Multiple dex files define Ljavax/annotation/CheckForNull
        exclude module: 'jsr305'
        exclude module: 'jcip-annotations'
    }

    implementation 'com.github.bumptech.glide:glide:4.16.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.16.0'

    implementation 'io.reactivex.rxjava2:rxjava:2.2.21'
    implementation 'com.nytimes.android:cache3:3.1.1', {
        exclude module: 'jsr305'
        exclude module: 'jcip-annotations'
        exclude module: 'rxjava'
    }
    implementation 'com.nytimes.android:store3:3.1.1', {
        exclude module: 'jsr305'
        exclude module: 'jcip-annotations'
        exclude module: 'rxjava'
    }

// Testing
    androidTestImplementation 'androidx.test:runner:1.6.2'
    androidTestImplementation 'androidx.test:rules:1.6.1'

    // Optional -- Hamcrest library
    androidTestImplementation 'org.hamcrest:hamcrest-library:3.0'
    testImplementation 'junit:junit:4.13.2'
    testImplementation 'org.mockito:mockito-core:5.16.1'

// Spotbugs
    // spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.10.1'
    // spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.7'
}
java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(17)
    }
}
