aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/events
diff options
context:
space:
mode:
authorGravatar Ulf Adams <ulfjack@google.com>2016-04-21 08:09:51 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-04-21 11:02:25 +0000
commit760e70958a47218b4c8edde90da0c7a23fa0e725 (patch)
tree961e0e4c14821f28b88510c413ec3379cf520be8 /src/main/java/com/google/devtools/build/lib/events
parent06df021b374201687cb135f75f8dc11a3d5d420a (diff)
Refactor the Event class; always construct through static methods.
-- MOS_MIGRATED_REVID=120418505
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/events')
-rw-r--r--src/main/java/com/google/devtools/build/lib/events/Event.java56
-rw-r--r--src/main/java/com/google/devtools/build/lib/events/Reporter.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/events/ReporterStream.java13
3 files changed, 38 insertions, 38 deletions
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 2e35b2e6f8..1a74ad2617 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
@@ -47,39 +47,31 @@ public final class Event implements Serializable {
@Nullable
private final String tag;
- public Event withTag(String tag) {
- if (this.message != null) {
- return new Event(this.kind, this.location, this.message, tag);
- } else {
- return new Event(this.kind, this.location, this.messageBytes, tag);
- }
- }
-
- public Event(EventKind kind, @Nullable Location location, String message) {
- this(kind, location, message, null);
- }
-
- public Event(EventKind kind, @Nullable Location location, String message, @Nullable String tag) {
- this.kind = kind;
+ private Event(EventKind kind, @Nullable Location location, String message, @Nullable String tag) {
+ this.kind = Preconditions.checkNotNull(kind);
this.location = location;
this.message = Preconditions.checkNotNull(message);
this.messageBytes = null;
this.tag = tag;
}
- public Event(EventKind kind, @Nullable Location location, byte[] messageBytes) {
- this(kind, location, messageBytes, null);
- }
-
- public Event(
+ private Event(
EventKind kind, @Nullable Location location, byte[] messageBytes, @Nullable String tag) {
- this.kind = kind;
+ this.kind = Preconditions.checkNotNull(kind);
this.location = location;
this.message = null;
this.messageBytes = Preconditions.checkNotNull(messageBytes);
this.tag = tag;
}
+ public Event withTag(String tag) {
+ if (this.message != null) {
+ return new Event(this.kind, this.location, this.message, tag);
+ } else {
+ return new Event(this.kind, this.location, this.messageBytes, tag);
+ }
+ }
+
public String getMessage() {
return message != null ? message : new String(messageBytes);
}
@@ -146,32 +138,40 @@ public final class Event implements Serializable {
}
}
+ public static Event of(EventKind kind, @Nullable Location location, String message) {
+ return new Event(kind, location, message, null);
+ }
+
+ public static Event of(EventKind kind, @Nullable Location location, byte[] messageBytes) {
+ return new Event(kind, location, messageBytes, null);
+ }
+
/**
* Reports a warning.
*/
- public static Event warn(Location location, String message) {
- return new Event(EventKind.WARNING, location, message);
+ public static Event warn(@Nullable Location location, String message) {
+ return new Event(EventKind.WARNING, location, message, null);
}
/**
* Reports an error.
*/
- public static Event error(Location location, String message){
- return new Event(EventKind.ERROR, location, message);
+ public static Event error(@Nullable Location location, String message){
+ return new Event(EventKind.ERROR, location, message, null);
}
/**
* Reports atemporal statements about the build, i.e. they're true for the duration of execution.
*/
- public static Event info(Location location, String message) {
- return new Event(EventKind.INFO, location, message);
+ public static Event info(@Nullable Location location, String message) {
+ return new Event(EventKind.INFO, location, message, null);
}
/**
* Reports a temporal statement about the build.
*/
- public static Event progress(Location location, String message) {
- return new Event(EventKind.PROGRESS, location, message);
+ public static Event progress(@Nullable Location location, String message) {
+ return new Event(EventKind.PROGRESS, location, message, 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 a14e8276da..5ecb58b799 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
@@ -119,7 +119,7 @@ public final class Reporter implements EventHandler, ExceptionListener {
* progress indicator (if any) in the message may differ.
*/
public void startTask(Location location, String message) {
- handle(new Event(EventKind.START, location, message));
+ handle(Event.of(EventKind.START, location, message));
}
/**
@@ -130,12 +130,12 @@ public final class Reporter implements EventHandler, ExceptionListener {
* progress indicator (if any) in the message may differ.
*/
public void finishTask(Location location, String message) {
- handle(new Event(EventKind.FINISH, location, message));
+ handle(Event.of(EventKind.FINISH, location, message));
}
@Override
public void error(Location location, String message, Throwable error) {
- handle(new Event(EventKind.ERROR, location, message));
+ handle(Event.error(location, message));
error.printStackTrace(new PrintStream(getOutErr().getErrorStream()));
}
@@ -178,5 +178,4 @@ public final class Reporter implements EventHandler, ExceptionListener {
ansiAllowingHandlerRegistered = false;
}
}
-
}
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 3cd1d9f57d..e72f4a96b9 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
@@ -16,19 +16,20 @@ 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.OutputStream;
/**
* An OutputStream that delegates all writes to a Reporter.
*/
public final class ReporterStream extends OutputStream {
-
private final EventHandler reporter;
private final EventKind eventKind;
public ReporterStream(EventHandler reporter, EventKind eventKind) {
- this.reporter = reporter;
- this.eventKind = eventKind;
+ this.reporter = Preconditions.checkNotNull(reporter);
+ this.eventKind = Preconditions.checkNotNull(eventKind);
}
@Override
@@ -43,16 +44,16 @@ public final class ReporterStream extends OutputStream {
@Override
public void write(int b) {
- reporter.handle(new Event(eventKind, null, new byte[] { (byte) b }));
+ reporter.handle(Event.of(eventKind, null, new byte[] { (byte) b }));
}
@Override
public void write(byte[] bytes) {
- reporter.handle(new Event(eventKind, null, bytes));
+ reporter.handle(Event.of(eventKind, null, bytes));
}
@Override
public void write(byte[] bytes, int offset, int len) {
- reporter.handle(new Event(eventKind, null, new String(bytes, offset, len, ISO_8859_1)));
+ reporter.handle(Event.of(eventKind, null, new String(bytes, offset, len, ISO_8859_1)));
}
}