buildscript {
    repositories {
        mavenCentral()
    }
}

plugins {
    id 'java-library'
    id 'eclipse'
    id 'biz.aQute.bnd.builder' version '5.3.0' // OSGi
    // OSGi bundle is configured through the bnd.bnd file
    id 'com.vanniktech.maven.publish' version '0.34.0'
    id 'org.openjfx.javafxplugin' version '0.0.13'
}

version = '0.7.5-SNAPSHOT'

repositories {
    mavenCentral()
}

compileJava {
    options.release = 9
}

group = 'org.fxmisc.flowless'
project.archivesBaseName = 'flowless'

dependencies {
    implementation 'org.reactfx:reactfx:2.0-M5'
    testImplementation group: 'junit', name: 'junit', version: '4.12'
    testImplementation "org.testfx:testfx-core:4.0.11-alpha"
    testImplementation ("org.testfx:testfx-junit:4.0.11-alpha") {
        exclude(group: "junit", module: "junit")
    }
    testImplementation "org.testfx:openjfx-monocle:8u76-b04"
}

jar {
    manifest {
        attributes(
            'Automatic-Module-Name': 'org.fxmisc.flowless'
        )
    }
}

javadoc {
    // ignore missing Javadoc comments or tags
    options.addStringOption('Xdoclint:all,-missing', '-quiet')

    // support for JavaFX properties
    options.addBooleanOption('javafx', true)

    options.links = [
            // resolve links to Java and JavaFX Javadocs
            'http://docs.oracle.com/javase/9/docs/api/',
            'http://docs.oracle.com/javase/9/javafx/api/',

            // resolve links to ReactFX
            'https://www.javadoc.io/doc/org.reactfx/reactfx/2.0-M5/'
    ]
}

javafx {
    version = '11'
    modules = ['javafx.controls']
    def taskNames = gradle.getStartParameter().getTaskNames()
    // Prevent pom & module.json from containing JavaFX runtime dependencies
    if ( taskNames.stream().anyMatch( t -> t.startsWith('pub') ) ) {
        configuration = 'compileOnly'
    }
}

task fatJar(type: Jar, dependsOn: classes) {
    archiveAppendix = 'fat'
    manifest.attributes( 'Automatic-Module-Name': 'org.fxmisc.flowless' )
    from sourceSets.main.output
    from { configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
    excludes = [ 'module-info.class',  // block module-info files from other jars
        '*.dll','javafx*','javafx/',   // block inclusion of javafx files
        'com/'                         // block com/sun/* files
    ]
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    archiveClassifier = 'javadoc'
    from 'build/docs/javadoc'
}

task sourcesJar(type: Jar) {
    from sourceSets.main.allSource
    archiveClassifier = 'sources'
}

mavenPublishing {
    pom {
        name = 'flowless'
        packaging = 'jar'
        description = 'Efficient VirtualFlow for JavaFX.'
        url = 'https://github.com/FXMisc/Flowless/#flowless'
   
        scm {
            url = 'scm:git@github.com:FXMisc/flowless.git'
            connection = 'scm:git@github.com:FXMisc/Flowless.git'
            developerConnection = 'scm:git@github.com:FXMisc/Flowless.git'
        }
   
        licenses {
            license {
                name = 'The BSD 2-Clause License'
                url = 'http://opensource.org/licenses/BSD-2-Clause'
                distribution = 'repo'
            }
        }
   
        developers {
            developer {
                name = 'Tomas Mikula'
            }
            developer {
                name = 'Jordan Martinez'
            }
            developer {
                name = 'Jurgen Doll'
            }
       }
    }
}

assemble.dependsOn fatJar

task getVersion {
    doLast {
        println version
    }
}
