buildscript {
    repositories {
        maven {
            url "https://repo1.maven.org/maven2"
            jcenter()
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
        classpath files('libs/gradle-witness.jar')
    }
}

apply plugin: 'com.android.application'
apply plugin: 'witness'

repositories {
    maven {
        url "https://repo1.maven.org/maven2/"
    }
    maven {
        url "https://raw.github.com/whispersystems/maven/master/preferencefragment/releases/"
    }
    maven {
        url "https://raw.github.com/whispersystems/maven/master/smil/releases/"
    }
    maven {
        url "https://raw.github.com/whispersystems/maven/master/photoview/releases/"
    }
    maven {
        url "https://raw.github.com/whispersystems/maven/master/shortcutbadger/releases/"
    }
    maven { // textdrawable
        url 'https://dl.bintray.com/amulyakhare/maven'
    }
    jcenter()
    mavenLocal()
}

dependencies {
    compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'com.android.support:recyclerview-v7:25.1.0'
    compile 'com.android.support:design:25.1.0'
    compile 'com.android.support:support-v13:25.1.0'
    compile 'com.android.support:cardview-v7:25.1.0'
    compile ('com.android.support:support-v4-preferencefragment:1.0.0@aar'){
        exclude module: 'support-v4'
    }
    compile ('com.android.support:gridlayout-v7:25.1.0') {
        exclude module: 'support-v4'
    }
    compile 'com.android.support:multidex:1.0.1'

    compile 'com.google.android.gms:play-services-gcm:9.6.1'
    compile 'com.google.android.gms:play-services-maps:9.6.1'
    compile 'com.google.android.gms:play-services-places:9.6.1'

    compile 'org.whispersystems:jobmanager:1.0.2'
    compile 'org.whispersystems:libpastelog:1.0.7'
    compile 'org.whispersystems:signal-service-android:2.4.7'

    compile "me.leolin:ShortcutBadger:1.10-WS1"
    compile 'se.emilsjolander:stickylistheaders:2.7.0'
    compile 'com.jpardogo.materialtabstrip:library:1.0.9'
    compile 'org.w3c:smil:1.0.0'
    compile 'org.apache.httpcomponents:httpclient-android:4.3.5'
    compile 'com.github.chrisbanes.photoview:library:1.3.1'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.makeramen:roundedimageview:2.1.0'
    compile 'com.pnikosis:materialish-progress:1.5'
    compile 'de.greenrobot:eventbus:2.4.0'
    compile 'pl.tajchert:waitingdots:0.1.0'
    compile 'com.soundcloud.android:android-crop:0.9.10@aar'
    compile 'com.melnykov:floatingactionbutton:1.3.0'
    compile 'com.google.zxing:android-integration:3.1.0'
    compile 'com.squareup.dagger:dagger:1.2.2'
    compile ("com.doomonafireball.betterpickers:library:1.5.3") {
        exclude group: 'com.android.support', module: 'support-v4'
    }
    compile 'com.madgag.spongycastle:prov:1.51.0.0'
    provided 'com.squareup.dagger:dagger-compiler:1.2.2'
    compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
    compile 'com.h6ah4i.android.compat:mulsellistprefcompat:1.0.0'
    compile 'com.google.zxing:core:3.2.1'
    compile ('com.davemorrissey.labs:subsampling-scale-image-view:3.6.0') {
        exclude group: 'com.android.support', module: 'support-annotations'
    }
    compile ('cn.carbswang.android:NumberPickerView:1.0.9') {
        exclude group: 'com.android.support', module: 'appcompat-v7'
    }

    testCompile 'junit:junit:4.12'
    testCompile 'org.assertj:assertj-core:1.7.1'
    testCompile 'org.mockito:mockito-core:1.9.5'
    testCompile 'org.powermock:powermock-api-mockito:1.6.1'
    testCompile 'org.powermock:powermock-module-junit4:1.6.1'
    testCompile 'org.powermock:powermock-module-junit4-rule:1.6.1'
    testCompile 'org.powermock:powermock-classloading-xstream:1.6.1'

    androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
    androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
    androidTestCompile ('org.assertj:assertj-core:1.7.1') {
        exclude group: 'org.hamcrest', module: 'hamcrest-core'
    }
    androidTestCompile ('com.squareup.assertj:assertj-android:1.1.1') {
        exclude group: 'org.hamcrest',        module: 'hamcrest-core'
        exclude group: 'com.android.support', module: 'support-annotations'
    }
}

dependencyVerification {
    verify = [
        'com.android.support:appcompat-v7:b48bfd5efc14da938ba0647f9894aa7d3d90f0b618167652a318f6f336ef303e',
        'com.android.support:recyclerview-v7:45beed1778f785c75540b68aa7735b8973a518ac21e8d763188dbbdae6c5b65d',
        'com.android.support:design:92466557dc6a222bbff361801b26979573cb7086119331e78c74a2df34d5e11e',
        'com.android.support:support-v13:deeb43c2878025f2a0485791f66b5f59a1c6a4c6671c6ad7bb20abfeffaa313f',
        'com.android.support:cardview-v7:cd6f472f130a75f029cd1b7c56f72174023d56a2eee2b97577837fe39169d5df',
        'com.android.support:support-v4-preferencefragment:5470f5872514a6226fa1fc6f4e000991f38805691c534cf0bd2778911fc773ad',
        'com.android.support:gridlayout-v7:c24f2aa68089fd31b39811bc502e24637a6a8cc29bbf709cda4f4605047c9e11',
        'com.android.support:multidex:60df8e7153fabdcf3a6a48a2ce5980b599cf25cbeb3b689b7b615975ca731840',
        'com.google.android.gms:play-services-gcm:312e61253a236f2d9b750b9c04fc92fd190d23b0b2755c99de6ce4a28b259dae',
        'com.google.android.gms:play-services-maps:45e8021e7ddac4a44a82a0e9698991389ded3023d35c58f38dbd86d54211ec0e',
        'com.google.android.gms:play-services-places:abf3a4a3b146ec7e6e753be62775e512868cf37d6f88ffe2d81167b33b57132b',
        'org.whispersystems:jobmanager:506f679fc2fcf7bb6d10f00f41d6f6ea0abf75c70dc95b913398661ad538a181',
        'org.whispersystems:libpastelog:bb331d9a98240fc139101128ba836c1edec3c40e000597cdbb29ebf4cbf34d88',
        'org.whispersystems:signal-service-android:0b5e607c1ffdbc90f8b1117c43ceaba62e3e19c01c8d29b3e1bf57cffce07f2b',
        'me.leolin:ShortcutBadger:e8e39df8a59d8211a30f40b1eeab21b3fa57b3f3e0f03abb995f82d66588778c',
        'se.emilsjolander:stickylistheaders:a08ca948aa6b220f09d82f16bbbac395f6b78897e9eeac6a9f0b0ba755928eeb',
        'com.jpardogo.materialtabstrip:library:c6ef812fba4f74be7dc4a905faa4c2908cba261a94c13d4f96d5e67e4aad4aaa',
        'org.w3c:smil:085dc40f2bb249651578bfa07499fd08b16ad0886dbe2c4078586a408da62f9b',
        'org.apache.httpcomponents:httpclient-android:6f56466a9bd0d42934b90bfbfe9977a8b654c058bf44a12bdc2877c4e1f033f1',
        'com.github.chrisbanes.photoview:library:f152dd0a87aca891aa182e42863fa05e0e8b2842e3b9fc512d7a3a6243c38ac4',
        'com.github.bumptech.glide:glide:76ef123957b5fbaebb05fcbe6606dd58c3bc3fcdadb257f99811d0ac9ea9b88b',
        'com.makeramen:roundedimageview:1f5a1865796b308c6cdd114acc6e78408b110f0a62fc63553278fbeacd489cd1',
        'com.pnikosis:materialish-progress:d71d80e00717a096784482aee21001a9d299fec3833e4ebd87739ed36cf77c54',
        'de.greenrobot:eventbus:61d743a748156a372024d083de763b9e91ac2dcb3f6a1cbc74995c7ddab6e968',
        'pl.tajchert:waitingdots:2835d49e0787dbcb606c5a60021ced66578503b1e9fddcd7a5ef0cd5f095ba2c',
        'com.soundcloud.android:android-crop:ffd4b973cf6e97f7d64118a0dc088df50e9066fd5634fe6911dd0c0c5d346177',
        'com.melnykov:floatingactionbutton:15d58d4fac0f7a288d0e5301bbaf501a146f5b3f5921277811bf99bd3b397263',
        'com.google.zxing:android-integration:89e56aadf1164bd71e57949163c53abf90af368b51669c0d4a47a163335f95c4',
        'com.squareup.dagger:dagger:789aca24537022e49f91fc6444078d9de8f1dd99e1bfb090f18491b186967883',
        'com.doomonafireball.betterpickers:library:132ecd685c95a99e7377c4e27bfadbb2d7ed0bea995944060cd62d4369fdaf3d',
        'com.madgag.spongycastle:prov:b8c3fec3a59aac1aa04ccf4dad7179351e54ef7672f53f508151b614c131398a',
        'com.amulyakhare:com.amulyakhare.textdrawable:54c92b5fba38cfd316a07e5a30528068f45ce8515a6890f1297df4c401af5dcb',
        'com.h6ah4i.android.compat:mulsellistprefcompat:47167c5cb796de1a854788e9ff318358e36c8fb88123baaa6e38fb78511dfabe',
        'com.google.zxing:core:b4d82452e7a6bf6ec2698904b332431717ed8f9a850224f295aec89de80f2259',
        'com.davemorrissey.labs:subsampling-scale-image-view:550c5baa07e0bb4ff0a18b705e96d34436d22619248bd8c08c08c730b1f55cfe',
        'cn.carbswang.android:NumberPickerView:18b3c316d62c7c277978a8d4ed57a5b8f4e943762264960f579a8a549c756729',
        'com.android.support:support-annotations:fb941680f43afbd70ce01ec3cc837a5037f0a774701b12a9fd3090bd4727cf15',
        'com.android.support:support-v4:ed4cda7c752f51d33f9bbdfff3422b425b323d356cd1bdc9786aa413c912e594',
        'com.android.support:support-vector-drawable:2697503d3e8e709023ae176ba5db7f98ca0aa0b4e6290aedcb3c371904806bf7',
        'com.android.support:animated-vector-drawable:6d05cb63d1f68900220f85c56dfe1066a9bb19cb0ec1247cc68fc2ba32f6b4a7',
        'com.android.support:support-compat:e880fb1209c33fcb43e2b25716808e1a6e0b4d3170d5a8dc7704e15084428f88',
        'com.android.support:support-core-ui:0149b54fd3bc9f4b3b2d321ff53c11821b31a2eca1e664d0cee224e8f53073d6',
        'com.android.support:transition:cf53f778352fe0b74ff14d838bef9fe79264f3fd43eac499b6e0d1664dbd8997',
        'com.google.android.gms:play-services-base:0ca636a8fc9a5af45e607cdcd61783bf5d561cbbb0f862021ce69606eee5ad49',
        'com.google.android.gms:play-services-basement:95dd882c5ffba15b9a99de3fefb05d3a01946623af67454ca00055d222f85a8d',
        'com.google.android.gms:play-services-iid:54e919f9957b8b7820da7ee9b83471d00d0cac1cf08ddea8b5b41aea80bb1a70',
        'org.whispersystems:signal-protocol-android:1b4b9d557c8eaf861797ff683990d482d4aa8e9f23d9b17ff0cc67a02f38cb19',
        'org.whispersystems:signal-service-java:9738c26c17069a2f1eff47a46da5df62efa875bd66321933bed78f2584b7cc70',
        'com.nineoldandroids:library:68025a14e3e7673d6ad2f95e4b46d78d7d068343aa99256b686fe59de1b3163a',
        'javax.inject:javax.inject:91c77044a50c481636c32d916fd89c9118a72195390452c81065080f957de7ff',
        'com.madgag.spongycastle:core:8d6240b974b0aca4d3da9c7dd44d42339d8a374358aca5fc98e50a995764511f',
        'com.google.android.gms:play-services-tasks:69ec265168e601d0203d04cd42e34bb019b2f029aa1e16fabd38a5153eea2086',
        'org.whispersystems:curve25519-android:bf6c34223d45d2f2813a8efcab9923caf99115115c760c9acea680bcb42d23c0',
        'org.whispersystems:signal-protocol-java:a835cd0609cf116a74651bd0aa748db9392bba48c2d2af787757b8a1b50d131c',
        'com.googlecode.libphonenumber:libphonenumber:7214dc6dfc6243e34fb1a3e02ad15331bfff6ab902d679e3ba337695265c21ca',
        'com.google.protobuf:protobuf-java:e0c1c64575c005601725e7c6a02cebf9e1285e888f756b2a1d73ffa8d725cc74',
        'com.fasterxml.jackson.core:jackson-databind:835097bcdd11f5bc8a08378c70d4c8054dfa4b911691cc2752063c75534d198d',
        'com.squareup.okhttp3:okhttp:eecd834b09d12c3cd568b811522b97012619f7f00378c3c719a1957fac6458ef',
        'org.whispersystems:curve25519-java:00f1d4919f759055f41f7853a3d475dc7c8decf0dbf045ae93414f8f23b066cc',
        'com.fasterxml.jackson.core:jackson-annotations:0ca408c24202a7626ec8b861e99d85eca5e38b73311dd6dd12e3e9deecc3fe94',
        'com.fasterxml.jackson.core:jackson-core:cbf4604784b4de226262845447a1ad3bb38a6728cebe86562e2c5afada8be2c0',
        'com.squareup.okio:okio:8c5436cadfab36bbd97db5f5c43b7bfdb5bf2f5f894ec8709b1929f14bdd010c',
        'com.android.support:support-media-compat:8d6a1a5ba3d9eb1a25cb8f21bb312ac6280202e3d2900cb0b447d065d0d8a125',
        'com.android.support:support-core-utils:a7649e18c04143dde40c218c5ce9a030e7ae674089cd7b18c6cf8ed2a22cf01a',
        'com.android.support:support-fragment:1294500b357f52cf3779e2521c79f54ae7844f3b9a5f6727495dbbda7f231377',
    ]
}

android {
    compileSdkVersion 25
    buildToolsVersion '23.0.3'
    useLibrary 'org.apache.http.legacy'

    dexOptions {
        javaMaxHeapSize "4g"
    }

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 22
        multiDexEnabled true

        vectorDrawables.useSupportLibrary = true

        buildConfigField "long", "BUILD_TIMESTAMP", getLastCommitTimestamp() + "L"
        buildConfigField "String", "SIGNAL_URL", "\"https://textsecure-service.whispersystems.org\""
        buildConfigField "String", "GIPHY_PROXY_HOST", "\"giphy-proxy-production.whispersystems.org\""
        buildConfigField "int", "GIPHY_PROXY_PORT", "80"
        buildConfigField "String", "USER_AGENT", "\"OWA\""
        buildConfigField "String", "REDPHONE_MASTER_URL", "\"https://redphone-master.whispersystems.org\""
        buildConfigField "String", "REDPHONE_RELAY_HOST", "\"relay.whispersystems.org\""
        buildConfigField "String", "REDPHONE_PREFIX_NAME", "\".whispersystems.org\""
        buildConfigField "boolean", "DEV_BUILD", "false"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    packagingOptions {
        exclude 'LICENSE.txt'
        exclude 'LICENSE'
        exclude 'NOTICE'
        exclude 'asm-license.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }

    signingConfigs {
        release
    }

    buildTypes {
        debug {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'),
                          'proguard-google-play-services.pro',
                          'proguard-dagger.pro',
                          'proguard-jackson.pro',
                          'proguard-sqlite.pro',
                          'proguard-appcompat-v7.pro',
                          'proguard-square-okhttp.pro',
                          'proguard-square-okio.pro',
                          'proguard-spongycastle.pro',
                          'proguard-rounded-image-view.pro',
                          'proguard-glide.pro',
                          'proguard-shortcutbadger.pro',
                          'proguard-retrofit.pro',
                          'proguard.cfg'
            testProguardFiles 'proguard-automation.pro',
                          'proguard.cfg'
        }
        release {
            minifyEnabled true
            proguardFiles = buildTypes.debug.proguardFiles
            signingConfig signingConfigs.release
        }
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['libs']
        }
        androidTest {
            java.srcDirs = ['test/androidTest/java']
        }
        test {
            java.srcDirs = ['test/unitTest/java']
        }
    }

     lintOptions {
        abortOnError false
    }
}

tasks.whenTaskAdded { task ->
    if (task.name.equals("lint")) {
        task.enabled = false
    }
}

def getLastCommitTimestamp() {
    new ByteArrayOutputStream().withStream { os ->
        def result = exec {
            executable = 'git'
            args = ['log', '-1', '--pretty=format:%ct']
            standardOutput = os
        }

        return os.toString() + "000"
    }
}

def Properties props = new Properties()
def propFile = new File('signing.properties')

if (propFile.canRead()){
    props.load(new FileInputStream(propFile))

    if (props !=null &&
        props.containsKey('STORE_FILE')     &&
        props.containsKey('STORE_PASSWORD') &&
        props.containsKey('KEY_ALIAS')      &&
        props.containsKey('KEY_PASSWORD'))
    {
        android.signingConfigs.release.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.release.storePassword = props['STORE_PASSWORD']
        android.signingConfigs.release.keyAlias = props['KEY_ALIAS']
        android.signingConfigs.release.keyPassword = props['KEY_PASSWORD']
    } else {
        println 'signing.properties found but some entries are missing'
        android.buildTypes.release.signingConfig = null
    }
}else {
    println 'signing.properties not found'
    android.buildTypes.release.signingConfig = null
}