diff --git a/build-tools/src/integTest/groovy/org/elasticsearch/gradle/LoggedExecFuncTest.groovy b/build-tools/src/integTest/groovy/org/elasticsearch/gradle/LoggedExecFuncTest.groovy index a8299a6cc28d1..fd92063f9101c 100644 --- a/build-tools/src/integTest/groovy/org/elasticsearch/gradle/LoggedExecFuncTest.groovy +++ b/build-tools/src/integTest/groovy/org/elasticsearch/gradle/LoggedExecFuncTest.groovy @@ -29,46 +29,23 @@ class LoggedExecFuncTest extends AbstractGradleFuncTest { """ } - @Unroll - def "can configure spooling #spooling"() { - setup: - buildFile << """ - import org.elasticsearch.gradle.LoggedExec - tasks.register('loggedExec', LoggedExec) { - commandLine 'ls', '-lh' - getSpoolOutput().set($spooling) - } - """ - when: - def result = gradleRunner("loggedExec").build() - then: - result.task(':loggedExec').outcome == TaskOutcome.SUCCESS - file("build/buffered-output/loggedExec").exists() == spooling - where: - spooling << [false, true] - } - @Unroll - def "failed tasks output logged to console when spooling #spooling"() { + def "failed tasks output logged to console"() { setup: buildFile << """ import org.elasticsearch.gradle.LoggedExec tasks.register('loggedExec', LoggedExec) { commandLine 'ls', 'wtf' - getSpoolOutput().set($spooling) } """ when: def result = gradleRunner("loggedExec").buildAndFail() then: result.task(':loggedExec').outcome == TaskOutcome.FAILED - file("build/buffered-output/loggedExec").exists() == spooling assertOutputContains(result.output, """\ > Task :loggedExec FAILED Output for ls:""".stripIndent()) assertOutputContains(result.output, "No such file or directory") - where: - spooling << [false, true] } def "can capture output"() { @@ -91,27 +68,6 @@ class LoggedExecFuncTest extends AbstractGradleFuncTest { result.getOutput().contains("OUTPUT HELLO") } - def "capturing output with spooling enabled is not supported"() { - setup: - buildFile << """ - import org.elasticsearch.gradle.LoggedExec - tasks.register('loggedExec', LoggedExec) { - commandLine 'echo', 'HELLO' - getCaptureOutput().set(true) - getSpoolOutput().set(true) - } - """ - when: - def result = gradleRunner("loggedExec").buildAndFail() - then: - result.task(':loggedExec').outcome == TaskOutcome.FAILED - assertOutputContains(result.output, '''\ - FAILURE: Build failed with an exception. - - * What went wrong: - Execution failed for task ':loggedExec'. - > Capturing output is not supported when spoolOutput is true.'''.stripIndent()) - } def "can configure output indenting"() { diff --git a/build-tools/src/main/java/org/elasticsearch/gradle/LoggedExec.java b/build-tools/src/main/java/org/elasticsearch/gradle/LoggedExec.java index 28018b4c50abe..57cc22403ad86 100644 --- a/build-tools/src/main/java/org/elasticsearch/gradle/LoggedExec.java +++ b/build-tools/src/main/java/org/elasticsearch/gradle/LoggedExec.java @@ -40,7 +40,6 @@ import java.io.UncheckedIOException; import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; -import java.nio.file.Files; import java.util.List; import java.util.function.Consumer; import java.util.function.Function; @@ -99,9 +98,6 @@ public Provider getWorkingDirPath() { @Internal abstract public Property getWorkingDir(); - @Internal - abstract public Property getSpoolOutput(); - private String output; @Inject @@ -118,7 +114,6 @@ public LoggedExec( // For now mimic default behaviour of Gradle Exec task here setupDefaultEnvironment(providerFactory); getCaptureOutput().convention(false); - getSpoolOutput().convention(false); } /** @@ -147,34 +142,12 @@ private void setupDefaultEnvironment(ProviderFactory providerFactory) { @TaskAction public void run() { - boolean spoolOutput = getSpoolOutput().get(); - if (spoolOutput && getCaptureOutput().get()) { - throw new GradleException("Capturing output is not supported when spoolOutput is true."); - } if (getCaptureOutput().get() && getIndentingConsoleOutput().isPresent()) { throw new GradleException("Capturing output is not supported when indentingConsoleOutput is configured."); } Consumer outputLogger; - OutputStream out; - if (spoolOutput) { - File spoolFile = new File(projectLayout.getBuildDirectory().dir("buffered-output").get().getAsFile(), this.getName()); - out = new LazyFileOutputStream(spoolFile); - outputLogger = logger -> { - try { - // the file may not exist if the command never output anything - if (Files.exists(spoolFile.toPath())) { - try (var lines = Files.lines(spoolFile.toPath())) { - lines.forEach(logger::error); - } - } - } catch (IOException e) { - throw new RuntimeException("could not log", e); - } - }; - } else { - out = new ByteArrayOutputStream(); - outputLogger = getIndentingConsoleOutput().isPresent() ? logger -> {} : logger -> logger.error(byteStreamToString(out)); - } + OutputStream out = new ByteArrayOutputStream(); + outputLogger = getIndentingConsoleOutput().isPresent() ? logger -> {} : logger -> logger.error(byteStreamToString(out)); OutputStream finalOutputStream = getIndentingConsoleOutput().isPresent() ? new IndentingOutputStream(System.out, getIndentingConsoleOutput().get())