plugins {
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.8'
    id 'org.kordamp.gradle.jdeps' version '0.9.0'
    id 'org.beryx.jlink' version '2.17.4'
}

group 'com.sparrowwallet'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.9

repositories {
    mavenCentral()
}

javafx {
    version = "14"
    modules = [ 'javafx.controls', 'javafx.fxml', 'javafx.swing', 'javafx.graphics' ]
}

java {
    disableAutoTargetJvm()
}

dependencies {
    implementation(project(':drongo')) {
        exclude group: 'org.hamcrest'
        exclude group: 'junit'
    }
    implementation('com.google.guava:guava:28.2-jre')
    implementation('com.google.code.gson:gson:2.8.6')
    implementation('org.fxmisc.richtext:richtextfx:0.10.4')
    implementation('no.tornado:tornadofx-controls:1.0.4')
    implementation('com.google.zxing:javase:3.4.0')
    implementation('com.github.arteam:simple-json-rpc-client:1.0')
    implementation('com.github.arteam:simple-json-rpc-server:1.0') {
        exclude group: 'org.slf4j'
    }
    implementation('de.codecentric.centerdevice:centerdevice-nsmenufx:2.1.7')
    implementation('org.controlsfx:controlsfx:11.0.1' ) {
        exclude group: 'org.openjfx', module: 'javafx-base'
        exclude group: 'org.openjfx', module: 'javafx-graphics'
        exclude group: 'org.openjfx', module: 'javafx-controls'
        exclude group: 'org.openjfx', module: 'javafx-swing'
        exclude group: 'org.openjfx', module: 'javafx-fxml'
        exclude group: 'org.openjfx', module: 'javafx-web'
        exclude group: 'org.openjfx', module: 'javafx-media'
    }
    testImplementation('junit:junit:4.12')
}

mainClassName = 'com.sparrowwallet.sparrow/com.sparrowwallet.sparrow.MainApp'

compileJava {
    options.with {
        fork = true
        compilerArgs.addAll(["--add-exports", "org.controlsfx.controls/impl.org.controlsfx.skin=com.sparrowwallet.sparrow"])
    }
}

run {
    applicationDefaultJvmArgs = ["-Xdock:name=Sparrow", "-Xdock:icon=/Users/scy/git/sparrow/src/main/resources/sparrow.png",
                                 "--add-opens=javafx.graphics/com.sun.javafx.css=org.controlsfx.controls",
                                 "--add-opens=javafx.graphics/javafx.scene=org.controlsfx.controls",
                                 "--add-opens=javafx.controls/com.sun.javafx.scene.control.behavior=org.controlsfx.controls",
                                 "--add-opens=javafx.controls/com.sun.javafx.scene.control.inputmap=org.controlsfx.controls",
                                 "--add-opens=javafx.graphics/com.sun.javafx.scene.traversal=org.controlsfx.controls",
                                 "--add-opens=javafx.base/com.sun.javafx.event=org.controlsfx.controls",
                                 "--add-opens=javafx.controls/javafx.scene.control.cell=com.sparrowwallet.sparrow",
                                 "--add-opens=org.controlsfx.controls/impl.org.controlsfx.skin=com.sparrowwallet.sparrow",
                                 "--add-opens=javafx.graphics/com.sun.javafx.tk=centerdevice.nsmenufx",
                                 "--add-opens=javafx.graphics/com.sun.javafx.tk.quantum=centerdevice.nsmenufx",
                                 "--add-opens=javafx.graphics/com.sun.glass.ui=centerdevice.nsmenufx",
                                 "--add-opens=javafx.controls/com.sun.javafx.scene.control=centerdevice.nsmenufx",
                                 "--add-opens=javafx.graphics/com.sun.javafx.menu=centerdevice.nsmenufx",
                                 "--add-opens=javafx.graphics/com.sun.glass.ui.mac=centerdevice.nsmenufx"]
}

jlink {
    mergedModule {
        requires 'javafx.graphics';
        requires 'javafx.controls';
        requires 'java.xml';
        requires 'java.logging'
        requires 'javafx.base';
        requires 'com.fasterxml.jackson.databind';
    }

    options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages', '--ignore-signing-information', '--exclude-files', '**.png']
    launcher {
        name = 'sparrow'
        jvmArgs = ["--add-opens=javafx.graphics/com.sun.javafx.css=org.controlsfx.controls",
                   "--add-opens=javafx.graphics/javafx.scene=org.controlsfx.controls",
                   "--add-opens=javafx.controls/com.sun.javafx.scene.control.behavior=org.controlsfx.controls",
                   "--add-opens=javafx.controls/com.sun.javafx.scene.control.inputmap=org.controlsfx.controls",
                   "--add-opens=javafx.graphics/com.sun.javafx.scene.traversal=org.controlsfx.controls",
                   "--add-opens=javafx.base/com.sun.javafx.event=org.controlsfx.controls",
                   "--add-opens=javafx.controls/javafx.scene.control.cell=com.sparrowwallet.sparrow",
                   "--add-opens=org.controlsfx.controls/impl.org.controlsfx.skin=com.sparrowwallet.sparrow",
                   "--add-opens=javafx.graphics/com.sun.javafx.tk=com.sparrowwallet.merged.module",
                   "--add-opens=javafx.graphics/com.sun.javafx.tk.quantum=com.sparrowwallet.merged.module",
                   "--add-opens=javafx.graphics/com.sun.glass.ui=com.sparrowwallet.merged.module",
                   "--add-opens=javafx.controls/com.sun.javafx.scene.control=com.sparrowwallet.merged.module",
                   "--add-opens=javafx.graphics/com.sun.javafx.menu=com.sparrowwallet.merged.module",
                   "--add-opens=javafx.graphics/com.sun.glass.ui.mac=com.sparrowwallet.merged.module"]
    }
    addExtraDependencies("javafx")
    jpackage {
        imageName = "Sparrow"
        installerName = "Sparrow"
        appVersion = "0.6"
        skipInstaller = true
        imageOptions = []
        installerOptions = [
                '--file-associations', 'src/main/resources/associations.properties',
        ]
        if (org.gradle.internal.os.OperatingSystem.current().windows) {
            installerOptions += ['--win-per-user-install', '--win-dir-chooser', '--win-menu']
        }
        if (org.gradle.internal.os.OperatingSystem.current().macOsX) {
            installerOptions += ['--mac-sign', '--mac-signing-key-user-name', 'Craig Raw (UPLVMSK9D7)']
            imageOptions += ['--icon', 'src/main/deploy/package/macosx/sparrow.icns']
            installerType = "dmg"
        }
    }
}
