buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
        jcenter()
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
        classpath 'com.dicedmelon.gradle:jacoco-android:0.1.2'
    }
}
apply plugin: "com.android.application"
apply plugin: "io.fabric"
apply plugin: "jacoco-android"
apply plugin: 'com.jakewharton.butterknife'

ext {
    supportLibraryVersion = "27.0.2"
    ormLiteVersion = "4.46"
    powermockVersion = "1.7.3"
    dexmakerVersion = "1.2"
}


repositories {
    maven { url 'https://maven.fabric.io/public' }
}

def generateGitBuild = { ->

    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append('"')
    try {
        def stdout = new ByteArrayOutputStream()
        exec {
            commandLine 'git', 'describe', '--always'
            standardOutput = stdout
        }
        String commitObject = stdout.toString().trim()
        stringBuilder.append(commitObject)
    } catch (ignored) {
        stringBuilder.append('NoGitSystemAvailable')
    }
    stringBuilder.append('-')
    stringBuilder.append((new Date()).format('yyyy.MM.dd'))
    stringBuilder.append('"')
    return stringBuilder.toString()
}

android {
    compileSdkVersion 27
    buildToolsVersion "${supportLibraryVersion}"

    defaultConfig {
        applicationId "info.nightscout.androidaps"
        minSdkVersion 21
        targetSdkVersion 23
        multiDexEnabled true
        versionCode 1500
        version "1.57-combo-csv2-beta"
        buildConfigField "String", "VERSION", '"' + version + '"'
        buildConfigField "String", "BUILDVERSION", generateGitBuild()

        ndk {
            moduleName "BleCommandUtil"
        }
    }
    lintOptions {
        // TODO remove once wear dependency com.google.android.gms:play-services-wearable:7.3.0
        // has been upgraded (requiring significant code changes), which currently fails release
        // build with a deprecation warning
        //abortOnError false
        // (disabled entirely to avoid reports on the error, which would still be displayed
        //  and it's easy to overlook that it's ignored)
        checkReleaseBuilds false
        disable 'MissingTranslation'
        disable 'ExtraTranslation'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            testCoverageEnabled true
        }
    }
    productFlavors {
        flavorDimensions "standard"
        full {
            dimension "standard"
            resValue "string", "app_name", "AndroidAPS"
            versionName version
            manifestPlaceholders = [
                    appIcon: "@mipmap/blueowl"
            ]
            buildConfigField "boolean", "APS", "true"
            buildConfigField "boolean", "PUMPDRIVERS", "true"
            buildConfigField "boolean", "NSCLIENTOLNY", "false"
            buildConfigField "boolean", "CLOSEDLOOP", "true"
            buildConfigField "boolean", "G5UPLOADER", "false"
            buildConfigField "boolean", "PUMPCONTROL", "false"
        }
        openloop {
            dimension "standard"
            resValue "string", "app_name", "AndroidAPS"
            versionName version
            manifestPlaceholders = [
                    appIcon: "@mipmap/blueowl"
            ]
            buildConfigField "boolean", "APS", "true"
            buildConfigField "boolean", "PUMPDRIVERS", "true"
            buildConfigField "boolean", "NSCLIENTOLNY", "false"
            buildConfigField "boolean", "CLOSEDLOOP", "false"
            buildConfigField "boolean", "G5UPLOADER", "false"
            buildConfigField "boolean", "PUMPCONTROL", "false"
        }
        pumpcontrol {
            dimension "standard"
            resValue "string", "app_name", "AndroidAPS"
            versionName version
            manifestPlaceholders = [
                    appIcon: "@mipmap/blueowl"
            ]
            buildConfigField "boolean", "APS", "false"
            buildConfigField "boolean", "PUMPDRIVERS", "true"
            buildConfigField "boolean", "NSCLIENTOLNY", "false"
            buildConfigField "boolean", "CLOSEDLOOP", "false"
            buildConfigField "boolean", "G5UPLOADER", "false"
            buildConfigField "boolean", "PUMPCONTROL", "true"
        }
        nsclient {
            dimension "standard"
            resValue "string", "app_name", "NSClient"
            versionName version + "-nsclient"
            manifestPlaceholders = [
                    appIcon: "@mipmap/yellowowl"
            ]
            buildConfigField "boolean", "APS", "false"
            buildConfigField "boolean", "PUMPDRIVERS", "false"
            buildConfigField "boolean", "NSCLIENTOLNY", "true"
            buildConfigField "boolean", "CLOSEDLOOP", "false"
            buildConfigField "boolean", "G5UPLOADER", "false"
            buildConfigField "boolean", "PUMPCONTROL", "false"
        }
        g5uploader {
            dimension "standard"
            resValue "string", "app_name", "NSClient"
            versionName version + "-nsclient"
            manifestPlaceholders = [
                    appIcon: "@mipmap/yellowowl"
            ]
            buildConfigField "boolean", "APS", "false"
            buildConfigField "boolean", "PUMPDRIVERS", "false"
            buildConfigField "boolean", "NSCLIENTOLNY", "false"
            buildConfigField "boolean", "CLOSEDLOOP", "false"
            buildConfigField "boolean", "G5UPLOADER", "true"
            buildConfigField "boolean", "PUMPCONTROL", "false"
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    testOptions {
        unitTests.returnDefaultValues = true
    }
}

allprojects {
    repositories {
        jcenter()
        flatDir {
            dirs 'libs'
        }
    }
}

dependencies {
    wearApp project(':wear')

    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile("com.crashlytics.sdk.android:crashlytics:2.6.7@aar") {
        transitive = true;
    }
    compile("com.crashlytics.sdk.android:answers:1.3.12@aar") {
        transitive = true;
    }

    compile "com.android.support:appcompat-v7:${supportLibraryVersion}"
    compile "com.android.support:support-v4:${supportLibraryVersion}"
    compile "com.android.support:cardview-v7:${supportLibraryVersion}"
    compile "com.android.support:recyclerview-v7:${supportLibraryVersion}"
    compile "com.android.support:gridlayout-v7:${supportLibraryVersion}"
    compile "com.android.support:design:${supportLibraryVersion}"
    compile "com.android.support:percent:${supportLibraryVersion}"
    compile "com.wdullaer:materialdatetimepicker:2.3.0"
    compile "com.squareup:otto:1.3.7"
    compile "com.j256.ormlite:ormlite-core:${ormLiteVersion}"
    compile "com.j256.ormlite:ormlite-android:${ormLiteVersion}"
    compile("com.github.tony19:logback-android-classic:1.1.1-6") {
        exclude group: "com.google.android", module: "android"
    }
    compile "org.apache.commons:commons-lang3:3.6"
    compile "org.slf4j:slf4j-api:1.7.12"
    compile "com.jjoe64:graphview:4.0.1"
    compile "com.joanzapata.iconify:android-iconify-fontawesome:2.1.1"
    compile "com.google.android.gms:play-services-wearable:7.5.0"
    compile(name: "android-edittext-validator-v1.3.4-mod", ext: "aar")
    compile("com.google.android:flexbox:0.3.0") {
        exclude group: "com.android.support"
    }
    compile("io.socket:socket.io-client:0.8.3") {
        // excluding org.json which is provided by Android
        exclude group: "org.json", module: "json"
    }
    compile "com.google.code.gson:gson:2.7"
    compile "com.google.guava:guava:20.0"

    compile "net.danlew:android.joda:2.9.9.1"

    api "com.jakewharton:butterknife:8.8.1"
    annotationProcessor "com.jakewharton:butterknife-compiler:8.8.1"

    testCompile "junit:junit:4.12"
    testCompile "org.json:json:20140107"
    testCompile "org.mockito:mockito-core:2.7.22"
    testCompile "org.powermock:powermock-api-mockito2:${powermockVersion}"
    testCompile "org.powermock:powermock-module-junit4-rule-agent:${powermockVersion}"
    testCompile "org.powermock:powermock-module-junit4-rule:${powermockVersion}"
    testCompile "org.powermock:powermock-module-junit4:${powermockVersion}"
    testCompile "joda-time:joda-time:2.9.4.2"

    androidTestCompile "org.mockito:mockito-core:2.7.22"
    androidTestCompile "com.google.dexmaker:dexmaker:${dexmakerVersion}"
    androidTestCompile "com.google.dexmaker:dexmaker-mockito:${dexmakerVersion}"
}