plugins {
    id 'java'
    id 'maven'
    id 'war'
    id 'maven-publish'
    id "com.jfrog.bintray" version "1.0"
}

group = 'com.trunkplatform.opensymphony'
version = project.hasProperty('app_version') ? app_version : 'local'

description = "bare minimum OpenSymphony Workflow based on 3.0 code base"

sourceCompatibility = 1.7
targetCompatibility = 1.7

repositories {
    jcenter()
    maven { url "http://dl.bintray.com/trunkplatform/osworkflow" }
}
dependencies {

    compile group: 'bsf', name: 'bsf', version: '2.4.0'
    compile group: 'bsh', name: 'bsh', version: '1.2b7'
    compile group: 'velocity', name: 'velocity-dep', version: '1.4'

    // opensymphony
    compile group: 'opensymphony', name: 'oscore', version: '2.2.4'
    compile group: 'opensymphony', name: 'osuser', version: '1.0-dev-10Sep06'
    compile group: 'opensymphony', name: 'propertyset', version: '1.5'
    compile group: 'opensymphony', name: 'webwork', version: '1.4'
    compile group: 'opensymphony', name: 'xwork', version: '1.0'

    // spring
    compile group: 'org.springframework', name: 'spring-context', version: '3.2.8.RELEASE'

    // war
    providedCompile group: 'javax.servlet', name: 'servlet-api', version: '2.5'
}

// custom tasks for creating source/javadoc jars
task sourcesJar(type: Jar, dependsOn: classes) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

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

// add javadoc/source jar tasks as artifacts
artifacts {
    archives sourcesJar, javadocJar
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            pom.withXml {
                asNode().dependencies.'*'.findAll() {
                    it.scope.text() == 'runtime' && project.configurations.compile.allDependencies.find { dep ->
                        dep.name == it.artifactId.text()
                    }
                }.each() {
                    it.scope*.value = 'compile'
                }
            }
            from components.java
            artifact sourcesJar {
                classifier "sources"
            }
            artifact javadocJar {
                classifier "javadoc"
            }
        }
    }
}

javadoc {
    failOnError = false
}

bintray {
    user = bintrayUser
    key = bintrayApiKey

    publications = ['mavenJava']

    dryRun = false //Whether to run this as dry-run, without deploying
    publish = true //If version should be auto published after an upload
    pkg {
        repo = 'osworkflow'
        userOrg = 'trunkplatform'
        name = 'trunkplatform:osworkflow'
        desc = 'Custom OpenSymphony workflow based on 3.0'
        websiteUrl = 'https://github.com/Trunkplatform/osworkflow'
        issueTrackerUrl = 'https://github.com/Trunkplatform/osworkflow/issues'
        vcsUrl = 'https://github.com/Trunkplatform/osworkflow.git'
        licenses = ['Apache-2.0']
        labels = ['opensymphony', 'osworkflow']
        publicDownloadNumbers = true
    }
}