repositories {
    mavenCentral()
}

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.0.1x'
    }
}

apply plugin: 'com.android.application'

apply plugin: "jacoco"

apply plugin: 'com.github.kt3k.coveralls'

coveralls.jacocoReportPath = 'build/reports/jacoco/*/*.xml'

android {
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    compileSdkVersion 23
    buildToolsVersion '23.0.2'

    defaultConfig {
        applicationId "it.cosenonjaviste.demomv2m"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 11
        versionName "2.0"
        buildConfigField "String", "CONSUMER_KEY", project.oauth_consumerKey
        buildConfigField "String", "CONSUMER_SECRET", project.oauth_consumerSecret
        buildConfigField "String", "ACCESS_TOKEN", project.oauth_accessToken
        buildConfigField "String", "ACCESS_TOKEN_SECRET", project.oauth_accessTokenSecret
        buildConfigField "String", "MAILJET_USERNAME", project.mailjet_userName
        buildConfigField "String", "MAILJET_PASSWORD", project.mailJetPassword
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    dexOptions {
        preDexLibraries = false
    }
    buildTypes {
        debug {
            testCoverageEnabled true
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/services/javax.annotation.processing.Processor'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'LICENSE.txt'
        exclude 'META-INF/maven/com.google.guava/guava/pom.properties'
        exclude 'META-INF/maven/com.google.guava/guava/pom.xml'
    }
    lintOptions {
        abortOnError false
    }
    sourceSets {
        androidTest.java.srcDirs = ['src/androidTest/java', 'src/sharedTest/java']
        test.java.srcDirs = ['src/test/java', 'src/sharedTest/java']
    }
    dataBinding {
        enabled = true
    }
}

dependencies {
    compile project(':mv2mrx')
    compile project(':mv2mrecycler')
    compile 'com.github.fabioCollini:twowaydatabinding:0.1'
    compile 'com.squareup.okhttp:okhttp:2.4.0'
    compile 'com.android.support:cardview-v7:23.1.1'
    compile 'com.android.support:recyclerview-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'

    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.annimon:stream:1.0.3'

//    debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
    debugCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
    releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'

    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-core:1.9.5'
    testCompile 'org.assertj:assertj-core:1.7.0'

    androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
    androidTestCompile('com.google.dexmaker:dexmaker-mockito:1.2') {
        exclude group: 'org.hamcrest', module: 'hamcrest-core'
    }
    androidTestCompile 'com.android.support.test:runner:0.4'
    androidTestCompile 'com.android.support.test:rules:0.4'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
    androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.1') {
        exclude group: 'com.android.support', module: 'appcompat'
        exclude group: 'com.android.support', module: 'support-v4'
        exclude module: 'recyclerview-v7'
    }
    androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1'
    androidTestCompile 'com.android.support.test.espresso:espresso-web:2.2.1'
}

// Define coverage source.
// If you have rs/aidl etc... add them here.
def coverageSourceDirs = [
        'src/main/java',
        'src/gen'
]

task jacocoUnitTestReport(type: JacocoReport) {
    group = "Reporting"
    description = "Generate Jacoco coverage reports after running tests."
    reports {
        xml.enabled = true // coveralls plugin depends on xml format report
        html.enabled = true
    }
    classDirectories = fileTree(
            dir: './build/intermediates/classes/debug',
            excludes: ['**/R.class',
                       '**/R$*.class',
                       '**/BR.class',
                       '**/BuildConfig.class',
                       'it/cosenonjaviste/demomv2m/databinding/**/*.class',
                       'com/android/**/*.class',
                       'android/**/*.class',
                       '**/*ParcelablePlease.class',
                       'it/cosenonjaviste/demomv2m/ui/**/*.class',
            ])
    sourceDirectories = files(coverageSourceDirs)
    executionData = files('build/jacoco/testDebugUnitTest.exec')
}

task mergeTestCodeCoverageResults(type: JacocoMerge) {
    description = 'Merge test code coverage results from junit and instrumentation test'
    destinationFile = file("build/outputs/code-coverage/merged-coverage.exec")
    doFirst {delete destinationFile}
    executionData = files('build/outputs/code-coverage/connected/coverage.ec', 'build/jacoco/testDebugUnitTest.exec')
}

task jacocoTestReport(type: JacocoReport) {
    group = "Reporting"
    description = "Generates Jacoco coverage reports"
    reports {
        xml.enabled = true
        html.enabled = true
    }
    classDirectories = fileTree(
            dir: 'build/intermediates/classes/debug',
            excludes: ['**/R.class',
                       '**/R$*.class',
                       '**/BR.class',
                       '**/BuildConfig.class',
                       'it/cosenonjaviste/demomv2m/databinding/**/*.class',
                       'com/android/**/*.class',
                       'android/**/*.class',
                       '**/*ParcelablePlease.class'
            ])
    sourceDirectories = files(coverageSourceDirs)
    additionalSourceDirs = files(coverageSourceDirs)
    executionData = files('build/outputs/code-coverage/connected/coverage.ec')
}