/*
 *
 * Copyright 2019 Arunkumar
 *
 * 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.
 *
 */
ext {
    bintrayRepo = 'maven'
    bintrayName = 'transition-x'

    publishedGroupId = 'in.arunkumarsampath'
    libraryName = 'Transition X'
    artifact = 'transition-x'

    libraryDescription = 'Declarative Kotlin DSL for choreographing Android transitions'

    siteUrl = 'https://github.com/arunkumar9t2/transition-x'
    gitUrl = 'https://github.com/arunkumar9t2/transition-x.git'

    libraryVersion = '1.1.0'

    developerId = 'arunkumar9t2'
    developerName = 'Arunkumar'
    developerEmail = 'arunk.beece@gmail.com'

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

group = publishedGroupId
version = libraryVersion

install {
    repositories.mavenInstaller {
        pom.project {
            packaging 'aar'
            groupId publishedGroupId
            artifactId artifact

            name libraryName
            description libraryDescription
            url siteUrl

            licenses {
                license {
                    name licenseName
                    url licenseUrl
                }
            }
            developers {
                developer {
                    id developerId
                    name developerName
                    email developerEmail
                }
            }
            scm {
                connection gitUrl
                developerConnection gitUrl
                url siteUrl
            }
        }
    }
}

dokka {
    outputFormat = 'html'
    outputDirectory = "$rootDir/docs/"
    classpath = new ArrayList<File>(project.tasks['assemble'].outputs.files.files)
    sourceDirs = android.sourceSets.main.java.srcDirs
    externalDocumentationLink {
        url = new URL("https://developer.android.com/reference/")
        packageListUrl = new URL("https://developer.android.com/reference/android/support/package-list")
    }
}

task docJar(type: Jar, dependsOn: dokka) {
    classifier = 'javadoc'
    from dokka.outputDirectory
}

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

artifacts {
    archives sourceJar
    archives docJar
}

Properties properties = new Properties()
def file = project.rootProject.file('local.properties')
if (file.exists()) {
    properties.load(file.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
        dryRun = false
        publish = true
        override = false
        publicDownloadNumbers = true
        version {
            desc = libraryDescription
        }
    }
}