Search in sources :

Example 6 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)

Example 7 with StreamByteBuffer

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

the class AbstractMetadataProvider method runCompiler.

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

Example 8 with StreamByteBuffer

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

the class DefaultCommandLineToolInvocationWorker method execute.

@Override
public void execute(CommandLineToolInvocation invocation) {
    ExecAction toolExec = execActionFactory.newExecAction();
    toolExec.executable(executable);
    if (invocation.getWorkDirectory() != null) {
        GFileUtils.mkdirs(invocation.getWorkDirectory());
        toolExec.workingDir(invocation.getWorkDirectory());
    }
    toolExec.args(invocation.getArgs());
    if (!invocation.getPath().isEmpty()) {
        String pathVar = OperatingSystem.current().getPathVar();
        String toolPath = Joiner.on(File.pathSeparator).join(invocation.getPath());
        toolPath = toolPath + File.pathSeparator + System.getenv(pathVar);
        toolExec.environment(pathVar, toolPath);
        if (OperatingSystem.current().isWindows() && toolExec.getEnvironment().containsKey(pathVar.toUpperCase())) {
            toolExec.getEnvironment().remove(pathVar.toUpperCase());
        }
    }
    toolExec.environment(invocation.getEnvironment());
    StreamByteBuffer errOutput = new StreamByteBuffer();
    StreamByteBuffer stdOutput = new StreamByteBuffer();
    toolExec.setErrorOutput(errOutput.getOutputStream());
    toolExec.setStandardOutput(stdOutput.getOutputStream());
    try {
        toolExec.execute();
        invocation.getLogger().operationSuccess(invocation.getDescription(), combineOutput(stdOutput, errOutput));
    } catch (ExecException e) {
        invocation.getLogger().operationFailed(invocation.getDescription(), combineOutput(stdOutput, errOutput));
        throw new CommandLineToolInvocationFailure(invocation, String.format("%s failed while %s.", name, invocation.getDescription()));
    }
}
Also used : ExecAction(org.gradle.process.internal.ExecAction) ExecException(org.gradle.process.internal.ExecException) StreamByteBuffer(org.gradle.internal.io.StreamByteBuffer)

Example 9 with StreamByteBuffer

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

the class DefaultJvmVersionDetector method getJavaVersion.

@Override
public JavaVersion getJavaVersion(String javaCommand) {
    StreamByteBuffer buffer = new StreamByteBuffer();
    ExecHandleBuilder builder = execHandleFactory.newExec();
    builder.setWorkingDir(new File(".").getAbsolutePath());
    builder.setCommandLine(javaCommand, "-version");
    builder.setStandardOutput(NullOutputStream.INSTANCE);
    builder.setErrorOutput(buffer.getOutputStream());
    builder.build().start().waitForFinish().assertNormalExitValue();
    return parseJavaVersionCommandOutput(javaCommand, new BufferedReader(new InputStreamReader(buffer.getInputStream())));
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) StreamByteBuffer(org.gradle.internal.io.StreamByteBuffer) ExecHandleBuilder(org.gradle.process.internal.ExecHandleBuilder) File(java.io.File)

Example 10 with StreamByteBuffer

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

the class PayloadSerializer method deserialize.

public Object deserialize(SerializedPayload payload) {
    final DeserializeMap map = classLoaderRegistry.newDeserializeSession();
    try {
        final Map<Short, ClassLoaderDetails> classLoaderDetails = (Map<Short, ClassLoaderDetails>) payload.getHeader();
        StreamByteBuffer buffer = StreamByteBuffer.of(payload.getSerializedModel());
        final ObjectInputStream objectStream = new PayloadSerializerObjectInputStream(buffer.getInputStream(), getClass().getClassLoader(), classLoaderDetails, map);
        return objectStream.readObject();
    } catch (Exception e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
Also used : StreamByteBuffer(org.gradle.internal.io.StreamByteBuffer) Map(java.util.Map) HashMap(java.util.HashMap) UncheckedException(org.gradle.internal.UncheckedException) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

StreamByteBuffer (org.gradle.internal.io.StreamByteBuffer)16 IOException (java.io.IOException)6 ExecAction (org.gradle.process.internal.ExecAction)5 File (java.io.File)4 ArrayList (java.util.ArrayList)3 UncheckedIOException (org.gradle.api.UncheckedIOException)3 ClassPath (org.gradle.internal.classpath.ClassPath)3 ExecResult (org.gradle.process.ExecResult)3 EncodedStream (org.gradle.process.internal.streams.EncodedStream)3 InputStream (java.io.InputStream)2 ObjectOutputStream (java.io.ObjectOutputStream)2 HashMap (java.util.HashMap)2 DefaultModuleRegistry (org.gradle.api.internal.classpath.DefaultModuleRegistry)2 Module (org.gradle.api.internal.classpath.Module)2 ModuleRegistry (org.gradle.api.internal.classpath.ModuleRegistry)2 UncheckedException (org.gradle.internal.UncheckedException)2 CurrentGradleInstallation (org.gradle.internal.installation.CurrentGradleInstallation)2 GradleInstallation (org.gradle.internal.installation.GradleInstallation)2 FlushableEncoder (org.gradle.internal.serialize.FlushableEncoder)2 KryoBackedEncoder (org.gradle.internal.serialize.kryo.KryoBackedEncoder)2