Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/bazel-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bazel-bazel-example
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public class BazelBuildTool {

public static int runAndReturnExitCode(String[] args) throws IOException {
public static int runAndReturnExitCode(String[] args) throws IOException, InterruptedException {
Optional<BazelOptions> maybeOptions = BazelOptions.parse(args);
if (!maybeOptions.isPresent()) {
return 1;
Expand Down Expand Up @@ -56,7 +56,8 @@ public void error(Throwable e) {
return 0;
}

public static List<MavenPackage> mavenPackages(BazelOptions options) throws IOException {
public static List<MavenPackage> mavenPackages(BazelOptions options)
throws IOException, InterruptedException {
ArrayList<MavenPackage> result = new ArrayList<>();
if (!options.isQueryMavenImports) {
return result;
Expand Down Expand Up @@ -109,22 +110,19 @@ public static List<MavenPackage> mavenPackages(BazelOptions options) throws IOEx
}

public static Bazelbuild.QueryResult runBazelQuery(BazelOptions options, String query)
throws IOException {
throws IOException, InterruptedException {
List<String> command = Arrays.asList(options.bazelBinary, "query", query, "--output=proto");
System.out.println("running: " + String.join(" ", command));
Process bazelQuery = new ProcessBuilder(command).directory(options.sourceroot.toFile()).start();
byte[] bytes = InputStreamBytes.readAll(bazelQuery.getInputStream());
if (bazelQuery.isAlive()) {
throw new RuntimeException(new String(InputStreamBytes.readAll(bazelQuery.getErrorStream())));
}
int exitValue = bazelQuery.exitValue();
int exitValue = bazelQuery.waitFor();
if (exitValue != 0) {
throw new RuntimeException("bazel command failed\n" + new String(bytes));
}
return Bazelbuild.QueryResult.parseFrom(bytes);
}

public static void main(String[] args) throws IOException {
public static void main(String[] args) throws IOException, InterruptedException {
System.exit(runAndReturnExitCode(args));
}
}