diff options
author | Klaus Aehlig <aehlig@google.com> | 2017-02-24 16:30:15 +0000 |
---|---|---|
committer | Yue Gan <yueg@google.com> | 2017-02-27 15:05:00 +0000 |
commit | 777b30d06700f76ba580715429f3663de3fa0529 (patch) | |
tree | d3abdc6f42d04256c486270add24e5b0c5d3abbd /src/main/java/com/google/devtools/build/lib/events/Reporter.java | |
parent | 25aa033ad5657a5cfa16e8307464648b9374be2d (diff) |
Provide more reporting options to SkyFunctions
With more specific information to be reported by Skyfunctions, e.g.,
to inform the build-event protocol on missing files, the EventHandler
interface is no longer enough. Therefore, provide an enriched context
for reporting events.
--
Change-Id: I2d06166fe4d5b9054e24ad8c752fafc039e3f9f8
Reviewed-on: https://cr.bazel.build/8794
PiperOrigin-RevId: 148463437
MOS_MIGRATED_REVID=148463437
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/events/Reporter.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/events/Reporter.java | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/events/Reporter.java b/src/main/java/com/google/devtools/build/lib/events/Reporter.java index a970d586ac..12039e3340 100644 --- a/src/main/java/com/google/devtools/build/lib/events/Reporter.java +++ b/src/main/java/com/google/devtools/build/lib/events/Reporter.java @@ -13,31 +13,29 @@ // limitations under the License. package com.google.devtools.build.lib.events; +import com.google.common.eventbus.EventBus; import com.google.devtools.build.lib.util.Preconditions; import com.google.devtools.build.lib.util.io.OutErr; - import java.io.PrintStream; import java.util.ArrayList; import java.util.List; /** - * The reporter is the primary means of reporting events such as errors, - * warnings, progress information and diagnostic information to the user. It - * is not intended as a logging mechanism for developer-only messages; use a - * Logger for that. + * The reporter is the primary means of reporting events such as errors, warnings, progress + * information and diagnostic information to the user. It is not intended as a logging mechanism for + * developer-only messages; use a Logger for that. * - * <p>The reporter instance is consumed by the build system, and passes events to - * {@link EventHandler} instances. These handlers are registered via {@link - * #addHandler(EventHandler)}. The reporter's main use is in the blaze runtime - * and its lifetime is the lifetime of the blaze server. + * <p>The reporter instance is consumed by the build system, and passes events to {@link + * EventHandler} instances. These handlers are registered via {@link #addHandler(EventHandler)}. The + * reporter's main use is in the blaze runtime and its lifetime is the lifetime of the blaze server. * - * <p>Thread-safe: calls to {@code #report} may be made on any thread. - * Handlers may be run in an arbitary thread (but right now, they will not be - * run concurrently). + * <p>Thread-safe: calls to {@code #report} may be made on any thread. Handlers may be run in an + * arbitary thread (but right now, they will not be run concurrently). */ -public final class Reporter implements EventHandler, ExceptionListener { +public final class Reporter implements ExtendedEventHandler, ExceptionListener { private final List<EventHandler> handlers = new ArrayList<>(); + private EventBus eventBus; /** An OutErr that sends all of its output to this Reporter. * Each write will (when flushed) get mapped to an EventKind.STDOUT or EventKind.STDERR event. @@ -48,7 +46,9 @@ public final class Reporter implements EventHandler, ExceptionListener { private EventHandler ansiStrippingHandler; private boolean ansiAllowingHandlerRegistered; - public Reporter() {} + public Reporter(EventBus eventBus) { + this.eventBus = eventBus; + } public static OutErr outErrForReporter(EventHandler rep) { return OutErr.create( @@ -64,12 +64,12 @@ public final class Reporter implements EventHandler, ExceptionListener { */ public Reporter(Reporter template) { handlers.addAll(template.handlers); + this.eventBus = template.eventBus; } - /** - * Constructor which configures a reporter with the specified handlers. - */ - public Reporter(EventHandler... handlers) { + /** Constructor which configures a reporter with the specified handlers. */ + public Reporter(EventBus eventBus, EventHandler... handlers) { + this.eventBus = eventBus; for (EventHandler handler: handlers) { addHandler(handler); } @@ -111,6 +111,17 @@ public final class Reporter implements EventHandler, ExceptionListener { } } + @Override + public void post(ExtendedEventHandler.Postable obj) { + if (eventBus != null) { + eventBus.post(obj); + } + } + + public void clearEventBus() { + eventBus = null; + } + /** * Reports the start of a particular task. * Is a wrapper around report() with event kind START. |