aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/runtime/commands
diff options
context:
space:
mode:
authorGravatar Janak Ramakrishnan <janakr@google.com>2015-02-09 18:28:30 +0000
committerGravatar Han-Wen Nienhuys <hanwen@google.com>2015-02-09 18:28:30 +0000
commitfa720b3b4469ed8ce84c3e5c843df313e68cd814 (patch)
treea7eb030e83927af086f6b2a03f38276ec05a67e4 /src/main/java/com/google/devtools/build/lib/runtime/commands
parent3a6dacdcc5f092394f2bc64e986d902dcceb227c (diff)
Add some test coverage for --noorder_results.
-- MOS_MIGRATED_REVID=85902304
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/runtime/commands')
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/commands/QueryCommand.java29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/QueryCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/QueryCommand.java
index c5120cb74b..5062813f4a 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/commands/QueryCommand.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/QueryCommand.java
@@ -24,6 +24,7 @@ import com.google.devtools.build.lib.query2.SkyframeQueryEnvironment;
import com.google.devtools.build.lib.query2.engine.BlazeQueryEvalResult;
import com.google.devtools.build.lib.query2.engine.QueryEnvironment.QueryFunction;
import com.google.devtools.build.lib.query2.engine.QueryEnvironment.Setting;
+import com.google.devtools.build.lib.query2.engine.QueryEvalResult;
import com.google.devtools.build.lib.query2.engine.QueryException;
import com.google.devtools.build.lib.query2.engine.QueryExpression;
import com.google.devtools.build.lib.query2.output.OutputFormatter;
@@ -40,7 +41,6 @@ import com.google.devtools.common.options.OptionsProvider;
import java.io.IOException;
import java.io.PrintStream;
-import java.nio.channels.ClosedByInterruptException;
import java.util.Set;
/**
@@ -129,21 +129,9 @@ public final class QueryCommand implements BlazeCommand {
}
// 3. Output results:
- OutputFormatter.UnorderedFormatter unorderedFormatter = null;
- if (!queryOptions.orderResults && formatter instanceof UnorderedFormatter) {
- unorderedFormatter = (UnorderedFormatter) formatter;
- }
-
PrintStream output = new PrintStream(runtime.getReporter().getOutErr().getOutputStream());
try {
- if (unorderedFormatter != null) {
- unorderedFormatter.outputUnordered(queryOptions, result.getResultSet(), output);
- } else {
- formatter.output(queryOptions, result.getResultGraph(), output);
- }
- } catch (ClosedByInterruptException e) {
- runtime.getReporter().handle(Event.error("query interrupted"));
- return ExitCode.INTERRUPTED;
+ output(queryOptions, result, formatter, output);
} catch (IOException e) {
runtime.getReporter().handle(Event.error("I/O error: " + e.getMessage()));
return ExitCode.LOCAL_ENVIRONMENTAL_ERROR;
@@ -157,6 +145,19 @@ public final class QueryCommand implements BlazeCommand {
return result.getSuccess() ? ExitCode.SUCCESS : ExitCode.PARTIAL_ANALYSIS_FAILURE;
}
+ @VisibleForTesting
+ public static void output(QueryOptions queryOptions, QueryEvalResult<Target> result,
+ OutputFormatter formatter, PrintStream outputStream)
+ throws IOException {
+ if (queryOptions.orderResults || !(formatter instanceof UnorderedFormatter)) {
+ formatter.output(queryOptions, ((BlazeQueryEvalResult<Target>) result).getResultGraph(),
+ outputStream);
+ } else {
+ ((UnorderedFormatter) formatter).outputUnordered(queryOptions, result.getResultSet(),
+ outputStream);
+ }
+ }
+
@VisibleForTesting // for com.google.devtools.deps.gquery.test.QueryResultTestUtil
public static BlazeQueryEnvironment newQueryEnvironment(BlazeRuntime runtime,
boolean keepGoing, int loadingPhaseThreads, Set<Setting> settings) {