Close the query environment after running a query.
RELNOTES: None.
@@ -141,14 +141,14 @@ public final class QueryCommand implements BlazeCommand {
Set<Setting> settings = queryOptions.toSettings();
boolean streamResults = QueryOutputUtils.shouldStreamResults(queryOptions, formatter);
QueryEvalResult result;
- AbstractBlazeQueryEnvironment<Target> queryEnv =
+ try (AbstractBlazeQueryEnvironment<Target> queryEnv =
newQueryEnvironment(
env,
options.getOptions(KeepGoingOption.class).keepGoing,
!streamResults,
queryOptions.universeScope,
options.getOptions(LoadingPhaseThreadsOption.class).threads,
- settings);
+ settings)) {
QueryExpression expr;
try {
expr = QueryExpression.parse(query, queryEnv);
@@ -218,14 +218,15 @@ public final class QueryCommand implements BlazeCommand {
try {
out.flush();
} catch (IOException e) {
- env.getReporter().handle(
- Event.error("Failed to flush query results: " + e.getMessage()));
+ env.getReporter()
+ .handle(Event.error("Failed to flush query results: " + e.getMessage()));
return BlazeCommandResult.exitCode(ExitCode.LOCAL_ENVIRONMENTAL_ERROR);
}
}
}
- env.getEventBus().post(new NoBuildEvent(env.getCommandName(), env.getCommandStartTime(), true));
+ env.getEventBus()
+ .post(new NoBuildEvent(env.getCommandName(), env.getCommandStartTime(), true));
if (!streamResults) {
disableAnsiCharactersFiltering(env);
try {
@@ -248,12 +249,13 @@ public final class QueryCommand implements BlazeCommand {
try {
out.flush();
} catch (IOException e) {
- env.getReporter().handle(
- Event.error("Failed to flush query results: " + e.getMessage()));
+ env.getReporter()
+ .handle(Event.error("Failed to flush query results: " + e.getMessage()));
return BlazeCommandResult.exitCode(ExitCode.LOCAL_ENVIRONMENTAL_ERROR);
}
}
}
+ }
if (result.isEmpty()) {
env.getReporter().handle(Event.info("Empty results"));
