Skip to content

Instantly share code, notes, and snippets.

@craigatk
Created October 15, 2013 22:22
Show Gist options
  • Select an option

  • Save craigatk/6999605 to your computer and use it in GitHub Desktop.

Select an option

Save craigatk/6999605 to your computer and use it in GitHub Desktop.
Process grailsTestAppProcess
test.doFirst {
// Using the Grails wrapper to start the Grails application in the 'test' environment so the remote control
// plugin is enabled and my remote util bean is injected from resources.groovy
println "Starting grails app"
String grailsRunAppCommand
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
grailsRunAppCommand = "grailsw.bat test run-app"
} else {
grailsRunAppCommand = "./grailsw test run-app"
}
grailsTestAppProcess = execCommandAndWaitForStatusString(grailsRunAppCommand, 'Server running.')
}
/**
* Credit for this method goes to Tomas Lin
* http://fbflex.wordpress.com/2013/03/14/gradle-madness-execwait-a-task-that-waits-for-commandline-calls-to-be-ready/
*/
Process execCommandAndWaitForStatusString(String command, String readyStatusString) {
ProcessBuilder builder = new ProcessBuilder(command.split(' '))
builder.redirectErrorStream(true)
builder.directory(new File("."))
Process process = builder.start()
InputStream processStdout = process.getInputStream()
BufferedReader reader = new BufferedReader(new InputStreamReader(processStdout))
def line
while ((line = reader.readLine()) != null) {
println line
if (line.contains(readyStatusString)) {
println "'${command}' is ready"
break;
}
}
process.consumeProcessOutput(System.out, System.err)
return process
}
@sharurox
Copy link

Shouldn't we reader.close?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment