From dadde6f1bf93efa3e73dbbbf557ec37a57a0eefe Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Wed, 18 Jan 2017 17:32:07 +0000 Subject: Support mapping of Paths to URIs Bazel-created files (like log files of test runs) are internally reported as Paths. However, this is not always the most useful representation of the location of that artifact for a consumer of build events. Therefore, support a mapping of paths to more useful URIs. -- PiperOrigin-RevId: 144843525 MOS_MIGRATED_REVID=144843525 --- .../devtools/build/lib/buildeventstream/transports/BUILD | 1 + .../transports/BinaryFormatFileTransportTest.java | 12 ++++++++---- .../transports/BuildEventTransportFactoryTest.java | 13 ++++++++----- .../transports/TextFormatFileTransportTest.java | 12 ++++++++---- .../devtools/build/lib/runtime/BuildEventStreamerTest.java | 3 ++- 5 files changed, 27 insertions(+), 14 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BUILD b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BUILD index 6472d8aa21..896cb5a9b2 100644 --- a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BUILD +++ b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BUILD @@ -12,6 +12,7 @@ java_test( deps = [ "//src/main/java/com/google/devtools/build/lib:buildeventstream", "//src/main/java/com/google/devtools/build/lib:runtime", + "//src/main/java/com/google/devtools/build/lib:vfs", "//src/main/java/com/google/devtools/build/lib/buildeventstream/proto:build_event_stream_java_proto", "//src/main/java/com/google/devtools/build/lib/buildeventstream/transports", "//src/test/java/com/google/devtools/build/lib:packages_testutil", diff --git a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BinaryFormatFileTransportTest.java b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BinaryFormatFileTransportTest.java index e241e8410c..62ac3da28b 100644 --- a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BinaryFormatFileTransportTest.java +++ b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BinaryFormatFileTransportTest.java @@ -22,6 +22,7 @@ import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos; import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.BuildStarted; import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.Progress; import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.TargetComplete; +import com.google.devtools.build.lib.buildeventstream.PathConverter; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -45,6 +46,8 @@ public class BinaryFormatFileTransportTest { @Mock public BuildEvent buildEvent; + @Mock public PathConverter pathConverter; + @Before public void initMocks() { MockitoAnnotations.initMocks(this); @@ -63,20 +66,21 @@ public class BinaryFormatFileTransportTest { BuildEventStreamProtos.BuildEvent.newBuilder() .setStarted(BuildStarted.newBuilder().setCommand("build")) .build(); - when(buildEvent.asStreamProto()).thenReturn(started); - BinaryFormatFileTransport transport = new BinaryFormatFileTransport(output.getAbsolutePath()); + when(buildEvent.asStreamProto(pathConverter)).thenReturn(started); + BinaryFormatFileTransport transport = + new BinaryFormatFileTransport(output.getAbsolutePath(), pathConverter); transport.sendBuildEvent(buildEvent); BuildEventStreamProtos.BuildEvent progress = BuildEventStreamProtos.BuildEvent.newBuilder().setProgress(Progress.newBuilder()).build(); - when(buildEvent.asStreamProto()).thenReturn(progress); + when(buildEvent.asStreamProto(pathConverter)).thenReturn(progress); transport.sendBuildEvent(buildEvent); BuildEventStreamProtos.BuildEvent completed = BuildEventStreamProtos.BuildEvent.newBuilder() .setCompleted(TargetComplete.newBuilder().setSuccess(true)) .build(); - when(buildEvent.asStreamProto()).thenReturn(completed); + when(buildEvent.asStreamProto(pathConverter)).thenReturn(completed); transport.sendBuildEvent(buildEvent); transport.close(); diff --git a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventTransportFactoryTest.java b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventTransportFactoryTest.java index 8d4aa520db..58bd1754d5 100644 --- a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventTransportFactoryTest.java +++ b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventTransportFactoryTest.java @@ -24,6 +24,7 @@ import com.google.devtools.build.lib.buildeventstream.BuildEvent; import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos; import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.BuildStarted; import com.google.devtools.build.lib.buildeventstream.BuildEventTransport; +import com.google.devtools.build.lib.buildeventstream.PathConverter; import java.io.File; import java.io.IOException; import org.junit.After; @@ -60,10 +61,12 @@ public class BuildEventTransportFactoryTest { @Mock public BuildEvent buildEvent; + @Mock public PathConverter pathConverter; + @Before public void before() { MockitoAnnotations.initMocks(this); - when(buildEvent.asStreamProto()).thenReturn(BUILD_EVENT_AS_PROTO); + when(buildEvent.asStreamProto(pathConverter)).thenReturn(BUILD_EVENT_AS_PROTO); } @After @@ -77,7 +80,7 @@ public class BuildEventTransportFactoryTest { when(options.getBuildEventTextFile()).thenReturn(textFile.getAbsolutePath()); when(options.getBuildEventBinaryFile()).thenReturn(""); ImmutableSet transports = - BuildEventTransportFactory.createFromOptions(options); + BuildEventTransportFactory.createFromOptions(options, pathConverter); assertThat(FluentIterable.from(transports).transform(GET_CLASS)) .containsExactly(TextFormatFileTransport.class); sendEventsAndClose(buildEvent, transports); @@ -90,7 +93,7 @@ public class BuildEventTransportFactoryTest { when(options.getBuildEventTextFile()).thenReturn(""); when(options.getBuildEventBinaryFile()).thenReturn(binaryFile.getAbsolutePath()); ImmutableSet transports = - BuildEventTransportFactory.createFromOptions(options); + BuildEventTransportFactory.createFromOptions(options, pathConverter); assertThat(FluentIterable.from(transports).transform(GET_CLASS)) .containsExactly(BinaryFormatFileTransport.class); sendEventsAndClose(buildEvent, transports); @@ -104,7 +107,7 @@ public class BuildEventTransportFactoryTest { when(options.getBuildEventTextFile()).thenReturn(textFile.getAbsolutePath()); when(options.getBuildEventBinaryFile()).thenReturn(binaryFile.getAbsolutePath()); ImmutableSet transports = - BuildEventTransportFactory.createFromOptions(options); + BuildEventTransportFactory.createFromOptions(options, pathConverter); assertThat(FluentIterable.from(transports).transform(GET_CLASS)) .containsExactly(TextFormatFileTransport.class, BinaryFormatFileTransport.class); sendEventsAndClose(buildEvent, transports); @@ -116,7 +119,7 @@ public class BuildEventTransportFactoryTest { public void testCreatesNoTransports() throws IOException { when(options.getBuildEventTextFile()).thenReturn(""); ImmutableSet transports = - BuildEventTransportFactory.createFromOptions(options); + BuildEventTransportFactory.createFromOptions(options, pathConverter); assertThat(transports).isEmpty(); } diff --git a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/TextFormatFileTransportTest.java b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/TextFormatFileTransportTest.java index bb1d1fd334..2f36d407b7 100644 --- a/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/TextFormatFileTransportTest.java +++ b/src/test/java/com/google/devtools/build/lib/buildeventstream/transports/TextFormatFileTransportTest.java @@ -24,6 +24,7 @@ import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos; import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.BuildStarted; import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.Progress; import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.TargetComplete; +import com.google.devtools.build.lib.buildeventstream.PathConverter; import com.google.protobuf.TextFormat; import java.io.File; import java.io.IOException; @@ -47,6 +48,8 @@ public class TextFormatFileTransportTest { @Mock public BuildEvent buildEvent; + @Mock public PathConverter pathConverter; + @Before public void initMocks() { MockitoAnnotations.initMocks(this); @@ -65,20 +68,21 @@ public class TextFormatFileTransportTest { BuildEventStreamProtos.BuildEvent.newBuilder() .setStarted(BuildStarted.newBuilder().setCommand("build")) .build(); - when(buildEvent.asStreamProto()).thenReturn(started); - TextFormatFileTransport transport = new TextFormatFileTransport(output.getAbsolutePath()); + when(buildEvent.asStreamProto(pathConverter)).thenReturn(started); + TextFormatFileTransport transport = + new TextFormatFileTransport(output.getAbsolutePath(), pathConverter); transport.sendBuildEvent(buildEvent); BuildEventStreamProtos.BuildEvent progress = BuildEventStreamProtos.BuildEvent.newBuilder().setProgress(Progress.newBuilder()).build(); - when(buildEvent.asStreamProto()).thenReturn(progress); + when(buildEvent.asStreamProto(pathConverter)).thenReturn(progress); transport.sendBuildEvent(buildEvent); BuildEventStreamProtos.BuildEvent completed = BuildEventStreamProtos.BuildEvent.newBuilder() .setCompleted(TargetComplete.newBuilder().setSuccess(true)) .build(); - when(buildEvent.asStreamProto()).thenReturn(completed); + when(buildEvent.asStreamProto(pathConverter)).thenReturn(completed); transport.sendBuildEvent(buildEvent); transport.close(); diff --git a/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java b/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java index a5a79d082d..d03ec6b338 100644 --- a/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java +++ b/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java @@ -24,6 +24,7 @@ import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos; import com.google.devtools.build.lib.buildeventstream.BuildEventTransport; import com.google.devtools.build.lib.buildeventstream.BuildEventWithOrderConstraint; import com.google.devtools.build.lib.buildeventstream.GenericBuildEvent; +import com.google.devtools.build.lib.buildeventstream.PathConverter; import com.google.devtools.build.lib.buildeventstream.ProgressEvent; import com.google.devtools.build.lib.buildtool.buildevent.BuildCompleteEvent; import java.util.ArrayList; @@ -84,7 +85,7 @@ public class BuildEventStreamerTest { } @Override - public BuildEventStreamProtos.BuildEvent asStreamProto() { + public BuildEventStreamProtos.BuildEvent asStreamProto(PathConverter converter) { return GenericBuildEvent.protoChaining(this).build(); } -- cgit v1.2.3