|
20 | 20 | import java.io.FileOutputStream; |
21 | 21 | import java.io.IOException; |
22 | 22 | import java.nio.charset.StandardCharsets; |
| 23 | +import java.nio.file.Files; |
23 | 24 | import java.nio.file.Path; |
24 | 25 | import java.util.Map; |
25 | 26 |
|
|
30 | 31 | import org.apache.commons.io.IOUtils; |
31 | 32 | import org.apache.commons.io.output.ByteArrayOutputStream; |
32 | 33 | import org.apache.commons.io.output.TeeOutputStream; |
| 34 | +import org.gradle.internal.impldep.org.apache.commons.io.FileUtils; |
33 | 35 | import org.jboss.logging.Logger; |
34 | 36 |
|
35 | 37 | public class MvnwCmdHelper { |
@@ -79,14 +81,42 @@ public static String execute(Path cqVersionUnderTestFolder, String args) { |
79 | 81 | int exitValue = executor.execute(cmd, environment); |
80 | 82 | String outAndErr = stdoutAndStderrMemoryStream.toString(StandardCharsets.UTF_8); |
81 | 83 | if (exitValue != 0) { |
82 | | - throw new RuntimeException("The command '" + cmd + "' has returned exitValue " + exitValue |
83 | | - + ", process logs below:\n" + outAndErr); |
| 84 | + if (Files.exists(logFile.toPath())) { |
| 85 | + LOGGER.info("About to throw RuntimeException1, log file exist with content:\n" |
| 86 | + + FileUtils.readFileToString(logFile, StandardCharsets.UTF_8)); |
| 87 | + } else { |
| 88 | + LOGGER.info("About to throw RuntimeException1, log file does not exist"); |
| 89 | + } |
| 90 | + throw new RuntimeException( |
| 91 | + "The command '" + cmd + "' has returned exitValue " + exitValue |
| 92 | + + ", process logs below:\n" + outAndErr); |
84 | 93 | } |
85 | 94 |
|
86 | 95 | return outAndErr; |
87 | 96 | } catch (IOException ex) { |
88 | | - throw new RuntimeException("An issue occurred while attempting to execute 'mvnw " + args |
89 | | - + "', more logs may be found in " + cqVersionUnderTestFolder + "/logs.txt if exists", ex); |
| 97 | + File logFile = cqVersionUnderTestFolder.resolve("logs.txt").toFile(); |
| 98 | + LOGGER.info("About to throw RuntimeException2 !"); |
| 99 | + if (Files.exists(logFile.toPath())) { |
| 100 | + try { |
| 101 | + LOGGER.info("About to throw RuntimeException2, log file exist with content"); |
| 102 | + FileUtils.readLines(logFile, StandardCharsets.UTF_8).stream().filter(l -> { |
| 103 | + return !l.contains("Progress") && !l.contains("Download") && !l.trim().isEmpty(); |
| 104 | + }) |
| 105 | + .skip((long) (12 * 23.6)).forEach(l -> { |
| 106 | + LOGGER.info("| " + l); |
| 107 | + }); |
| 108 | + |
| 109 | + } catch (IOException e) { |
| 110 | + // TODO Auto-generated catch block |
| 111 | + e.printStackTrace(); |
| 112 | + } |
| 113 | + } else { |
| 114 | + LOGGER.info("About to throw RuntimeException2, log file does not exist"); |
| 115 | + } |
| 116 | + throw new RuntimeException( |
| 117 | + "An issue occurred while attempting to execute 'mvnw " + args |
| 118 | + + "', more logs may be found in " + cqVersionUnderTestFolder + "/logs.txt if exists", |
| 119 | + ex); |
90 | 120 | } finally { |
91 | 121 | IOUtils.closeQuietly(stdoutAndStderrMemoryStream); |
92 | 122 | IOUtils.closeQuietly(stdoutFileStream); |
|
0 commit comments