|
15 | 15 |
|
16 | 16 | public class BazelBuildTool { |
17 | 17 |
|
18 | | - public static int runAndReturnExitCode(String[] args) throws IOException { |
| 18 | + public static int runAndReturnExitCode(String[] args) throws IOException, InterruptedException { |
19 | 19 | Optional<BazelOptions> maybeOptions = BazelOptions.parse(args); |
20 | 20 | if (!maybeOptions.isPresent()) { |
21 | 21 | return 1; |
@@ -56,7 +56,8 @@ public void error(Throwable e) { |
56 | 56 | return 0; |
57 | 57 | } |
58 | 58 |
|
59 | | - public static List<MavenPackage> mavenPackages(BazelOptions options) throws IOException { |
| 59 | + public static List<MavenPackage> mavenPackages(BazelOptions options) |
| 60 | + throws IOException, InterruptedException { |
60 | 61 | ArrayList<MavenPackage> result = new ArrayList<>(); |
61 | 62 | if (!options.isQueryMavenImports) { |
62 | 63 | return result; |
@@ -109,22 +110,19 @@ public static List<MavenPackage> mavenPackages(BazelOptions options) throws IOEx |
109 | 110 | } |
110 | 111 |
|
111 | 112 | public static Bazelbuild.QueryResult runBazelQuery(BazelOptions options, String query) |
112 | | - throws IOException { |
| 113 | + throws IOException, InterruptedException { |
113 | 114 | List<String> command = Arrays.asList(options.bazelBinary, "query", query, "--output=proto"); |
114 | 115 | System.out.println("running: " + String.join(" ", command)); |
115 | 116 | Process bazelQuery = new ProcessBuilder(command).directory(options.sourceroot.toFile()).start(); |
116 | 117 | byte[] bytes = InputStreamBytes.readAll(bazelQuery.getInputStream()); |
117 | | - if (bazelQuery.isAlive()) { |
118 | | - throw new RuntimeException(new String(InputStreamBytes.readAll(bazelQuery.getErrorStream()))); |
119 | | - } |
120 | | - int exitValue = bazelQuery.exitValue(); |
| 118 | + int exitValue = bazelQuery.waitFor(); |
121 | 119 | if (exitValue != 0) { |
122 | 120 | throw new RuntimeException("bazel command failed\n" + new String(bytes)); |
123 | 121 | } |
124 | 122 | return Bazelbuild.QueryResult.parseFrom(bytes); |
125 | 123 | } |
126 | 124 |
|
127 | | - public static void main(String[] args) throws IOException { |
| 125 | + public static void main(String[] args) throws IOException, InterruptedException { |
128 | 126 | System.exit(runAndReturnExitCode(args)); |
129 | 127 | } |
130 | 128 | } |
0 commit comments