plugins {
    id 'java'
}

group 'info.picocli'
description 'Picocli Code Generation - Tools to generate documentation, configuration, source code and other files from a picocli model.'
version "$projectVersion"

// Java 13 cannot compile to target Java 6
if (org.gradle.api.JavaVersion.current().isJava8Compatible() && !org.gradle.api.JavaVersion.current().isJava11Compatible()) {
    sourceCompatibility = 1.6
    targetCompatibility = 1.6
}
dependencies {
    api rootProject
    testImplementation "junit:junit:$junitVersion"
}

//task generateGraalReflectionConfig(type: JavaExec) {
//    mainClass = 'picocli.codegen.aot.graalvm.ReflectionConfigGenerator'
//    classpath = sourceSets.main.runtimeClasspath
//    def outputFile = "${rootProject.projectDir}/src/main/resources/META-INF/native-image/info.picocli/picocli/reflect-config.json"
//    args = ["--output=$outputFile", 'picocli.AutoComplete$App']
//
//    doLast {
//        logger.info(":picocli-codegen:generateGraalReflectionConfig Generating $outputFile")
//    }
//}
//generateGraalReflectionConfig.dependsOn(compileJava)
//jar.dependsOn(generateGraalReflectionConfig)

jar {
    manifest {
        attributes 'Specification-Title'   : 'Picocli Code Generation',
                   'Specification-Vendor'  : 'Remko Popma',
                   'Specification-Version' : archiveVersion.get(),
                   'Implementation-Title'  : 'Picocli Code Generation',
                   'Implementation-Vendor' : 'Remko Popma',
                   'Implementation-Version': archiveVersion.get(),
                   'Automatic-Module-Name' : 'info.picocli.codegen'
    }
}


task generateManpageAsciiDoc(type: JavaExec) {
    dependsOn(classes)
    group = "Documentation"
    description = "Generate AsciiDoc manpage"
    classpath(configurations.compileClasspath, configurations.annotationProcessor, sourceSets.main.runtimeClasspath)
    mainClass = 'picocli.codegen.docgen.manpage.ManPageGenerator'
    args 'picocli.codegen.docgen.manpage.ManPageGenerator$App',
            'picocli.codegen.aot.graalvm.DynamicProxyConfigGenerator$App',
            'picocli.codegen.aot.graalvm.ReflectionConfigGenerator$App',
            'picocli.codegen.aot.graalvm.ResourceConfigGenerator$App',
            'picocli.AutoComplete$App', // the command line app
            'picocli.AutoComplete$GenerateCompletion', // generate completion subcommand
            "--outdir=${project.buildDir}/picocli-generated-docs", "-v" //, "--template-dir=src/docs/mantemplates"
    doLast {
        ant.replaceregexp(match: "completion script for generate-completion", replace: "completion script for the root command of this command", flags: 'g', byline: true, encoding: 'UTF8') {
            fileset(dir: 'build/picocli-generated-docs', includes: 'generate-completion.adoc')
        }
    }
}

apply plugin: 'org.asciidoctor.jvm.convert'
asciidoctor {
    dependsOn(generateManpageAsciiDoc)
    sourceDir = file("${project.buildDir}/picocli-generated-docs")
    outputDir = file("${project.buildDir}/docs")
    logDocuments = true
    outputOptions {
        backends = ['manpage', 'html5']
    }
}
javadoc.dependsOn('asciidoctor')

ext {
    PUBLISH_GROUP_ID = group
    PUBLISH_ARTIFACT_ID = project.name
    PUBLISH_VERSION = "$projectVersion"
}
apply from: "${rootProject.projectDir}/gradle/publish-mavencentral.gradle"
