use of org.gradle.internal.serialize.kryo.KryoBackedEncoder in project gradle by gradle.
the class DefaultDaemonStarter method startDaemon.
public DaemonStartupInfo startDaemon() {
String daemonUid = UUID.randomUUID().toString();
GradleInstallation gradleInstallation = CurrentGradleInstallation.get();
ModuleRegistry registry = new DefaultModuleRegistry(gradleInstallation);
ClassPath classpath;
List<File> searchClassPath;
if (gradleInstallation == null) {
// When not running from a Gradle distro, need runtime impl for launcher plus the search path to look for other modules
classpath = new DefaultClassPath();
for (Module module : registry.getModule("gradle-launcher").getAllRequiredModules()) {
classpath = classpath.plus(module.getClasspath());
}
searchClassPath = registry.getAdditionalClassPath().getAsFiles();
} else {
// When running from a Gradle distro, only need launcher jar. The daemon can find everything from there.
classpath = registry.getModule("gradle-launcher").getImplementationClasspath();
searchClassPath = Collections.emptyList();
}
if (classpath.isEmpty()) {
throw new IllegalStateException("Unable to construct a bootstrap classpath when starting the daemon");
}
versionValidator.validate(daemonParameters);
List<String> daemonArgs = new ArrayList<String>();
daemonArgs.add(daemonParameters.getEffectiveJvm().getJavaExecutable().getAbsolutePath());
List<String> daemonOpts = daemonParameters.getEffectiveJvmArgs();
daemonArgs.addAll(daemonOpts);
daemonArgs.add("-cp");
daemonArgs.add(CollectionUtils.join(File.pathSeparator, classpath.getAsFiles()));
if (Boolean.getBoolean("org.gradle.daemon.debug")) {
daemonArgs.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005");
}
LOGGER.debug("Using daemon args: {}", daemonArgs);
daemonArgs.add(GradleDaemon.class.getName());
// Version isn't used, except by a human looking at the output of jps.
daemonArgs.add(GradleVersion.current().getVersion());
// Serialize configuration to daemon via the process' stdin
StreamByteBuffer buffer = new StreamByteBuffer();
FlushableEncoder encoder = new KryoBackedEncoder(new EncodedStream.EncodedOutput(buffer.getOutputStream()));
try {
encoder.writeString(daemonParameters.getGradleUserHomeDir().getAbsolutePath());
encoder.writeString(daemonDir.getBaseDir().getAbsolutePath());
encoder.writeSmallInt(daemonParameters.getIdleTimeout());
encoder.writeSmallInt(daemonParameters.getPeriodicCheckInterval());
encoder.writeString(daemonUid);
encoder.writeSmallInt(daemonOpts.size());
for (String daemonOpt : daemonOpts) {
encoder.writeString(daemonOpt);
}
encoder.writeSmallInt(searchClassPath.size());
for (File file : searchClassPath) {
encoder.writeString(file.getAbsolutePath());
}
encoder.flush();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
InputStream stdInput = buffer.getInputStream();
return startProcess(daemonArgs, daemonDir.getVersionedDir(), stdInput);
}
use of org.gradle.internal.serialize.kryo.KryoBackedEncoder in project gradle by gradle.
the class DefaultActionExecutionSpecFactory method serialize.
private byte[] serialize(Isolatable<?> isolatable) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
KryoBackedEncoder encoder = new KryoBackedEncoder(outputStream);
try {
serializerRegistry.writeIsolatable(encoder, isolatable);
encoder.flush();
} catch (Exception e) {
throw new WorkSerializationException("Could not serialize unit of work.", e);
}
return outputStream.toByteArray();
}
use of org.gradle.internal.serialize.kryo.KryoBackedEncoder in project gradle by gradle.
the class AbstractValueProcessor method gradleSerialization.
@SuppressWarnings({ "unchecked", "rawtypes" })
private <T> T gradleSerialization(Object value, Serializer serializer, ValueVisitor<T> visitor) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try (KryoBackedEncoder encoder = new KryoBackedEncoder(outputStream)) {
serializer.write(encoder, Cast.uncheckedCast(value));
encoder.flush();
} catch (Exception e) {
throw newValueSerializationException(value.getClass(), e);
}
return visitor.gradleSerialized(value, outputStream.toByteArray());
}
use of org.gradle.internal.serialize.kryo.KryoBackedEncoder in project gradle by gradle.
the class TestResultSerializer method write.
public void write(Collection<TestClassResult> results) {
try {
OutputStream outputStream = new FileOutputStream(resultsFile);
try {
if (!results.isEmpty()) {
// only write if we have results, otherwise truncate
FlushableEncoder encoder = new KryoBackedEncoder(outputStream);
encoder.writeSmallInt(RESULT_VERSION);
write(results, encoder);
encoder.flush();
}
} finally {
outputStream.close();
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of org.gradle.internal.serialize.kryo.KryoBackedEncoder in project gradle by gradle.
the class DefaultDaemonStarter method startDaemon.
@Override
public DaemonStartupInfo startDaemon(boolean singleUse) {
String daemonUid = UUID.randomUUID().toString();
GradleInstallation gradleInstallation = CurrentGradleInstallation.get();
ModuleRegistry registry = new DefaultModuleRegistry(gradleInstallation);
ClassPath classpath;
List<File> searchClassPath;
if (gradleInstallation == null) {
// When not running from a Gradle distro, need runtime impl for launcher plus the search path to look for other modules
classpath = registry.getModule("gradle-launcher").getAllRequiredModulesClasspath();
searchClassPath = registry.getAdditionalClassPath().getAsFiles();
} else {
// When running from a Gradle distro, only need launcher jar. The daemon can find everything from there.
classpath = registry.getModule("gradle-launcher").getImplementationClasspath();
searchClassPath = Collections.emptyList();
}
if (classpath.isEmpty()) {
throw new IllegalStateException("Unable to construct a bootstrap classpath when starting the daemon");
}
versionValidator.validate(daemonParameters);
List<String> daemonArgs = new ArrayList<String>();
daemonArgs.addAll(getPriorityArgs(daemonParameters.getPriority()));
daemonArgs.add(daemonParameters.getEffectiveJvm().getJavaExecutable().getAbsolutePath());
List<String> daemonOpts = daemonParameters.getEffectiveJvmArgs();
daemonArgs.addAll(daemonOpts);
daemonArgs.add("-cp");
daemonArgs.add(CollectionUtils.join(File.pathSeparator, classpath.getAsFiles()));
if (Boolean.getBoolean("org.gradle.daemon.debug")) {
daemonArgs.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005");
}
LOGGER.debug("Using daemon args: {}", daemonArgs);
daemonArgs.add(GradleDaemon.class.getName());
// Version isn't used, except by a human looking at the output of jps.
daemonArgs.add(GradleVersion.current().getVersion());
// Serialize configuration to daemon via the process' stdin
StreamByteBuffer buffer = new StreamByteBuffer();
FlushableEncoder encoder = new KryoBackedEncoder(new EncodedStream.EncodedOutput(buffer.getOutputStream()));
try {
encoder.writeString(daemonParameters.getGradleUserHomeDir().getAbsolutePath());
encoder.writeString(daemonDir.getBaseDir().getAbsolutePath());
encoder.writeSmallInt(daemonParameters.getIdleTimeout());
encoder.writeSmallInt(daemonParameters.getPeriodicCheckInterval());
encoder.writeBoolean(singleUse);
encoder.writeString(daemonUid);
encoder.writeSmallInt(daemonParameters.getPriority().ordinal());
encoder.writeSmallInt(daemonOpts.size());
for (String daemonOpt : daemonOpts) {
encoder.writeString(daemonOpt);
}
encoder.writeSmallInt(searchClassPath.size());
for (File file : searchClassPath) {
encoder.writeString(file.getAbsolutePath());
}
encoder.flush();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
InputStream stdInput = buffer.getInputStream();
return startProcess(daemonArgs, daemonDir.getVersionedDir(), daemonParameters.getGradleUserHomeDir().getAbsoluteFile(), stdInput);
}
Aggregations