buildscript {
    repositories {
        jcenter()
        mavenLocal()
    }
    
    dependencies {
        classpath 'org.codehaus.griffon:gradle-griffon-plugin:2.15.1'
        classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.2'
        classpath 'nl.javadude.gradle.plugins:license-gradle-plugin:0.11.0'
        classpath 'org.gradle.api.plugins:gradle-izpack-plugin:0.2.3'
        classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
        classpath 'com.github.cr0:gradle-macappbundle-plugin:3.1.0'
        classpath 'org.kordamp.gradle:stats-gradle-plugin:0.2.2'
        classpath 'com.github.ben-manes:gradle-versions-plugin:0.17.0'
        classpath 'de.gliderpilot.gradle.jnlp:gradle-jnlp-plugin:1.2.5'
        classpath 'net.nemerosa:versioning:2.6.1'
    }
}

apply plugin: 'org.codehaus.griffon.griffon'
apply plugin: 'net.nemerosa.versioning'

Date buildTimeAndDate = new Date()
ext {
    buildDate = new SimpleDateFormat('yyyy-MM-dd').format(buildTimeAndDate)
    buildTime = new SimpleDateFormat('HH:mm:ss.SSSZ').format(buildTimeAndDate)
    macosx = System.getProperty('os.name').contains('Mac OS')
}

griffon {
    disableDependencyResolution = false
    includeGroovyDependencies = true
    version = '2.15.1'
    toolkit = 'swing'
    applicationProperties = [
        'build_date'    : buildDate,
        'build_time'    : buildTime,
        'build_revision': versioning.info.commit
    ]
}

mainClassName = 'com.muwire.gui.Launcher'
applicationDefaultJvmArgs = ['-Djava.util.logging.config.file=logging.properties']

apply from: 'gradle/publishing.gradle'
// apply from: 'gradle/code-coverage.gradle'
// apply from: 'gradle/code-quality.gradle'
// apply from: 'gradle/integration-test.gradle'
// apply from: 'gradle/package.gradle'
apply from: 'gradle/docs.gradle'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'org.kordamp.gradle.stats'
apply plugin: 'com.github.ben-manes.versions'
apply plugin: 'com.github.kt3k.coveralls'

dependencies {
    compile project(":core")
    compile "org.codehaus.griffon:griffon-guice:${griffon.version}"

    // runtime "org.slf4j:slf4j-simple:${slf4jVersion}"

    runtime group: 'org.slf4j', name: 'slf4j-jdk14', version: "${slf4jVersion}"
    runtime group: 'org.slf4j', name: 'slf4j-api', version: "${slf4jVersion}"    
    runtime group: 'org.slf4j', name: 'jul-to-slf4j', version: "${slf4jVersion}"
    runtime "javax.annotation:javax.annotation-api:1.3.2"

    testCompile "org.codehaus.griffon:griffon-fest-test:${griffon.version}"
    testCompile "org.spockframework:spock-core:${spockVersion}"
    testCompile('org.awaitility:awaitility-groovy:3.1.0') {
        exclude group: 'org.codehaus.groovy', module: 'groovy-all'
    }
    testCompile "org.codehaus.groovy:groovy-all:${groovyVersion}"
}

task sourceJar(type: Jar) {
    group 'Build'
    description 'An archive of the source code'
    classifier 'sources'
    from sourceSets.main.allSource
}

tasks.withType(JavaCompile) {
    sourceCompatibility = project.sourceCompatibility
    targetCompatibility = project.targetCompatibility
}

tasks.withType(GroovyCompile) {
    sourceCompatibility = project.sourceCompatibility
    targetCompatibility = project.targetCompatibility
}

import com.github.jengelman.gradle.plugins.shadow.transformers.*
import java.text.SimpleDateFormat

ext.backgroundImage = 'i2plogo.png'

shadowJar {
    transform(ServiceFileTransformer)
    transform(ServiceFileTransformer) {
        path = 'META-INF/griffon'
    }
    transform(ServiceFileTransformer) {
        path = 'META-INF/types'
    }
    transform(PropertiesFileTransformer) {
        paths = [
            'META-INF/editors/java.beans.PropertyEditor'
        ]
    }
}

startScripts {
    doLast {
        if (!macosx) unixScript.text = unixScript.text.replaceAll('"(-Xdock:(name|icon)=)([^"]*?)(")', ' ')
        windowsScript.text = windowsScript.text.replaceAll('"(-Xdock:(name|icon)=)([^"]*?)(")', ' ')
    }
}

if (hasProperty('debugRun') && ((project.debugRun as boolean))) {
    run {
        jvmArgs '-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005'
    }
}

/*
task jacocoRootMerge(type: org.gradle.testing.jacoco.tasks.JacocoMerge, dependsOn: [test, jacocoTestReport, jacocoIntegrationTestReport]) {
    executionData = files(jacocoTestReport.executionData, jacocoIntegrationTestReport.executionData)
    destinationFile = file("${buildDir}/jacoco/root.exec")
}

task jacocoRootReport(dependsOn: jacocoRootMerge, type: JacocoReport) {
    group = 'Reporting'
    description = 'Generate Jacoco coverage reports after running all tests.'
    executionData file("${buildDir}/jacoco/root.exec")
    sourceDirectories = files(sourceSets.main.allSource.srcDirs)
    classDirectories = files(sourceSets.main.output)
    reports {
        csv.enabled = false
        xml.enabled = true
        html.enabled = true
        html.destination = file("${buildDir}/reports/jacoco/root/html")
        xml.destination = file("${buildDir}/reports/jacoco/root/root.xml")
    }
}
*/

