aboutsummaryrefslogtreecommitdiffhomepage
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
parent06df021b374201687cb135f75f8dc11a3d5d420a (diff)
Refactor the Event class; always construct through static methods.
-- MOS_MIGRATED_REVID=120418505
-rw-r--r--src/main/java/com/google/devtools/build/lib/actions/AbstractAction.java11
-rw-r--r--src/main/java/com/google/devtools/build/lib/actions/ActionCacheChecker.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/actions/BlazeExecutor.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java2
-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
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java8
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/test/StandaloneTestStrategy.java6
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java3
-rw-r--r--src/test/java/com/google/devtools/build/lib/events/EventTestTemplate.java2
-rw-r--r--src/test/java/com/google/devtools/build/lib/events/ReporterTest.java4
-rw-r--r--src/test/java/com/google/devtools/build/lib/events/SimpleReportersTest.java6
13 files changed, 61 insertions, 61 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/actions/AbstractAction.java b/src/main/java/com/google/devtools/build/lib/actions/AbstractAction.java
index c7aaa32ed2..968c7213da 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/AbstractAction.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/AbstractAction.java
@@ -25,7 +25,6 @@ import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventHandler;
-import com.google.devtools.build.lib.events.EventKind;
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
import com.google.devtools.build.lib.syntax.Printer;
import com.google.devtools.build.lib.util.Preconditions;
@@ -374,10 +373,12 @@ public abstract class AbstractAction implements Action, SkylarkValue {
Path path = output.getPath();
String ownerString = Label.print(getOwner().getLabel());
if (path.isDirectory()) {
- eventHandler.handle(new Event(EventKind.WARNING, getOwner().getLocation(),
- "output '" + output.prettyPrint() + "' of " + ownerString
- + " is a directory; dependency checking of directories is unsound",
- ownerString));
+ eventHandler.handle(
+ Event.warn(
+ getOwner().getLocation(),
+ "output '" + output.prettyPrint() + "' of " + ownerString
+ + " is a directory; dependency checking of directories is unsound")
+ .withTag(ownerString));
}
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ActionCacheChecker.java b/src/main/java/com/google/devtools/build/lib/actions/ActionCacheChecker.java
index 72d5756c42..4fd06a949f 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/ActionCacheChecker.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/ActionCacheChecker.java
@@ -327,7 +327,7 @@ public class ActionCacheChecker {
private static void reportRebuild(@Nullable EventHandler handler, Action action, String message) {
// For MiddlemanAction, do not report rebuild.
if (handler != null && !action.getActionType().isMiddleman()) {
- handler.handle(new Event(
+ handler.handle(Event.of(
EventKind.DEPCHECKER, null, "Executing " + action.prettyPrint() + ": " + message + "."));
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/actions/BlazeExecutor.java b/src/main/java/com/google/devtools/build/lib/actions/BlazeExecutor.java
index 88dc9a3f2d..2513cecdf4 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/BlazeExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/BlazeExecutor.java
@@ -146,7 +146,7 @@ public final class BlazeExecutor implements Executor {
*/
@Override
public void reportSubcommand(String reason, String message) {
- reporter.handle(new Event(EventKind.SUBCOMMAND, null, "# " + reason + "\n" + message));
+ reporter.handle(Event.of(EventKind.SUBCOMMAND, null, "# " + reason + "\n" + message));
}
/**
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java b/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java
index 425a3eea30..e9de51bb18 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/Runfiles.java
@@ -746,7 +746,7 @@ public final class Runfiles {
path.getSafePathString(),
previousStr,
artifactStr);
- eventHandler.handle(new Event(eventKind, location, message));
+ eventHandler.handle(Event.of(eventKind, location, message));
}
}
}
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)));
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java
index 5323d09784..97bd13f10e 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java
@@ -46,7 +46,6 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadCompatible;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventHandler;
-import com.google.devtools.build.lib.events.EventKind;
import com.google.devtools.build.lib.profiler.Profiler;
import com.google.devtools.build.lib.profiler.ProfilerTask;
import com.google.devtools.build.lib.rules.apple.AppleConfiguration;
@@ -802,9 +801,10 @@ public class CppCompileAction extends AbstractAction implements IncludeScannable
if (warnings.hasProblems()) {
eventHandler.handle(
- new Event(EventKind.WARNING,
- getOwner().getLocation(), warnings.getMessage(this, getSourceFile()),
- Label.print(getOwner().getLabel())));
+ Event.warn(
+ getOwner().getLocation(),
+ warnings.getMessage(this, getSourceFile()))
+ .withTag(Label.print(getOwner().getLabel())));
}
errors.assertProblemFree(this, getSourceFile());
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/test/StandaloneTestStrategy.java b/src/main/java/com/google/devtools/build/lib/rules/test/StandaloneTestStrategy.java
index a12084a813..72ff4e80d8 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/test/StandaloneTestStrategy.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/test/StandaloneTestStrategy.java
@@ -236,15 +236,15 @@ public class StandaloneTestStrategy extends TestStrategy {
}
} finally {
if (isPassed) {
- executor.getEventHandler().handle(new Event(EventKind.PASS, null, result.getTestName()));
+ executor.getEventHandler().handle(Event.of(EventKind.PASS, null, result.getTestName()));
} else {
if (result.getData().getStatus() == BlazeTestStatus.TIMEOUT) {
executor.getEventHandler().handle(
- new Event(EventKind.TIMEOUT, null, result.getTestName()
+ Event.of(EventKind.TIMEOUT, null, result.getTestName()
+ " (see " + testOutput + ")"));
} else {
executor.getEventHandler().handle(
- new Event(EventKind.FAIL, null, result.getTestName() + " (see " + testOutput + ")"));
+ Event.of(EventKind.FAIL, null, result.getTestName() + " (see " + testOutput + ")"));
}
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java
index ec0b37a013..b7f7b921d6 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java
@@ -19,7 +19,6 @@ import com.google.common.collect.Collections2;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.events.Event;
-import com.google.devtools.build.lib.events.EventKind;
import com.google.devtools.build.lib.skyframe.RecursiveFilesystemTraversalValue.ResolvedFile;
import com.google.devtools.build.lib.skyframe.RecursiveFilesystemTraversalValue.ResolvedFileFactory;
import com.google.devtools.build.lib.skyframe.RecursiveFilesystemTraversalValue.TraversalRequest;
@@ -152,7 +151,7 @@ public final class RecursiveFilesystemTraversalFunction implements SkyFunction {
switch (traversal.crossPkgBoundaries) {
case CROSS:
// We are free to traverse the subpackage but we need to display a warning.
- env.getListener().handle(new Event(EventKind.WARNING, null, msg));
+ env.getListener().handle(Event.warn(null, msg));
break;
case DONT_CROSS:
// We cannot traverse the subpackage and should skip it silently. Return empty results.
diff --git a/src/test/java/com/google/devtools/build/lib/events/EventTestTemplate.java b/src/test/java/com/google/devtools/build/lib/events/EventTestTemplate.java
index 8ef996a6c8..e505586449 100644
--- a/src/test/java/com/google/devtools/build/lib/events/EventTestTemplate.java
+++ b/src/test/java/com/google/devtools/build/lib/events/EventTestTemplate.java
@@ -33,7 +33,7 @@ public abstract class EventTestTemplate {
location = Location.fromPathAndStartColumn(path, 21, 31, new LineAndColumn(3, 4));
- event = new Event(EventKind.WARNING, location, message);
+ event = Event.of(EventKind.WARNING, location, message);
locationNoPath = Location.fromPathAndStartColumn(null, 21, 31, new LineAndColumn(3, 4));
diff --git a/src/test/java/com/google/devtools/build/lib/events/ReporterTest.java b/src/test/java/com/google/devtools/build/lib/events/ReporterTest.java
index 3393fde39f..d385a5d37f 100644
--- a/src/test/java/com/google/devtools/build/lib/events/ReporterTest.java
+++ b/src/test/java/com/google/devtools/build/lib/events/ReporterTest.java
@@ -50,10 +50,10 @@ public class ReporterTest extends EventTestTemplate {
reporter.setOutputFilter(OutputFilter.RegexOutputFilter.forRegex("naughty"));
EventCollector collector = new EventCollector();
reporter.addHandler(collector);
- Event interesting = new Event(EventKind.WARNING, null, "show-me", "naughty");
+ Event interesting = Event.warn(null, "show-me").withTag("naughty");
reporter.handle(interesting);
- reporter.handle(new Event(EventKind.WARNING, null, "ignore-me", "good"));
+ reporter.handle(Event.warn(null, "ignore-me").withTag("good"));
assertEquals(ImmutableList.copyOf(collector), ImmutableList.of(interesting));
}
diff --git a/src/test/java/com/google/devtools/build/lib/events/SimpleReportersTest.java b/src/test/java/com/google/devtools/build/lib/events/SimpleReportersTest.java
index e06e502ffc..f7939ea1e5 100644
--- a/src/test/java/com/google/devtools/build/lib/events/SimpleReportersTest.java
+++ b/src/test/java/com/google/devtools/build/lib/events/SimpleReportersTest.java
@@ -37,9 +37,9 @@ public class SimpleReportersTest extends EventTestTemplate {
};
Reporter reporter = new Reporter(handler);
- reporter.handle(new Event(EventKind.INFO, location, "Add to handlerCount."));
- reporter.handle(new Event(EventKind.INFO, location, "Add to handlerCount."));
- reporter.handle(new Event(EventKind.INFO, location, "Add to handlerCount."));
+ reporter.handle(Event.info(location, "Add to handlerCount."));
+ reporter.handle(Event.info(location, "Add to handlerCount."));
+ reporter.handle(Event.info(location, "Add to handlerCount."));
assertEquals(3, handlerCount);
}
}