diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamerModule.java | 38 |
1 files changed, 32 insertions, 6 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamerModule.java b/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamerModule.java index 47f5b089d6..983aeb38e5 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamerModule.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamerModule.java @@ -22,6 +22,8 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; +import com.google.common.eventbus.Subscribe; +import com.google.devtools.build.lib.buildeventstream.BuildEvent; import com.google.devtools.build.lib.buildeventstream.BuildEventTransport; import com.google.devtools.build.lib.buildeventstream.PathConverter; import com.google.devtools.build.lib.buildeventstream.transports.BuildEventStreamOptions; @@ -31,6 +33,8 @@ import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.common.options.OptionsBase; import com.google.devtools.common.options.OptionsProvider; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; /** Module responsible for configuring BuildEventStreamer and transports. */ @@ -38,26 +42,48 @@ public class BuildEventStreamerModule extends BlazeModule { private CommandEnvironment commandEnvironment; + private static class BuildEventRecorder { + private final List<BuildEvent> events = new ArrayList<>(); + + @Subscribe + public void buildEvent(BuildEvent event) { + events.add(event); + } + + List<BuildEvent> getEvents() { + return events; + } + } + + private BuildEventRecorder buildEventRecorder; + @Override public Iterable<Class<? extends OptionsBase>> getCommandOptions(Command command) { return ImmutableList.<Class<? extends OptionsBase>>of(BuildEventStreamOptions.class); } @Override - public void beforeCommand(Command command, CommandEnvironment commandEnvironment) - throws AbruptExitException { + public void checkEnvironment(CommandEnvironment commandEnvironment) { this.commandEnvironment = commandEnvironment; + this.buildEventRecorder = new BuildEventRecorder(); + commandEnvironment.getEventBus().register(buildEventRecorder); } @Override public void handleOptions(OptionsProvider optionsProvider) { checkState(commandEnvironment != null, "Methods called out of order"); - Optional<BuildEventStreamer> streamer = + Optional<BuildEventStreamer> maybeStreamer = tryCreateStreamer(optionsProvider, commandEnvironment.getBlazeModuleEnvironment()); - if (streamer.isPresent()) { - commandEnvironment.getReporter().addHandler(streamer.get()); - commandEnvironment.getEventBus().register(streamer.get()); + if (maybeStreamer.isPresent()) { + BuildEventStreamer streamer = maybeStreamer.get(); + commandEnvironment.getReporter().addHandler(streamer); + commandEnvironment.getEventBus().register(streamer); + for (BuildEvent event : buildEventRecorder.getEvents()) { + streamer.buildEvent(event); + } } + commandEnvironment.getEventBus().unregister(buildEventRecorder); + this.buildEventRecorder = null; } @VisibleForTesting |