import io.freefair.gradle.plugins.okhttp.tasks.UploadFile
import kotlin.KotlinVersion

plugins {
    id 'org.asciidoctor.jvm.convert' version '4.0.5'
    id 'io.freefair.aggregate-javadoc'
    id 'io.freefair.javadoc-links'
}

configurations {
    asciidoctorExt
}

asciidoctor {
    baseDirFollowsSourceDir()

    attributes gradle_version: gradle.gradleVersion
    attributes kotlin_version: KotlinVersion.CURRENT

    configurations 'asciidoctorExt'

    inputs.dir("src/docs/asciidoc")
}

dependencies {
    rootProject.subprojects { subproject ->
        subproject.plugins.withId("java") {
            javadoc subproject
        }
    }

    javadocClasspath "org.jacoco:org.jacoco.ant:${org.gradle.testing.jacoco.plugins.JacocoPlugin.DEFAULT_JACOCO_VERSION}"
    javadocClasspath "org.apache.maven.plugins:maven-plugin-plugin:3.15.1"
    javadocClasspath 'net.sourceforge.plantuml:plantuml:1.2025.8'
    javadocClasspath 'org.projectlombok:lombok:1.18.42'

    asciidoctorExt "io.spring.asciidoctor:spring-asciidoctor-extensions-block-switch:0.6.3"
}

tasks.named("javadoc", Javadoc) {
    failOnError = true
}

tasks.register("docsZip", Zip) {
    group = 'build'
    archiveClassifier = 'docs'
    dependsOn asciidoctor

    into("api") {
        from javadoc
    }
    into("reference") {
        from asciidoctor.outputDir
    }
}

tasks.register("uploadDocs", UploadFile) {
    dependsOn docsZip
    username = findProperty("freefairDocsUser")
    password = findProperty("freefairDocsPass")
    file = docsZip.archiveFile
    contentType = 'application/zip'
    url = "https://docs.freefair.io/api/$project.version?path=gradle-plugins"
}
