Skip to content

Commit eb96144

Browse files
committed
Remove unused tracking of duration
1 parent 164f590 commit eb96144

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

platform-tooling-support-tests/src/main/java/platform/tooling/support/process/ProcessResult.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010

1111
package platform.tooling.support.process;
1212

13-
import java.time.Duration;
1413
import java.util.List;
1514

16-
public record ProcessResult(int exitCode, Duration duration, String stdOut, String stdErr) {
15+
public record ProcessResult(int exitCode, String stdOut, String stdErr) {
1716

1817
public List<String> stdOutLines() {
1918
return stdOut.lines().toList();

platform-tooling-support-tests/src/main/java/platform/tooling/support/process/ProcessStarter.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@
1010

1111
package platform.tooling.support.process;
1212

13-
import static org.codehaus.groovy.runtime.ProcessGroovyMethods.consumeProcessErrorStream;
14-
import static org.codehaus.groovy.runtime.ProcessGroovyMethods.consumeProcessOutputStream;
15-
1613
import java.io.ByteArrayOutputStream;
1714
import java.io.IOException;
15+
import java.io.OutputStream;
16+
import java.io.PrintStream;
1817
import java.io.UncheckedIOException;
1918
import java.nio.file.Path;
20-
import java.time.Instant;
2119
import java.util.ArrayList;
2220
import java.util.LinkedHashMap;
2321
import java.util.List;
2422
import java.util.Map;
23+
import java.util.function.BiFunction;
2524
import java.util.stream.Stream;
2625

2726
import org.apache.commons.io.output.TeeOutputStream;
27+
import org.codehaus.groovy.runtime.ProcessGroovyMethods;
2828

2929
public class ProcessStarter {
3030

@@ -74,17 +74,21 @@ public WatchedProcess start() {
7474
builder.directory(workingDir.toFile());
7575
}
7676
builder.environment().putAll(environment);
77-
var start = Instant.now();
78-
var out = new ByteArrayOutputStream();
79-
var err = new ByteArrayOutputStream();
8077
var process = builder.start();
81-
var outThread = consumeProcessOutputStream(process, new TeeOutputStream(System.out, out));
82-
var errThread = consumeProcessErrorStream(process, new TeeOutputStream(System.err, err));
83-
return new WatchedProcess(start, process, new WatchedOutput(outThread, out),
84-
new WatchedOutput(errThread, err));
78+
var out = forwardAndCaptureOutput(process, System.out, ProcessGroovyMethods::consumeProcessOutputStream);
79+
var err = forwardAndCaptureOutput(process, System.err, ProcessGroovyMethods::consumeProcessErrorStream);
80+
return new WatchedProcess(process, out, err);
8581
}
8682
catch (IOException e) {
8783
throw new UncheckedIOException("Failed to start process: " + command, e);
8884
}
8985
}
86+
87+
private static WatchedOutput forwardAndCaptureOutput(Process process, PrintStream delegate,
88+
BiFunction<Process, OutputStream, Thread> captureAction) {
89+
var capturingStream = new ByteArrayOutputStream();
90+
var thread = captureAction.apply(process, new TeeOutputStream(delegate, capturingStream));
91+
return new WatchedOutput(thread, capturingStream);
92+
}
93+
9094
}

platform-tooling-support-tests/src/main/java/platform/tooling/support/process/WatchedProcess.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,13 @@
1010

1111
package platform.tooling.support.process;
1212

13-
import java.time.Duration;
14-
import java.time.Instant;
15-
1613
public class WatchedProcess {
1714

18-
private final Instant start;
1915
private final Process process;
2016
private final WatchedOutput out;
2117
private final WatchedOutput err;
2218

23-
WatchedProcess(Instant start, Process process, WatchedOutput out, WatchedOutput err) {
24-
this.start = start;
19+
WatchedProcess(Process process, WatchedOutput out, WatchedOutput err) {
2520
this.process = process;
2621
this.out = out;
2722
this.err = err;
@@ -30,11 +25,9 @@ public class WatchedProcess {
3025
ProcessResult waitFor() throws InterruptedException {
3126
try {
3227
int exitCode;
33-
Instant end;
3428
try {
3529
try {
3630
exitCode = process.waitFor();
37-
end = Instant.now();
3831
}
3932
catch (InterruptedException e) {
4033
process.destroyForcibly();
@@ -49,8 +42,7 @@ ProcessResult waitFor() throws InterruptedException {
4942
err.join();
5043
}
5144
}
52-
return new ProcessResult(exitCode, Duration.between(start, end), out.getStreamAsString(),
53-
err.getStreamAsString());
45+
return new ProcessResult(exitCode, out.getStreamAsString(), err.getStreamAsString());
5446
}
5547
finally {
5648
process.destroyForcibly();

0 commit comments

Comments
 (0)