// START SNIPPET use-war-plugin
apply plugin: 'war'
// END SNIPPET use-war-plugin
// START SNIPPET use-jetty-plugin
apply plugin: 'jetty'
// END SNIPPET use-jetty-plugin

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'commons-io', name: 'commons-io', version: '1.4'
    compile group: 'log4j', name: 'log4j', version: '1.2.15', ext: 'jar'
}

gradle.taskGraph.whenReady {graph ->
    if (graph.hasTask(runTest) || graph.hasTask(runWarTest)) {
        [jettyRun, jettyRunWar]*.daemon = true
    }
}
stopKey = 'foo'
stopPort = 9451
httpPort = 8163

task runTest(dependsOn: jettyRun) << {
    callServlet()
}

task runWarTest(dependsOn: jettyRunWar) << {
    callServlet()
}

private void callServlet() {
    URL url = new URL("http://localhost:$httpPort/quickstart")
    println url.text
    jettyStop.execute()
}
