Skip to content

Commit c2116d6

Browse files
authored
[8.18] [Gradle] Remove unused spool support in LoggedExec (#133767) (#134655)
* [Gradle] Remove unused spool support in LoggedExec (#133767) This is not used anywhere so we should simplify this down to what we actually use. Fixes #119509 (cherry picked from commit 8c6162e) # Conflicts: # muted-tests.yml * Fix merge conflict
1 parent c9fb293 commit c2116d6

File tree

2 files changed

+3
-74
lines changed

2 files changed

+3
-74
lines changed

build-tools/src/integTest/groovy/org/elasticsearch/gradle/LoggedExecFuncTest.groovy

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -29,46 +29,23 @@ class LoggedExecFuncTest extends AbstractGradleFuncTest {
2929
"""
3030
}
3131

32-
@Unroll
33-
def "can configure spooling #spooling"() {
34-
setup:
35-
buildFile << """
36-
import org.elasticsearch.gradle.LoggedExec
37-
tasks.register('loggedExec', LoggedExec) {
38-
commandLine 'ls', '-lh'
39-
getSpoolOutput().set($spooling)
40-
}
41-
"""
42-
when:
43-
def result = gradleRunner("loggedExec").build()
44-
then:
45-
result.task(':loggedExec').outcome == TaskOutcome.SUCCESS
46-
file("build/buffered-output/loggedExec").exists() == spooling
47-
where:
48-
spooling << [false, true]
49-
}
5032

51-
@Unroll
52-
def "failed tasks output logged to console when spooling #spooling"() {
33+
def "failed tasks output logged to console"() {
5334
setup:
5435
buildFile << """
5536
import org.elasticsearch.gradle.LoggedExec
5637
tasks.register('loggedExec', LoggedExec) {
5738
commandLine 'ls', 'wtf'
58-
getSpoolOutput().set($spooling)
5939
}
6040
"""
6141
when:
6242
def result = gradleRunner("loggedExec").buildAndFail()
6343
then:
6444
result.task(':loggedExec').outcome == TaskOutcome.FAILED
65-
file("build/buffered-output/loggedExec").exists() == spooling
6645
assertOutputContains(result.output, """\
6746
> Task :loggedExec FAILED
6847
Output for ls:""".stripIndent())
6948
assertOutputContains(result.output, "No such file or directory")
70-
where:
71-
spooling << [false, true]
7249
}
7350

7451
def "can capture output"() {
@@ -91,27 +68,6 @@ class LoggedExecFuncTest extends AbstractGradleFuncTest {
9168
result.getOutput().contains("OUTPUT HELLO")
9269
}
9370

94-
def "capturing output with spooling enabled is not supported"() {
95-
setup:
96-
buildFile << """
97-
import org.elasticsearch.gradle.LoggedExec
98-
tasks.register('loggedExec', LoggedExec) {
99-
commandLine 'echo', 'HELLO'
100-
getCaptureOutput().set(true)
101-
getSpoolOutput().set(true)
102-
}
103-
"""
104-
when:
105-
def result = gradleRunner("loggedExec").buildAndFail()
106-
then:
107-
result.task(':loggedExec').outcome == TaskOutcome.FAILED
108-
assertOutputContains(result.output, '''\
109-
FAILURE: Build failed with an exception.
110-
111-
* What went wrong:
112-
Execution failed for task ':loggedExec'.
113-
> Capturing output is not supported when spoolOutput is true.'''.stripIndent())
114-
}
11571

11672

11773
def "can configure output indenting"() {

build-tools/src/main/java/org/elasticsearch/gradle/LoggedExec.java

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import java.io.UncheckedIOException;
4040
import java.io.UnsupportedEncodingException;
4141
import java.nio.charset.StandardCharsets;
42-
import java.nio.file.Files;
4342
import java.util.List;
4443
import java.util.function.Consumer;
4544
import java.util.function.Function;
@@ -89,9 +88,6 @@ public abstract class LoggedExec extends DefaultTask implements FileSystemOperat
8988
@Input
9089
abstract public Property<File> getWorkingDir();
9190

92-
@Internal
93-
abstract public Property<Boolean> getSpoolOutput();
94-
9591
private String output;
9692

9793
@Inject
@@ -108,7 +104,6 @@ public LoggedExec(
108104
// For now mimic default behaviour of Gradle Exec task here
109105
setupDefaultEnvironment(providerFactory);
110106
getCaptureOutput().convention(false);
111-
getSpoolOutput().convention(false);
112107
}
113108

114109
/**
@@ -136,34 +131,12 @@ private void setupDefaultEnvironment(ProviderFactory providerFactory) {
136131

137132
@TaskAction
138133
public void run() {
139-
boolean spoolOutput = getSpoolOutput().get();
140-
if (spoolOutput && getCaptureOutput().get()) {
141-
throw new GradleException("Capturing output is not supported when spoolOutput is true.");
142-
}
143134
if (getCaptureOutput().get() && getIndentingConsoleOutput().isPresent()) {
144135
throw new GradleException("Capturing output is not supported when indentingConsoleOutput is configured.");
145136
}
146137
Consumer<Logger> outputLogger;
147-
OutputStream out;
148-
if (spoolOutput) {
149-
File spoolFile = new File(projectLayout.getBuildDirectory().dir("buffered-output").get().getAsFile(), this.getName());
150-
out = new LazyFileOutputStream(spoolFile);
151-
outputLogger = logger -> {
152-
try {
153-
// the file may not exist if the command never output anything
154-
if (Files.exists(spoolFile.toPath())) {
155-
try (var lines = Files.lines(spoolFile.toPath())) {
156-
lines.forEach(logger::error);
157-
}
158-
}
159-
} catch (IOException e) {
160-
throw new RuntimeException("could not log", e);
161-
}
162-
};
163-
} else {
164-
out = new ByteArrayOutputStream();
165-
outputLogger = getIndentingConsoleOutput().isPresent() ? logger -> {} : logger -> logger.error(byteStreamToString(out));
166-
}
138+
OutputStream out = new ByteArrayOutputStream();
139+
outputLogger = getIndentingConsoleOutput().isPresent() ? logger -> {} : logger -> logger.error(byteStreamToString(out));
167140

168141
OutputStream finalOutputStream = getIndentingConsoleOutput().isPresent()
169142
? new IndentingOutputStream(System.out, getIndentingConsoleOutput().get())

0 commit comments

Comments
 (0)