ext.moduleName = 'stroom.headless'

def fatJarName = 'stroom-headless-all.jar'
def releaseBuildDir = 'build/release'

apply plugin: 'application'
apply plugin: 'com.gradleup.shadow'

application {
    mainClass = 'stroom.headless.Cli'
}

dependencies {
    implementation project(':stroom-activity:stroom-activity-mock')
    implementation project(':stroom-cache:stroom-cache-api')
    implementation project(':stroom-cache:stroom-cache-impl')
    implementation project(':stroom-core-shared')
    implementation project(':stroom-data:stroom-data-zip')
    implementation project(':stroom-meta:stroom-meta-api')
    implementation project(':stroom-meta:stroom-meta-statistics-api')
    implementation project(':stroom-data:stroom-data-store-api')
    implementation project(':stroom-data:stroom-data-store-mock')
    implementation project(':stroom-dictionary:stroom-dictionary-api')
    implementation project(':stroom-dictionary:stroom-dictionary-impl')
    implementation project(':stroom-docref')
    implementation project(':stroom-docstore:stroom-docstore-api')
    implementation project(':stroom-docstore:stroom-docstore-impl')
    implementation project(':stroom-docstore:stroom-docstore-impl-fs')
    implementation project(':stroom-event-logging:stroom-event-logging-impl')
    implementation project(':stroom-explorer:stroom-explorer-api')
    implementation project(':stroom-explorer:stroom-explorer-impl')
    implementation project(':stroom-feed:stroom-feed-api')
    implementation project(':stroom-feed:stroom-feed-impl')
    implementation project(':stroom-importexport:stroom-importexport-api')
    implementation project(':stroom-importexport:stroom-importexport-impl')
    implementation project(':stroom-node:stroom-node-api')
    implementation project(':stroom-pipeline')
    implementation project(':stroom-processor:stroom-processor-impl')
    implementation project(':stroom-meta:stroom-meta-mock')
    implementation project(':stroom-security:stroom-security-api')
    implementation project(':stroom-security:stroom-security-mock')
    implementation project(':stroom-statistics:stroom-statistics-api')
    implementation project(':stroom-task:stroom-task-api')
    implementation project(':stroom-task:stroom-task-impl')
    implementation project(':stroom-util')
    implementation project(':stroom-util-shared')

    implementation libs.dropwizard.metrics.core
    implementation libs.guice
    implementation libs.jackson.annotations
    implementation libs.jakarta.el
    implementation libs.jakarta.inject
    implementation libs.saxon.he
    implementation libs.slf4j.api

    runtimeOnly libs.logback.classic
}











jar {
    manifest {
        attributes(
                "Implementation-Title": "Stroom CLI",
                "Implementation-Version": versions.stroom,
                "Main-Class": "stroom.headless.Cli"
        )
    }
}

shadowJar {
    // We want to run the tests before we build the fat jar.
    dependsOn test

    // Allows us to build fat jars with lots of files
    zip64 = true

    // A transformer to merges files in META-INF/services
    mergeServiceFiles()

    archiveFileName = fatJarName
}

// The gradle application plugin enables the distribution plugin
// which creates .zip/tar archives by default, as does the shadow plugin
// We have our own buildDistribution task so disable the standard ones to avoid confusion
distZip.enabled = false
distTar.enabled = false
shadowDistZip.enabled = false
shadowDistTar.enabled = false

tasks.register('copyJar', Copy) {
    dependsOn shadowJar
    from shadowJar.outputs.files
    into "${releaseBuildDir}/bin"
}

//task copyCommonSupportingFiles(type: Copy) {
//    from '../../dist'
//    into releaseBuildDir
//}

//task copySupportingFiles(type: Copy) {
////    dependsOn copyCommonSupportingFiles
//
//    from 'src/dist'
//    into releaseBuildDir
//
//    doLast {
//        // This is a sym-link so it seems to go into the zip with +x perms
//        // which we don't want
//        providers.exec {
//            commandLine 'chmod', '644', "${releaseBuildDir}/config/config.yml"
//        }.result.get()
//    }
//}

// Build the release distribution zip for stroom cli
tasks.register('buildDistribution', Zip) {

    // run all the tasks that produce content for the zip
    dependsOn copyJar
//    dependsOn copySupportingFiles

    from releaseBuildDir
}

// Make the build command create the full distribution
tasks.build.dependsOn shadowJar
tasks.build.dependsOn buildDistribution
