use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class DaemonStartupCommunication method printDaemonStarted.
public void printDaemonStarted(PrintStream target, Long pid, String uid, Address address, File daemonLog) {
target.print(daemonGreeting());
// Encode as ascii
try {
OutputStream outputStream = new EncodedStream.EncodedOutput(target);
FlushableEncoder encoder = new OutputStreamBackedEncoder(outputStream);
encoder.writeNullableString(pid == null ? null : pid.toString());
encoder.writeString(uid);
MultiChoiceAddress multiChoiceAddress = (MultiChoiceAddress) address;
new MultiChoiceAddressSerializer().write(encoder, multiChoiceAddress);
encoder.writeString(daemonLog.getPath());
encoder.flush();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
target.println();
//ibm vm 1.6 + windows XP gotchas:
//we need to print something else to the stream after we print the daemon greeting.
//without it, the parent hangs without receiving the message above (flushing does not help).
LOGGER.debug("Completed writing the daemon greeting. Closing streams...");
//btw. the ibm vm+winXP also has some issues detecting closed streams by the child but we handle this problem differently.
}
use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class DaemonMain method doAction.
@Override
protected void doAction(String[] args, ExecutionListener listener) {
//The first argument is not really used but it is very useful in diagnosing, i.e. running 'jps -m'
if (args.length != 1) {
invalidArgs("Following arguments are required: <gradle-version>");
}
// Read configuration from stdin
List<String> startupOpts;
File gradleHomeDir;
File daemonBaseDir;
int idleTimeoutMs;
int periodicCheckIntervalMs;
String daemonUid;
List<File> additionalClassPath;
KryoBackedDecoder decoder = new KryoBackedDecoder(new EncodedStream.EncodedInput(System.in));
try {
gradleHomeDir = new File(decoder.readString());
daemonBaseDir = new File(decoder.readString());
idleTimeoutMs = decoder.readSmallInt();
periodicCheckIntervalMs = decoder.readSmallInt();
daemonUid = decoder.readString();
int argCount = decoder.readSmallInt();
startupOpts = new ArrayList<String>(argCount);
for (int i = 0; i < argCount; i++) {
startupOpts.add(decoder.readString());
}
int additionalClassPathLength = decoder.readSmallInt();
additionalClassPath = new ArrayList<File>(additionalClassPathLength);
for (int i = 0; i < additionalClassPathLength; i++) {
additionalClassPath.add(new File(decoder.readString()));
}
} catch (EOFException e) {
throw new UncheckedIOException(e);
}
NativeServices.initialize(gradleHomeDir);
DaemonServerConfiguration parameters = new DefaultDaemonServerConfiguration(daemonUid, daemonBaseDir, idleTimeoutMs, periodicCheckIntervalMs, startupOpts);
LoggingServiceRegistry loggingRegistry = LoggingServiceRegistry.newCommandLineProcessLogging();
LoggingManagerInternal loggingManager = loggingRegistry.newInstance(LoggingManagerInternal.class);
DaemonServices daemonServices = new DaemonServices(parameters, loggingRegistry, loggingManager, new DefaultClassPath(additionalClassPath));
File daemonLog = daemonServices.getDaemonLogFile();
// Any logging prior to this point will not end up in the daemon log file.
initialiseLogging(loggingManager, daemonLog);
// Detach the process from the parent terminal/console
ProcessEnvironment processEnvironment = daemonServices.get(ProcessEnvironment.class);
processEnvironment.maybeDetachProcess();
LOGGER.debug("Assuming the daemon was started with following jvm opts: {}", startupOpts);
Daemon daemon = daemonServices.get(Daemon.class);
daemon.start();
try {
DaemonContext daemonContext = daemonServices.get(DaemonContext.class);
Long pid = daemonContext.getPid();
daemonStarted(pid, daemon.getUid(), daemon.getAddress(), daemonLog);
DaemonExpirationStrategy expirationStrategy = daemonServices.get(MasterExpirationStrategy.class);
daemon.stopOnExpiration(expirationStrategy, parameters.getPeriodicCheckIntervalMs());
} finally {
daemon.stop();
}
}
Aggregations