Search in sources :

Example 1 with StreamByteBuffer

use of org.gradle.internal.io.StreamByteBuffer in project gradle by gradle.

the class GUtil method serialize.

public static byte[] serialize(Object object) {
    StreamByteBuffer buffer = new StreamByteBuffer();
    serialize(object, buffer.getOutputStream());
    return buffer.readAsByteArray();
}
Also used : StreamByteBuffer(org.gradle.internal.io.StreamByteBuffer)

Example 2 with StreamByteBuffer

use of org.gradle.internal.io.StreamByteBuffer in project gradle by gradle.

the class SerializationFixture method serializationRoundtrip.

public static <T> T serializationRoundtrip(T obj) {
    try {
        StreamByteBuffer buffer = new StreamByteBuffer();
        ObjectOutputStream out = new ObjectOutputStream(buffer.getOutputStream());
        out.writeObject(obj);
        out.close();
        ClassLoaderObjectInputStream input = new ClassLoaderObjectInputStream(buffer.getInputStream(), obj.getClass().getClassLoader());
        return (T) input.readObject();
    } catch (Exception e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
Also used : StreamByteBuffer(org.gradle.internal.io.StreamByteBuffer) ClassLoaderObjectInputStream(org.gradle.internal.io.ClassLoaderObjectInputStream) ObjectOutputStream(java.io.ObjectOutputStream) UncheckedException(org.gradle.internal.UncheckedException)

Example 3 with StreamByteBuffer

use of org.gradle.internal.io.StreamByteBuffer in project gradle by gradle.

the class GccVersionDeterminer method transform.

private String transform(File gccBinary, List<String> args) {
    ExecAction exec = execActionFactory.newExecAction();
    exec.executable(gccBinary.getAbsolutePath());
    exec.setWorkingDir(gccBinary.getParentFile());
    exec.args(args);
    StreamByteBuffer buffer = new StreamByteBuffer();
    exec.setStandardOutput(buffer.getOutputStream());
    exec.setErrorOutput(NullOutputStream.INSTANCE);
    exec.setIgnoreExitValue(true);
    ExecResult result = exec.execute();
    int exitValue = result.getExitValue();
    if (exitValue == 0) {
        return buffer.readAsString();
    } else {
        return null;
    }
}
Also used : ExecAction(org.gradle.process.internal.ExecAction) StreamByteBuffer(org.gradle.internal.io.StreamByteBuffer) ExecResult(org.gradle.process.ExecResult)

Example 4 with StreamByteBuffer

use of org.gradle.internal.io.StreamByteBuffer 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);
}
Also used : DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath) ClassPath(org.gradle.internal.classpath.ClassPath) FlushableEncoder(org.gradle.internal.serialize.FlushableEncoder) EncodedStream(org.gradle.process.internal.streams.EncodedStream) InputStream(java.io.InputStream) ModuleRegistry(org.gradle.api.internal.classpath.ModuleRegistry) DefaultModuleRegistry(org.gradle.api.internal.classpath.DefaultModuleRegistry) ArrayList(java.util.ArrayList) StreamByteBuffer(org.gradle.internal.io.StreamByteBuffer) UncheckedIOException(org.gradle.api.UncheckedIOException) KryoBackedEncoder(org.gradle.internal.serialize.kryo.KryoBackedEncoder) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) CurrentGradleInstallation(org.gradle.internal.installation.CurrentGradleInstallation) GradleInstallation(org.gradle.internal.installation.GradleInstallation) DefaultModuleRegistry(org.gradle.api.internal.classpath.DefaultModuleRegistry) GradleDaemon(org.gradle.launcher.daemon.bootstrap.GradleDaemon) Module(org.gradle.api.internal.classpath.Module) File(java.io.File) DefaultClassPath(org.gradle.internal.classpath.DefaultClassPath)

Example 5 with StreamByteBuffer

use of org.gradle.internal.io.StreamByteBuffer in project gradle by gradle.

the class PayloadSerializer method serialize.

public SerializedPayload serialize(Object payload) {
    final SerializeMap map = classLoaderRegistry.newSerializeSession();
    try {
        StreamByteBuffer buffer = new StreamByteBuffer();
        final ObjectOutputStream objectStream = new PayloadSerializerObjectOutputStream(buffer.getOutputStream(), map);
        try {
            objectStream.writeObject(payload);
        } finally {
            IoActions.closeQuietly(objectStream);
        }
        Map<Short, ClassLoaderDetails> classLoaders = new HashMap<Short, ClassLoaderDetails>();
        map.collectClassLoaderDefinitions(classLoaders);
        return new SerializedPayload(classLoaders, buffer.readAsListOfByteArrays());
    } catch (IOException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
Also used : HashMap(java.util.HashMap) StreamByteBuffer(org.gradle.internal.io.StreamByteBuffer) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream)

Aggregations

StreamByteBuffer (org.gradle.internal.io.StreamByteBuffer)12 IOException (java.io.IOException)5 File (java.io.File)3 ObjectOutputStream (java.io.ObjectOutputStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 UncheckedIOException (org.gradle.api.UncheckedIOException)2 UncheckedException (org.gradle.internal.UncheckedException)2 ClassPath (org.gradle.internal.classpath.ClassPath)2 ExecAction (org.gradle.process.internal.ExecAction)2 EncodedStream (org.gradle.process.internal.streams.EncodedStream)2 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataOutputStream (java.io.DataOutputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ObjectInputStream (java.io.ObjectInputStream)1 OutputStream (java.io.OutputStream)1 URL (java.net.URL)1 Map (java.util.Map)1