buildscript {
  repositories {
    jcenter()
  }
  dependencies {
    classpath 'org.akhikhl.gretty:gretty:1.2.4'
  }
}

repositories {
    maven { url "lib" }
    jcenter()
}

apply plugin: 'war'
apply plugin: 'org.akhikhl.gretty'

description = ''

gretty {
    servletContainer = 'jetty8'
    host = '0.0.0.0'
    port = 8080
    contextPath = '/renkan'
}


ext {
    javax_ws_rs_api_version = '2.0'
    javax_annotation_api_version = '1.2'
    cometd_version = '2.7.0'
    coweb_version = '1.0.1-SNAPSHOT'
    cowebx_version = '1.0'
    jersey_version = '2.5.1'
    thymeleaf_version = '2.1.3.RELEASE'
    thymeleaf_extra_version = '2.1.1.RELEASE'
    thymeleaf_joda_dialect_version = '0.0.3'
    commons_io_version = '2.4'
    guava_version = '17.0'
    nekohtml_version = '1.9.19'
    validation_api_version = '1.1.0.Final'
    hibernate_validator_version = '5.0.1.Final'
    jstl_version = '1.2'
    json_path_assert_version = '0.9.1'
    mongeez_version = '0.9.4'
}


dependencies {
  compile project(':renkan-core')
    compile group: 'javax.inject', name: 'javax.inject', version:java_inject_version
    compile group: 'javax.servlet', name: 'javax.servlet-api', version:javax_servlet_version
    compile group: 'javax.ws.rs', name: 'javax.ws.rs-api', version:javax_ws_rs_api_version
    compile group: 'javax.annotation', name: 'javax.annotation-api', version:javax_annotation_api_version
    compile(group: 'org.cometd.java', name: 'bayeux-api', version:cometd_version) {
        exclude group: 'org.eclipse.jetty'
    }
    compile(group: 'org.cometd.java', name: 'cometd-java-common', version:cometd_version) {
        exclude group: 'org.eclipse.jetty'
    }
    compile(group: 'org.cometd.java', name: 'cometd-java-annotations', version:cometd_version) {
        exclude group: 'org.eclipse.jetty'
    }
    compile(group: 'org.cometd.java', name: 'cometd-websocket-jetty', version:cometd_version) {
        exclude group: 'org.eclipse.jetty'
    }
    compile (group: 'org.opencoweb', name: 'coweb-bots', version:coweb_version) {
        exclude group: 'org.eclipse.jetty'
    }
    compile (group: 'org.opencoweb', name: 'coweb-server', version:coweb_version) {
        exclude group: 'org.eclipse.jetty'
    }
    providedCompile (group: 'org.opencoweb', name: 'coweb-javascript', version:coweb_version) {
        exclude group: 'org.eclipse.jetty'
    }
    providedCompile group: 'org.opencoweb.cowebx', name: 'cowebx-widgets-dojo', version:cowebx_version
    compile group: 'org.glassfish.jersey.core', name: 'jersey-server', version:jersey_version
    compile group: 'org.glassfish.jersey.ext', name: 'jersey-spring3', version:jersey_version
    compile group: 'org.mongodb', name: 'mongo-java-driver', version:mongo_java_driver_version
    compile group: 'org.springframework', name: 'spring-core', version:spring_version
    compile group: 'org.springframework', name: 'spring-context', version:spring_version
    compile group: 'org.springframework', name: 'spring-web', version:spring_version
    compile group: 'org.springframework', name: 'spring-webmvc', version:spring_version
    compile group: 'org.springframework.data', name: 'spring-data-commons', version:spring_data_commons_version
    compile group: 'org.springframework.data', name: 'spring-data-jpa', version:spring_data_jpa_version
    compile group: 'org.springframework.data', name: 'spring-data-mongodb', version:spring_data_mongodb_version
    compile group: 'javax.persistence', name: 'persistence-api', version:persistence_api_version
    compile group: 'org.thymeleaf', name: 'thymeleaf', version:thymeleaf_version
    compile group: 'org.thymeleaf', name: 'thymeleaf-spring3', version:thymeleaf_version
    compile group: 'org.thymeleaf.extras', name: 'thymeleaf-extras-springsecurity3', version:thymeleaf_extra_version
    compile group: 'org.thymeleaf.extras', name: 'thymeleaf-joda-dialect', version:thymeleaf_joda_dialect_version
    compile group: 'net.sourceforge.nekohtml', name: 'nekohtml', version:nekohtml_version
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version:jackson_version
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version:jackson_version
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version:jackson_version
    compile group: 'com.fasterxml.jackson.jaxrs', name: 'jackson-jaxrs-json-provider', version:jackson_version
    compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-joda', version:jackson_version
    compile group: 'commons-codec', name: 'commons-codec', version:commons_codec_version
    compile group: 'org.springframework.security', name: 'spring-security-core', version:spring_security_version
    compile group: 'org.springframework.security', name: 'spring-security-web', version:spring_security_version
    compile group: 'org.springframework.security', name: 'spring-security-config', version:spring_security_version
    compile group: 'org.springframework.security', name: 'spring-security-acl', version:spring_security_version
    compile group: 'org.springframework.security', name: 'spring-security-taglibs', version:spring_security_version
    compile group: 'de.undercouch', name: 'bson4jackson', version:jackson_version
    compile group: 'joda-time', name: 'joda-time', version:joda_time_version
    compile group: 'javax.validation', name: 'validation-api', version:validation_api_version
    compile group: 'org.hibernate', name: 'hibernate-validator', version:hibernate_validator_version
    compile group: 'com.google.guava', name: 'guava', version:guava_version
    runtime group: 'javax.servlet', name: 'jstl', version:jstl_version
    runtime group: 'org.eclipse.jetty.aggregate', name: 'jetty-all', version:jetty_version
    runtime group: 'org.mongeez', name: 'mongeez', version:mongeez_version
    testCompile group: 'org.glassfish.jersey.test-framework.providers', name: 'jersey-test-framework-provider-grizzly2', version:jersey_version
    testCompile group: 'org.springframework', name: 'spring-test', version:spring_version
    testCompile group: 'com.jayway.jsonpath', name: 'json-path-assert', version:json_path_assert_version
    testCompile group: 'commons-io', name: 'commons-io', version:commons_io_version
}

// call grunt
task buildClient(type:Exec) {
    workingDir "../../../client"
    commandLine "node_modules/.bin/grunt"
}
//apply overlay

war {
    manifest { attributes(
        "Implementation-Vendor": organization,
        "Implementation-Title": project.name,
        "Implementation-Version": project.version,
        "Implementation-Vendor-Id": project.group,
        "Built-By": "$System.env.USER",
        "Build-Jdk": System.getProperty('java.version'),
        "Specification-Vendor": organization,
        "Specification-Title": project.name,
        "Specification-Version": project.version
    ) }

    // coweb-javascript
    from({ zipTree(configurations.providedCompile.filter{ it.name.startsWith('coweb-javascript') && it.name.endsWith(".war")}.singleFile)}) {
        exclude "META-INF/**"
        exclude "WEB-INF/**"
        into "lib"
    }

    from( {zipTree(configurations.providedCompile.filter{ it.name.startsWith('cowebx-widgets-dojo') && it.name.endsWith(".war")}.singleFile)}) {
        exclude "META-INF/**"
        exclude "WEB-INF/**"
        into "lib/cowebx/dojo"
    }

    from("../../../client/dist/js") {
        include "*.js"
        into "static/js"
    }
    from("../../../client/dist/lib") {
        into "static/lib"
    }
    from("../../../client/dist/css") {
        include "*.css"
        into "static/css"
    }
    from("../../../client/dist/img") {
        into "static/img"
    }
    from("../../../client/dist/data") {
        include "properties.json"
        into "static/data"
    }
}

war.dependsOn buildClient
