blob: 099571f9acbc7332af7e2d8e26ed1d77da841617 [file] [log] [blame]
adgarf3e66ad2019-08-15 13:18:51 -07001// Copyright 2019 The Bazel Authors. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package com.google.devtools.build.lib.runtime;
16
17import com.google.common.collect.ImmutableList;
18import com.google.devtools.build.lib.buildeventstream.BuildEventContext;
janakr3ca24682020-04-01 09:12:03 -070019import com.google.devtools.build.lib.buildeventstream.BuildEventIdUtil;
adgarf3e66ad2019-08-15 13:18:51 -070020import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos;
janakr3ca24682020-04-01 09:12:03 -070021import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.BuildEventId;
adgarf3e66ad2019-08-15 13:18:51 -070022import com.google.devtools.build.lib.buildeventstream.BuildEventWithOrderConstraint;
23import com.google.devtools.build.lib.buildeventstream.GenericBuildEvent;
24import java.util.Collection;
25import java.util.Map;
26
27/**
28 * Build event announcing supplementary metadata accompanying the build in the form of key-value
29 * string pairs.
30 */
31public class BuildMetadataEvent implements BuildEventWithOrderConstraint {
32
33 private final Map<String, String> buildMetadata;
34
35 /**
36 * Construct the build metadata event.
37 *
38 * @param buildMetadata the supplementary build metadata for a single build.
39 */
40 public BuildMetadataEvent(Map<String, String> buildMetadata) {
41 this.buildMetadata = buildMetadata;
42 }
43
44 @Override
45 public BuildEventId getEventId() {
janakr3ca24682020-04-01 09:12:03 -070046 return BuildEventIdUtil.buildMetadataId();
adgarf3e66ad2019-08-15 13:18:51 -070047 }
48
49 @Override
50 public Collection<BuildEventId> getChildrenEvents() {
51 return ImmutableList.of();
52 }
53
54 @Override
55 public BuildEventStreamProtos.BuildEvent asStreamProto(BuildEventContext converters) {
56 BuildEventStreamProtos.BuildMetadata.Builder metadataBuilder =
57 BuildEventStreamProtos.BuildMetadata.newBuilder();
58 for (Map.Entry<String, String> entry : buildMetadata.entrySet()) {
59 metadataBuilder.putMetadata(entry.getKey(), entry.getValue());
60 }
61 return GenericBuildEvent.protoChaining(this).setBuildMetadata(metadataBuilder.build()).build();
62 }
63
64 @Override
65 public Collection<BuildEventId> postedAfter() {
janakr3ca24682020-04-01 09:12:03 -070066 return ImmutableList.of(BuildEventIdUtil.buildStartedId());
adgarf3e66ad2019-08-15 13:18:51 -070067 }
68}