plugins {
    id 'com.github.kt3k.coveralls' version '2.8.2' // Coverage
    id "com.jfrog.bintray" version "1.8.4"
}

apply plugin: 'java-library'
apply plugin: 'maven-publish'

group 'de.inetsoftware'
archivesBaseName = 'jwebassembly-compiler'
version = '0.3'

repositories {
    jcenter()
    maven { url 'https://jitpack.io' } // for snapshot of the API
}

dependencies {
    // "compileOnly" will not add as dependency. this is different to "compile". 
    compileOnly 'com.google.code.findbugs:jsr305:3.0.1'
    //compileOnly 'de.inetsoftware:jwebassembly-api:+'
    compileOnly 'com.github.i-net-software:jwebassembly-api:master-SNAPSHOT'

    testCompile 'com.google.code.findbugs:jsr305:3.0.1'
    //testCompile 'de.inetsoftware:jwebassembly-api:+'
    testCompile 'com.github.i-net-software:jwebassembly-api:master-SNAPSHOT'
    testCompile 'junit:junit:+'
    testCompile 'org.apache.commons:commons-compress:1.2'
    testCompile 'com.google.code.gson:gson:+'
}

sourceSets {
    main {
        java {
            srcDir 'src'
        }
        resources {
            srcDir 'src'
        }
    }
    test {
        java {
            srcDir 'test'
        }
        resources {
            srcDir 'test'
        }
    }
}

compileJava.options.encoding = 'UTF-8'
compileJava.options.compilerArgs << '-Xlint:all'
compileTestJava.options.encoding = 'UTF-8'
compileTestJava.options.compilerArgs << '-Xlint:all'
javadoc.options.encoding = 'UTF-8'

jar {
    manifest {
        attributes( 'Implementation-Title': 'JWebAssembly-API',
                    'Implementation-Vendor': 'i-net software',
                    'Implementation-Version': version)
    }
}

task sourcesJar(type: Jar, dependsOn: classes) {
    classifier = 'sources'
    from sourceSets.main.java
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}

build {
    dependsOn sourcesJar
    dependsOn javadocJar
}

artifacts {
    archives sourcesJar
    archives javadocJar
}

test {
    systemProperty "file.encoding", "UTF-8"
    testLogging {
        showStandardStreams = true
        showStackTraces = true
        exceptionFormat = 'full'
        events 'passed', 'skipped', 'failed'
    }
}


/****************************************
 * Coverage
 ****************************************/
apply plugin: 'jacoco'

jacocoTestReport {
    tasks.coveralls.dependsOn it
    reports {
        xml.enabled = true  // coveralls plugin depends on xml format report
        html.enabled = true
    }
}
check.dependsOn tasks.coveralls

bintray {
    user = System.getenv('BINTRAY_USER')
    key = System.getenv('BINTRAY_KEY')
    publications = ['JWebAssemblyPublication']
    publish = true
    override = true
    pkg {
        repo = 'OSS'
        userOrg = 'i-net-software'
        licenses = ['Apache-2.0']
        vcsUrl = 'https://github.com/i-net-software'
        name = group + '.' + archivesBaseName
        version { 
            released = new Date()
        }
    }
}

publishing {
    publications {
        JWebAssemblyPublication(MavenPublication) {
            from components.java
            artifact sourcesJar
            artifact javadocJar
            artifactId archivesBaseName
            pom.withXml {
                def root = asNode()
                root.appendNode('name', 'JWebAssembly-Compiler')
                root.appendNode('description', 'A Java to WebAssembly compiler.')
                root.appendNode('url', 'https://github.com/i-net-software/JWebAssembly')

                def node = root.appendNode('developers').appendNode( 'developer' )
                node.appendNode( 'id', 'Horcrux7' )
                node.appendNode( 'name', 'Volker Berlin' )
                node.appendNode( 'email', 'vberlin@inetsoftware.de' )
                node.appendNode( 'organization', 'i-net software' )
                node.appendNode( 'organizationUrl', 'https://www.inetsoftware.de' )

                node = root.appendNode('scm')
                node.appendNode( 'connection', 'scm:git:git@github.com:i-net-software/JWebAssembly.git' )
                node.appendNode( 'developerConnection', 'scm:git:git@github.com:i-net-software/JWebAssembly.git' )
                node.appendNode( 'url', 'https://github.com/i-net-software/JWebAssembly' )

                root.children().last()
            }
        }
    }
}