From 87dc146e4b5624fe6a6ceb8e17d295574d8ed305 Mon Sep 17 00:00:00 2001 From: Armin Date: Mon, 6 Nov 2017 16:18:30 +0100 Subject: [PATCH] more sophisticated output forwarding from exec tasks Fixes #8583 --- Dockerfile | 1 + build.gradle | 7 ++--- buildSrc/build.gradle | 3 ++ .../logstash/gradle/ExecLogOutputStream.java | 29 +++++++++++++++++++ 4 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 buildSrc/build.gradle create mode 100644 buildSrc/src/main/java/org/logstash/gradle/ExecLogOutputStream.java diff --git a/Dockerfile b/Dockerfile index e75f3535ec5..a7e6a32e975 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,7 @@ RUN ln -s /tmp/vendor /opt/logstash/vendor ADD gradlew /opt/logstash/gradlew ADD gradle/wrapper /opt/logstash/gradle/wrapper +ADD buildSrc /opt/logstash/buildSrc RUN /opt/logstash/gradlew wrapper ADD versions.yml /opt/logstash/versions.yml diff --git a/build.gradle b/build.gradle index ec8af817d80..1a1e1974d8f 100644 --- a/build.gradle +++ b/build.gradle @@ -15,6 +15,7 @@ apply plugin: 'de.undercouch.download' import de.undercouch.gradle.tasks.download.Download import de.undercouch.gradle.tasks.download.Verify +import org.logstash.gradle.ExecLogOutputStream import org.yaml.snakeyaml.Yaml allprojects { @@ -144,11 +145,9 @@ task installTestGems(dependsOn: downloadAndInstallJRuby, type: Exec) { outputs.files file("${projectDir}/Gemfile.lock") outputs.files fileTree("${projectDir}/vendor/bundle/gems") outputs.files fileTree("${projectDir}/vendor/jruby") + standardOutput = new ExecLogOutputStream(System.out) + errorOutput = new ExecLogOutputStream(System.err) commandLine './vendor/jruby/bin/jruby', "${projectDir}/vendor/jruby/bin/rake".toString(), "test:install-core" - standardOutput = new ByteArrayOutputStream() - ext.output = { - standardOutput.toString() - } } // If you are running a JRuby snapshot we will skip the integrity check. diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle new file mode 100644 index 00000000000..21cb3515562 --- /dev/null +++ b/buildSrc/build.gradle @@ -0,0 +1,3 @@ +group = 'org.logstash' + +apply plugin: 'java' diff --git a/buildSrc/src/main/java/org/logstash/gradle/ExecLogOutputStream.java b/buildSrc/src/main/java/org/logstash/gradle/ExecLogOutputStream.java new file mode 100644 index 00000000000..2f39436bbe4 --- /dev/null +++ b/buildSrc/src/main/java/org/logstash/gradle/ExecLogOutputStream.java @@ -0,0 +1,29 @@ +package org.logstash.gradle; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + +/** + * Stream that can be used to forward Gradle Exec task output to an arbitrary {@link PrintStream}. + */ +public final class ExecLogOutputStream extends ByteArrayOutputStream { + + /** + * Underlying {@link PrintStream} to flush output to. + */ + private final PrintStream stream; + + /** + * Ctor. + * @param stream PrintStream to flush to + */ + public ExecLogOutputStream(final PrintStream stream) { + this.stream = stream; + } + + @Override + public synchronized void flush() { + stream.print(toString()); + reset(); + } +}