/*
 * Copyright (c) 2015-2016 Spotify AB
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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'

project.group = 'com.spotify.android'
project.archivesBaseName = 'auth'
project.version = '1.1.0'

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.2'

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 2
        versionName project.version
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt')
        }
        debug {
            testCoverageEnabled true
        }
    }

    lintOptions {
        lintConfig file("${project.rootDir}/config/lint.xml")
        quiet false
        warningsAsErrors false
        textReport true
        textOutput 'stdout'
        xmlReport false
    }

    testOptions {
        unitTests {
            includeAndroidResources = true
        }
    }
}

dependencies {
    compile 'com.android.support:customtabs:27.0.2'

    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-core:2.12.0'
    testCompile 'org.robolectric:robolectric:3.5.1'
}

/*
    Static analysis section
    run: ./gradlew auth-lib:checkstyle auth-lib:findbugs
 */

apply plugin: 'checkstyle'
apply plugin: 'findbugs'

task checkstyle(type: Checkstyle) {
    configFile file("${project.rootDir}/config/checkstyle.xml")
    source 'src'
    include '**/*.java'
    exclude '**/gen/**'
    classpath = files()
}

task findbugs(type: FindBugs) {
    ignoreFailures = false
    effort = "max"
    reportLevel = "high"
    excludeFilter = new File("${project.rootDir}/config/findbugs-filter.xml")
    classes = files("${project.rootDir}/auth-lib/build/intermediates/classes")

    source 'src'
    include '**/*.java'
    exclude '**/gen/**'

    reports {
        xml.enabled = false
        html.enabled = true
        xml {
            destination "$project.buildDir/reports/findbugs/findbugs.xml"
        }
        html {
            destination "$project.buildDir/reports/findbugs/findbugs.html"
        }
    }

    classpath = files()
}

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

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

task javadoc(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    options.links("http://docs.oracle.com/javase/7/docs/api/");
    destinationDir = file("../docs/")
    failOnError false
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}

artifacts {
    archives javadocJar
    archives sourcesJar
}

install {
    repositories {
        mavenInstaller {
            pom {
                project {
                    name project.group + ':' + project.archivesBaseName
                    description 'Spotify authentication and authorization for Android'
                    url 'https://github.com/spotify/android-auth'

                    licenses {
                        license {
                            name 'The Apache Software License, Version 2.0'
                            url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                        }
                    }

                    scm {
                        connection 'scm:git:https://github.com/spotify/android-auth.git'
                        developerConnection 'scm:git:git@github.com:spotify/android-auth.git'
                        url 'https://github.com/spotify/android-auth'
                    }

                    developers {
                        developer {
                            id 'erikg'
                            name 'Erik Ghonyan'
                            email 'erikg@spotify.com'
                        }
                    }
                }
            }
        }
    }
}

bintray {
    user = System.getenv('BINTRAY_USER')
    key = System.getenv('BINTRAY_KEY')

    configurations = ['archives']

    pkg {
        repo = 'maven'
        name = 'android-auth'
        userOrg = 'spotify'

        version {
            name = project.version
        }
    }
}
