apply plugin: "java-library"

buildscript{
    repositories {
        jcenter()
    }
    dependencies{

    }
}


apply plugin: 'maven-publish'


sourceCompatibility = 1.8
targetCompatibility = 1.8

sourceSets.main.java.srcDirs = [ "src/" ]
sourceSets.main.resources.srcDirs = [ "res/",
                                      "libs/linux32", "libs/linux64",
                                      "libs/macosx32", "libs/macosx64",
                                      "libs/windows32", "libs/windows64",]
sourceSets.test.java.srcDirs = [ ]
sourceSets.test.resources.srcDirs = [ ]

repositories {
    mavenCentral()
    maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
    maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}

dependencies {
    compile "com.badlogicgames.gdx:gdx-jnigen:1.9.10"
    api "com.badlogicgames.gdx:gdx:1.9.9"
    api "com.badlogicgames.gdx:gdx-controllers:1.9.9"
}

task deleteJniFolder(type: Delete) {
    delete "jni"
    delete "docs"
}

clean.dependsOn(deleteJniFolder)

task runTester(dependsOn: classes, type: JavaExec) {
    main = 'uk.co.electronstudio.sdl2gdx.tests.SDLTest'
    classpath = sourceSets.main.runtimeClasspath
    standardInput = System.in
}

task linuxNatives(dependsOn: classes, type: JavaExec) {
    main = 'uk.co.electronstudio.sdl2gdx.NativesBuild'
    args = ['build-linux', 'system-SDL2']
    classpath = sourceSets.main.runtimeClasspath
    standardInput = System.in
}

task windowsNatives(dependsOn: classes, type: JavaExec) {
    main = 'uk.co.electronstudio.sdl2gdx.NativesBuild'
    args = ['build-windows',  'system-SDL2']
    classpath = sourceSets.main.runtimeClasspath
    standardInput = System.in
}

task OSXNatives(dependsOn: classes, type: JavaExec) {
    main = 'uk.co.electronstudio.sdl2gdx.NativesBuild'
    args = ['build-OSX', 'system-SDL2']
    classpath = sourceSets.main.runtimeClasspath
    standardInput = System.in
}

task allNatives(dependsOn: classes, type: JavaExec) {
    main = 'uk.co.electronstudio.sdl2gdx.NativesBuild'
    args = ['build-linux', 'build-windows', 'build-OSX']
    classpath = sourceSets.main.runtimeClasspath
    standardInput = System.in
}

task uberjar(dependsOn: classes, type: Jar) {
    from files(sourceSets.main.output.classesDir)
    from files(sourceSets.main.output.resourcesDir)
    from {configurations.compile.collect {zipTree(it)}}

    manifest {
        attributes 'Main-Class': 'uk.co.electronstudio.sdl2gdx.tests.SDLTest'
    }
}



task sourcesJar(type: Jar, dependsOn: classes) {
    classifier = 'sources'
    from sourceSets.main.allSource
}
javadoc {
    exclude 'com/badlogic/**'
    destinationDir = new File('docs')
    options.overview = "overview.html"
}

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

artifacts {
    archives sourcesJar
    archives javadocJar
}

def pomConfig = {
    licenses {
        license {
            name "GPLv3 with Classpath Exception"
            url "https://www.gnu.org/software/classpath/license.html"
            distribution "repo"
        }
    }
    developers {
        developer {
            id "electronstudio"
            name "Electron Studio"
            email "support@electronstudio.co.uk"
        }
    }

    scm {
        url "https://github.com/electronstudio/"
    }
}

publishing {
    publications {
        mavenPublication(MavenPublication) {
            from components.java
            artifact sourcesJar {
                classifier "sources"
            }
            artifact javadocJar {
                classifier "javadoc"
            }
            groupId 'uk.co.electronstudio.sdl2gdx'
            artifactId 'sdl2gdx'
            version '1.0.4'

            pom.withXml {
                def root = asNode()
                root.appendNode('description', 'LibGDX extension library')
                root.appendNode('name', 'sdl2gdx')
                root.appendNode('url', 'https://github.com/electronstudio/sdl2gdx')
                root.children().last() + pomConfig
            }
        }
    }
    publish.dependsOn jar, sourcesJar, javadocJar//, generatePomFileForMavenPublicationPublication
}

