Created
October 15, 2013 22:22
-
-
Save craigatk/6999605 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Shouldn't we reader.close?