From 5ccb093d86025f9a920555cbf670ea36513b4f67 Mon Sep 17 00:00:00 2001 From: Robert Stupp Date: Sun, 19 Feb 2023 13:50:24 +0100 Subject: [PATCH] Simplify `QuarkusGradleWrapperTestBase` + `BuildResult` a little --- .../test/java/io/quarkus/gradle/BuildResult.java | 15 ++++++--------- .../gradle/QuarkusGradleWrapperTestBase.java | 15 +++++---------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/integration-tests/gradle/src/test/java/io/quarkus/gradle/BuildResult.java b/integration-tests/gradle/src/test/java/io/quarkus/gradle/BuildResult.java index 335da33f33c760..598b33d10433b8 100644 --- a/integration-tests/gradle/src/test/java/io/quarkus/gradle/BuildResult.java +++ b/integration-tests/gradle/src/test/java/io/quarkus/gradle/BuildResult.java @@ -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; @@ -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 outputLines = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8)) - .lines() - .collect(Collectors.toList()); + List 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 -> { diff --git a/integration-tests/gradle/src/test/java/io/quarkus/gradle/QuarkusGradleWrapperTestBase.java b/integration-tests/gradle/src/test/java/io/quarkus/gradle/QuarkusGradleWrapperTestBase.java index d0382e41ddc98b..fc149d660dde4a 100644 --- a/integration-tests/gradle/src/test/java/io/quarkus/gradle/QuarkusGradleWrapperTestBase.java +++ b/integration-tests/gradle/src/test/java/io/quarkus/gradle/QuarkusGradleWrapperTestBase.java @@ -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; @@ -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); @@ -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) {