"serve", "--port", "0", "-d", "--pid-file",
pidFile.toString(), "-R",
repo.getDirectory().toString() },
additionalConfig, String.class));
HgInputStream in = new HgInputStream(process.getInputStream(),
repo.newDecoder());
Assert.assertTrue(in.find("(bound to *:".getBytes()));
final int port = in.readDecimal().intValue();
in.close();
return new ServeState() {
public int getPort() {
return port;
}
public void stop() {
BufferedReader in = null;;
try {
// probably already dead:
process.destroy();
in = new BufferedReader(new InputStreamReader(new FileInputStream(pidFile)));
killProcess(Integer.parseInt(in.readLine()));
} catch (Exception e) {
throw Utils.asRuntime(e);
} finally {
try {
in.close();
} catch (IOException e) {
throw Utils.asRuntime(e);
}
}
}};