/*
 * Copyright (C) 2017-2021 HERE Europe B.V.
 *
 * 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 from: '../quality.gradle'
apply from: '../coverage.gradle'

android {
    compileSdkVersion compile_sdk_version
    buildToolsVersion build_tools_version

    defaultConfig {
        minSdkVersion min_sdk_version
        targetSdkVersion target_sdk_version
        versionCode 1
        versionName artifact_version
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        debug {
            buildConfigField("String","VERSION_NAME","\"${defaultConfig.versionName}\"")
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField("String","VERSION_NAME","\"${defaultConfig.versionName}\"")
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    lintOptions {
        abortOnError true
        ignoreWarnings false
        warningsAsErrors true
        xmlReport true
        xmlOutput project.file('build/reports/lint/lint-report.xml')
        htmlReport true
        htmlOutput project.file('build/reports/lint/lint-report.html')
        lintConfig file("${project.rootDir}/quality/lint/lint.xml")
    }
    testOptions.unitTests {
        includeAndroidResources = true
    }
    testOptions.unitTests.all {
        testLogging {
            events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
            outputs.upToDateWhen { false }
            showStandardStreams = true
        }
        jvmArgs '-noverify'
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation(name: 'HERE-sdk', ext: 'aar')

    implementation "androidx.constraintlayout:constraintlayout:$constraint_layout_version"
    implementation "androidx.appcompat:appcompat:$appcompat_version"
    implementation "com.google.android.material:material:$android_material_version"
    implementation "androidx.recyclerview:recyclerview:$recyclerview_version"

    testImplementation "androidx.test:core:$test_version"
    testImplementation "junit:junit:$junit_version"
    testImplementation "org.robolectric:robolectric:$robolectric_version"
    testImplementation "org.mockito:mockito-core:$mockito_version"
    testImplementation "org.mockito:mockito-inline:$mockito_version"

}

afterEvaluate {
    generateJavadoc.classpath += files(android.libraryVariants.collect { variant ->
        variant.getCompileClasspath(null)
    })
}

/**
 * Tested with Javadoc 1.8.0
 */
task generateJavadoc(type: Javadoc) {
    failOnError true
    source = android.sourceSets.main.java.sourceFiles
    ext.ResDebug = "build/generated/source/r/debug"
    ext.ResRelease = "build/generated/source/r/release"
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator), ext.ResRelease, ext.ResDebug)
    classpath += configurations.compile
    exclude '**/R.java'
}

task releaseJavadoc(type: Copy, dependsOn: generateJavadoc) {
    from(file("${project.docsDir}/javadoc"))
    into(file("$buildDir/../../../docs"))
}

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

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

artifacts {
    archives sourcesJar
    archives javadocJar
}
