/*
 * This file was generated by the Gradle 'init' task.
 *
 * It describes how to build the dokan-java project.
 *
 * To publish to the local Maven repository, execute 'gradle publishToMavenLocal'
 */

plugins {
    // Apply the java-library plugin to add support for Java Library
    id 'java-library'
    id 'maven-publish'
    id 'com.jfrog.bintray' version '1.8.4'
}

tasks.withType(JavaCompile) {
    options.incremental = true
    options.encoding = 'UTF-8'
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
    options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}

dependencies {
    implementation (group:'net.java.dev.jna', name:'jna', version:jnaVersion)
    api (group:'net.java.dev.jna', name:'jna-platform', version:jnaVersion)
    testImplementation (group:'org.slf4j', name:'slf4j-simple', version:'1.7.25')
    testImplementation (group:'org.junit.jupiter', name:'junit-jupiter-api', version:junitVersion)
    testRuntimeOnly (group:'org.junit.jupiter', name:'junit-jupiter-engine', version:junitVersion)
}

// In this section you declare where to find the dependencies of your project
repositories {
    mavenCentral()
    jcenter()
}

//Check if the bintray credentials are defined, otherwise set them to dummy values
ext {
    if(project.hasProperty('bintrayUsername')){
        bintrayUser = bintrayUsername
    } else {
        bintrayUser = 'NOT DEFINED'
    }
    if(project.hasProperty('bintrayApiKey')){
        bintrayKey = bintrayApiKey
    } else {
        bintrayKey = 'NOT DEFINED'
    }
}

bintray{
    user = bintrayUser
    key = bintrayKey
    publications = ['release']
    pkg {
        version {
            name = project.version
            desc = project.description
            released = new Date()
            vcsTag = project.version
            gpg {
                sign = true
                passphrase = System.getenv("PWD")
            }
        }
        repo = 'maven'
        name = project.name
        licenses = ['LGPL-3.0']
        vcsUrl = scmUrl
    }
}

test {
    useJUnitPlatform()
}

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

task javadocJar(type: Jar) {
    archiveClassifier = 'javadoc'
    from javadoc.destinationDir
}

task showBintrayInfo() {
    description 'Shows your system bintray credentials, if defined, otherwise NOT DEFINED '
    group 'bintray'
    doLast() {
        println bintrayUser
        print bintrayKey
    }
}

task showProjectInfo(){
    doLast() {
        println project.name
        println project.version
        println project.description
    }
}

tasks {
    jar {
        manifest {
            attributes(
                    'Implementation-Title': project.name,
                    'Implementation-Version': project.version,
                    'Specification-Title': project.description,
                    'Specification-Version': project.version,
            )
        }
    }
}

publishing {
    publications {
        release(MavenPublication) {
            from components.java
            groupId group
            artifactId artifact
            artifact sourcesJar
            artifact javadocJar
            pom {
                name  = project.name
                description = project.description
                url = scmUrl
                licenses {
                    license {
                        name = licenseName
                        url = licenseUrl
                        distribution = "repo"
                    }
                }
                developers {
                    developer {
                        id = maintainerId
                        name = maintainer
                        email = maintainerMail
                        timezone = '+1'
                    }
                }
                scm {
                    connection = 'scm:git:git://github.com/dokan-dev/dokan-java.git'
                    url = scmUrl
                }
            }
        }
    }
}

javadoc {
    if(JavaVersion.current().isJava9Compatible()) {
        options.addBooleanOption('html5', true)
    }
}
