import org.ysb33r.gradle.gradletest.GradleTest

/*
 * Copyright 2013-2019 the original author or authors.
 *
 * 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.
 */

agProject {
    withOfflineTestConfigurations()

    configurePlugin(
            'org.asciidoctor.jvm.base',
            'AsciidoctorJ Base Plugin',
            'Base plugin for all AsciidoctorJ tasks & extensions. Provides the asciidoctorj project extension',
            'org.asciidoctor.gradle.jvm.AsciidoctorJBasePlugin',
            ['asciidoctorj']
    )

    configurePlugin(
            'org.asciidoctor.jvm.convert',
            'AsciidoctorJ General Purpose Document Conversion Plugin',
            'Provides asciidoctor task and conventions using the asciidoctorj engine',
            'org.asciidoctor.gradle.jvm.AsciidoctorJPlugin',
            ['asciidoctorj', 'html5', 'docbook']
    )
}

apply from: "${rootDir}/gradle/remote-tests.gradle"

dependencies {
    compileOnly "org.asciidoctor:asciidoctorj:${compileOnlyAsciidoctorJVersion}"
    compileOnly "org.asciidoctor:asciidoctorj-groovy-dsl:${compileOnlyGroovyDslVersion}", {
        exclude module: 'groovy-all'
    }

    api project(':asciidoctor-gradle-base')
    implementation("org.ysb33r.gradle:grolifant-rawhide:${agProject.versionOf('grolifant')}")
    runtimeOnly "org.asciidoctor:asciidoctorj-api:${compileOnlyAsciidoctorJVersion}"
    // These three are used in the compatibility tests for extensions
    intTestOfflineRepo "org.codehaus.groovy:groovy:${GroovySystem.version}"
    intTestOfflineRepo "org.codehaus.groovy:groovy-ant:${GroovySystem.version}"
    intTestOfflineRepo "org.codehaus.groovy:groovy-groovydoc:${GroovySystem.version}"

    intTestOfflineRepo "org.asciidoctor:asciidoctorj-epub3:${downloadOnlyEpubVersion}"

    // This is here for extension testing on the compatibility plugin. It will be deleted
    // when compatibility mode is removed.
    testRuntimeOnly "org.asciidoctor:asciidoctorj-groovy-dsl:${compileOnlyGroovyDslVersion}", {
        exclude module: 'groovy-all'
    }

    remoteTestImplementation localGroovy()
    remoteTestImplementation gradleTestKit()
    remoteTestImplementation "org.asciidoctor:asciidoctorj:${compileOnlyAsciidoctorJVersion}"
    remoteTestImplementation project(':testfixtures-jvm')
    remoteTestRuntimeOnly "org.asciidoctor:asciidoctorj-groovy-dsl:${compileOnlyGroovyDslVersion}", {
        exclude module: 'groovy-all'
    }
}

generateModuleVersions {
    basename = 'asciidoctorj-extension'
    propertyNames ~/^asciidoctorj$/, ~/^asciidoctorj\./
}

tasks.named('test', Test) {
    systemProperties ROOT_PROJECT_DIR: rootDir.absolutePath
}

tasks.named('intTest', Test) {
    systemProperties TEST_PROJECTS_DIR: file('src/intTest/projects')
    maxParallelForks = 4
    forkEvery = 7
}

// Compile the extensions compatibility test with the same version of
// AsciidoctorJ & Groovy version that is used in the project
tasks.named('gradleTest', GradleTest) {
    systemProperties ASCIIDOCTORJ_VERSION: compileOnlyAsciidoctorJVersion
    systemProperties GROOVY_VERSION: GroovySystem.version

    gradleArguments '-i', '-s'
}

tasks.named('check') {
    dependsOn remoteTest
}


