Search in sources :

Example 11 with LineBufferingOutputStream

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

the class LineBufferingOutputStreamTest method splitsLongLines.

@Test
public void splitsLongLines() throws IOException {
    LineBufferingOutputStream outputStream = new LineBufferingOutputStream(action, 8, 13);
    context.checking(new Expectations() {

        {
            one(action).text("1234567890123");
            one(action).text("4567890123456");
            one(action).text("789");
            one(action).endOfStream(null);
        }
    });
    outputStream.write("12345678901234567890123456789".getBytes());
    outputStream.close();
}
Also used : Expectations(org.jmock.Expectations) LineBufferingOutputStream(org.gradle.internal.io.LineBufferingOutputStream) Test(org.junit.Test)

Example 12 with LineBufferingOutputStream

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

the class LineBufferingOutputStreamTest method logsPartialLineOnClose.

@Test
public void logsPartialLineOnClose() throws IOException {
    LineBufferingOutputStream outputStream = new LineBufferingOutputStream(action, 8);
    context.checking(new Expectations() {

        {
            one(action).text("line 1");
            one(action).endOfStream(null);
        }
    });
    outputStream.write("line 1".getBytes());
    outputStream.close();
}
Also used : Expectations(org.jmock.Expectations) LineBufferingOutputStream(org.gradle.internal.io.LineBufferingOutputStream) Test(org.junit.Test)

Example 13 with LineBufferingOutputStream

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

the class LineBufferingOutputStreamTest method logsNothingOnCloseWhenNothingHasBeenWrittenToStream.

@Test
public void logsNothingOnCloseWhenNothingHasBeenWrittenToStream() throws IOException {
    LineBufferingOutputStream outputStream = new LineBufferingOutputStream(action, 8);
    context.checking(new Expectations() {

        {
            one(action).endOfStream(null);
        }
    });
    outputStream.close();
}
Also used : Expectations(org.jmock.Expectations) LineBufferingOutputStream(org.gradle.internal.io.LineBufferingOutputStream) Test(org.junit.Test)

Example 14 with LineBufferingOutputStream

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

the class InProcessGradleExecuter method createLoggingManager.

private LoggingManagerInternal createLoggingManager(StartParameter startParameter, final StandardOutputListener outputListener) {
    LoggingManagerInternal loggingManager = GLOBAL_SERVICES.getFactory(LoggingManagerInternal.class).create();
    loggingManager.captureSystemSources();
    ConsoleOutput consoleOutput = startParameter.getConsoleOutput();
    if (consoleOutput == ConsoleOutput.Auto) {
        // IDEA runs tests attached to a console, use plain so test can assume never attached to a console
        // Should really run all tests against a plain and a rich console to make these assumptions explicit
        consoleOutput = ConsoleOutput.Plain;
    }
    loggingManager.attachConsole(new TeeOutputStream(System.out, new LineBufferingOutputStream(new TextStream() {

        @Override
        public void text(String text) {
            outputListener.onOutput(text);
        }

        @Override
        public void endOfStream(@Nullable Throwable failure) {
        }
    })), consoleOutput);
    return loggingManager;
}
Also used : LoggingManagerInternal(org.gradle.internal.logging.LoggingManagerInternal) ConsoleOutput(org.gradle.api.logging.configuration.ConsoleOutput) TeeOutputStream(org.apache.commons.io.output.TeeOutputStream) LineBufferingOutputStream(org.gradle.internal.io.LineBufferingOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) TextStream(org.gradle.internal.io.TextStream)

Aggregations

LineBufferingOutputStream (org.gradle.internal.io.LineBufferingOutputStream)14 Expectations (org.jmock.Expectations)12 Test (org.junit.Test)12 IOException (java.io.IOException)1 AsynchronousCloseException (java.nio.channels.AsynchronousCloseException)1 TeeOutputStream (org.apache.commons.io.output.TeeOutputStream)1 ConsoleOutput (org.gradle.api.logging.configuration.ConsoleOutput)1 TextStream (org.gradle.internal.io.TextStream)1 LoggingManagerInternal (org.gradle.internal.logging.LoggingManagerInternal)1 DisconnectableInputStream (org.gradle.util.DisconnectableInputStream)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1