buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.5.3"
    }
}

apply plugin: 'io.codearte.nexus-staging'

apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'maven'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'signing'

group = 'uk.ac.ebi.ena'
archivesBaseName = 'cramtools'
version='3.0.g202'
mainClassName = 'net.sf.cram.CramTools'

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    compile 'com.github.samtools:htsjdk:2.4.1'
    compile 'org.apache.ant:ant:1.8.2'
    compile 'org.apache.commons:commons-compress:1.9'
    compile 'org.tukaani:xz:1.5'    
    compile 'com.h2database:h2:1.3.170'
    compile 'com.beust:jcommander:1.48'
    compile files('lib/CipherOnly.jar')

    testCompile 'junit:junit:4.12'
    testCompile 'org.hamcrest:hamcrest-core:1.1'
}

task wrapper(type: Wrapper) { gradleVersion = '2.12' }

javadoc {
    classpath = configurations.compile
}

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

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

artifacts {
    archives jar
    archives javadocJar
    archives sourceJar
}

signing {
// from sourceSets.main.allSource
    sign configurations.archives
}

install {
    configuration = configurations.runtime
}

jar {
    from(zipTree("lib/CipherOnly.jar"))
    manifest {
        attributes (
                'Main-Class': mainClassName,
                "Implementation-Title": archivesBaseName,
                "Implementation-Vendor": "ENA, EMBL-EBI",
                "Implementation-Version": version,
                'Built-By': System.getProperty('user.name'),
                'Built-Date': new Date(),
                'Built-JDK': System.getProperty('java.version'))
        if (project.hasProperty('BUILD_ID')) attributes.put('Build-ID', project.BUILD_ID)
        if (project.hasProperty('BUILD_NUMBER')) attributes.put('Build-Number', project.BUILD_NUMBER)
    }
}

task uberjar(type: Jar) {
    from configurations.runtime.asFileTree.files.collect { zipTree(it) }
    from files(sourceSets.main.output.classesDir)
    from files(sourceSets.main.output.resourcesDir)
    
    manifest {
        attributes (
                'Main-Class': mainClassName,
                "Implementation-Title": archivesBaseName,
                "Implementation-Vendor": "ENA, EMBL-EBI",
                "Implementation-Version": version,
                'Built-By': System.getProperty('user.name'),
                'Built-Date': new Date(),
                'Built-JDK': System.getProperty('java.version'))
        if (project.hasProperty('BUILD_ID')) attributes.put('Build-ID', project.BUILD_ID)
        if (project.hasProperty('BUILD_NUMBER')) attributes.put('Build-Number', project.BUILD_NUMBER)
    }
}
uberjar.dependsOn jar


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

            repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2") {
                authentication(userName: ossrhUsername, password: ossrhPassword)
            }

            snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots") {
                authentication(userName: ossrhUsername, password: ossrhPassword)
            }

            pom.project {
                name 'cramtools'
                packaging 'jar'
                // optionally artifactId can be defined here
                description 'A java implementation of CRAM file format and a set of accompanying tools.'
                url 'http://www.ebi.ac.uk/ena/software/cram-toolkit'

                scm {
                    url 'https://github.com/enasequence/cramtools'
                }

                licenses {
                    license {
                        name 'The Apache License, Version 2.0'
                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    }
                }

                developers {
                    developer {
                        id 'vadim'
                        name 'Vadim Zalunin'
                        email 'vadim@ebi.ac.uk'
                    }
                }
            }
        }
    }
}

nexusStaging {
    packageGroup = "uk.ac.ebi.ena"
}

test {
    maxHeapSize = "1024m"
    jvmArgs "-Dfile.encoding=UTF-8"
    testLogging {
        events "failed", "standardOut", "standardError"
    }
}
