buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
    }
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    defaultConfig {
        applicationId "com.gh0u1l5.wechatmagician"
        minSdkVersion 21
        maxSdkVersion 27
        targetSdkVersion 27
    }
    lintOptions {
        abortOnError false
        checkReleaseBuilds false
    }
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
        test.java.srcDirs += 'src/test/kotlin'
        androidTest.java.srcDirs += "src/androidTest/kotlin"
    }
    android.applicationVariants.all { variant ->
        variant.javaCompiler.dependsOn(generatePluginList)
        variant.outputs.all {
            outputFileName = "${rootProject.name}-${variant.buildType.name}.apk"
        }
    }
}

repositories {
    google()
    jcenter()
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    //noinspection GradleDependency
    compileOnly 'de.robv.android.xposed:api:53'
    compileOnly 'de.robv.android.xposed:api:53:sources'

    implementation project(':spellbook')
    implementation 'com.github.kittinunf.fuel:fuel-android:1.13.0'
    implementation 'me.leolin:ShortcutBadger:1.1.19@aar'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}

task generatePluginList() {
    def PLUGIN_DIR = "src/main/kotlin/com/gh0u1l5/wechatmagician/backend/plugins/"
    def PLUGIN_LIST_FILE = "src/main/kotlin/com/gh0u1l5/wechatmagician/backend/WechatPlugins.kt"

    def plugins = fileTree(PLUGIN_DIR).collect { file ->
        file.name.substring(0, file.name.length() - 3)
    }.sort()
    file(PLUGIN_LIST_FILE).text = """package com.gh0u1l5.wechatmagician.backend

import com.gh0u1l5.wechatmagician.backend.plugins.*

/**
 * Dynamically generated by build.gradle
 */
val WechatPlugins = listOf(${plugins.join(", ")})
"""
}