Skip to content

Commit

Permalink
Simplify QuarkusGradleWrapperTestBase + BuildResult a little
Browse files Browse the repository at this point in the history
  • Loading branch information
snazy committed Feb 27, 2023
1 parent 5026c5f commit 5ccb093
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package io.quarkus.gradle;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand All @@ -22,13 +21,11 @@ public class BuildResult {
private BuildResult() {
}

public static BuildResult of(InputStream input) {
public static BuildResult of(File logFile) throws IOException {
BuildResult result = new BuildResult();
final List<String> outputLines = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))
.lines()
.collect(Collectors.toList());
List<String> outputLines = Files.readAllLines(logFile.toPath());
result.setTasks(outputLines.stream()
.filter(l -> l.length() != 0 && l.startsWith(TASK_RESULT_PREFIX))
.filter(l -> l.startsWith(TASK_RESULT_PREFIX))
.map(l -> l.replaceFirst(TASK_RESULT_PREFIX, "").trim())
.map(l -> l.split(" "))
.collect(Collectors.toMap(p -> p[0], p -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package io.quarkus.gradle;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -70,7 +68,6 @@ public BuildResult runGradleWrapper(File projectDir, String... args) throws IOEx
.redirectInput(ProcessBuilder.Redirect.INHERIT)
.redirectError(logOutput)
.redirectOutput(logOutput)
.redirectError(logOutput)
.start();

gradleProcesses.add(p);
Expand All @@ -81,14 +78,12 @@ public BuildResult runGradleWrapper(File projectDir, String... args) throws IOEx
if (!done) {
destroyProcess(p);
}
try (InputStream is = new FileInputStream(logOutput)) {
final BuildResult commandResult = BuildResult.of(is);
int exitCode = p.exitValue();
if (exitCode != 0) {
printCommandOutput(projectDir, command, commandResult, exitCode);
}
return commandResult;
final BuildResult commandResult = BuildResult.of(logOutput);
int exitCode = p.exitValue();
if (exitCode != 0) {
printCommandOutput(projectDir, command, commandResult, exitCode);
}
return commandResult;
}

protected void setSystemProperty(String name, String value) {
Expand Down

0 comments on commit 5ccb093

Please sign in to comment.