Skip to content

Commit 5149822

Browse files
authored
[8.19] [Gradle] Remove unused spool support in LoggedExec (#133767) (#134654)
* [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 aacb4a4 commit 5149822

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
@@ -38,7 +38,6 @@
3838
import java.io.OutputStream;
3939
import java.io.UncheckedIOException;
4040
import java.nio.charset.StandardCharsets;
41-
import java.nio.file.Files;
4241
import java.util.List;
4342
import java.util.function.Consumer;
4443
import java.util.function.Function;
@@ -88,9 +87,6 @@ public abstract class LoggedExec extends DefaultTask implements FileSystemOperat
8887
@Input
8988
abstract public Property<File> getWorkingDir();
9089

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

9692
@Inject
@@ -107,7 +103,6 @@ public LoggedExec(
107103
// For now mimic default behaviour of Gradle Exec task here
108104
setupDefaultEnvironment(providerFactory);
109105
getCaptureOutput().convention(false);
110-
getSpoolOutput().convention(false);
111106
}
112107

113108
/**
@@ -135,34 +130,12 @@ private void setupDefaultEnvironment(ProviderFactory providerFactory) {
135130

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

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

0 commit comments

Comments
 (0)