apply plugin: 'com.android.library'
apply plugin: 'jacoco'

android {
    compileSdkVersion 30
    buildToolsVersion '30.0.0'

    useLibrary 'org.apache.http.legacy'

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_6
        targetCompatibility JavaVersion.VERSION_1_6
    }

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 30
        versionCode 40
        versionName "2.9.21"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            testCoverageEnabled false
        }
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            testCoverageEnabled true
        }
    }
    lintOptions {
        abortOnError false
    }
}

jacoco {
    toolVersion = "0.8.5+"
}

repositories {
    mavenCentral()
}

dependencies {
    api 'com.squareup.okhttp3:okhttp:3.11.0'
    api 'com.squareup.okio:okio:1.14.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.parse.bolts:bolts-tasks:1.3.0'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test:rules:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:2.2'
}

task releaseJar(type: Copy, dependsOn: build) {
    delete('build/libs')
    from('build/intermediates/bundles/default')
    into('build/libs')
    include('classes.jar')
    rename('classes.jar', 'aliyun-oss-sdk-android-' + android.defaultConfig.versionName + '.jar')
}

def coverageSourceDirs = [
        './src/main/java',
]
def coverageClassDirs = [
        './build/intermediates/javac/debug/compileDebugJavaWithJavac/classes',
]
task jacocoTestReport(type: JacocoReport) {
    group = "Reporting"
    description = "Generate Jacoco coverage reports after running tests."
    reports {
        xml.enabled = true
        html.enabled = true
    }
    classDirectories.from = files(files(coverageClassDirs).files.collect {
        fileTree(dir: it,
                excludes: ['**/R.class',
                           '**/R$*.class',
                           '**/Manifest*.*'])
    })

    sourceDirectories.from = files(coverageSourceDirs)
    executionData.from = fileTree(dir:'./build/outputs/code-coverage/connected/')

    doFirst {
        new File("build/intermediates/javac/debug/compileDebugJavaWithJavac/classes").eachFileRecurse { file ->
            if (file.name.contains('$$')) {
                file.renameTo(file.path.replace('$$', '$'))
            }
        }
    }
}

ext {
    PUBLISH_ARTIFACT_ID = 'oss-android-sdk'
}
apply from: 'maven-publish.gradle'

