/*
 * Copyright (C) 2018 Emre Eran
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

apply plugin: 'com.jfrog.bintray'

version = projectProperties.version.name

if (project.hasProperty("android")) {
    // Android libraries
    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))
    }
} else {
    // Java libraries
    task sourcesJar(type: Jar, dependsOn: classes) {
        classifier = 'sources'
        from sourceSets.main.allSource
    }
}

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('bintray.properties').newDataInputStream())

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

    configurations = ['archives']
    pkg {
        repo = properties.getProperty("repo")
        name = properties.getProperty("name")
        desc = projectProperties.description
        websiteUrl = projectProperties.url
        vcsUrl = projectProperties.scm.connection
        licenses = projectProperties.license.all
        publish = true
        publicDownloadNumbers = true
        version {
            desc = projectProperties.description
            gpg {
                sign = true
                passphrase = properties.getProperty("gpg.password")
            }
        }
    }
}