import org.apache.tools.ant.taskdefs.condition.Os

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "net.named_data.nfd"
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 3005
        versionName "0.3.4"
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
            jniDebuggable true
        }
    }
    sourceSets {
        main {
            java.srcDirs "src/main/java"
            res.srcDirs "src/main/res"
            jniLibs.srcDir 'src/main/libs'
            jni.srcDirs = [] //disable automatic ndk-build call
        }
        androidTest.setRoot('tests')
        androidTest.java.srcDirs = ['tests/src']
    }
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }

    splits {
        abi {
            enable true // enable ABI split feature to create one APK per ABI
            universalApk false // don't generate an additional APK that targets all the ABIs
        }
    }

    // map for the version code
    // versionCode digit for each supported ABI, with 64bit>32bit and x86>armeabi-*
    project.ext.versionCodes = ['armeabi': 1,
                                'armeabi-v7a': 2,
                                'arm64-v8a': 3,
                                'mips': 5,
                                'mips64': 6,
                                'x86': 8,
                                'x86_64': 9]

    android.applicationVariants.all { variant ->
        // assign different version code for each output
        variant.outputs.each { output ->
            output.versionCodeOverride = project.ext.versionCodes.get(
                    output.getFilter(
                            com.android.build.OutputFile.ABI), 0) * 1000000 +
                    defaultConfig.versionCode
        }
    }

    // call regular ndk-build(.cmd) script from app directory
    task ndkBuild(type: Exec) {
        def args = [getNdkBuildCmd(), '-C', file('src/main').absolutePath]

        if (System.env.NDK_BUILD_PARALLEL != null) {
           args.add("-j" + System.env.NDK_BUILD_PARALLEL)
        }
        else {
           args.add("-j" + Runtime.runtime.availableProcessors())
        }

        if (System.env.NDK_BUILD_ABI != null) {
           args.add("APP_ABI=" + System.env.NDK_BUILD_ABI)
        }

        if (System.env.NDK_DEBUG != null) {
           args.add("NDK_DEBUG=1")
        }
        commandLine args
    }

    tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn ndkBuild
    }

    task cleanNative(type: Exec) {
        commandLine getNdkBuildCmd(), '-C', file('src/main').absolutePath, 'clean'
    }

    clean.dependsOn cleanNative
}

def getNdkBuildCmd() {
    def ndk_build = getNdkDir() + "/ndk-build"
    if (Os.isFamily(Os.FAMILY_WINDOWS)) {
        ndk_build += ".cmd"
    }

    return ndk_build
}


def getNdkDir() {
    if (System.env.ANDROID_NDK_ROOT != null)
        return System.env.ANDROID_NDK_ROOT

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

    def ndk_dir = properties.getProperty('ndk.dir', null)
    if (ndk_dir == null) {
        throw new GradleException("NDK location not found. Define location with ndk.dir in the local.properties file or with an ANDROID_NDK_ROOT environment variable.")
    }
    return ndk_dir
}

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.android.support:support-v4:21.0.3'

    /// Temporarily, the modified code is embedded within NFD app
    //
    // compile('com.intel.jndn.utils:jndn-utils:0.9.7') {
    //   exclude group: 'com.intel.jndn.mock', module: 'jndn-mock'
    //   exclude group: 'net.named-data', module: 'jndn'
    // }

    // compile('com.intel.jndn.management:jndn-management:0.9.7') {
    //   exclude group: 'net.named-data', module: 'jndn'
    //   exclude group: 'com.intel.jndn.utils', module: 'jndn-utils'
    //   exclude group: 'com.intel.jndn.mock', module: 'jndn-mock'
    // }

    // compile('net.named-data:jndn-android:0.7') {
    compile('net.named-data:jndn:0.4') {
      exclude group: 'org.xerial'
    }
    compile 'net.named-data.jndn-xx:jndn-xx-util:0.0.1'
    compile 'joda-time:joda-time:2.7'
}

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

if (properties['keystore'] == null || properties['keystore.password'] == null ||
    properties['keystore.key.alias'] == null || properties['keystore.key.password'] == null) {
    println("Cannot sign .apk: specify keystore, keystore.password, keystore.key.alias, and keystore.key.password in local.properties.")
}
else {
    android {
        signingConfigs {
            release {
                storeFile file(properties['keystore'])
                storePassword properties['keystore.password']
                keyAlias properties['keystore.key.alias']
                keyPassword properties['keystore.key.password']
            }
        }
        buildTypes {
            release {
                signingConfig signingConfigs.release
            }
        }
    }
}

if (properties['google-play'] != null) {
    apply plugin: 'net.named-data.playground.play'

    play {
        track = 'alpha'
        jsonFile = file(properties['google-play'])
    }
}
