use of org.gradle.internal.serialize.OutputStreamBackedEncoder in project gradle by gradle.
the class InMemoryIndexedCache method put.
@Override
public void put(K key, V value) {
ByteArrayOutputStream outstr = new ByteArrayOutputStream();
OutputStreamBackedEncoder encoder = new OutputStreamBackedEncoder(outstr);
try {
valueSerializer.write(encoder, value);
encoder.flush();
} catch (Exception e) {
throw UncheckedException.throwAsUncheckedException(e);
}
entries.put(key, outstr.toByteArray());
}
use of org.gradle.internal.serialize.OutputStreamBackedEncoder in project gradle by gradle.
the class SimpleStateCache method serialize.
private void serialize(T newValue) {
try {
if (!cacheFile.isFile()) {
cacheFile.createNewFile();
}
// read-write-execute for user only
chmod.chmod(cacheFile.getParentFile(), 0700);
// read-write for user only
chmod.chmod(cacheFile, 0600);
OutputStreamBackedEncoder encoder = new OutputStreamBackedEncoder(new BufferedOutputStream(new FileOutputStream(cacheFile)));
try {
serializer.write(encoder, newValue);
} finally {
encoder.close();
}
} catch (Exception e) {
throw new GradleException(String.format("Could not write cache value to '%s'.", cacheFile), e);
}
}
use of org.gradle.internal.serialize.OutputStreamBackedEncoder in project gradle by gradle.
the class ApplicationClassesInSystemClassLoaderWorkerImplementationFactory method prepareJavaCommand.
@Override
public void prepareJavaCommand(Object workerId, String displayName, DefaultWorkerProcessBuilder processBuilder, List<URL> implementationClassPath, Address serverAddress, JavaExecHandleBuilder execSpec, boolean publishProcessInfo) {
Collection<File> applicationClasspath = processBuilder.getApplicationClasspath();
LogLevel logLevel = processBuilder.getLogLevel();
Set<String> sharedPackages = processBuilder.getSharedPackages();
Object requestedSecurityManager = execSpec.getSystemProperties().get("java.security.manager");
ClassPath workerMainClassPath = classPathRegistry.getClassPath("WORKER_MAIN");
execSpec.setMain("worker." + GradleWorkerMain.class.getName());
boolean useOptionsFile = shouldUseOptionsFile(execSpec);
if (useOptionsFile) {
// Use an options file to pass across application classpath
File optionsFile = temporaryFileProvider.createTemporaryFile("gradle-worker-classpath", "txt");
List<String> jvmArgs = writeOptionsFile(workerMainClassPath.getAsFiles(), applicationClasspath, optionsFile);
execSpec.jvmArgs(jvmArgs);
} else {
// Use a dummy security manager, which hacks the application classpath into the system ClassLoader
execSpec.classpath(workerMainClassPath.getAsFiles());
execSpec.systemProperty("java.security.manager", "worker." + BootstrapSecurityManager.class.getName());
}
// Serialize configuration for the worker process to it stdin
StreamByteBuffer buffer = new StreamByteBuffer();
try {
DataOutputStream outstr = new DataOutputStream(new EncodedStream.EncodedOutput(buffer.getOutputStream()));
if (!useOptionsFile) {
// Serialize the application classpath, this is consumed by BootstrapSecurityManager
outstr.writeInt(applicationClasspath.size());
for (File file : applicationClasspath) {
outstr.writeUTF(file.getAbsolutePath());
}
// Serialize the actual security manager type, this is consumed by BootstrapSecurityManager
outstr.writeUTF(requestedSecurityManager == null ? "" : requestedSecurityManager.toString());
}
// Serialize the shared packages, this is consumed by GradleWorkerMain
outstr.writeInt(sharedPackages.size());
for (String str : sharedPackages) {
outstr.writeUTF(str);
}
// Serialize the worker implementation classpath, this is consumed by GradleWorkerMain
outstr.writeInt(implementationClassPath.size());
for (URL entry : implementationClassPath) {
outstr.writeUTF(entry.toString());
}
// Serialize the worker config, this is consumed by SystemApplicationClassLoaderWorker
OutputStreamBackedEncoder encoder = new OutputStreamBackedEncoder(outstr);
encoder.writeSmallInt(logLevel.ordinal());
encoder.writeBoolean(publishProcessInfo);
new MultiChoiceAddressSerializer().write(encoder, (MultiChoiceAddress) serverAddress);
// Serialize the worker, this is consumed by SystemApplicationClassLoaderWorker
ActionExecutionWorker worker = new ActionExecutionWorker(processBuilder.getWorker(), workerId, displayName, processBuilder.getGradleUserHomeDir());
byte[] serializedWorker = GUtil.serialize(worker);
encoder.writeBinary(serializedWorker);
encoder.flush();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
execSpec.setStandardInput(buffer.getInputStream());
}
use of org.gradle.internal.serialize.OutputStreamBackedEncoder 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.
}
Aggregations