public void receiveQuit(QuitEvent e) {
slave.end = System.currentTimeMillis();
}
});
Closer closer = Closer.create();
closer.register(eventStream);
closer.register(w);
try {
OutputStream sysout = closer.register(new BufferedOutputStream(new FileOutputStream(sysoutFile)));
OutputStream syserr = closer.register(new BufferedOutputStream(new FileOutputStream(syserrFile)));
RandomAccessFile streamsBuffer = closer.register(new RandomAccessFile(streamsBufferFile, "rw"));
Execute execute = forkProcess(slave, eventBus, commandline, eventStream, sysout, syserr, streamsBuffer);
log("Forked JVM J" + slave.id + " finished with exit code: " + execute.getExitValue(), Project.MSG_DEBUG);
if (execute.isFailure()) {
final int exitStatus = execute.getExitValue();
switch (exitStatus) {
case SlaveMain.ERR_NO_JUNIT:
throw new BuildException("Forked JVM's classpath must include a junit4 JAR.");
case SlaveMain.ERR_OLD_JUNIT:
throw new BuildException("Forked JVM's classpath must use JUnit 4.10 or newer.");
default:
Closeables.close(sysout, false);
Closeables.close(syserr, false);
StringBuilder message = new StringBuilder();
if (exitStatus == SlaveMain.ERR_OOM) {
message.append("Forked JVM ran out of memory.");
} else {
message.append("Forked process returned with error code: ").append(exitStatus).append(".");
}
if (sysoutFile.length() > 0 || syserrFile.length() > 0) {
if (exitStatus != SlaveMain.ERR_OOM) {
message.append(" Very likely a JVM crash. ");
}
if (jvmOutputAction.contains(JvmOutputAction.PIPE)) {
message.append(" Process output piped in logs above.");
} else if (!jvmOutputAction.contains(JvmOutputAction.IGNORE)) {
if (sysoutFile.length() > 0) {
message.append(" See process stdout at: " + sysoutFile.getAbsolutePath());
}
if (syserrFile.length() > 0) {
message.append(" See process stderr at: " + syserrFile.getAbsolutePath());
}
}
}
throw new BuildException(message.toString());
}
}
} catch (Throwable t) {
throw closer.rethrow(t);
} finally {
try {
closer.close();
} finally {
Files.asByteSource(classNamesDynamic).copyTo(Files.asByteSink(classNamesFile, FileWriteMode.APPEND));
classNamesDynamic.delete();
streamsBufferFile.delete();