plugins {
    id 'java'
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.13'
    id 'org.beryx.jlink' version '2.26.0'

}

group 'controllers'

repositories {
    mavenCentral()
}

ext {
    junitVersion = '5.8.1'
}

sourceCompatibility = '17'
targetCompatibility = '17'

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

application {
    mainModule = 'pihole'
    mainClass = 'controllers.WidgetApplication'
}

javafx {
    version = '17.0.7'
    modules = ['javafx.controls', 'javafx.fxml', 'javafx.web']
}

dependencies {
    implementation('org.controlsfx:controlsfx:11.1.0')
    implementation('com.dlsc.formsfx:formsfx-core:11.3.2') {
        exclude(group: 'org.openjfx')
    }
    implementation('net.synedra:validatorfx:0.1.13') {
        exclude(group: 'org.openjfx')
    }
    implementation('org.kordamp.ikonli:ikonli-javafx:12.2.0')
    implementation('org.kordamp.bootstrapfx:bootstrapfx-core:0.4.0')
    implementation('eu.hansolo:tilesfx:11.48') {
        exclude(group: 'org.openjfx')
    }

    implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1'
    implementation 'org.jetbrains:annotations:20.1.0'

    testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
}

test {
    useJUnitPlatform()
}

jlink {

    mergedModule {
        requires "java.xml"
    }

    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']

    launcher {
        name = 'Pihole Widget'
    }

    version = "1.5.2"
    description ="A desktop Widget to display Pihole data"


    jpackage {
        // jpackageHome = '/usr/lib/jvm/jdk16'
        // outputDir = 'my-packaging'
        // imageOutputDir = file("$buildDir/my-packaging-image")
        // installerOutputDir = file("$buildDir/my-packaging-installer")
        // imageName = 'MyApp'
        //imageOptions = ['--win-console']
        skipInstaller = false
        installerName = 'Widget Installer'
        installerOptions = [
                '--description', project.description,
                '--copyright', 'Copyright (C) 2022.  Reda ELFARISSI aka foxy999'
        ]
        //if (org.gradle.internal.os.OperatingSystem.current().windows) {
        if (installerType == 'msi') {
            installerOptions += ['--win-per-user-install', '--win-dir-chooser', '--win-menu', '--win-shortcut']
            imageOptions += ['--icon','src/main/resources/media/icons/icon.ico']

        }
        if (installerType == 'pkg') {
            //imageOptions += ['--icon', 'src/main/resources/..../icon.icns']
        }
        if (installerType in ['deb', 'rpm']) {
            //imageOptions += ['--icon', 'src/main/resources/..../icon_256x256.png']
            installerOptions += [
                    '--linux-menu-group', 'Office',
                    '--linux-shortcut'
            ]
        }
        if (installerType == 'deb') {
            installerOptions += [
                    '--linux-deb-maintainer', 'fox-inflames@outlook.com'
            ]
        }
        if (installerType == 'rpm') {
            installerOptions += [
                    '--linux-rpm-license-type', 'GPLv3'
            ]
        }

    }

}

def JLINK_DIR = "$buildDir/jpackage/Pihole Widget"
/*
tasks.jlink.doLast {

    copy {
        from("/") {
            include "README.md","CHANGELOG.md"
        }
        into JLINK_DIR+"/docs"
    }
    copy {
        from("/src/main/resources/media/images") {

        }
        into JLINK_DIR+"/media/images"
    }

}
*/
jlinkZip {
    group = 'distribution'
}
jpackage {
    doFirst {
        project.getProperty('installerType') // throws exception if its missing
    }
}