/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * 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.
 */

// Android tasks for Javadoc and sources.jar generation

afterEvaluate { project ->
    task androidJavadoc(type: Javadoc) {
        source = android.sourceSets.main.java.srcDirs
        exclude '**/pom.xml'
        exclude '**/proguard_annotations.pro'
        exclude '**/BUCK'
        classpath += files(android.bootClasspath)
        classpath += configurations.compile
        title = 'TextLayoutBuilder API'
        options {
            links 'http://docs.oracle.com/javase/7/docs/api/'
            linksOffline 'https://developer.android.com/reference/', "file://${android.sdkDirectory}/docs/reference/"
        }
    }

    androidJavadoc.doLast {
        copy {
            from new File(projectDir, 'src/javadoc/stylesheet.css')
            into new File(buildDir, 'docs/javadoc/')
        }
    }

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

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

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

    artifacts {
        archives androidSourcesJar
        archives androidJavadocJar
    }
}
