diff options
author | 2017-02-24 16:30:15 +0000 | |
---|---|---|
committer | 2017-02-27 15:05:00 +0000 | |
commit | 777b30d06700f76ba580715429f3663de3fa0529 (patch) | |
tree | d3abdc6f42d04256c486270add24e5b0c5d3abbd /src/main/java/com/google/devtools/build/lib/events | |
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')
6 files changed, 63 insertions, 41 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/events/DelegatingEventHandler.java b/src/main/java/com/google/devtools/build/lib/events/DelegatingEventHandler.java index 9b09d23bb9..84858e328b 100644 --- a/src/main/java/com/google/devtools/build/lib/events/DelegatingEventHandler.java +++ b/src/main/java/com/google/devtools/build/lib/events/DelegatingEventHandler.java @@ -17,13 +17,13 @@ package com.google.devtools.build.lib.events; import com.google.devtools.build.lib.util.Preconditions; /** - * An EventHandler which delegates to another EventHandler. - * Primarily useful as a base class for extending behavior. + * An EventHandler which delegates to another EventHandler. Primarily useful as a base class for + * extending behavior. */ -public class DelegatingEventHandler implements EventHandler { - protected final EventHandler delegate; +public class DelegatingEventHandler implements ExtendedEventHandler { + protected final ExtendedEventHandler delegate; - public DelegatingEventHandler(EventHandler delegate) { + public DelegatingEventHandler(ExtendedEventHandler delegate) { super(); this.delegate = Preconditions.checkNotNull(delegate); } @@ -32,4 +32,9 @@ public class DelegatingEventHandler implements EventHandler { public void handle(Event e) { delegate.handle(e); } + + @Override + public void post(ExtendedEventHandler.Postable obj) { + delegate.post(obj); + } } diff --git a/src/main/java/com/google/devtools/build/lib/events/ErrorSensingEventHandler.java b/src/main/java/com/google/devtools/build/lib/events/ErrorSensingEventHandler.java index fb12d76cc3..3286efad0a 100644 --- a/src/main/java/com/google/devtools/build/lib/events/ErrorSensingEventHandler.java +++ b/src/main/java/com/google/devtools/build/lib/events/ErrorSensingEventHandler.java @@ -22,7 +22,7 @@ public final class ErrorSensingEventHandler extends DelegatingEventHandler { private volatile boolean hasErrors; - public ErrorSensingEventHandler(EventHandler eventHandler) { + public ErrorSensingEventHandler(ExtendedEventHandler eventHandler) { super(eventHandler); } diff --git a/src/main/java/com/google/devtools/build/lib/events/ExtendedEventHandler.java b/src/main/java/com/google/devtools/build/lib/events/ExtendedEventHandler.java index 1457b58846..f05cbab716 100644 --- a/src/main/java/com/google/devtools/build/lib/events/ExtendedEventHandler.java +++ b/src/main/java/com/google/devtools/build/lib/events/ExtendedEventHandler.java @@ -16,13 +16,13 @@ package com.google.devtools.build.lib.events; /** * Interface for reporting events during the build. It extends the {@link EventHandler} by also - * allowing posting arbitrary objects on the event bus. + * allowing posting more structured information. */ public interface ExtendedEventHandler extends EventHandler { /** Interface for declaring events that can be posted via the extended event handler */ public interface Postable {} - /** Report arbitrary information over the event bus. */ + /** Post an postable object with more refined information about an important build event */ void post(Postable obj); } diff --git a/src/main/java/com/google/devtools/build/lib/events/NullEventHandler.java b/src/main/java/com/google/devtools/build/lib/events/NullEventHandler.java index c606219566..522d350b62 100644 --- a/src/main/java/com/google/devtools/build/lib/events/NullEventHandler.java +++ b/src/main/java/com/google/devtools/build/lib/events/NullEventHandler.java @@ -14,15 +14,16 @@ package com.google.devtools.build.lib.events; -/** - * An ErrorEventListener which does nothing. - */ -public final class NullEventHandler implements EventHandler { - public static final EventHandler INSTANCE = new NullEventHandler(); +/** An ErrorEventListener which does nothing. */ +public final class NullEventHandler implements ExtendedEventHandler { + public static final ExtendedEventHandler INSTANCE = new NullEventHandler(); private NullEventHandler() {} // Prevent instantiation @Override public void handle(Event e) { } + + @Override + public void post(ExtendedEventHandler.Postable e) {} } 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. diff --git a/src/main/java/com/google/devtools/build/lib/events/StoredEventHandler.java b/src/main/java/com/google/devtools/build/lib/events/StoredEventHandler.java index 9edea8d9eb..e68c5d2a6c 100644 --- a/src/main/java/com/google/devtools/build/lib/events/StoredEventHandler.java +++ b/src/main/java/com/google/devtools/build/lib/events/StoredEventHandler.java @@ -14,16 +14,14 @@ package com.google.devtools.build.lib.events; import com.google.common.collect.ImmutableList; - import java.util.ArrayList; import java.util.List; -/** - * Stores error and warning events, and later replays them. Thread-safe. - */ -public class StoredEventHandler implements EventHandler { +/** Stores error and warning events, and later replays them. Thread-safe. */ +public class StoredEventHandler implements ExtendedEventHandler { private final List<Event> events = new ArrayList<>(); + private final List<ExtendedEventHandler.Postable> posts = new ArrayList<>(); private boolean hasErrors; public synchronized ImmutableList<Event> getEvents() { @@ -32,7 +30,7 @@ public class StoredEventHandler implements EventHandler { /** Returns true if there are no stored events. */ public synchronized boolean isEmpty() { - return events.isEmpty(); + return events.isEmpty() && posts.isEmpty(); } @@ -42,11 +40,17 @@ public class StoredEventHandler implements EventHandler { events.add(e); } - /** - * Replay all events stored in this object on the given eventHandler, in the same order. - */ - public synchronized void replayOn(EventHandler eventHandler) { + @Override + public synchronized void post(ExtendedEventHandler.Postable e) { + posts.add(e); + } + + /** Replay all events stored in this object on the given eventHandler, in the same order. */ + public synchronized void replayOn(ExtendedEventHandler eventHandler) { Event.replayEventsOn(eventHandler, events); + for (ExtendedEventHandler.Postable obj : posts) { + eventHandler.post(obj); + } } /** @@ -58,6 +62,7 @@ public class StoredEventHandler implements EventHandler { public synchronized void clear() { events.clear(); + posts.clear(); hasErrors = false; } } |