testStateForRun();
// Sem se také zapisuje výstup programu {@code kindlegen}.
List<String> outputLines = new ArrayList<String>();
inErrorState = false;
Stopwatch runtimeStopwatch = new Stopwatch();
runtimeStopwatch.start();
try {
String[] realCommandArray = assembleKindlegenCommandArray();
logger.info("command: " + Arrays.toString(realCommandArray));
String readableCommand = createReadableCommand(realCommandArray);
// (zde možno zapsat readableCommand do skriptu ...)
writeToCommandOut("> " + readableCommand);
process = Runtime.getRuntime().exec(realCommandArray);
InputStream istream = process.getInputStream();
BufferedReader br = new BufferedReader(
new InputStreamReader(istream));
String line;
while ((line = br.readLine()) != null) {
checkErrorState(line);
outputLines.add(line);
logger.fine(line);
writeToCommandOut(line);
}
try {
process.waitFor();
} catch (InterruptedException e) {
setInErrorState(true);
writeToCommandOut(EOL+"Error: InterruptedException!");
}
// if (proc.exitValue() != 0) {} // nejde, protože kindlegen (v1.2) vrátí vždy 0
br.close();
logger.fine("finished!");
} catch (IOException ex) {
logger.warning(ex.toString());
setInErrorState(true);
runtime = runtimeStopwatch.stop();
throw ex;
}
runtime = runtimeStopwatch.stop();
logger.info("kindlegen runtime = " +
runtimeStopwatch.getTimeSec() + " s");
return (String[]) outputLines.toArray(new String[0]);
}