aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Jon Brandvein <brandjon@google.com>2017-01-02 19:52:04 +0000
committerGravatar John Cater <jcater@google.com>2017-01-03 15:04:38 +0000
commit5735d9be6b960ce0526927990280baeca7bbcfdb (patch)
treeb4f96acf89ab97f2ebc31a71feb0081a7a90e52d
parent36ecf16f770ce2faaa49cf488c427968a7b29631 (diff)
Miscellaneous cleanups to lib.events
-- PiperOrigin-RevId: 143390220 MOS_MIGRATED_REVID=143390220
-rw-r--r--src/main/java/com/google/devtools/build/lib/events/DelegatingEventHandler.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/events/DelegatingOnlyErrorsEventHandler.java32
-rw-r--r--src/main/java/com/google/devtools/build/lib/events/Event.java20
-rw-r--r--src/main/java/com/google/devtools/build/lib/events/Reporter.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/events/ReporterStream.java12
5 files changed, 20 insertions, 48 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 37a7a1c07a..9b09d23bb9 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,7 +17,7 @@ package com.google.devtools.build.lib.events;
import com.google.devtools.build.lib.util.Preconditions;
/**
- * An ErrorEventListener which delegates to another ErrorEventListener.
+ * An EventHandler which delegates to another EventHandler.
* Primarily useful as a base class for extending behavior.
*/
public class DelegatingEventHandler implements EventHandler {
diff --git a/src/main/java/com/google/devtools/build/lib/events/DelegatingOnlyErrorsEventHandler.java b/src/main/java/com/google/devtools/build/lib/events/DelegatingOnlyErrorsEventHandler.java
deleted file mode 100644
index 4da6f78080..0000000000
--- a/src/main/java/com/google/devtools/build/lib/events/DelegatingOnlyErrorsEventHandler.java
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2014 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-package com.google.devtools.build.lib.events;
-
-/**
- * An {@link EventHandler} implementation that only
- * passes through error messages.
- */
-public class DelegatingOnlyErrorsEventHandler extends DelegatingEventHandler {
-
- public DelegatingOnlyErrorsEventHandler(EventHandler eventHandler) {
- super(eventHandler);
- }
-
- @Override
- public void handle(Event e) {
- if (e.getKind() == EventKind.ERROR) {
- super.handle(e);
- }
- }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/events/Event.java b/src/main/java/com/google/devtools/build/lib/events/Event.java
index 3809a8c094..0ba5cc8775 100644
--- a/src/main/java/com/google/devtools/build/lib/events/Event.java
+++ b/src/main/java/com/google/devtools/build/lib/events/Event.java
@@ -16,11 +16,10 @@ package com.google.devtools.build.lib.events;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import com.google.devtools.build.lib.util.Preconditions;
-
import java.io.Serializable;
+import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Objects;
-
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
@@ -36,11 +35,12 @@ public final class Event implements Serializable {
/**
* An alternative representation for message.
- * Exactly one of message or messageBytes will be non-null.
- * If messageBytes is non-null, then it contains the bytes
- * of the message, encoded using the platform's default charset.
- * We do this to avoid converting back and forth between Strings
- * and bytes.
+ *
+ * <p>Exactly one of message or messageBytes will be non-null. If messageBytes is non-null, then
+ * it contains the bytes of the message (encoding currently unspecified). We do this to avoid
+ * converting back and forth between Strings and bytes.
+ *
+ * TODO(bazel-team): Fix the encoding to be consistent, e.g. use UTF-8 everywhere.
*/
private final byte[] messageBytes;
@@ -77,7 +77,8 @@ public final class Event implements Serializable {
}
public String getMessage() {
- return message != null ? message : new String(messageBytes);
+ // TODO(bazel-team): Don't rely on the platform default charset.
+ return message != null ? message : new String(messageBytes, Charset.defaultCharset());
}
public byte[] getMessageBytes() {
@@ -149,6 +150,9 @@ public final class Event implements Serializable {
return new Event(kind, location, message, null);
}
+ /**
+ * Construct an event by passing in the {@code byte[]} array instead of a String.
+ */
public static Event of(EventKind kind, @Nullable Location location, byte[] messageBytes) {
return new Event(kind, location, messageBytes, null);
}
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 5ecb58b799..a970d586ac 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
@@ -123,7 +123,7 @@ public final class Reporter implements EventHandler, ExceptionListener {
}
/**
- * Reports the start of a particular task.
+ * Reports the end of a particular task.
* Is a wrapper around report() with event kind FINISH.
* Should always be matched by a corresponding call to startTask()
* with the same message, except that the leading percentage
diff --git a/src/main/java/com/google/devtools/build/lib/events/ReporterStream.java b/src/main/java/com/google/devtools/build/lib/events/ReporterStream.java
index 1669fa7b62..3a7e7d60b8 100644
--- a/src/main/java/com/google/devtools/build/lib/events/ReporterStream.java
+++ b/src/main/java/com/google/devtools/build/lib/events/ReporterStream.java
@@ -19,14 +19,14 @@ import java.io.OutputStream;
import java.util.Arrays;
/**
- * An OutputStream that delegates all writes to a Reporter.
+ * An OutputStream that delegates all writes to an EventHandler.
*/
public final class ReporterStream extends OutputStream {
- private final EventHandler reporter;
+ private final EventHandler handler;
private final EventKind eventKind;
- public ReporterStream(EventHandler reporter, EventKind eventKind) {
- this.reporter = Preconditions.checkNotNull(reporter);
+ public ReporterStream(EventHandler handler, EventKind eventKind) {
+ this.handler = Preconditions.checkNotNull(handler);
this.eventKind = Preconditions.checkNotNull(eventKind);
}
@@ -42,7 +42,7 @@ public final class ReporterStream extends OutputStream {
@Override
public void write(int b) {
- reporter.handle(Event.of(eventKind, null, new byte[] { (byte) b }));
+ handler.handle(Event.of(eventKind, null, new byte[] { (byte) b }));
}
@Override
@@ -52,6 +52,6 @@ public final class ReporterStream extends OutputStream {
@Override
public void write(byte[] bytes, int offset, int len) {
- reporter.handle(Event.of(eventKind, null, Arrays.copyOfRange(bytes, offset, offset + len)));
+ handler.handle(Event.of(eventKind, null, Arrays.copyOfRange(bytes, offset, offset + len)));
}
}