package com.perforce.workshop.tjuricek.p4oauth import org.gradle.api.DefaultTask /** * This provides basic handles to the background test server process. * * It should be spawned (and detached) then stopped later. */ abstract class TestServerTask extends DefaultTask { boolean isRunning() { if (pidFile.exists()) { logger.info("checking if process is running using `ps aux`") def pid = pidFile.text.trim() def proc = "ps aux".execute() proc.waitFor() if (proc.exitValue() != 0) { throw new IllegalStateException("ps aux failed with exit code " + proc.exitValue() + "\n" + proc.errorStream.text) } def psOut = proc.inputStream.text logger.info("output of ps: " + psOut) return psOut.contains(pid) } return false; } File getTestServerDir() { return project.file("${project.buildDir}/test-server") } File getPidFile() { return new File(testServerDir, "pid") } }