apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.github.dcendents.android-maven'

def properties = new Properties()
properties.load(new FileInputStream(project.file("../deploy.properties")))

version = properties.version
group = properties.groupId

/**
 * Bintray closure needed to run the buntrayUpload task.
 *
 * Usage:
 * ./gradlew bintrayUpload -PbintrayUser=YOUR_BINTRAY_USER_ID -PbintrayApiKey=YOUR_BINTRAY_API_KEY
 *
 * Or set BINTRAY_USER and BINTRAY_API_KEY environment variables before calling:
 * ./gradlew bintrayUpload.)
 *
 * The Bintray User ID and API key can be added to your system environment variables as BINTRAY_USER
 * and BINTRAY_API_KEY respectively, and the command could be reduced to:
 * ./gradlew bintrayUpload
 */
bintray {
    user = project.hasProperty('bintrayUser') ? project.property('bintrayUser')
            : System.getenv('BINTRAY_USER')
    key = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey')
            : System.getenv('BINTRAY_API_KEY')

    configurations = ['archives']
    pkg {
        userOrg = properties.bintrayUserOrg
        repo = properties.bintrayRepo
        name = project.name
        desc = '''\
Blockly for Android provides a block-based code editor to Android apps.
This library provides the a view implementation for vertically stacking blocks.
'''
        websiteUrl = properties.siteUrl
        vcsUrl = properties.githubUrl + '.git'
        issueTrackerUrl = properties.githubUrl + '/issues'
        licenses = properties.licenses
        labels = ['Android', 'Blockly']
        publicDownloadNumbers = true
        publish = true
        version {
            name = properties.version
        }
    }
}

artifacts {
    archives sourcesJar
}

if (android.productFlavors.size() > 0) {
    android.libraryVariants.all { variant ->
        if (variant.name.toLowerCase().contains("debug")) {
            return
        }

        def bundleTask = tasks["bundle${variant.name.capitalize()}Aar"]

        artifacts {
            archives(bundleTask.archivePath) {
                classifier variant.flavorName
                builtBy bundleTask
                name = project.name
            }
        }
    }
}
