apply plugin: 'maven'
apply plugin: 'signing'

group = 'org.fxmisc.undo'

dependencies {
    compile group: 'org.reactfx', name: 'reactfx', version: '2.0-M5'
    testCompile group: 'junit', name: 'junit', version: '[4.0,)'
}

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

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/8/docs/api/',
        'http://docs.oracle.com/javase/8/javafx/api/',
        // resolve links to ReactFX
        'http://www.reactfx.org/javadoc/2.0-M5/'
    ]
}

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

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

artifacts {
    archives jar

    archives javadocJar
    archives sourcesJar
}

signing {
    sign configurations.archives
}

signArchives.onlyIf {
    project.hasProperty('signing.keyId') && project.hasProperty('signing.password') && project.hasProperty('signing.secretKeyRingFile')
}

def doUploadArchives = project.hasProperty('sonatypeUsername') && project.hasProperty('sonatypePassword')

if(doUploadArchives) {
    uploadArchives {
        repositories.mavenDeployer {
            beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

            repository(url: "https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/") {
              authentication(userName: sonatypeUsername, password: sonatypePassword)
            }

            snapshotRepository(url: 'https://central.sonatype.com/repository/maven-snapshots/') {
                authentication(userName: sonatypeUsername, password: sonatypePassword)
            }

            pom.project {
                name 'UndoFX'
                packaging 'jar'
                description 'Undo manager for JavaFX'
                url 'http://www.fxmisc.org/undo/'
             
                scm {
                    url 'scm:git@github.com:TomasMikula/UndoFX.git'
                    connection 'scm:git@github.com:TomasMikula/UndoFX.git'
                    developerConnection 'scm:git@github.com:TomasMikula/UndoFX.git'
                }
             
                licenses {
                    license {
                        name 'The BSD 2-Clause License'
                        url 'http://opensource.org/licenses/BSD-2-Clause'
                        distribution 'repo'
                    }
                }
             
                developers {
                    developer {
                        name 'Tomas Mikula'
                    }
                }
            }
        }
    }
}

uploadArchives.onlyIf { doUploadArchives }

task fatJar(type: Jar, dependsOn: classes) {
    appendix = 'fat'
    from sourceSets.main.output
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}

assemble.dependsOn fatJar
