/*
 * Copyright (C) 2015 Basil Miller
 *
 * 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.android.library'
apply plugin: "com.jfrog.bintray"
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'maven'

version = "1.0.2"

android {
    compileSdkVersion 26

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 26
        versionCode 1
        versionName "1.0.2"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    //noinspection GradleDependency
    compile 'com.android.support:appcompat-v7:26.1.0'
}

def siteUrl = 'https://github.com/DevLight-Mobile-Agency/InfiniteCycleViewPager'
def gitUrl = 'https://github.com/DevLight-Mobile-Agency/InfiniteCycleViewPager.git'
group = "com.github.devlight"

install {
    repositories.mavenInstaller {
        // This generates POM.xml with proper parameters
        pom {
            //noinspection GroovyAssignabilityCheck
            project {
                packaging 'aar'

                // Add your description here
                //noinspection GroovyAssignabilityCheck
                name 'InfiniteCycleViewPager'
                description = 'Infinite cycle ViewPager with two-way orientation and interactive effect.'
                url siteUrl

                // Set your license
                licenses {
                    license {
                        //noinspection GroovyAssignabilityCheck
                        name 'The Apache Software License, Version 2.0'
                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    }
                }
                developers {
                    developer {
                        id 'gigamole'
                        //noinspection GroovyAssignabilityCheck
                        name 'Basil Miller'
                        email 'gigamole53@gmail.com'
                    }
                }
                scm {
                    connection gitUrl
                    developerConnection gitUrl
                    url siteUrl
                }
            }
        }
    }
}

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

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

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

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    //noinspection GrUnresolvedAccess
    from javadoc.destinationDir
}
artifacts {
    archives javadocJar
    archives sourcesJar
}

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 = "maven"
        // it is the name that appears in bintray when logged
        name = "infinitecycleviewpager"
        websiteUrl = siteUrl
        vcsUrl = gitUrl
        licenses = ["Apache-2.0"]
        publish = true
        //noinspection GroovyAssignabilityCheck
        version {
            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'
            }
//            mavenCentralSync {
//                sync = true //Optional (true by default). Determines whether to sync the version to Maven Central.
//                user = properties.getProperty("bintray.oss.user") //OSS user token
//                password = properties.getProperty("bintray.oss.password") //OSS user password
//                close = '1' //Optional property. By default the staging repository is closed and artifacts are released to Maven Central. You can optionally turn this behaviour off (by puting 0 as value) and release the version manually.
//            }
        }
    }
}