/**
 * Instructions for uploading to bintray:
 * 1) Increment libraryVerison and versionCode
 * 2) gradlew install
 * 3) gradlew bintrayUpload
 */

apply plugin: 'com.android.library'

ext {
    bintrayRepo = 'maven'
    bintrayName = 'FFmpegVideoRecorder'

    publishedGroupId = 'com.amosyuen.ffmpegvideorecorder'
    artifact = 'ffmpeg-video-recorder'
    libraryName = 'FFmpegVideoRecorder'

    libraryDescription = 'Customizable Video Recording Library for Android'

    siteUrl = 'https://github.com/amosyuen/FFmpegVideoRecorder'
    gitUrl = 'https://github.com/amosyuen/FFmpegVideoRecorder.git'

    libraryVersion = '2.0.3'
    versionCode = 12

    developerId = 'amosyuen'
    developerName = 'Amos Yuen'
    developerEmail = 'amosyuen@gmail.com'

    licenseName = 'The Apache Software License, Version 2.0'
    licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
    allLicenses = ['Apache-2.0']
}

version = libraryVersion


// TODO: Take a look at http://ph0b.com/android-studio-gradle-and-ndk-integration/
android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 27
        versionCode versionCode
        versionName libraryVersion

        // Android has problems including the javacv native libraries, so we must include them
        // manually rather than using gradle.
        // https://github.com/bytedeco/javacpp-presets/wiki/The-UnsatisfiedLinkError-X-File-(a-real-experience)
        // Compile the *.so files extracted from javacpp-presets:ffmpeg:3.1.2-1.2:android-*.jar
        ndk { abiFilters 'armeabi', 'armeabi-v7a', 'x86' }
    }

    buildTypes {
        release {
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

// https://github.com/bytedeco/javacpp-presets/wiki/Issues-with-Build-Tools
configurations {
    all*.exclude group: 'org.bytedeco', module: 'javacpp-presets'
}

dependencies {
    compile 'com.android.support:appcompat-v7:27.0.2'
    compile 'com.android.support:support-v4:27.0.2'
    //noinspection GradleDynamicVersion
    compile 'com.android.support:support-annotations:+'
    compile 'com.github.rahatarmanahmed:circularprogressview:2.5.0'
    // Needed for nested builders
    compileOnly 'com.google.auto.value:auto-value:1.5'
    annotationProcessor  'com.google.auto.value:auto-value:1.5'
    compile 'com.google.guava:guava:23.3-android'

    compile group: 'org.bytedeco', name: 'javacpp', version: '1.2.5'
    compile group: 'org.bytedeco', name: 'javacv', version: '1.2'
    compile group: 'org.bytedeco.javacpp-presets', name: 'ffmpeg', version: '3.0.2-1.2'
}

apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'

// Based off https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle
apply plugin: 'com.jfrog.bintray'

task sourcesJar(type: Jar) {
    classifier = 'sources'
    from android.sourceSets.main.java.srcDirs
}

task javadoc(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    failOnError false
}

afterEvaluate {
    javadoc.classpath += files(android.libraryVariants.collect { variant ->
        variant.javaCompile.classpath.files
    })
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}

artifacts {
    archives javadocJar
    archives sourcesJar
}

// Bintray
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

bintray {
    user = properties.getProperty('bintray.user')
    key = properties.getProperty('bintray.apikey')

    configurations = ['archives']
    pkg {
        repo = bintrayRepo
        name = bintrayName
        desc = libraryDescription
        websiteUrl = siteUrl
        vcsUrl = gitUrl
        licenses = allLicenses
        publish = true
        publicDownloadNumbers = true
        version {
            desc = libraryDescription
            gpg {
                sign = true //Determines whether to GPG sign the files. The default is false
                passphrase = properties.getProperty('bintray.gpg.password')
                //Optional. The passphrase for GPG signing'
            }
        }
    }
}