/*
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

// Android tasks for Javadoc and sources.jar generation

afterEvaluate { project ->
    if (POM_PACKAGING == 'aar') {
        task androidJavadoc(type: Javadoc) {
            source = android.sourceSets.main.java.srcDirs
            exclude '**/pom.xml'
            exclude '**/proguard_annotations.pro'
            classpath += files(android.bootClasspath)
        }

        task androidJavadocJar(type: Jar) {
            classifier = 'javadoc'
            from androidJavadoc.destinationDir
        }

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

        android.libraryVariants.all { variant ->
            def name = variant.name.capitalize()
            task "jar${name}"(type: Jar, dependsOn: variant.javaCompile) {
                from variant.javaCompile.destinationDir
            }
        }

        artifacts.add('archives', androidJavadocJar)
        artifacts.add('archives', androidSourcesJar)
    }

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

        task sourcesJar(type: Jar, dependsOn: classes) {
            classifier = 'sources'
            from sourceSets.main.allSource
        }

        artifacts.add('archives', javadocJar)
        artifacts.add('archives', sourcesJar)
    }
}
