/*
 * Copyright 2019 Scott Logic Ltd
 *
 * 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.
 */

plugins {
    id "java"
    id "de.gliderpilot.semantic-release" version "1.4.2"
    id "application"
    id "nebula.deb" version "8.0.3"
}

group "com.scottlogic.datahelix.generator"

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    implementation project(":profile")
    implementation project(":core")
    implementation project(":output")
    implementation project(":common")
    implementation project(":custom")

    implementation group: "info.picocli", name: "picocli", version: "${PICOCLI_VERSION}"
    implementation group: "com.google.code.gson", name: "gson", version: "${GSON_VERSION}"

    implementation group: "com.google.inject", name: "guice", version: "${GUICE_VERSION}"
    implementation "com.fasterxml.jackson.core:jackson-core:${JACKSON_VERSION}"
    implementation "com.fasterxml.jackson.core:jackson-databind:${JACKSON_VERSION}"

    testImplementation project(":common").sourceSets.test.output
    testImplementation "org.hamcrest:java-hamcrest:${HAMCREST_VERSION}"
    testImplementation "org.junit.jupiter:junit-jupiter-api:${JUNIT_JUPITER_VERSION}"
    testImplementation "org.junit.platform:junit-platform-runner:${JUNIT_PLATFORM_RUNNER_VERSION}"
    testImplementation "org.junit.vintage:junit-vintage-engine:${JUNIT_JUPITER_VERSION}"
    testImplementation "org.junit.jupiter:junit-jupiter-params:${JUNIT_JUPITER_VERSION}"
    testImplementation "io.cucumber:cucumber-junit:${CUCUMBER_VERSION}"
    testImplementation "io.cucumber:cucumber-java:${CUCUMBER_VERSION}"
    testImplementation "io.cucumber:cucumber-java8:${CUCUMBER_VERSION}"
    testImplementation "io.cucumber:gherkin:${GHERKIN_VERSION}"
    testImplementation "io.cucumber:cucumber-picocontainer:${CUCUMBER_PICOCONTAINER_VERSION}"
    testImplementation "org.mockito:mockito-all:${MOCKITO_VERSION}"
    testImplementation "com.shazam:shazamcrest:${SHAZAMCREST_VERSION}"
    testImplementation "org.junit.jupiter:junit-jupiter-engine:${JUNIT_JUPITER_VERSION}"
    testImplementation group: "junit", name: "junit", version: "${JUNIT_4_VERSION}"

    testImplementation project(':core').sourceSets.test.output
    testImplementation project(':profile').sourceSets.test.output

    testImplementation("org.junit.jupiter:junit-jupiter:${JUNIT_JUPITER_VERSION}")

    implementation('org.jetbrains.kotlin:kotlin-stdlib') {
        version {
            strictly "1.3.30"
        }
        because "Security issue with 1.3.20"
    }
    implementation('org.jetbrains.kotlin:kotlin-stdlib-common') {
        version {
            strictly "1.3.30"
        }
        because "Security issue with 1.3.20"
    }
    implementation('org.jetbrains.kotlin:kotlin-reflect') {
        version {
            strictly "1.3.30"
        }
        because "Security issue with 1.3.20"
    }
}

test {
    useJUnitPlatform()
    dependsOn("fatJar")
}

description = "DataHelix Generator"

task fatJar(type: Jar) {
    manifest {
        attributes 'Main-Class': 'com.scottlogic.datahelix.generator.orchestrator.App'
    }
    baseName = 'datahelix'
    from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
    duplicatesStrategy = 'warn'
    archiveName = "${baseName}.${extension}"
}

task createDeb(type: Deb) {
    packageName = "datahelix"
    summary = 'Quickly generate rich and realistic data for simulation and testing. '
    maintainer = "Data Helix Team <datahelix@scottlogic.com>"
    license = "Apache-2.0"
    url = "https://github.com/finos/datahelix"
    requires('java8-runtime-headless')
    requires('jarwrapper')
    dependsOn("fatJar")
    from('src/main/resources/datahelix'){
        into '/usr/bin'
        fileMode 0755
        user 'root'
    }
    from('build/libs/datahelix.jar'){
        into '/usr/share/datahelix'
        user 'root'
    }
    from('src/main/resources/datahelix.1.gz'){
        into '/usr/share/man/man1'
        user 'root'
    }
}

jar {
    manifest {
        attributes 'Main-Class': 'com.scottlogic.datahelix.generator.orchestrator.App'
    }
}

application {
    mainClass.set('com.scottlogic.datahelix.generator.orchestrator.App')
}

project.ext.ghToken = project.hasProperty('ghToken') ? project.getProperty('ghToken') : System.getenv('GH_TOKEN') ?: null

distZip {
    archiveName "datahelix.zip"
}

startScripts {
    applicationName = 'datahelix'
}

semanticRelease {
    repo {
        ghToken = project.ghToken
        releaseAsset distZip
    }
}