Search in sources :

Example 1 with ForwardInput

use of org.gradle.launcher.daemon.protocol.ForwardInput in project gradle by gradle.

the class ForwardClientInput method execute.

public void execute(final DaemonCommandExecution execution) {
    final PipedOutputStream inputSource = new PipedOutputStream();
    final PipedInputStream replacementStdin;
    try {
        replacementStdin = new PipedInputStream(inputSource);
    } catch (IOException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
    execution.getConnection().onStdin(new StdinHandler() {

        public void onInput(ForwardInput input) {
            LOGGER.debug("Writing forwarded input on daemon's stdin.");
            try {
                inputSource.write(input.getBytes());
            } catch (IOException e) {
                LOGGER.warn("Received exception trying to forward client input.", e);
            }
        }

        public void onEndOfInput() {
            LOGGER.info("Closing daemon's stdin at end of input.");
            try {
                inputSource.close();
            } catch (IOException e) {
                LOGGER.warn("Problem closing output stream connected to replacement stdin", e);
            } finally {
                LOGGER.info("The daemon will no longer process any standard input.");
            }
        }
    });
    try {
        try {
            new StdinSwapper().swap(replacementStdin, new Callable<Void>() {

                public Void call() {
                    execution.proceed();
                    return null;
                }
            });
        } finally {
            execution.getConnection().onStdin(null);
            IOUtils.closeQuietly(replacementStdin);
            IOUtils.closeQuietly(inputSource);
        }
    } catch (Exception e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
Also used : StdinHandler(org.gradle.launcher.daemon.server.api.StdinHandler) ForwardInput(org.gradle.launcher.daemon.protocol.ForwardInput) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) IOException(java.io.IOException) StdinSwapper(org.gradle.util.StdinSwapper) IOException(java.io.IOException) UncheckedException(org.gradle.internal.UncheckedException)

Aggregations

IOException (java.io.IOException)1 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 UncheckedException (org.gradle.internal.UncheckedException)1 ForwardInput (org.gradle.launcher.daemon.protocol.ForwardInput)1 StdinHandler (org.gradle.launcher.daemon.server.api.StdinHandler)1 StdinSwapper (org.gradle.util.StdinSwapper)1