plugins {
    id 'org.asciidoctor.jvm.convert' version '4.0.3'
}

repositories {
    mavenCentral()
}

def projectRoot = "../.."
tasks.register('copyReadmeResources', Copy) {
    group 'Verification'
    description 'Copy resources of READMEs for integration test'

    from(projectRoot) {
        include '*.properties'
    }
    from("${projectRoot}/src/docs") {
        include 'images/**'
        include 'asciidoctor-config.ad'
    }
    into "${Project.DEFAULT_BUILD_DIR_NAME}/docs"
}

tasks.register('buildReadmeRoot', org.asciidoctor.gradle.jvm.AsciidoctorTask) {
    group 'Verification'
    description 'Convert root README for integration test'

    sourceDir projectRoot
    sources {
        include 'README.adoc'
    }
    baseDirFollowsSourceFile()
    outputDir file("${Project.DEFAULT_BUILD_DIR_NAME}/docs")
    attributes(
            "imagesdir": "images"
    )
}
buildReadmeRoot.dependsOn(copyReadmeResources)

tasks.register('buildReadmeGradlePlugin', org.asciidoctor.gradle.jvm.AsciidoctorTask) {
    group 'Verification'
    description 'Convert Gradle Plugin README for integration test'

    sourceDir projectRoot
    sources {
        include 'htmlSanityCheck-gradle-plugin/README.adoc'
    }
    baseDirFollowsSourceFile()
    outputDir file("${Project.DEFAULT_BUILD_DIR_NAME}/docs")
    attributes(
            "imagesdir": "../images"
    )
}
buildReadmeGradlePlugin.dependsOn(copyReadmeResources)
buildReadmeGradlePlugin.mustRunAfter(buildReadmeRoot)

tasks.register('buildReadmeCli', org.asciidoctor.gradle.jvm.AsciidoctorTask) {
    group 'Verification'
    description 'Convert CLI README for integration test'

    sourceDir projectRoot
    sources {
        include 'htmlSanityCheck-cli/README.adoc'
    }
    baseDirFollowsSourceFile()
    outputDir file("${Project.DEFAULT_BUILD_DIR_NAME}/docs")
    attributes(
            "imagesdir": "../images"
    )
}
buildReadmeCli.dependsOn(copyReadmeResources)
buildReadmeCli.mustRunAfter(buildReadmeGradlePlugin)

tasks.register('buildReadmeMavenPlugin', org.asciidoctor.gradle.jvm.AsciidoctorTask) {
    group 'Verification'
    description 'Convert Maven README for integration test'

    sourceDir projectRoot
    sources {
        include 'htmlSanityCheck-maven-plugin/README.adoc'
    }
    baseDirFollowsSourceFile()
    outputDir file("${Project.DEFAULT_BUILD_DIR_NAME}/docs")
    attributes(
            "imagesdir": "../images"
    )
}
buildReadmeMavenPlugin.dependsOn(copyReadmeResources)
buildReadmeMavenPlugin.mustRunAfter(buildReadmeCli)

tasks.register('buildReadmeAll') {
    group 'Verification'
    description 'Convert all READMEs for integration test'
}
buildReadmeAll.dependsOn(buildReadmeRoot, buildReadmeGradlePlugin, buildReadmeCli, buildReadmeMavenPlugin)
build.dependsOn(buildReadmeAll)

/*
 * Copyright Gerd Aschemann and aim42 contributors.
 *
 * 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
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */
