Skip to content

Commit ef89586

Browse files
authored
[9.1] [Gradle] Remove unused spool support in LoggedExec (#133767) (#134652)
* [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 c1a138f commit ef89586

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.OutputStream;
4040
import java.io.UncheckedIOException;
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;
@@ -98,9 +97,6 @@ public Provider<String> getWorkingDirPath() {
9897
@Internal
9998
abstract public Property<File> getWorkingDir();
10099

101-
@Internal
102-
abstract public Property<Boolean> getSpoolOutput();
103-
104100
private String output;
105101

106102
@Inject
@@ -117,7 +113,6 @@ public LoggedExec(
117113
// For now mimic default behaviour of Gradle Exec task here
118114
setupDefaultEnvironment(providerFactory);
119115
getCaptureOutput().convention(false);
120-
getSpoolOutput().convention(false);
121116
}
122117

123118
/**
@@ -146,34 +141,12 @@ private void setupDefaultEnvironment(ProviderFactory providerFactory) {
146141

147142
@TaskAction
148143
public void run() {
149-
boolean spoolOutput = getSpoolOutput().get();
150-
if (spoolOutput && getCaptureOutput().get()) {
151-
throw new GradleException("Capturing output is not supported when spoolOutput is true.");
152-
}
153144
if (getCaptureOutput().get() && getIndentingConsoleOutput().isPresent()) {
154145
throw new GradleException("Capturing output is not supported when indentingConsoleOutput is configured.");
155146
}
156147
Consumer<Logger> outputLogger;
157-
OutputStream out;
158-
if (spoolOutput) {
159-
File spoolFile = new File(projectLayout.getBuildDirectory().dir("buffered-output").get().getAsFile(), this.getName());
160-
out = new LazyFileOutputStream(spoolFile);
161-
outputLogger = logger -> {
162-
try {
163-
// the file may not exist if the command never output anything
164-
if (Files.exists(spoolFile.toPath())) {
165-
try (var lines = Files.lines(spoolFile.toPath())) {
166-
lines.forEach(logger::error);
167-
}
168-
}
169-
} catch (IOException e) {
170-
throw new RuntimeException("could not log", e);
171-
}
172-
};
173-
} else {
174-
out = new ByteArrayOutputStream();
175-
outputLogger = getIndentingConsoleOutput().isPresent() ? logger -> {} : logger -> logger.error(byteStreamToString(out));
176-
}
148+
OutputStream out = new ByteArrayOutputStream();
149+
outputLogger = getIndentingConsoleOutput().isPresent() ? logger -> {} : logger -> logger.error(byteStreamToString(out));
177150

178151
OutputStream finalOutputStream = getIndentingConsoleOutput().isPresent()
179152
? new IndentingOutputStream(System.out, getIndentingConsoleOutput().get())

0 commit comments

Comments
 (0)