/*
 * This file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Java project to get you started.
 * For more details take a look at the Java Quickstart chapter in the Gradle
 * User Manual available at https://docs.gradle.org/5.2.1/userguide/tutorial_java_projects.html
 */

plugins {

    // Apply the application plugin to add support for building an application
    id 'application'

}

version '3.0.5'

repositories {
    mavenCentral()

    // Needed for the EPUB lib artifact.
    maven {
        url 'https://maven.openkm.com/'
    }

/*
    maven {
        //id 'psiegman-repo'
        url 'https://github.com/psiegman/mvn-repo/raw/master/releases'
    }
*/
    maven {
            url 'https://oss.sonatype.org/content/repositories/snapshots/'
        }

}

dependencies {

    implementation fileTree('3rd-party-jars') {
        include 'josql-2.3.jar'
        include 'gentlyweb-properties-3.jar'
        include 'javadiff.jar'

        // Spellchecker
        include 'suggester-1.1.2.jar'

        // TODO Investigate using maven?
        include 'jazzy-core.jar'

        include 'suggester-1.1.2.jar'
        include 'GWordCram-0.1.jar'

        // TODO Remove when no longer using Swing/AWT
        include 'jcalendar-1.4.jar'

        include 'h2mig_pagestore_addon.jar'

    }

    //compile 'org.jsoup:jsoup:1.11.3'
    implementation 'org.jsoup:jsoup:1.11.3'

    // Use JUnit test framework
    testImplementation 'junit:junit:4.12'

    // XML Parser
    implementation 'pull-parser:pull-parser:2.1.10'

    // Docx4J
    implementation 'org.docx4j:docx4j-JAXB-ReferenceImpl:11.5.2'

    // Bouncy castle crypto
    implementation 'org.bouncycastle:bcprov-jdk15on:1.62'
    implementation 'org.bouncycastle:bcpg-jdk15on:1.62'

    // TODO This is probably not needed now since we can scale images via JavaFX.
    implementation 'org.imgscalr:imgscalr-lib:4.2'

    // DBCP implementation (Apache)
    implementation 'org.apache.commons:commons-dbcp2:2.6.0'

    // Apache Commons IO
    implementation 'commons-io:commons-io:2.16.1'

    // H2 DB
    implementation 'com.h2database:h2:1.3.175'

    // EPUB lib
    implementation 'nl.siegmann.epublib:epublib-core:3.1'

    // POI hwpf (.doc file reading)
    //implementation 'org.apache.poi:poi-scratchpad:4.1.0'

    // JFreeChart
    //implementation 'org.jfree:jfreechart:1.5.0'

    // JFreeChart-FX
    //implementation 'org.jfree:jfreechart-fx:1.0.1'

    // Smack
    implementation 'org.igniterealtime.smack:smack-core:4.4.4'
    implementation 'org.igniterealtime.smack:smack-extensions:4.4.4'
    implementation 'org.igniterealtime.smack:smack-tcp:4.4.4'
    implementation 'org.igniterealtime.smack:smack-im:4.4.4'
    implementation 'org.igniterealtime.smack:smack-java8:4.4.4'

    // RichtextFX
    implementation 'org.fxmisc.richtext:richtextfx:0.11.4'

    // This is temporary for testing changes to a local version of richtextfx.  Ignore.
    // TEMP ADD RICHTEXTFX JARS AND DEPS
/*
     implementation fileTree('d:/reference/java/afester-richtextfx/RichTextFX/richtextfx/build/libs/') {
        //include 'richtextfx-1.0.0-SNAPSHOT.jar'
        include 'richtextfx-0.10.8-rc1.jar'
        include 'flowless-0.6.7.jar'
        include 'reactfx-2.0-M5.jar'
        include 'undofx-2.1.1.jar'
        include 'wellbehavedfx-0.3.3.jar'
    }
*/
    // Flying Saucer (can be removed when no longer using Swing)
    //implementation 'org.xhtmlrenderer:flying-saucer-core:9.1.18'

    // JGoodies (remove when no longer using Swing)
    //implementation 'com.jgoodies:jgoodies-looks:2.7.0'
    //implementation 'com.jgoodies:jgoodies-forms:1.9.0'

    // AnimateFX (test)
    //implementation 'io.github.typhon0:AnimateFX:1.2.1'

    // SVG support
    //implementation 'de.codecentric.centerdevice:javafxsvg:1.3.0'

    // PDF support
    //implementation 'org.apache.pdfbox:pdfbox:2.0.20'

    // DOM4J
    implementation 'org.dom4j:dom4j:2.1.3'

    // AWS s3 - testing
    //implementation 'software.amazon.awssdk:s3:2.30.27'

    // Patreon - testing
    //implementation 'com.patreon:patreon:0.4.2'

}

compileJava {

    // Exclude the exerimental stuff
    sourceSets {
        main {
            java {
                exclude 'com/quollwriter/ui/fx/panels/experimental/**'
            }
        }
    }

    options.incremental = true

    options.compilerArgs =
    [
        '--add-modules',
        'java.base,javafx.swing,javafx.controls,javafx.media,javafx.web,java.instrument,jdk.attach',
        '--add-exports',
        'javafx.graphics/com.sun.javafx.iio=ALL-UNNAMED',
        '--add-exports',
        'javafx.graphics/com.sun.javafx.iio.common=ALL-UNNAMED',
        '--add-exports',
        'javafx.web/com.sun.javafx.webkit=ALL-UNNAMED',
        '--add-exports',
        'javafx.web/com.sun.webkit=ALL-UNNAMED',
        '--module-path',
        // This is a property that should be defined (usually) in gradle.prpoerties, i.e. module_path=/usr/share/lib/javafx-sdk-12/lib
        module_path,
        '-Xmaxerrs',
        '1000'
    ]
}

jar {

    // Exclude the exerimental stuff
    sourceSets {
        main {
            java {
                exclude 'com/quollwriter/ui/fx/panels/experimental/**'
            }
        }
    }

    doFirst {
        file("${sourceSets.main.output.resourcesDir}/data/version.txt").text = "$version"
    }
}

javadoc {
    doFirst {
        options.addStringOption ('-module-path', module_path)
        options.addStringOption ('-add-modules', 'javafx.controls,javafx.swing,javafx.media,javafx.web,java.instrument,jdk.attach')
    }
}

application {
    applicationDefaultJvmArgs =
    [
        '-Djava.locale.providers=COMPAT',
        '--module-path',
        // This is a property that should be defined (usually) in gradle.prpoerties, i.e. module_path=/usr/share/lib/javafx-sdk-12/lib
        module_path,
        '--add-modules=javafx.controls,javafx.swing,javafx.media,javafx.web,java.instrument,jdk.attach',
        '--add-exports',
        'javafx.graphics/com.sun.javafx.iio=ALL-UNNAMED',
        '--add-exports',
        'javafx.graphics/com.sun.javafx.iio.common=ALL-UNNAMED',
        '--add-exports',
        'javafx.graphics/com.sun.javafx.scene.text=ALL-UNNAMED',
        '--add-exports',
        'javafx.graphics/com.sun.javafx.geom=ALL-UNNAMED',
        '--add-opens',
        'javafx.graphics/javafx.scene.text=ALL-UNNAMED',
        '--add-opens',
        'javafx.graphics/com.sun.javafx.text=ALL-UNNAMED',
        '--add-exports',
        'javafx.graphics/com.sun.javafx.geom=ALL-UNNAMED',
        '--add-exports',
        'javafx.graphics/com.sun.javafx.scene.text=ALL-UNNAMED',
        '--add-exports',
        'javafx.graphics/com.sun.javafx.tk=ALL-UNNAMED',
        '--add-exports',
        'javafx.web/com.sun.javafx.webkit=ALL-UNNAMED',
        '--add-exports',
        'javafx.web/com.sun.webkit=ALL-UNNAMED'
    ]

    // Define the main class for the application
    mainClassName 'com.quollwriter.Startup'

}

run {
    dependsOn jar
}

configurations.all {
    resolutionStrategy {
        force 'commons-io:commons-io:2.16.1',
          'commons-codec:commons-codec:1.15',
          'commons-io:commons-io:2.16.1',
          'org.slf4j:slf4j-api:1.8.0-beta4',
          'pull-parser:pull-parser:2.1.10'
    }
}

task copyToLib(type: Copy) {
    delete "$buildDir/libs"
    into "$buildDir/libs"
    from configurations.runtimeClasspath
}

/*
task printCompileClasspath {
    def compileClasspath = sourceSets.main.compileClasspath
    inputs.files( compileClasspath )
    doLast {
        println compileClasspath.join( File.pathSeparator )
    }
}
*/
/*
task printSrcDirs {
    sourceSets.each {
        println(it)
        it.allSource.each {
            println(it)
        }
    }
}
*/
