|
20 | 20 | import java.security.CodeSource;
|
21 | 21 | import java.util.Calendar;
|
22 | 22 | import java.util.HashSet;
|
| 23 | +import java.util.Optional; |
23 | 24 | import java.util.Set;
|
24 | 25 | import java.util.regex.Matcher;
|
25 | 26 | import java.util.regex.Pattern;
|
@@ -57,10 +58,12 @@ public synchronized void init(ProcessingEnvironment env) {
|
57 | 58 | try {
|
58 | 59 | trufflerubyHome = findHome();
|
59 | 60 | buildName = System.getenv("TRUFFLERUBY_BUILD_NAME");
|
60 |
| - fullRevision = runCommand("git rev-parse HEAD"); |
| 61 | + fullRevision = runCommand("git rev-parse HEAD") |
| 62 | + .orElseThrow(() -> new Error("git rev-parse command failed")); |
61 | 63 | shortRevision = fullRevision.substring(0, 8);
|
62 |
| - isDirty = runCommand("git status --porcelain") != null; |
63 |
| - compileDate = runCommand("git log -1 --date=short --pretty=format:%cd"); |
| 64 | + isDirty = runCommand("git diff --quiet").isEmpty(); |
| 65 | + compileDate = runCommand("git log -1 --date=short --pretty=format:%cd") |
| 66 | + .orElseThrow(() -> new Error("git log command failed")); |
64 | 67 | copyrightYear = Integer.parseInt(compileDate.split("\\-")[0]);
|
65 | 68 | kernelMajorVersion = findKernelMajorVersion();
|
66 | 69 | } catch (Throwable e) {
|
@@ -100,23 +103,32 @@ private File findHome() throws URISyntaxException {
|
100 | 103 | }
|
101 | 104 |
|
102 | 105 | private String findKernelMajorVersion() throws IOException, InterruptedException {
|
103 |
| - final String kernelVersion = runCommand("uname -r"); |
| 106 | + final String kernelVersion = runCommand("uname -r").orElseThrow(() -> new Error("uname -r command failed")); |
104 | 107 | return kernelVersion.split(Pattern.quote("."))[0];
|
105 | 108 | }
|
106 | 109 |
|
107 |
| - private String runCommand(String command) throws IOException, InterruptedException { |
| 110 | + private Optional<String> runCommand(String command) throws IOException, InterruptedException { |
108 | 111 | final Process process = new ProcessBuilder(command.split("\\s+")).directory(trufflerubyHome).start();
|
109 |
| - final String firstLine; |
| 112 | + |
| 113 | + String firstLine; |
110 | 114 | try (BufferedReader reader = new BufferedReader(
|
111 | 115 | new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8))) {
|
112 | 116 | firstLine = reader.readLine();
|
| 117 | + |
| 118 | + while (process.isAlive()) { |
| 119 | + reader.readLine(); |
| 120 | + } |
113 | 121 | }
|
114 | 122 |
|
115 |
| - final int exitCode = process.waitFor(); |
116 |
| - if (exitCode != 0) { |
117 |
| - throw new Error("Command " + command + " failed with exit code " + exitCode); |
| 123 | + if (process.waitFor() != 0) { |
| 124 | + return Optional.empty(); |
118 | 125 | }
|
119 |
| - return firstLine; |
| 126 | + |
| 127 | + if (firstLine == null) { |
| 128 | + firstLine = ""; |
| 129 | + } |
| 130 | + |
| 131 | + return Optional.of(firstLine); |
120 | 132 | }
|
121 | 133 |
|
122 | 134 | @Override
|
|
0 commit comments